Skip to content

Commit

Permalink
Restructure src/
Browse files Browse the repository at this point in the history
The distinction between library and driver code was super vague in the
old structure, so now it's sorted into common/, lib/ and driver/. This
is still just a first pass, many incorrect includes across lib/ and
driver/ still exist, I marked the ones I could spot with 'FIXME: CROSS'.

Huge diff, mostly just the files moving, and fixing the include paths. I
also added src/lib/renderer/samplers/vec.h to separate the sampler from
the shared src/common/vector.h.
  • Loading branch information
vkoskiv committed Dec 3, 2023
1 parent 08d79bb commit a06e82d
Show file tree
Hide file tree
Showing 199 changed files with 427 additions and 394 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ include(set_up_ccache)

include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
configure_file("${c-ray_SOURCE_DIR}/src/utils/gitsha1.c.in" "${c-ray_BINARY_DIR}/generated/gitsha1.c" @ONLY)
configure_file("${c-ray_SOURCE_DIR}/src/common/gitsha1.c.in" "${c-ray_BINARY_DIR}/generated/gitsha1.c" @ONLY)
list(APPEND SOURCES "${c-ray_BINARY_DIR}/generated/gitsha1.c")

add_executable(c-ray ${SOURCES})
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(BIN): $(OBJS) $(OBJDIR)
# A sneaky target to run a bit of code generation
dummy:
@echo "Generating gitsha1.c"
$(shell sed "s/@GIT_SHA1@/`git rev-parse --verify HEAD || echo "NoHash" | cut -c 1-8`/g" src/utils/gitsha1.c.in > generated/gitsha1.c)
$(shell sed "s/@GIT_SHA1@/`git rev-parse --verify HEAD || echo "NoHash" | cut -c 1-8`/g" src/common/gitsha1.c.in > generated/gitsha1.c)
clean:
rm -rf bin/*

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/datatypes/color.c → src/common/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../includes.h"
#include <stdio.h>
#include "color.h"
#include "../utils/assert.h"
#include "assert.h"

//Some standard colours
const struct color g_red_color = { 1.0f, 0.0f, 0.0f, 1.0f };
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/fileio.c → src/common/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "../includes.h"
#include "fileio.h"
#include "../utils/logging.h"
#include "logging.h"
#include "assert.h"
#ifndef WINDOWS
#include <sys/mman.h>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/utils/hashtable.c → src/common/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#include <inttypes.h>
#include <string.h>
#include "../datatypes/vector.h"
#include "vector.h"
#include "assert.h"
#include "fileio.h"
#include "string.h"
#include "../utils/mempool.h"
#include "mempool.h"

#define FNV_OFFSET UINT32_C(0x811C9DC5) // Initial value for an empty hash
#define FNV_PRIME UINT32_C(0x01000193)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include "textureloader.h"
#include "../logging.h"
#include "../../datatypes/image/texture.h"
#include "../../utils/assert.h"
#include "../../utils/mempool.h"
#include "../texture.h"
#include "../assert.h"
#include "../mempool.h"

#define STBI_NO_PSD
#define STBI_NO_GIF
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/utils/networking.c → src/common/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "networking.h"

//Windows is annoying, so it's just not going to have networking. Because it is annoying and proprietary.
#include "../utils/logging.h"
#include "logging.h"
#ifndef WINDOWS

#include <netdb.h>
Expand All @@ -22,7 +22,7 @@
#include <fcntl.h>
#include <arpa/inet.h>
#include <string.h>
#include "../utils/assert.h"
#include "assert.h"
#include <errno.h>
#include "fileio.h"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void term_init() {
#ifndef WINDOWS
//Disable output buffering
setbuf(stdout, NULL);
show_cursor(false);
// show_cursor(false);
#endif

//Configure Windows terminals to handle color escape codes
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/testrunner.c → src/common/testrunner.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "logging.h"
#include "timer.h"

#include "../utils/assert.h"
#include "../common/assert.h"
#include "testrunner.h"

#ifdef CRAY_TESTING
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/datatypes/image/texture.c → src/common/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2019-2022 Valtteri Koskivuori. All rights reserved.
//

#include "../../includes.h"
#include "../includes.h"

#include "texture.h"
#include "../../utils/logging.h"
#include "../../utils/assert.h"
#include "logging.h"
#include "assert.h"
#include <string.h>

//General-purpose setPixel function
Expand Down
4 changes: 2 additions & 2 deletions src/datatypes/image/texture.h → src/common/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <stdbool.h>
#include <stddef.h>
#include "../color.h"
#include "../../utils/dyn_array.h"
#include "color.h"
#include "dyn_array.h"

enum colorspace {
linear,
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 2 additions & 21 deletions src/datatypes/vector.h → src/common/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#pragma once

#include <math.h>
#include "../renderer/samplers/sampler.h"
#include "../utils/dyn_array.h"
#include "../utils/assert.h"
#include "dyn_array.h"
#include "assert.h"
#include "../includes.h"

struct vector {
Expand Down Expand Up @@ -186,16 +185,6 @@ static inline struct vector vec_get_midpoint(struct vector v1, struct vector v2,
return vec_scale(vec_add(vec_add(v1, v2), v3), 1.0f/3.0f);
}

static inline float rand_in_range(float min, float max, sampler *sampler) {
return ((getDimension(sampler)) * (max - min)) + min;
}

static inline struct coord coord_on_unit_disc(sampler *sampler) {
float r = sqrtf(getDimension(sampler));
float theta = rand_in_range(0.0f, 2.0f * PI, sampler);
return (struct coord){r * cosf(theta), r * sinf(theta)};
}

static inline struct vector vec_negate(struct vector v) {
return (struct vector){ -v.x, -v.y, -v.z };
}
Expand Down Expand Up @@ -243,14 +232,6 @@ static inline bool vec_equals(struct vector a, struct vector b) {
return a.x == b.x && a.y == b.y && a.z == b.z;
}

static inline struct vector vec_on_unit_sphere(sampler *sampler) {
const float sample_x = getDimension(sampler);
const float sample_y = getDimension(sampler);
const float a = sample_x * (2.0f * PI);
const float s = 2.0f * sqrtf(max(0.0f, sample_y * (1.0f - sample_y)));
return (struct vector){ cosf(a) * s, sinf(a) * s, 1.0f - 2.0f * sample_y };
}

//TODO: Consider moving these two to a better place.
static inline bool vec_refract(const struct vector in, const struct vector normal, float niOverNt, struct vector *refracted) {
const struct vector uv = vec_normalize(in);
Expand Down
20 changes: 10 additions & 10 deletions src/driver/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#include <stdio.h>
#include "args.h"

#include "../utils/platform/terminal.h"
#include "../utils/platform/capabilities.h"
#include "../utils/hashtable.h"
#include "../utils/logging.h"
#include "../utils/fileio.h"
#include "../utils/assert.h"
#include "../utils/textbuffer.h"
#include "../utils/testrunner.h"
#include "../utils/string.h"
#include "../utils/protocol/server.h"
#include "../common/platform/terminal.h"
#include "../common/platform/capabilities.h"
#include "../common/hashtable.h"
#include "../common/logging.h"
#include "../common/fileio.h"
#include "../common/assert.h"
#include "../common/textbuffer.h"
#include "../common/testrunner.h"
#include "../common/string.h"
#include "../lib/protocol/server.h"

static void printUsage(const char *progname) {
printf("Usage: %s [-hjsdtocv] [input_json...]\n", progname);
Expand Down
8 changes: 4 additions & 4 deletions src/driver/encoders/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#include "encoder.h"

#include "../../datatypes/image/texture.h"
#include "../../datatypes/image/imagefile.h"
#include "../../utils/logging.h"
#include "../imagefile.h"
#include "../../common/logging.h"
#include "../../vendored/asprintf.h"
#include "../../utils/assert.h"
#include "../../common/texture.h"
#include "../../common/assert.h"

#include "formats/png.h"
#include "formats/bmp.h"
Expand Down
2 changes: 1 addition & 1 deletion src/driver/encoders/formats/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string.h>
#include "bmp.h"

#include "../../../utils/fileio.h"
#include "../../../common/fileio.h"

void encodeBMPFromArray(const char *file_name, const unsigned char *imgData, size_t width, size_t height) {
//Apparently BMP is BGR, whereas C-ray's internal buffer is RGB (Like it should be)
Expand Down
6 changes: 3 additions & 3 deletions src/driver/encoders/formats/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// Copyright © 2020-2022 Valtteri Koskivuori. All rights reserved.
//

#include "../../../datatypes/image/imagefile.h"
#include "../../imagefile.h"
#include <stddef.h>
#include "png.h"

#include <stdio.h>
#include <stdlib.h>
#include "../../../utils/fileio.h"
#include "../../../utils/logging.h"
#include "../../../common/fileio.h"
#include "../../../common/logging.h"

#include "../../../vendored/lodepng.h"

Expand Down
2 changes: 1 addition & 1 deletion src/driver/encoders/formats/qoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <stddef.h>
#include "qoi.h"
#include "../../../utils/fileio.h"
#include "../../../common/fileio.h"

#define QOI_IMPLEMENTATION
#define QOI_NO_STDIO
Expand Down
2 changes: 1 addition & 1 deletion src/datatypes/image/imagefile.h → src/driver/imagefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "../../utils/fileio.h"
#include "../common/fileio.h"

struct renderInfo {
int samples;
Expand Down
20 changes: 10 additions & 10 deletions src/driver/json_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
#include "../vendored/cJSON.h"
#include "node_parse.h"
#include "loaders/meshloader.h"
#include "../utils/loaders/textureloader.h"
#include "../common/loaders/textureloader.h"

#include <c-ray/c-ray.h>

#include "../datatypes/transforms.h"
#include "../datatypes/quaternion.h"
#include "../datatypes/spline.h"
#include "../datatypes/vector.h"
#include "../utils/string.h"
#include "../utils/platform/capabilities.h"
#include "../utils/logging.h"
#include "../utils/fileio.h"
#include "../utils/timer.h"
#include "../lib/datatypes/transforms.h" // FIXME: CROSS
#include "../lib/datatypes/quaternion.h" // FIXME: CROSS
#include "../lib/datatypes/spline.h"
#include "../common/vector.h"
#include "../common/string.h"
#include "../common/platform/capabilities.h"
#include "../common/logging.h"
#include "../common/fileio.h"
#include "../common/timer.h"

static struct transform parse_tform(const cJSON *data) {
const cJSON *type = cJSON_GetObjectItem(data, "type");
Expand Down
14 changes: 7 additions & 7 deletions src/driver/loaders/formats/gltf/gltf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include "gltf.h"
#include <string.h>
#include "../../../../vendored/cJSON.h"
#include "../../../../utils/string.h"
#include "../../../../utils/base64.h"
#include "../../../../datatypes/vector.h"
#include "../../../../utils/logging.h"
#include "../../../../utils/fileio.h"
#include "../../../../datatypes/image/texture.h"
#include "../../../../utils/loaders/textureloader.h"
#include "../../../../common/string.h"
#include "../../../../common/base64.h"
#include "../../../../common/vector.h"
#include "../../../../common/logging.h"
#include "../../../../common/fileio.h"
#include "../../../../common/texture.h"
#include "../../../../common/loaders/textureloader.h"

enum accessor_type {
UNKNOWN,
Expand Down
14 changes: 7 additions & 7 deletions src/driver/loaders/formats/wavefront/mtlloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include "../../../../includes.h"
#include "mtlloader.h"

#include "../../../../utils/logging.h"
#include "../../../../utils/string.h"
#include "../../../../utils/textbuffer.h"
#include "../../../../utils/fileio.h"
#include "../../../../utils/assert.h"
#include "../../../../common/logging.h"
#include "../../../../common/string.h"
#include "../../../../common/textbuffer.h"
#include "../../../../common/fileio.h"
#include "../../../../common/assert.h"
#include "../../meshloader.h"
#include "../../../../datatypes/color.h"
#include "../../../../nodes/textures/image.h"
#include "../../../../common/color.h"
#include "../../../../lib/nodes/textures/image.h" // FIXME: CROSS

/*
From: https://blenderartists.org/forum/showthread.php?71202-Material-IOR-Value-reference
Expand Down
14 changes: 7 additions & 7 deletions src/driver/loaders/formats/wavefront/wavefront.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <stdint.h>
#include <string.h>
#include "../../../../includes.h"
#include "../../../../datatypes/mesh.h"
#include "../../../../datatypes/vector.h"
#include "../../../../datatypes/poly.h"
#include "../../../../utils/logging.h"
#include "../../../../utils/string.h"
#include "../../../../utils/fileio.h"
#include "../../../../utils/textbuffer.h"
#include "../../mesh.h"
#include "../../../../common/vector.h"
#include "../../../../lib/datatypes/poly.h" // FIXME: CROSS
#include "../../../../common/logging.h"
#include "../../../../common/string.h"
#include "../../../../common/fileio.h"
#include "../../../../common/textbuffer.h"
#include "../../../loaders/meshloader.h"
#include <c-ray/c-ray.h>
#include "mtlloader.h"
Expand Down
9 changes: 5 additions & 4 deletions src/datatypes/mesh.c → src/driver/loaders/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
// Copyright © 2017-2022 Valtteri Koskivuori. All rights reserved.
//

#include "../includes.h"
#include "../../includes.h"
#include "mesh.h"

#include "../accelerators/bvh.h"
#include "poly.h"
#include "vector.h"
#include "../../lib/accelerators/bvh.h" // FIXME: CROSS
#include "../../lib/datatypes/poly.h" // FIXME: CROSS
#include "../../common/vector.h"

// FIXME: CROSS bvh should be built & torn down internally
void destroyMesh(struct mesh *mesh) {
if (mesh) {
free(mesh->name);
Expand Down
6 changes: 3 additions & 3 deletions src/datatypes/mesh.h → src/driver/loaders/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include "../utils/dyn_array.h"
#include "vector.h"
#include "poly.h"
#include "../../common/dyn_array.h"
#include "../../common/vector.h"
#include "../../lib/datatypes/poly.h" // FIXME: CROSS

struct vertex_buffer {
struct vector_arr vertices;
Expand Down
4 changes: 2 additions & 2 deletions src/driver/loaders/meshloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "meshloader.h"
#include "formats/wavefront/wavefront.h"
#include "../../utils/fileio.h"
#include "../../utils/logging.h"
#include "../../common/fileio.h"
#include "../../common/logging.h"

struct mesh_parse_result load_meshes_from_file(const char *file_path) {
switch (guess_file_type(file_path)) {
Expand Down
Loading

0 comments on commit a06e82d

Please sign in to comment.