From f260bf6579d77914d5e0d97c37635c1cf4aad4ba Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 5 Mar 2024 14:34:35 -0600 Subject: [PATCH] fix fmod --- src/game.c | 1 + src/math.h | 6 +++--- src/user.c | 54 +++++++++++++++--------------------------------------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/game.c b/src/game.c index 50dab81e..9546ab7a 100644 --- a/src/game.c +++ b/src/game.c @@ -178,6 +178,7 @@ INTERNAL void game_update(void) struct entity *e = entity_alloc(); e->active = true; + //e->rel_trs = TRS(.t = pos, .r = 0, .s = V2(3, 1)); e->rel_trs = TRS(.t = pos, .r = 0, .s = V2(1, 1)); e->sprite_name = sprite_name; diff --git a/src/math.h b/src/math.h index bd2b4fb9..f754737f 100644 --- a/src/math.h +++ b/src/math.h @@ -47,7 +47,7 @@ INLINE i64 math_ceil_f64(f64 f) INLINE f32 math_mod_f32(f32 x, f32 m) { - return x - m * math_floor_f32(x / m); + return x - m * (i32)(x / m); } INLINE f32 math_abs_f32(f32 f) @@ -249,8 +249,8 @@ INLINE f32 math_atan2(f32 x, f32 y) { res = swap ? (s >= 0.0f ? (PI / 2.f) : -(PI / 2.f)) - res : res; /* Adjust quadrants */ - if (x < 0.0f && y >= 0.0f) { res = PI + res; } /* 2nd quadrant */ - else if (x <= 0.0f && y < 0.0f) { res = -PI + res; } /* 3rd quadrant */ + if (x < 0.0f && y >= 0.0f) { res = PI + res; } /* 2nd quadrant */ + else if (x <= 0.0f && y < 0.0f) { res = -PI + res; } /* 3rd quadrant */ return res; } diff --git a/src/user.c b/src/user.c index f7434dad..e7f859b1 100644 --- a/src/user.c +++ b/src/user.c @@ -426,14 +426,15 @@ INTERNAL void user_update(void) struct tick *tick = arena_push_zero(scratch.arena, struct tick); { __profscope(produce_interpolated_tick); - sys_timestamp_t tick_dt_time = t1->published_ts - t0->published_ts; - f32 blend = (f32)((sys_timestamp() - t1->published_ts) / (f64)tick_dt_time); + + sys_timestamp_t tick_publish_delta = t1->published_ts - t0->published_ts; + f32 tick_blend = (f32)((sys_timestamp() - t1->published_ts) / (f64)tick_publish_delta); tick_cpy(tick, t1); #if 1 /* Blend time */ - tick->time = math_lerp_f64(t0->time, t1->time, (f64)blend); + tick->time = math_lerp_f64(t0->time, t1->time, (f64)tick_blend); /* Blend entities */ u64 num_entities = min_u64(t0->entities_count, t1->entities_count); @@ -442,24 +443,15 @@ INTERNAL void user_update(void) struct entity *e0 = &t0->entities[i]; struct entity *e1 = &t1->entities[i]; if (e0->handle.gen == e1->handle.gen && e0->continuity_gen == e1->continuity_gen) { - e->rel_trs = trs_lerp(e0->rel_trs, e1->rel_trs, blend); - e->sprite_trs = trs_lerp(e0->sprite_trs, e1->sprite_trs, blend); - e->sprite_pivot_norm = v2_lerp(e0->sprite_pivot_norm, e1->sprite_pivot_norm, blend); + e->rel_trs = trs_lerp(e0->rel_trs, e1->rel_trs, tick_blend); + e->sprite_trs = trs_lerp(e0->sprite_trs, e1->sprite_trs, tick_blend); + e->sprite_pivot_norm = v2_lerp(e0->sprite_pivot_norm, e1->sprite_pivot_norm, tick_blend); + e->world_xform = mat3x3_lerp(e0->world_xform, e1->world_xform, tick_blend); - if (e->handle.idx == 0) { - struct mat3x3 world_xform_test = mat3x3_lerp(e0->world_xform, e1->world_xform, blend); - (UNUSED)world_xform_test; - //if (world_xform_test.e[1][0] != e0->world_xform.e[1][0] || world_xform_test.e[1][1] != e0->world_xform.e[1][1]) { - // DEBUGBREAK; - //} - //DEBUGBREAK; - } - - e->world_xform = mat3x3_lerp(e0->world_xform, e1->world_xform, blend); } } #else - (UNUSED)blend; + (UNUSED)tick_blend; #endif } @@ -520,21 +512,6 @@ INTERNAL void user_update(void) /* Draw texture */ struct quad quad = QUAD_UNIT_SQUARE_CENTERED; - /* TODO: Do this calculation in game loop */ -#if 0 - struct mat3x3 mtx; - { - /* Entity trs */ - mtx = mat3x3_from_trs(ent->world_trs); - - /* Sprite trs & pivot */ - struct v2 scale_div_2 = v2_mul(ent->sprite_trs.s, 0.5f); - struct v2 pivot = v2_mul_v2(ent->sprite_pivot_norm, scale_div_2); - mtx = mat3x3_trs_pivot_r(mtx, ent->sprite_trs, pivot); - - quad = quad_mul_mat3x3(quad, mtx); - } -#else struct mat3x3 mtx; { struct v2 scale_div_2 = v2_mul(ent->sprite_trs.s, 0.5f); @@ -543,7 +520,6 @@ INTERNAL void user_update(void) quad = quad_mul_mat3x3(quad, mtx); } -#endif struct texture *texture = texture_load_async(tex_name); if (texture) { @@ -591,13 +567,13 @@ INTERNAL void user_update(void) struct font *disp_font = font_load_async(STR("res/fonts/fixedsys.ttf"), 12.0f); - f32 offset = 0.75; - - struct v2 dir = v2_mul(mat3x3_get_up(mtx), 0.5f); - dir = v2_add(dir, v2_mul(v2_norm(dir), offset)); - - struct v2 pos = v2_add(mat3x3_get_pos(mtx), dir); + //f32 offset = 0.75; + //struct v2 dir = v2_mul(mat3x3_get_up(mtx), 0.5f); + //dir = v2_add(dir, v2_mul(v2_norm(dir), offset)); + //struct v2 pos = v2_add(mat3x3_get_pos(mtx), dir); + f32 offset = 1.5; + struct v2 pos = v2_add(mat3x3_get_pos(mtx), v2_mul(V2(0, -1), offset)); if (disp_font) { struct string disp_name = ent->sprite_name;