diff --git a/src/game.c b/src/game.c index e359beb0..c5d292f8 100644 --- a/src/game.c +++ b/src/game.c @@ -386,16 +386,22 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, array) /* Create test blood */ /* TODO: Remove this */ { - struct xform xf = XFORM_TRS(.t = point); + struct xform xf = XFORM_TRS(.t = point, .r = sys_rand_f32(0, TAU)); struct entity *decal = entity_alloc(root); decal->sprite = sprite_tag_from_path(STR("res/graphics/blood.ase")); decal->sprite_tint = RGBA_32_F(1, 1, 1, 0.25f); entity_set_xform(decal, xf); + f32 perp_range = 0.5; + struct v2 linear_velocity = v2_mul(normal, 0.5); + linear_velocity = v2_add(linear_velocity, v2_mul(v2_perp(normal), sys_rand_f32(-perp_range, perp_range))); + f32 angular_velocity_range = 5; + f32 angular_velocity = sys_rand_f32(-angular_velocity_range, angular_velocity_range); + entity_enable_prop(decal, ENTITY_PROP_PHYSICAL_KINEMATIC); - entity_set_linear_velocity(decal, v2_mul(v2_norm(v2_neg(vrel)), 0.5f)); - entity_set_angular_velocity(decal, angular_velocity_range - (((f32)sys_rand_u32() / (f32)U32_MAX) * (angular_velocity_range * 2))); + entity_set_linear_velocity(decal, linear_velocity); + entity_set_angular_velocity(decal, angular_velocity); decal->linear_damping = 5.0f; decal->angular_damping = 5.0f; @@ -1067,7 +1073,6 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) ent->tracer_gradient_start = gradient_start; ent->tracer_gradient_end = gradient_end; - } /* ========================== * diff --git a/src/sys.h b/src/sys.h index 6bbf1777..cd72d19b 100644 --- a/src/sys.h +++ b/src/sys.h @@ -447,6 +447,7 @@ u32 sys_num_logical_processors(void); void sys_exit(void); u32 sys_rand_u32(void); +f32 sys_rand_f32(f32 range_start, f32 range_end); void sys_panic(struct string msg); diff --git a/src/sys_win32.c b/src/sys_win32.c index 25aa1edf..248f503e 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -1872,6 +1872,11 @@ u32 sys_rand_u32(void) return v; } +f32 sys_rand_f32(f32 range_start, f32 range_end) +{ + return ((f32)sys_rand_u32() / (f32)U32_MAX) * (range_end - range_start) + range_start; +} + void sys_panic(struct string msg) { ASSERT(false); diff --git a/src/user.c b/src/user.c index 99d7c866..1b829b1f 100644 --- a/src/user.c +++ b/src/user.c @@ -881,35 +881,6 @@ INTERNAL void user_update(void) struct xform sprite_xform = xf; - /* Draw bullet trail */ -#if 0 - if (entity_has_prop(ent, ENTITY_PROP_BULLET)) { - f32 max_len = 0.75; - - f32 thickness = 0.0025; - u32 color = RGBA_32_F(1, 1, 1, 1); - - struct v2 end = xf.og; - - struct v2 start; - struct entity *src = entity_from_handle(store, ent->bullet_src); - if (src->valid) { - start = xform_mul_v2(src->sprite_local_xform, sprite_sheet_get_slice(sprite_sheet_from_tag_await(sprite_frame_scope, src->sprite), STR("out"), src->animation_frame).center); - start = xform_mul_v2(entity_get_xform(src), start); - } else { - start = v2_sub(end, v2_div(ent->velocity, 50)); - } - - struct v2 rel = v2_sub(start, end); - if (v2_len(rel) > max_len) { - rel = v2_mul(v2_norm(rel), max_len); - start = v2_add(end, rel); - } - - draw_solid_line(G.world_canvas, start, end, thickness, color); - } -#endif - /* Draw tracer */ if (entity_has_prop(ent, ENTITY_PROP_TRACER)) { struct v2 velocity = ent->tracer_start_velocity; @@ -968,42 +939,6 @@ INTERNAL void user_update(void) /* Debug draw entity info */ if (G.debug_draw && !skip_debug_draw) { struct temp_arena temp = arena_temp_begin(scratch.arena); -#if 0 - struct font *disp_font = font_load_async(STR("res/fonts/fixedsys.ttf"), 12.0f); - if (disp_font) { - struct xform xf = ent->xform_world; - struct trs trs = trs_from_xform(xf); - struct v2 velocity = ent->velocity; - struct v2 acceleration = ent->acceleration; - - f32 offset = 1; - struct v2 pos = v2_add(xf.og, v2_mul(V2(0, -1), offset)); - pos = xform_mul_v2(G.world_view, pos); - pos = v2_round(pos); - - struct string disp_name = ent->sprite_name; - - struct string fmt = STR( - "sprite name: \"%F\"\n" - "pos: (%F, %F)\n" - "scale: (%F, %F)\n" - "rot: %F\n" - "velocity: (%F, %F)\n" - "acceleration: (%F, %F)\n" - ); - struct string text = string_format(temp.arena, fmt, - FMT_STR(disp_name), - FMT_FLOAT((f64)trs.t.x), FMT_FLOAT((f64)trs.t.y), - FMT_FLOAT((f64)trs.s.x), FMT_FLOAT((f64)trs.s.y), - FMT_FLOAT((f64)trs.r), - FMT_FLOAT((f64)velocity.x), FMT_FLOAT((f64)velocity.y), - FMT_FLOAT((f64)acceleration.x), FMT_FLOAT((f64)acceleration.y) - ); - - - draw_text(G.viewport_canvas, disp_font, pos, text); - } -#endif if (entity_has_prop(ent, ENTITY_PROP_PHYSICAL_DYNAMIC) || entity_has_prop(ent, ENTITY_PROP_PHYSICAL_KINEMATIC)) { debug_draw_movement(ent); @@ -1015,7 +950,6 @@ INTERNAL void user_update(void) debug_draw_xform(xf, color_x, color_y); } -#if 1 /* Draw focus arrow */ if (entity_has_prop(ent, ENTITY_PROP_PLAYER_CONTROLLED)) { struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, ent->sprite); @@ -1026,7 +960,6 @@ INTERNAL void user_update(void) end = xform_mul_v2(G.world_view, end); draw_solid_arrow_line(G.viewport_canvas, start, end, 3, 10, RGBA_32_F(1, 1, 1, 0.5)); } -#endif #if 0 /* Draw slices */