diff --git a/Makefile b/Makefile index 6ae71eb8..7e00815e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=cc -CFLAGS=-I./include/ -Wall -Wextra -Wno-missing-field-initializers -std=c99 -D_GNU_SOURCE -O2 -ftree-vectorize +CFLAGS=-I./include/ -Wall -Wextra -Wno-missing-field-initializers -std=c99 -D_POSIX_C_SOURCE -O2 -ftree-vectorize LDFLAGS=-lpthread -lm -ldl BIN=bin/c-ray OBJDIR=bin/obj diff --git a/src/common/dyn_array.h b/src/common/dyn_array.h index 429e060e..de8eea41 100644 --- a/src/common/dyn_array.h +++ b/src/common/dyn_array.h @@ -85,8 +85,8 @@ static inline size_t grow_x_2(size_t capacity, size_t elem_size) { T##_arr_free(b); \ } -dyn_array_def(int); -dyn_array_def(float); -dyn_array_def(size_t); +dyn_array_def(int) +dyn_array_def(float) +dyn_array_def(size_t) #endif diff --git a/src/common/fileio.c b/src/common/fileio.c index 267acd3f..fc0a0cfc 100644 --- a/src/common/fileio.c +++ b/src/common/fileio.c @@ -112,7 +112,6 @@ file_data file_load(const char *file_path) { logr(warning, "Couldn't mmap '%.*s': %s\n", (int)strlen(file_path), file_path, strerror(errno)); return (file_data){ 0 }; } - madvise(data, size, MADV_SEQUENTIAL); file_data file = (file_data){ .items = data, .count = size, .capacity = size }; return file; #else diff --git a/src/common/fileio.h b/src/common/fileio.h index 51589521..5bd27ccc 100644 --- a/src/common/fileio.h +++ b/src/common/fileio.h @@ -30,7 +30,7 @@ enum fileType { }; typedef byte file_bytes; -dyn_array_def(file_bytes); +dyn_array_def(file_bytes) typedef struct file_bytes_arr file_data; enum fileType match_file_type(const char *ext); diff --git a/src/common/loaders/formats/wavefront/mtlloader.c b/src/common/loaders/formats/wavefront/mtlloader.c index 0efae2e2..fdd70de4 100644 --- a/src/common/loaders/formats/wavefront/mtlloader.c +++ b/src/common/loaders/formats/wavefront/mtlloader.c @@ -87,7 +87,7 @@ struct material { }; typedef struct material material; -dyn_array_def(material); +dyn_array_def(material) // FIXME: Delete these and use ones in node.c instead static struct cr_shader_node *alloc(struct cr_shader_node d) { diff --git a/src/common/loaders/meshloader.h b/src/common/loaders/meshloader.h index 881889f7..1c37a471 100644 --- a/src/common/loaders/meshloader.h +++ b/src/common/loaders/meshloader.h @@ -17,10 +17,10 @@ struct mesh_material { }; typedef struct mesh_material mesh_material; -dyn_array_def(mesh_material); +dyn_array_def(mesh_material) typedef struct cr_face cr_face; -dyn_array_def(cr_face); +dyn_array_def(cr_face) struct ext_mesh { struct vertex_buffer *vbuf; @@ -32,7 +32,7 @@ struct ext_mesh { }; typedef struct ext_mesh ext_mesh; -dyn_array_def(ext_mesh); +dyn_array_def(ext_mesh) static inline void ext_mesh_free(struct ext_mesh *m) { if (m->vbuf) vertex_buf_free(m->vbuf); diff --git a/src/common/platform/terminal.c b/src/common/platform/terminal.c index e25a0e96..88c19602 100644 --- a/src/common/platform/terminal.c +++ b/src/common/platform/terminal.c @@ -32,7 +32,7 @@ bool isTeleType(void) { static void show_cursor(bool show) { (void)show; #ifndef NO_COLOR - if (isTeleType()) show ? fputs("\e[?25h", stdout) : fputs("\e[?25l", stdout); + if (isTeleType()) show ? fputs("\033[?25h", stdout) : fputs("\033[?25l", stdout); #endif } @@ -46,7 +46,7 @@ static void handler(int sig) { } } -void term_init() { +void term_init(void) { if (registerHandler(sigint, handler)) { logr(warning, "Unable to catch SIGINT\n"); } @@ -70,7 +70,7 @@ void term_init() { #endif } -void term_restore() { +void term_restore(void) { #ifndef WINDOWS show_cursor(true); #endif diff --git a/src/common/platform/thread.h b/src/common/platform/thread.h index d42c556a..6a6962a4 100644 --- a/src/common/platform/thread.h +++ b/src/common/platform/thread.h @@ -43,7 +43,7 @@ struct cr_cond { }; typedef struct cr_thread cr_thread; -dyn_array_def(cr_thread); +dyn_array_def(cr_thread) // Create & detach a thread. Used by thread pool. int thread_create_detach(struct cr_thread *t); diff --git a/src/common/texture.h b/src/common/texture.h index 7705bb34..2b14068c 100644 --- a/src/common/texture.h +++ b/src/common/texture.h @@ -42,7 +42,7 @@ struct texture_asset { }; typedef struct texture_asset texture_asset; -dyn_array_def(texture_asset); +dyn_array_def(texture_asset) //FIXME: These are opposite states, which is kinda confusing. #define SRGB_TRANSFORM 0x01 diff --git a/src/common/timer.c b/src/common/timer.c index daff0075..b775261f 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -6,7 +6,6 @@ // Copyright © 2018-2020 Valtteri Koskivuori. All rights reserved. // -#include "../includes.h" #include "timer.h" #ifdef WINDOWS @@ -67,6 +66,9 @@ void timer_sleep_ms(int ms) { ts.tv_nsec = (ms % 1000) * 1000000; nanosleep(&ts, NULL); #else - usleep(ms * 1000); + struct timeval tv = { 0 }; + tv.tv_sec = ms / 1000; + tv.tv_usec = ms % 1000 * 1000; + select(0, NULL, NULL, NULL, &tv); #endif } diff --git a/src/common/timer.h b/src/common/timer.h index 1e660140..5e753a34 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -9,6 +9,8 @@ #pragma once +#include "../includes.h" + #ifdef WINDOWS typedef struct timeval { long tv_sec; diff --git a/src/common/transforms.c b/src/common/transforms.c index 7ffd829b..82ce2390 100644 --- a/src/common/transforms.c +++ b/src/common/transforms.c @@ -23,7 +23,7 @@ float rad_to_deg(float radians) { return radians * (180.0f / PI); } -struct matrix4x4 mat_id() { +struct matrix4x4 mat_id(void) { return (struct matrix4x4) { .mtx = { {1.0f, 0.0f, 0.0f, 0.0f}, @@ -34,7 +34,7 @@ struct matrix4x4 mat_id() { }; } -struct transform tform_new() { +struct transform tform_new(void) { struct transform tf; tf.A = mat_id(); tf.Ainv = tf.A; // Inverse of I == I @@ -212,7 +212,7 @@ float findDeterminant4x4(const float A[4][4]) { } //Find det of a given 4x4 matrix A -float findDeterminant(float A[4][4], int n) { +float findDeterminant(const float A[4][4], int n) { float det = 0.0f; if (n == 1) diff --git a/src/common/vector.h b/src/common/vector.h index 790821ea..537cd07a 100644 --- a/src/common/vector.h +++ b/src/common/vector.h @@ -18,7 +18,7 @@ struct vector { }; typedef struct vector vector; -dyn_array_def(vector); +dyn_array_def(vector) struct base { struct vector i, j, k; @@ -29,7 +29,7 @@ struct coord { }; typedef struct coord coord; -dyn_array_def(coord); +dyn_array_def(coord) struct intCoord { int x, y; @@ -38,11 +38,11 @@ struct intCoord { static const struct vector g_world_up = { 0.0f, 1.0f, 0.0f }; //For defaults -static inline struct vector vec_zero() { +static inline struct vector vec_zero(void) { return (struct vector){ 0.0f, 0.0f, 0.0f }; } -static inline struct coord coord_zero() { +static inline struct coord coord_zero(void) { return (struct coord){ 0.0f, 0.0f }; } @@ -53,7 +53,7 @@ struct vertex_buffer { }; typedef struct vertex_buffer vertex_buffer; -dyn_array_def(vertex_buffer); +dyn_array_def(vertex_buffer) static inline void vertex_buf_free(struct vertex_buffer *buf) { diff --git a/src/lib/datatypes/camera.h b/src/lib/datatypes/camera.h index 47ace0ba..86525e9e 100644 --- a/src/lib/datatypes/camera.h +++ b/src/lib/datatypes/camera.h @@ -44,7 +44,7 @@ struct camera { }; typedef struct camera camera; -dyn_array_def(camera); +dyn_array_def(camera) struct sampler; diff --git a/src/lib/datatypes/mesh.h b/src/lib/datatypes/mesh.h index fc23e604..9ed2383a 100644 --- a/src/lib/datatypes/mesh.h +++ b/src/lib/datatypes/mesh.h @@ -14,7 +14,7 @@ #include "../../common/vector.h" typedef struct cr_face cr_face; -dyn_array_def(cr_face); +dyn_array_def(cr_face) struct mesh { struct vertex_buffer *vbuf; @@ -27,6 +27,6 @@ struct mesh { }; typedef struct mesh mesh; -dyn_array_def(mesh); +dyn_array_def(mesh) void mesh_free(struct mesh *mesh); diff --git a/src/lib/datatypes/poly.h b/src/lib/datatypes/poly.h index 285f7c65..50d7b6d9 100644 --- a/src/lib/datatypes/poly.h +++ b/src/lib/datatypes/poly.h @@ -21,7 +21,7 @@ struct poly { }; typedef struct poly poly; -dyn_array_def(poly); +dyn_array_def(poly) struct lightRay; struct hitRecord; diff --git a/src/lib/datatypes/sphere.h b/src/lib/datatypes/sphere.h index 5a8ee35d..dece1eaf 100644 --- a/src/lib/datatypes/sphere.h +++ b/src/lib/datatypes/sphere.h @@ -18,6 +18,6 @@ struct sphere { }; typedef struct sphere sphere; -dyn_array_def(sphere); +dyn_array_def(sphere) bool rayIntersectsWithSphere(const struct lightRay *ray, const struct sphere *sphere, struct hitRecord *isect); diff --git a/src/lib/datatypes/tile.h b/src/lib/datatypes/tile.h index 97bf12c8..ee0a3ffb 100644 --- a/src/lib/datatypes/tile.h +++ b/src/lib/datatypes/tile.h @@ -43,7 +43,7 @@ struct render_tile { }; typedef struct render_tile render_tile; -dyn_array_def(render_tile); +dyn_array_def(render_tile) struct tile_set { struct render_tile_arr tiles; diff --git a/src/lib/nodes/bsdfnode.h b/src/lib/nodes/bsdfnode.h index 32a9eb9e..4ad8f3df 100644 --- a/src/lib/nodes/bsdfnode.h +++ b/src/lib/nodes/bsdfnode.h @@ -32,10 +32,10 @@ struct bsdfNode { }; typedef const struct bsdfNode * bsdf_node_ptr; -dyn_array_def(bsdf_node_ptr); +dyn_array_def(bsdf_node_ptr) typedef struct cr_shader_node * cr_shader_node_ptr; -dyn_array_def(cr_shader_node_ptr); +dyn_array_def(cr_shader_node_ptr) struct bsdf_buffer { struct bsdf_node_ptr_arr bsdfs; @@ -45,7 +45,7 @@ struct bsdf_buffer { void bsdf_buffer_free(struct bsdf_buffer *b); typedef struct bsdf_buffer bsdf_buffer; -dyn_array_def(bsdf_buffer); +dyn_array_def(bsdf_buffer) #include "shaders/diffuse.h" #include "shaders/glass.h" diff --git a/src/lib/nodes/converter/color_ramp.c b/src/lib/nodes/converter/color_ramp.c index 98c2c61a..b4a6f5b4 100644 --- a/src/lib/nodes/converter/color_ramp.c +++ b/src/lib/nodes/converter/color_ramp.c @@ -16,7 +16,7 @@ #include "color_ramp.h" typedef struct ramp_element ramp_element; -dyn_array_def(ramp_element); +dyn_array_def(ramp_element) struct color_ramp_node { struct colorNode node; diff --git a/src/lib/nodes/converter/vecmath.c b/src/lib/nodes/converter/vecmath.c index 2b16a3f5..a09281a5 100644 --- a/src/lib/nodes/converter/vecmath.c +++ b/src/lib/nodes/converter/vecmath.c @@ -135,7 +135,7 @@ static inline float wrap(float value, float max, float min) { return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min; } -static struct vectorValue eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { +static union vector_value eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { struct vecMathNode *this = (struct vecMathNode *)node; const struct vector a = this->A->eval(this->A, sampler, record).v; @@ -145,56 +145,56 @@ static struct vectorValue eval(const struct vectorNode *node, sampler *sampler, switch (this->op) { case VecAdd: - return (struct vectorValue){ .v = vec_add(a, b) }; + return (union vector_value){ .v = vec_add(a, b) }; case VecSubtract: - return (struct vectorValue){ .v = vec_sub(a, b) }; + return (union vector_value){ .v = vec_sub(a, b) }; case VecMultiply: - return (struct vectorValue){ .v = vec_mul(a, b) }; + return (union vector_value){ .v = vec_mul(a, b) }; case VecDivide: - return (struct vectorValue){ .v = { a.x / b.x, a.y / b.y, a.z / b.z } }; + return (union vector_value){ .v = { a.x / b.x, a.y / b.y, a.z / b.z } }; case VecCross: - return (struct vectorValue){ .v = vec_cross(a, b) }; + return (union vector_value){ .v = vec_cross(a, b) }; case VecReflect: - return (struct vectorValue){ .v = vec_reflect(a, b) }; + return (union vector_value){ .v = vec_reflect(a, b) }; case VecRefract: { - struct vectorValue v = { 0 }; + union vector_value v = { 0 }; v.f = vec_refract(a, b, f, &v.v) ? 1.0f : 0.0f; return v; } case VecDot: - return (struct vectorValue){ .f = vec_dot(a, b) }; + return (union vector_value){ .f = vec_dot(a, b) }; case VecDistance: - return (struct vectorValue){ .f = vec_distance_to(a, b) }; + return (union vector_value){ .f = vec_distance_to(a, b) }; case VecLength: - return (struct vectorValue){ .f = vec_length(a) }; + return (union vector_value){ .f = vec_length(a) }; case VecScale: - return (struct vectorValue){ .v = vec_scale(a, f) }; + return (union vector_value){ .v = vec_scale(a, f) }; case VecNormalize: - return (struct vectorValue){ .v = vec_normalize(a) }; + return (union vector_value){ .v = vec_normalize(a) }; case VecWrap: - return (struct vectorValue){ .v = { wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y), wrap(a.z, b.z, c.z) } }; + return (union vector_value){ .v = { wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y), wrap(a.z, b.z, c.z) } }; case VecFloor: - return (struct vectorValue){ .v = { .x = floorf(a.x), .y = floorf(a.y), .z = floorf(a.z) } }; + return (union vector_value){ .v = { .x = floorf(a.x), .y = floorf(a.y), .z = floorf(a.z) } }; case VecCeil: - return (struct vectorValue){ .v = { .x = ceilf(a.x), .y = ceilf(a.y), .z = ceilf(a.z) } }; + return (union vector_value){ .v = { .x = ceilf(a.x), .y = ceilf(a.y), .z = ceilf(a.z) } }; case VecModulo: - return (struct vectorValue){ .v = { .x = fmodf(a.x, b.x), .y = fmodf(a.y, b.y), .z = fmodf(a.z, b.z) } }; + return (union vector_value){ .v = { .x = fmodf(a.x, b.x), .y = fmodf(a.y, b.y), .z = fmodf(a.z, b.z) } }; case VecAbs: - return (struct vectorValue){ .v = { .x = fabsf(a.x), .y = fabsf(a.y), .z = fabsf(a.z) } }; + return (union vector_value){ .v = { .x = fabsf(a.x), .y = fabsf(a.y), .z = fabsf(a.z) } }; case VecMin: - return (struct vectorValue){ .v = { .x = fminf(a.x, b.x), .y = fminf(a.y, b.y), .z = fminf(a.z, b.z) } }; + return (union vector_value){ .v = { .x = fminf(a.x, b.x), .y = fminf(a.y, b.y), .z = fminf(a.z, b.z) } }; case VecMax: - return (struct vectorValue){ .v = { .x = fmaxf(a.x, b.x), .y = fmaxf(a.y, b.y), .z = fmaxf(a.z, b.z) } }; + return (union vector_value){ .v = { .x = fmaxf(a.x, b.x), .y = fmaxf(a.y, b.y), .z = fmaxf(a.z, b.z) } }; case VecSin: - return (struct vectorValue){ .v = { .x = sinf(a.x), .y = sinf(a.y), .z = sinf(a.z) } }; + return (union vector_value){ .v = { .x = sinf(a.x), .y = sinf(a.y), .z = sinf(a.z) } }; case VecCos: - return (struct vectorValue){ .v = { .x = cosf(a.x), .y = cosf(a.y), .z = cosf(a.z) } }; + return (union vector_value){ .v = { .x = cosf(a.x), .y = cosf(a.y), .z = cosf(a.z) } }; case VecTan: - return (struct vectorValue){ .v = { .x = tanf(a.x), .y = tanf(a.y), .z = tanf(a.z) } }; + return (union vector_value){ .v = { .x = tanf(a.x), .y = tanf(a.y), .z = tanf(a.z) } }; } ASSERT_NOT_REACHED(); - return (struct vectorValue){ 0 }; + return (union vector_value){ 0 }; } const struct vectorNode *newVecMath(const struct node_storage *s, const struct vectorNode *A, const struct vectorNode *B, const struct vectorNode *C, const struct valueNode *f, const enum cr_vec_op op) { diff --git a/src/lib/nodes/converter/vecmix.c b/src/lib/nodes/converter/vecmix.c index a0c05a4f..44aa20f7 100644 --- a/src/lib/nodes/converter/vecmix.c +++ b/src/lib/nodes/converter/vecmix.c @@ -48,15 +48,15 @@ static void dump(const void *node, char *dumpbuf, int bufsize) { snprintf(dumpbuf, bufsize, "vec_mix { A: %s, B: %s, f: %s }", A, B, f); } -static struct vectorValue eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { +static union vector_value eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { struct vec_mix *this = (struct vec_mix *)node; const float lerp = this->f->eval(this->f, sampler, record); if (getDimension(sampler) > lerp) { - return (struct vectorValue){ .v = this->A->eval(this->A, sampler, record).v }; + return (union vector_value){ .v = this->A->eval(this->A, sampler, record).v }; } else { - return (struct vectorValue){ .v = this->B->eval(this->B, sampler, record).v }; + return (union vector_value){ .v = this->B->eval(this->B, sampler, record).v }; } } diff --git a/src/lib/nodes/converter/vectovalue.c b/src/lib/nodes/converter/vectovalue.c index 8aa2a083..9d8bdafb 100644 --- a/src/lib/nodes/converter/vectovalue.c +++ b/src/lib/nodes/converter/vectovalue.c @@ -57,7 +57,7 @@ static void dump(const void *node, char *dumpbuf, int bufsize) { static float eval(const struct valueNode *node, sampler *sampler, const struct hitRecord *record) { struct vecToValueNode *this = (struct vecToValueNode *)node; - const struct vectorValue val = this->vec->eval(this->vec, sampler, record); + const union vector_value val = this->vec->eval(this->vec, sampler, record); switch (this->component_to_get) { case X: return val.v.x; case Y: return val.v.y; diff --git a/src/lib/nodes/input/normal.c b/src/lib/nodes/input/normal.c index a7a78b78..dc9227de 100644 --- a/src/lib/nodes/input/normal.c +++ b/src/lib/nodes/input/normal.c @@ -40,11 +40,11 @@ static void dump(const void *node, char *dumpbuf, int bufsize) { snprintf(dumpbuf, bufsize, "normalNode { }"); } -static struct vectorValue eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { +static union vector_value eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { (void)record; (void)node; (void)sampler; - return (struct vectorValue){ .v = record->surfaceNormal }; + return (union vector_value){ .v = record->surfaceNormal }; } const struct vectorNode *newNormal(const struct node_storage *s) { diff --git a/src/lib/nodes/input/uv.c b/src/lib/nodes/input/uv.c index 7edc3dcb..7436d4c4 100644 --- a/src/lib/nodes/input/uv.c +++ b/src/lib/nodes/input/uv.c @@ -40,11 +40,11 @@ static void dump(const void *node, char *dumpbuf, int bufsize) { snprintf(dumpbuf, bufsize, "uvNode { }"); } -static struct vectorValue eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { +static union vector_value eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { (void)record; (void)node; (void)sampler; - return (struct vectorValue){ .c = record->uv }; + return (union vector_value){ .c = record->uv }; } const struct vectorNode *newUV(const struct node_storage *s) { diff --git a/src/lib/nodes/vectornode.c b/src/lib/nodes/vectornode.c index eec326f1..9540d9ab 100644 --- a/src/lib/nodes/vectornode.c +++ b/src/lib/nodes/vectornode.c @@ -42,11 +42,11 @@ static void dump(const void *node, char *dumpbuf, int bufsize) { snprintf(dumpbuf, bufsize, "constantVector { %.2f, %.2f, %.2f }", (double)self->vector.x, (double)self->vector.y, (double)self->vector.z); } -static struct vectorValue eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { +static union vector_value eval(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { (void)record; (void)sampler; struct constantVector *this = (struct constantVector *)node; - return (struct vectorValue){ .v = this->vector }; + return (union vector_value){ .v = this->vector }; } const struct vectorNode *newConstantVector(const struct node_storage *s, const struct vector vector) { @@ -82,11 +82,11 @@ static void dump_uv(const void *node, char *dumpbuf, int bufsize) { snprintf(dumpbuf, bufsize, "constantUV { %.2f, %.2f }", (double)self->uv.x, (double)self->uv.y); } -static struct vectorValue eval_uv(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { +static union vector_value eval_uv(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record) { (void)record; (void)sampler; struct constantUV *this = (struct constantUV *)node; - return (struct vectorValue){ .c = this->uv }; + return (union vector_value){ .c = this->uv }; } const struct vectorNode *newConstantUV(const struct node_storage *s, const struct coord c) { diff --git a/src/lib/nodes/vectornode.h b/src/lib/nodes/vectornode.h index cfde923e..e6d81323 100644 --- a/src/lib/nodes/vectornode.h +++ b/src/lib/nodes/vectornode.h @@ -12,17 +12,15 @@ #include "../../common/vector.h" #include "nodebase.h" -struct vectorValue { - union { - struct vector v; - struct coord c; - float f; - }; +union vector_value { + struct vector v; + struct coord c; + float f; }; struct vectorNode { struct nodeBase base; - struct vectorValue (*eval)(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record); + union vector_value (*eval)(const struct vectorNode *node, sampler *sampler, const struct hitRecord *record); }; #include "input/normal.h" diff --git a/src/lib/protocol/protocol.c b/src/lib/protocol/protocol.c index 2257ba2d..193fca2f 100644 --- a/src/lib/protocol/protocol.c +++ b/src/lib/protocol/protocol.c @@ -62,7 +62,7 @@ cJSON *errorResponse(const char *error) { return errorMsg; } -cJSON *goodbye() { +cJSON *goodbye(void) { cJSON *goodbye = cJSON_CreateObject(); cJSON_AddStringToObject(goodbye, "action", "goodbye"); return goodbye; diff --git a/src/lib/protocol/server.c b/src/lib/protocol/server.c index bff2c922..97d24a35 100644 --- a/src/lib/protocol/server.c +++ b/src/lib/protocol/server.c @@ -62,7 +62,7 @@ static struct sockaddr_in parse_address(const char *str) { address.sin_family = AF_INET; char *addr_string = firstToken(&line); struct hostent *ent = gethostbyname(addr_string); - memcpy(&address.sin_addr.s_addr, ent->h_addr, ent->h_length); + memcpy(&address.sin_addr.s_addr, ent->h_addr_list[0], ent->h_length); address.sin_port = line.amountOf.tokens > 1 ? htons(atoi(lastToken(&line))) : htons(2222); return address; } diff --git a/src/lib/protocol/server.h b/src/lib/protocol/server.h index 33e71a74..45b5b529 100644 --- a/src/lib/protocol/server.h +++ b/src/lib/protocol/server.h @@ -38,7 +38,7 @@ struct render_client { }; typedef struct render_client render_client; -dyn_array_def(render_client); +dyn_array_def(render_client) void clients_shutdown(const char *node_list); diff --git a/src/lib/protocol/worker.c b/src/lib/protocol/worker.c index c0976c45..59820723 100644 --- a/src/lib/protocol/worker.c +++ b/src/lib/protocol/worker.c @@ -384,7 +384,7 @@ int worker_start(int port, size_t thread_limit) { logr(error, "Socket creation failed.\n"); } - bzero(&ownAddress, sizeof(ownAddress)); + memset(&ownAddress, 0, sizeof(ownAddress)); ownAddress.sin_family = AF_INET; ownAddress.sin_addr.s_addr = htonl(INADDR_ANY); ownAddress.sin_port = htons(port); diff --git a/src/lib/renderer/instance.h b/src/lib/renderer/instance.h index 04720a08..b6b81ed9 100644 --- a/src/lib/renderer/instance.h +++ b/src/lib/renderer/instance.h @@ -33,7 +33,7 @@ struct instance { }; typedef struct instance instance; -dyn_array_def(instance); +dyn_array_def(instance) struct instance new_sphere_instance(struct sphere_arr *spheres, size_t idx, float *density, struct block **pool); struct instance new_mesh_instance(struct mesh_arr *meshes, size_t idx, float *density, struct block **pool); diff --git a/src/lib/renderer/renderer.c b/src/lib/renderer/renderer.c index 050320c2..f89bd524 100644 --- a/src/lib/renderer/renderer.c +++ b/src/lib/renderer/renderer.c @@ -451,7 +451,7 @@ void *render_thread(void *arg) { return 0; } -struct prefs default_prefs() { +struct prefs default_prefs(void) { return (struct prefs){ .tileOrder = ro_from_middle, .threads = sys_get_cores() + 2, @@ -465,7 +465,7 @@ struct prefs default_prefs() { }; } -struct renderer *renderer_new() { +struct renderer *renderer_new(void) { struct renderer *r = calloc(1, sizeof(*r)); r->prefs = default_prefs(); r->state.finishedPasses = 1; diff --git a/src/lib/renderer/renderer.h b/src/lib/renderer/renderer.h index 3b111c8c..64efa7e8 100644 --- a/src/lib/renderer/renderer.h +++ b/src/lib/renderer/renderer.h @@ -34,7 +34,7 @@ struct worker { struct render_client *client; // Optional }; typedef struct worker worker; -dyn_array_def(worker); +dyn_array_def(worker) struct callback { void (*fn)(struct cr_renderer_cb_info *, void *); @@ -89,4 +89,4 @@ void renderer_render(struct renderer *r); void renderer_start_interactive(struct renderer *r); void renderer_destroy(struct renderer *r); -struct prefs default_prefs(); // TODO: Remove +struct prefs default_prefs(void); // TODO: Remove diff --git a/tests/test_nodes.h b/tests/test_nodes.h index 08d6f792..7e22a697 100644 --- a/tests/test_nodes.h +++ b/tests/test_nodes.h @@ -626,7 +626,7 @@ bool mathnode_sine(void) { struct node_storage *s = make_storage(); struct sampler *sampler = newSampler(); initSampler(sampler, Halton, 0, 16, 128); - const struct valueNode *A = newConstantValue(s, M_PI); + const struct valueNode *A = newConstantValue(s, PI); const struct valueNode *result = newMath(s, A, NULL, Sine); roughly_equals(result->eval(result, sampler, NULL), 0.0f); @@ -640,7 +640,7 @@ bool mathnode_cosine(void) { struct node_storage *s = make_storage(); struct sampler *sampler = newSampler(); initSampler(sampler, Halton, 0, 16, 128); - const struct valueNode *A = newConstantValue(s, M_PI); + const struct valueNode *A = newConstantValue(s, PI); const struct valueNode *result = newMath(s, A, NULL, Cosine); roughly_equals(result->eval(result, sampler, NULL), -1.0f); @@ -654,7 +654,7 @@ bool mathnode_tangent(void) { struct node_storage *s = make_storage(); struct sampler *sampler = newSampler(); initSampler(sampler, Halton, 0, 16, 128); - const struct valueNode *A = newConstantValue(s, M_PI); + const struct valueNode *A = newConstantValue(s, PI); const struct valueNode *result = newMath(s, A, NULL, Tangent); roughly_equals(result->eval(result, sampler, NULL), -0.0f); @@ -671,7 +671,7 @@ bool mathnode_toradians(void) { const struct valueNode *A = newConstantValue(s, 180.0f); const struct valueNode *result = newMath(s, A, NULL, ToRadians); - roughly_equals(result->eval(result, sampler, NULL), M_PI); + roughly_equals(result->eval(result, sampler, NULL), PI); delete_storage(s); destroySampler(sampler); @@ -682,7 +682,7 @@ bool mathnode_todegrees(void) { struct node_storage *s = make_storage(); struct sampler *sampler = newSampler(); initSampler(sampler, Halton, 0, 16, 128); - const struct valueNode *A = newConstantValue(s, M_PI); + const struct valueNode *A = newConstantValue(s, PI); const struct valueNode *result = newMath(s, A, NULL, ToDegrees); roughly_equals(result->eval(result, sampler, NULL), 180.0f); @@ -701,7 +701,7 @@ bool vecmath_vecAdd(void) { const struct vectorNode *add = newVecMath(s, A, B, NULL, NULL, VecAdd); - struct vectorValue result = add->eval(add, sampler, NULL); + union vector_value result = add->eval(add, sampler, NULL); struct vector expected = (struct vector){2.0f, 4.0f, 6.0f}; vec_roughly_equals(result.v, expected); @@ -719,7 +719,7 @@ bool vecmath_vecSubtract(void) { const struct vectorNode *add = newVecMath(s, A, B, NULL, NULL, VecSubtract); - struct vectorValue result = add->eval(add, sampler, NULL); + union vector_value result = add->eval(add, sampler, NULL); struct vector expected = vec_zero(); vec_roughly_equals(result.v, expected); @@ -737,7 +737,7 @@ bool vecmath_vecMultiply(void) { const struct vectorNode *add = newVecMath(s, A, B, NULL, NULL, VecMultiply); - struct vectorValue result = add->eval(add, sampler, NULL); + union vector_value result = add->eval(add, sampler, NULL); struct vector expected = (struct vector){1.0f, 4.0f, 9.0f}; vec_roughly_equals(result.v, expected); @@ -755,7 +755,7 @@ bool vecmath_vecDot(void) { const struct vectorNode *dot = newVecMath(s, up, right, NULL, NULL, VecDot); - struct vectorValue result = dot->eval(dot, sampler, NULL); + union vector_value result = dot->eval(dot, sampler, NULL); roughly_equals(result.f, 0.0f); const struct vectorNode *down = newConstantVector(s, vec_negate(g_world_up)); @@ -781,7 +781,7 @@ bool vecmath_vecCross(void) { const struct vectorNode *op = newVecMath(s, A, B, NULL, NULL, VecCross); - struct vectorValue result = op->eval(op, sampler, NULL); + union vector_value result = op->eval(op, sampler, NULL); struct vector expected = (struct vector){0.0f, 0.0f, 1.0f}; vec_roughly_equals(result.v, expected); @@ -815,7 +815,7 @@ bool vecmath_vecReflect(void) { const struct vectorNode *op = newVecMath(s, toReflect, normal, NULL, NULL, VecReflect); - struct vectorValue reflected = op->eval(op, sampler, NULL); + union vector_value reflected = op->eval(op, sampler, NULL); roughly_equals(vec_length(reflected.v), 1.0f); struct vector expected = vec_normalize((struct vector){1.0f, -1.0f, 0.0f}); @@ -834,7 +834,7 @@ bool vecmath_vecLength(void) { const struct vectorNode *op = newVecMath(s, A, NULL, NULL, NULL, VecLength); - struct vectorValue lengthValue = op->eval(op, sampler, NULL); + union vector_value lengthValue = op->eval(op, sampler, NULL); roughly_equals(lengthValue.f, 2.0f); delete_storage(s); @@ -850,7 +850,7 @@ bool vecmath_vecAbs(void) { const struct vectorNode *op = newVecMath(s, A, NULL, NULL, NULL, VecAbs); - struct vectorValue result = op->eval(op, sampler, NULL); + union vector_value result = op->eval(op, sampler, NULL); struct vector expected = (struct vector){10.0f, 2.0f, 3.0f}; vec_roughly_equals(result.v, expected); @@ -867,7 +867,7 @@ bool vecmath_vecScale(void) { const struct vectorNode *op = newVecMath(s, A, NULL, NULL, newConstantValue(s, 2.0f), VecScale); - struct vectorValue result = op->eval(op, sampler, NULL); + union vector_value result = op->eval(op, sampler, NULL); struct vector expected = (struct vector){ 2.0f, 0.0f, 0.0f }; vec_roughly_equals(result.v, expected);