diff --git a/src/host.c b/src/host.c index 2d166cc1..29b9f96c 100644 --- a/src/host.c +++ b/src/host.c @@ -8,13 +8,9 @@ #include "buddy.h" #include "atomic.h" -//#define HOST_NETWORK_ADDRESS_STRING(str) -//#define HOST_NETWORK_ADDRESS_ALL_LOCAL_INTERFACES(port) -//#define HOST_NETWORK_ADDRESS_NONE - #define PACKET_MAGIC 0xd9e3b8b6 #define PACKET_MSG_CHUNK_MAX_LEN 1024 -#define PACKET_DATA_MAX_LEN (1280 * 2) /* Give enough space for msg chunk + header */ +#define PACKET_DATA_MAX_LEN 1280 /* Give enough space for msg chunk + header */ #define NUM_CHANNEL_LOOKUP_BUCKETS 512 #define NUM_MSG_ASSEMBLER_LOOKUP_BUCKETS 16384 @@ -722,7 +718,6 @@ void host_update(struct host *host) u64 msg_id = br_read_var_uint(&br); u64 chunk_id = br_read_var_uint(&br); u64 chunk_count = br_read_var_uint(&br); - b32 is_last_chunk = (chunk_id + 1) == chunk_count; u64 data_len = is_last_chunk ? br_read_var_uint(&br) : PACKET_MSG_CHUNK_MAX_LEN; @@ -900,6 +895,9 @@ void host_update(struct host *host) b32 is_last_chunk = i + 1 == chunk_count; if (is_last_chunk) { data_len = msg.len % PACKET_MSG_CHUNK_MAX_LEN; + if (data_len == 0) { + data_len = PACKET_MSG_CHUNK_MAX_LEN; + } } u8 *data = msg.text + (i * PACKET_MSG_CHUNK_MAX_LEN); struct host_snd_packet *host_packet = host_channel_snd_packet_alloc(channel, is_reliable); diff --git a/src/math.h b/src/math.h index 8a195030..5cba4738 100644 --- a/src/math.h +++ b/src/math.h @@ -300,7 +300,7 @@ INLINE f32 math_exp(f32 x) LOCAL_PERSIST const f32 two_m100 = 7.8886090522e-31f; u32 x_uint = *(u32 *)&x; - u32 x_sign_bit = (x_uint >> 31) & 1; + i32 x_sign_bit = (i32)((x_uint >> 31) & 1); x_uint &= 0x7fffffff; /* Filter out non-finite argument */ @@ -312,7 +312,7 @@ INLINE f32 math_exp(f32 x) } if (x > o_threshold) { /* Overflow */ - return huge * huge; + return F32_INFINITY; } else if (x < u_threshold) { /* Underflow */ return two_m100 * two_m100; @@ -376,7 +376,7 @@ INLINE f32 math_pow(f32 a, f32 b) return math_exp(math_ln(a) * b); } else { /* a is negative */ - i32 res_sign = math_round_to_int(b) % 2 == 0 ? 1 : -1; + f32 res_sign = math_round_to_int(b) % 2 == 0 ? 1 : -1; return math_exp(math_ln(-a) * b) * res_sign; } } @@ -455,7 +455,7 @@ INLINE f32 math_reduce_positive_to_pio4(f32 x, i32 *octant_out) INLINE f32 math_sin(f32 x) { - i32 sign = 1; + f32 sign = 1; if (F32_IS_NAN(x)) { return 0; @@ -482,7 +482,7 @@ INLINE f32 math_sin(f32 x) INLINE f32 math_cos(f32 x) { - i32 sign = 1; + f32 sign = 1; if (F32_IS_NAN(x)) { return 0; @@ -512,7 +512,7 @@ INLINE f32 math_cos(f32 x) INLINE f32 math_atan(f32 x) { - i32 sign = 1; + f32 sign = 1; if (x < 0) { sign = -1; x = -x; @@ -898,10 +898,10 @@ INLINE struct mat4x4 mat4x4_mul(struct mat4x4 m1, struct mat4x4 m2) * ========================== */ /* Construct identity xform */ -#define XFORM_IDENT CPPCOMPAT_INITLIST_TYPE(struct xform) { .bx.x = 1, .by.y = 1 } -#define XFORM_IDENT_NOCAST { .bx.x = 1, .by.y = 1 } +#define XFORM_IDENT CPPCOMPAT_INITLIST_TYPE(struct xform) { .bx = V2(1, 0), .by = V2(0, 1) } +#define XFORM_IDENT_NOCAST { .bx = V2(1, 0), .by = V2(0, 1) } -#define XFORM_POS(p) CPPCOMPAT_INITLIST_TYPE(struct xform) { .bx.x = 1, .by.y = 1, .og = (p) } +#define XFORM_POS(p) CPPCOMPAT_INITLIST_TYPE(struct xform) { .bx = V2(1, 0), .by = V2(0, 1), .og = (p) } /* Takes a translation, rotation, and scale as optional parameters for constructing an xform */ #define XFORM_TRS(...) xform_from_trs((struct trs) { .t = V2(0,0), .s = V2(1, 1), .r = 0, __VA_ARGS__ }) @@ -1078,12 +1078,12 @@ INLINE struct v2 xform_invert_mul_v2(struct xform xf, struct v2 v) INLINE struct quad xform_mul_quad(struct xform xf, struct quad quad) { - return (struct quad) { - xform_mul_v2(xf, quad.p0), - xform_mul_v2(xf, quad.p1), - xform_mul_v2(xf, quad.p2), - xform_mul_v2(xf, quad.p3) - }; + struct quad res; + res.p0 = xform_mul_v2(xf, quad.p0); + res.p1 = xform_mul_v2(xf, quad.p1); + res.p2 = xform_mul_v2(xf, quad.p2); + res.p3 = xform_mul_v2(xf, quad.p3); + return res; } INLINE f32 xform_get_determinant(struct xform xf) @@ -1128,22 +1128,22 @@ INLINE struct v2 xform_get_scale(struct xform xf) INLINE struct quad quad_from_rect(struct rect rect) { - return (struct quad) { - (struct v2) { rect.x, rect.y }, /* Top left */ - (struct v2) { rect.x + rect.width, rect.y }, /* Top right */ - (struct v2) { rect.x + rect.width, rect.y + rect.height }, /* Bottom right */ - (struct v2) { rect.x, rect.y + rect.height } /* Bottom left */ - }; + struct quad res; + res.p0 = V2(rect.x, rect.y); /* Top left */ + res.p1 = V2(rect.x + rect.width, rect.y); /* Top right */ + res.p2 = V2(rect.x + rect.width, rect.y + rect.height); /* Bottom right */ + res.p3 = V2(rect.x, rect.y + rect.height); /* Bottom left */ + return res; } INLINE struct quad quad_from_aabb(struct aabb aabb) { - return (struct quad) { - (struct v2) { aabb.p0.x, aabb.p0.y }, /* Top left */ - (struct v2) { aabb.p1.x, aabb.p0.y }, /* Top right */ - (struct v2) { aabb.p1.x, aabb.p1.y }, /* Bottom right */ - (struct v2) { aabb.p0.x, aabb.p1.y } /* Bottom left */ - }; + struct quad res; + res.p0 = V2(aabb.p0.x, aabb.p0.y); /* Top left */ + res.p0 = V2(aabb.p1.x, aabb.p0.y); /* Top right */ + res.p0 = V2(aabb.p1.x, aabb.p1.y); /* Bottom right */ + res.p0 = V2(aabb.p0.x, aabb.p1.y); /* Bottom left */ + return res; } INLINE struct quad quad_from_line(struct v2 start, struct v2 end, f32 thickness) @@ -1155,12 +1155,13 @@ INLINE struct quad quad_from_line(struct v2 start, struct v2 end, f32 thickness) struct v2 left = v2_mul(dir_perp, -width); struct v2 right = v2_mul(dir_perp, width); - return (struct quad) { - .p0 = v2_add(start, left), - .p1 = v2_add(start, right), - .p2 = v2_add(end, right), - .p3 = v2_add(end, left) - }; + + struct quad res; + res.p0 = v2_add(start, left); + res.p1 = v2_add(start, right); + res.p2 = v2_add(end, right); + res.p3 = v2_add(end, left); + return res; } INLINE struct quad quad_from_ray(struct v2 pos, struct v2 rel, f32 thickness) @@ -1180,22 +1181,22 @@ INLINE struct quad quad_scale(struct quad q, f32 s) INLINE struct quad quad_round(struct quad quad) { - return (struct quad) { - v2_round(quad.p0), - v2_round(quad.p1), - v2_round(quad.p2), - v2_round(quad.p3) - }; + struct quad res; + res.p0 = v2_round(quad.p0); + res.p0 = v2_round(quad.p1); + res.p0 = v2_round(quad.p2); + res.p0 = v2_round(quad.p3); + return res; } INLINE struct quad quad_floor(struct quad quad) { - return (struct quad) { - v2_floor(quad.p0), - v2_round(quad.p1), - v2_round(quad.p2), - v2_round(quad.p3) - }; + struct quad res; + res.p0 = v2_floor(quad.p0); + res.p0 = v2_floor(quad.p1); + res.p0 = v2_floor(quad.p2); + res.p0 = v2_floor(quad.p3); + return res; } /* ========================== * diff --git a/src/sim.c b/src/sim.c index 6f151b6b..917d6520 100644 --- a/src/sim.c +++ b/src/sim.c @@ -626,9 +626,10 @@ void sim_update(struct sim_ctx *ctx, i64 target_dt_ns) case SIM_CMD_KIND_SPAWN_TEST: { logf_info("Spawning (test)"); - u32 count = 1000; + u32 count = 1; + f32 spread = 1; for (u32 j = 0; j < count; ++j) { - spawn_test_entities(ctx, V2(0, (((f32)j / (f32)count) - 0.5) * 2000)); + spawn_test_entities(ctx, V2(0, (((f32)j / (f32)count) - 0.5) * spread)); } } break;