spawn1 & spawn2 commands

This commit is contained in:
jacob 2025-05-16 12:05:37 -05:00
parent 84b0caf379
commit f4c8264c96
8 changed files with 125 additions and 110 deletions

View File

@ -35,13 +35,20 @@ ps_input vs_main(vs_input input)
float4 ps_main(ps_input input) : SV_TARGET float4 ps_main(ps_input input) : SV_TARGET
{ {
float2 screen_pos = input.screen_pos.xy + input.offset; float2 screen_pos = input.screen_pos.xy + input.offset;
float thickness = input.line_thickness; float half_thickness = input.line_thickness / 2;
float spacing = input.line_spacing; float spacing = input.line_spacing;
float4 color = 0; float4 color = 0;
float2 v = abs(round(screen_pos / spacing) * spacing - screen_pos); float2 v = abs(round(screen_pos / spacing) * spacing - screen_pos);
float dist = min(v.x, v.y); float dist = min(v.x, v.y);
color = input.col * step(dist, thickness / 2); color = input.col * step(dist, half_thickness);
if (screen_pos.y <= half_thickness && screen_pos.y >= -half_thickness) {
color.r = 1;
}
if (screen_pos.x <= half_thickness && screen_pos.x >= -half_thickness) {
color.g = 1;
}
return color; return color;
} }

View File

@ -902,11 +902,7 @@ f32 collider_time_of_impact(struct collider_shape *c0, struct collider_shape *c1
} }
u32 iteration = 0; u32 iteration = 0;
while (math_fabs(t_sep) > tolerance) { while (math_fabs(t_sep) > tolerance && iteration < max_iterations) {
if (iteration >= max_iterations) {
break;
}
/* Use mix of bisection & false position method to find root /* Use mix of bisection & false position method to find root
* (as described in https://box2d.org/files/ErinCatto_ContinuousCollision_GDC2013.pdf) */ * (as described in https://box2d.org/files/ErinCatto_ContinuousCollision_GDC2013.pdf) */
if (iteration & 1) { if (iteration & 1) {

View File

@ -284,18 +284,29 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define RGBA_32(r, g, b, a) (u32)((u32)(r) | ((u32)(g) << 8) | ((u32)(b) << 16) | ((u32)(a) << 24)) #define RGBA_32(r, g, b, a) (u32)((u32)(r) | ((u32)(g) << 8) | ((u32)(b) << 16) | ((u32)(a) << 24))
#define RGB_32(r, g, b) RGBA_32((r), (g), (b), 0xFF) #define RGB_32(r, g, b) RGBA_32((r), (g), (b), 0xFF)
#define _RGB_F_TO_U8(fl) ((u8)((fl * 255.0f) + 0.5f)) #define _RGB_U8_FROM_F32(fl) ((u8)((fl * 255.0) + 0.5))
#define RGBA_32_F(r, g, b, a) RGBA_32(_RGB_F_TO_U8((r)), _RGB_F_TO_U8((g)), _RGB_F_TO_U8((b)), _RGB_F_TO_U8((a))) #define RGBA_32F(r, g, b, a) RGBA_32(_RGB_U8_FROM_F32((r)), _RGB_U8_FROM_F32((g)), _RGB_U8_FROM_F32((b)), _RGB_U8_FROM_F32((a)))
#define RGB_32_F(r, g, b) RGBA_32_F((r), (g), (b), 1.f) #define RGB_32F(r, g, b) RGBA_32F((r), (g), (b), 1.f)
#define COLOR_WHITE RGB_32(0xFF, 0xFF, 0xFF) #define ALPHA_32_F(color, a) ((color) & 0xFFFFFF00) | _RGB_U8_FROM_F32((a))
#define COLOR_BLACK RGB_32(0 , 0 , 0 )
#define COLOR_RED RGB_32(0xFF, 0 , 0 ) /* Palette color defines */
#define COLOR_GREEN RGB_32(0 , 0xFF, 0 ) #define COLOR_WHITE COLOR_TRUE_WHITE
#define COLOR_BLUE RGB_32(0 , 0 , 0xFF) #define COLOR_BLACK COLOR_TRUE_BLACK
#define COLOR_YELLOW RGB_32(0xFF, 0xFF, 0 ) #define COLOR_RED RGB_32(0xFF, 0x7F, 0x51)
#define COLOR_TURQOISE RGB_32(0, 0xFF, 0XFF) #define COLOR_GREEN RGB_32(0x9E, 0xB2, 0x5D)
#define COLOR_PURPLE RGB_32(0xFF, 0, 0XFF) #define COLOR_BLUE RGB_32(0x25, 0x8E, 0xA6)
#define COLOR_YELLOW COLOR_TRUE_YELLOW
#define COLOR_PURPLE RGB_32(0xFF, 0x57, 0xBB)
/* True color defines */
#define COLOR_TRUE_WHITE RGB_32(0xFF, 0xFF, 0xFF)
#define COLOR_TRUE_BLACK RGB_32(0xFF, 0xFF, 0xFF)
#define COLOR_TRUE_RED RGB_32(0xFF, 0xFF, 0xFF)
#define COLOR_TRUE_GREEN RGB_32(0xFF, 0xFF, 0xFF)
#define COLOR_TRUE_BLUE RGB_32(0xFF, 0xFF, 0xFF)
#define COLOR_TRUE_YELLOW RGB_32(0xFF, 0xFF, 0xFF)
#define COLOR_TRUE_PURPLE RGB_32(0xFF, 0xFF, 0XFF)
/* Barrier */ /* Barrier */
#if COMPILER_MSVC #if COMPILER_MSVC

View File

@ -60,7 +60,7 @@
#define SIM_MAX_LINEAR_VELOCITY 500 #define SIM_MAX_LINEAR_VELOCITY 500
#define SIM_MAX_ANGULAR_VELOCITY (TAU * 20) #define SIM_MAX_ANGULAR_VELOCITY (TAU * 20)
#define COLLIDER_DEBUG 0 #define COLLIDER_DEBUG 1
#define COLLIDER_DEBUG_DETAILED 1 #define COLLIDER_DEBUG_DETAILED 1
#define COLLIDER_DEBUG_DETAILED_DRAW_MENKOWSKI 1 #define COLLIDER_DEBUG_DETAILED_DRAW_MENKOWSKI 1

View File

@ -139,10 +139,11 @@ enum sim_control_flag {
/* Testing */ /* Testing */
SIM_CONTROL_FLAG_DRAG = 1 << 1, SIM_CONTROL_FLAG_DRAG = 1 << 1,
SIM_CONTROL_FLAG_CLEAR_ALL = 1 << 2, SIM_CONTROL_FLAG_CLEAR_ALL = 1 << 2,
SIM_CONTROL_FLAG_SPAWN_TEST = 1 << 3, SIM_CONTROL_FLAG_SPAWN1_TEST = 1 << 3,
SIM_CONTROL_FLAG_TILE_TEST = 1 << 4, SIM_CONTROL_FLAG_SPAWN2_TEST = 1 << 4,
SIM_CONTROL_FLAG_EXPLODE_TEST = 1 << 5, SIM_CONTROL_FLAG_TILE_TEST = 1 << 5,
SIM_CONTROL_FLAG_TELEPORT_TEST = 1 << 6, SIM_CONTROL_FLAG_EXPLODE_TEST = 1 << 6,
SIM_CONTROL_FLAG_TELEPORT_TEST = 1 << 7,
}; };
struct sim_control { struct sim_control {

View File

@ -176,54 +176,38 @@ INTERNAL void test_teleport(struct sim_ent *ent, struct v2 pos)
sim_ent_set_xform(ent, xf); sim_ent_set_xform(ent, xf);
} }
INTERNAL void spawn_test_entities(struct sim_step_ctx *ctx, struct v2 offset) INTERNAL void spawn_test_entities1(struct sim_step_ctx *ctx, struct v2 pos)
{ {
struct sim_snapshot *world = ctx->world; struct sim_snapshot *world = ctx->world;
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID); struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
(UNUSED)offset; (UNUSED)pos;
root->mass_unscaled = F32_INFINITY; root->mass_unscaled = F32_INFINITY;
root->inertia_unscaled = F32_INFINITY; root->inertia_unscaled = F32_INFINITY;
#if 0
/* Enemy */
if (ctx->is_master) {
struct sim_ent *e = sim_ent_alloc_sync_src(root);
struct v2 pos = V2(1, -2);
pos = v2_add(pos, offset);
f32 r = 0;
struct v2 size = V2(1, 1);
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
sim_ent_set_xform(e, xf);
e->sprite = sprite_tag_from_path(LIT("res/graphics/tim.ase"));
e->sprite_collider_slice = LIT("shape");
e->layer = SIM_LAYER_SHOULDERS;
sim_ent_enable_prop(e, SEPROP_PHYSICAL_DYNAMIC);
e->mass_unscaled = 100;
e->inertia_unscaled = 10;
e->linear_ground_friction = 250;
e->angular_ground_friction = 200;
}
#endif
/* Enemy */ /* Enemy */
if (ctx->is_master) { if (ctx->is_master) {
struct sim_ent *e = spawn_test_employee(ctx); struct sim_ent *e = spawn_test_employee(ctx);
struct xform xf = sim_ent_get_xform(e); struct xform xf = sim_ent_get_xform(e);
xf.og = offset; xf.og = pos;
sim_ent_set_xform(e, xf); sim_ent_set_xform(e, xf);
} }
}
INTERNAL void spawn_test_entities2(struct sim_step_ctx *ctx, struct v2 pos)
{
struct sim_snapshot *world = ctx->world;
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
(UNUSED)pos;
root->mass_unscaled = F32_INFINITY;
root->inertia_unscaled = F32_INFINITY;
/* Big box */ /* Big box */
#if 0 #if 1
{ {
struct sim_ent *e = sim_ent_alloc_local(root); struct sim_ent *e = sim_ent_alloc_local(root);
struct v2 pos = V2(1, -0.5);
pos = v2_add(pos, offset);
f32 r = 0; f32 r = 0;
struct v2 size = V2(0.5, 0.25); struct v2 size = V2(0.5, 0.25);
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
@ -246,8 +230,6 @@ INTERNAL void spawn_test_entities(struct sim_step_ctx *ctx, struct v2 offset)
{ {
struct sim_ent *e = sim_ent_alloc_sync_src(root); struct sim_ent *e = sim_ent_alloc_sync_src(root);
struct v2 pos = V2(1, -0.5);
pos = v2_add(pos, offset);
f32 r = PI / 4; f32 r = PI / 4;
struct v2 size = V2(0.5, 0.25); struct v2 size = V2(0.5, 0.25);
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
@ -320,7 +302,7 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
struct xform xf = XFORM_TRS(.t = point, .r = rand_f64_from_state(&step_ctx->rand, 0, TAU)); struct xform xf = XFORM_TRS(.t = point, .r = rand_f64_from_state(&step_ctx->rand, 0, TAU));
struct sim_ent *decal = sim_ent_alloc_sync_src(root); struct sim_ent *decal = sim_ent_alloc_sync_src(root);
decal->sprite = sprite_tag_from_path(LIT("res/graphics/blood.ase")); decal->sprite = sprite_tag_from_path(LIT("res/graphics/blood.ase"));
decal->sprite_tint = RGBA_32_F(1, 1, 1, 0.25f); decal->sprite_tint = RGBA_32F(1, 1, 1, 0.25f);
decal->layer = SIM_LAYER_FLOOR_DECALS; decal->layer = SIM_LAYER_FLOOR_DECALS;
sim_ent_set_xform(decal, xf); sim_ent_set_xform(decal, xf);
@ -604,15 +586,27 @@ void sim_step(struct sim_step_ctx *ctx)
test_clear_level(ctx); test_clear_level(ctx);
} }
} }
if (flags & SIM_CONTROL_FLAG_SPAWN_TEST) { if (flags & SIM_CONTROL_FLAG_SPAWN1_TEST) {
if (!(old_control.flags & SIM_CONTROL_FLAG_SPAWN_TEST)) { if (!(old_control.flags & SIM_CONTROL_FLAG_SPAWN1_TEST)) {
logf_info("Spawning (test)"); logf_info("Spawn1 (test)");
u32 count = 1; u32 count = 1;
f32 spread = 0; f32 spread = 0;
for (u32 j = 0; j < count; ++j) { for (u32 j = 0; j < count; ++j) {
struct v2 pos = player->player_cursor_pos; struct v2 pos = player->player_cursor_pos;
pos.y += (((f32)j / (f32)count) - 0.5) * spread; pos.y += (((f32)j / (f32)count) - 0.5) * spread;
spawn_test_entities(ctx, pos); spawn_test_entities1(ctx, pos);
}
}
}
if (flags & SIM_CONTROL_FLAG_SPAWN2_TEST) {
if (!(old_control.flags & SIM_CONTROL_FLAG_SPAWN2_TEST)) {
logf_info("Spawn1 (test)");
u32 count = 1;
f32 spread = 0;
for (u32 j = 0; j < count; ++j) {
struct v2 pos = player->player_cursor_pos;
pos.y += (((f32)j / (f32)count) - 0.5) * spread;
spawn_test_entities2(ctx, pos);
} }
} }
} }

View File

@ -148,7 +148,8 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = {
[SYS_BTN_F] = USER_BIND_KIND_DEBUG_EXPLODE, [SYS_BTN_F] = USER_BIND_KIND_DEBUG_EXPLODE,
[SYS_BTN_T] = USER_BIND_KIND_DEBUG_TELEPORT, [SYS_BTN_T] = USER_BIND_KIND_DEBUG_TELEPORT,
[SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR, [SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR,
[SYS_BTN_V] = USER_BIND_KIND_DEBUG_SPAWN, [SYS_BTN_1] = USER_BIND_KIND_DEBUG_SPAWN1,
[SYS_BTN_2] = USER_BIND_KIND_DEBUG_SPAWN2,
[SYS_BTN_N] = USER_BIND_KIND_DEBUG_STEP, [SYS_BTN_N] = USER_BIND_KIND_DEBUG_STEP,
[SYS_BTN_Q] = USER_BIND_KIND_DEBUG_FOLLOW, [SYS_BTN_Q] = USER_BIND_KIND_DEBUG_FOLLOW,
[SYS_BTN_F1] = USER_BIND_KIND_DEBUG_PAUSE, [SYS_BTN_F1] = USER_BIND_KIND_DEBUG_PAUSE,
@ -319,7 +320,7 @@ INTERNAL void debug_draw_xform(struct xform xf, u32 color_x, u32 color_y)
draw_arrow_ray(G.ui_cmd_buffer, pos, x_ray, thickness, arrowhead_len, color_x); draw_arrow_ray(G.ui_cmd_buffer, pos, x_ray, thickness, arrowhead_len, color_x);
draw_arrow_ray(G.ui_cmd_buffer, pos, y_ray, thickness, arrowhead_len, color_y); draw_arrow_ray(G.ui_cmd_buffer, pos, y_ray, thickness, arrowhead_len, color_y);
//u32 color_quad = RGBA_32_F(0, 1, 1, 0.3); //u32 color_quad = RGBA_32F(0, 1, 1, 0.3);
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1)); //struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f)); //quad = xform_mul_quad(xf, quad_scale(quad, 0.075f));
//draw_quad(G.ui_cmd_buffer, quad, color); //draw_quad(G.ui_cmd_buffer, quad, color);
@ -331,7 +332,7 @@ INTERNAL void debug_draw_movement(struct sim_ent *ent)
f32 thickness = 2.f; f32 thickness = 2.f;
f32 arrow_len = 15.f; f32 arrow_len = 15.f;
u32 color_vel = RGBA_32_F(1, 0.5, 0, 1); u32 color_vel = RGBA_32F(1, 0.5, 0, 1);
struct xform xf = sim_ent_get_xform(ent); struct xform xf = sim_ent_get_xform(ent);
struct v2 velocity = ent->linear_velocity; struct v2 velocity = ent->linear_velocity;
@ -1068,8 +1069,8 @@ INTERNAL void user_update(void)
} }
f32 thickness = 0.01f; f32 thickness = 0.01f;
u32 color_start = RGBA_32_F(1, 0.5, 0, opacity_a); u32 color_start = RGBA_32F(1, 0.5, 0, opacity_a);
u32 color_end = RGBA_32_F(1, 0.8, 0.4, opacity_b); u32 color_end = RGBA_32F(1, 0.8, 0.4, opacity_b);
if (opacity_b > 0.99f) { if (opacity_b > 0.99f) {
draw_circle(G.world_cmd_buffer, b, thickness / 2, color_end, 20); draw_circle(G.world_cmd_buffer, b, thickness / 2, color_end, 20);
@ -1108,8 +1109,8 @@ INTERNAL void user_update(void)
/* Draw xform */ /* Draw xform */
if (!skip_debug_draw_transform) { if (!skip_debug_draw_transform) {
u32 color_x = RGBA_32_F(1, 0, 0, 0.5); u32 color_x = RGBA_32F(1, 0, 0, 0.5);
u32 color_y = RGBA_32_F(0, 1, 0, 0.5); u32 color_y = RGBA_32F(0, 1, 0, 0.5);
debug_draw_xform(xf, color_x, color_y); debug_draw_xform(xf, color_x, color_y);
} }
@ -1117,7 +1118,7 @@ INTERNAL void user_update(void)
if (ent->local_collider.count > 0) { if (ent->local_collider.count > 0) {
struct aabb aabb = collider_aabb_from_collider(&ent->local_collider, xf); struct aabb aabb = collider_aabb_from_collider(&ent->local_collider, xf);
f32 thickness = 1; f32 thickness = 1;
u32 color = RGBA_32_F(1, 0, 1, 0.5); u32 color = RGBA_32F(1, 0, 1, 0.5);
struct quad quad = quad_from_aabb(aabb); struct quad quad = quad_from_aabb(aabb);
quad = xform_mul_quad(G.world_to_ui_xf, quad); quad = xform_mul_quad(G.world_to_ui_xf, quad);
draw_quad_line(G.ui_cmd_buffer, quad, thickness, color); draw_quad_line(G.ui_cmd_buffer, quad, thickness, color);
@ -1131,7 +1132,7 @@ INTERNAL void user_update(void)
start = xform_mul_v2(G.world_to_ui_xf, start); start = xform_mul_v2(G.world_to_ui_xf, start);
struct v2 end = v2_add(xf.og, ent->control.focus); struct v2 end = v2_add(xf.og, ent->control.focus);
end = xform_mul_v2(G.world_to_ui_xf, end); end = xform_mul_v2(G.world_to_ui_xf, end);
draw_arrow_line(G.ui_cmd_buffer, start, end, 3, 10, RGBA_32_F(1, 1, 1, 0.5)); draw_arrow_line(G.ui_cmd_buffer, start, end, 3, 10, RGBA_32F(1, 1, 1, 0.5));
} }
#if 0 #if 0
@ -1139,9 +1140,9 @@ INTERNAL void user_update(void)
if (!sprite_tag_is_nil(ent->sprite)) { if (!sprite_tag_is_nil(ent->sprite)) {
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite); struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
u32 quad_color = RGBA_32_F(1, 0, 0.5, 1); u32 quad_color = RGBA_32F(1, 0, 0.5, 1);
u32 point_color = RGBA_32_F(1, 0, 0, 1); u32 point_color = RGBA_32F(1, 0, 0, 1);
u32 ray_color = RGBA_32_F(1, 0, 0.5, 1); u32 ray_color = RGBA_32F(1, 0, 0.5, 1);
for (u64 i = 0; i < sheet->slice_groups_count; ++i) { for (u64 i = 0; i < sheet->slice_groups_count; ++i) {
struct sprite_sheet_slice_group *group = &sheet->slice_groups[i]; struct sprite_sheet_slice_group *group = &sheet->slice_groups[i];
@ -1176,7 +1177,7 @@ INTERNAL void user_update(void)
/* Draw collider */ /* Draw collider */
if (ent->local_collider.count > 0) { if (ent->local_collider.count > 0) {
struct collider_shape collider = ent->local_collider; struct collider_shape collider = ent->local_collider;
u32 color = RGBA_32_F(1, 1, 0, 0.5); u32 color = RGBA_32F(1, 1, 0, 0.5);
f32 thickness = 2; f32 thickness = 2;
{ {
/* Draw collider using support points */ /* Draw collider using support points */
@ -1227,8 +1228,8 @@ INTERNAL void user_update(void)
/* Draw point */ /* Draw point */
{ {
//u32 color = contact.persisted ? RGBA_32_F(1, 1, 0, 0.50) : RGBA_32_F(1, 0, 0, 0.50); //u32 color = contact.persisted ? RGBA_32F(1, 1, 0, 0.50) : RGBA_32F(1, 0, 0, 0.50);
u32 color = RGBA_32_F(1, 1, 0, 0.50); u32 color = ALPHA_32_F(COLOR_YELLOW, 0.50);
//struct v2 point = xform_mul_v2(e0_xf, contact.p0_local); //struct v2 point = xform_mul_v2(e0_xf, contact.p0_local);
//struct v2 point = contact.p0_initial_world; //struct v2 point = contact.p0_initial_world;
draw_circle(G.ui_cmd_buffer, xform_mul_v2(G.world_to_ui_xf, dbg_pt), radius, color, 10); draw_circle(G.ui_cmd_buffer, xform_mul_v2(G.world_to_ui_xf, dbg_pt), radius, color, 10);
@ -1296,7 +1297,7 @@ INTERNAL void user_update(void)
#if 0 #if 0
{ {
f32 radius = 4; f32 radius = 4;
u32 color = RGBA_32_F(1, 1, 0, 0.5); u32 color = RGBA_32F(1, 1, 0, 0.5);
struct v2 a = xform_mul_v2(G.world_to_ui_xf, data->closest0); struct v2 a = xform_mul_v2(G.world_to_ui_xf, data->closest0);
struct v2 b = xform_mul_v2(G.world_to_ui_xf, data->closest1); struct v2 b = xform_mul_v2(G.world_to_ui_xf, data->closest1);
draw_circle(G.ui_cmd_buffer, a, radius, color, 10); draw_circle(G.ui_cmd_buffer, a, radius, color, 10);
@ -1308,12 +1309,12 @@ INTERNAL void user_update(void)
{ {
f32 thickness = 2; f32 thickness = 2;
f32 radius = 4; f32 radius = 4;
u32 color_line = RGBA_32_F(1, 0, 1, 0.25); u32 color_line = RGBA_32F(1, 0, 1, 0.25);
u32 color_a = RGBA_32_F(1, 0, 0, 0.25); u32 color_a = RGBA_32F(1, 0, 0, 0.25);
u32 color_b = RGBA_32_F(0, 1, 0, 0.25); u32 color_b = RGBA_32F(0, 1, 0, 0.25);
u32 color_line_clipped = RGBA_32_F(1, 0, 1, 1); u32 color_line_clipped = RGBA_32F(1, 0, 1, 1);
u32 color_a_clipped = RGBA_32_F(1, 0, 0, 1); u32 color_a_clipped = RGBA_32F(1, 0, 0, 1);
u32 color_b_clipped = RGBA_32_F(0, 1, 0, 1); u32 color_b_clipped = RGBA_32F(0, 1, 0, 1);
{ {
struct v2 a = xform_mul_v2(G.world_to_ui_xf, collider_res.a0); struct v2 a = xform_mul_v2(G.world_to_ui_xf, collider_res.a0);
struct v2 b = xform_mul_v2(G.world_to_ui_xf, collider_res.b0); struct v2 b = xform_mul_v2(G.world_to_ui_xf, collider_res.b0);
@ -1387,7 +1388,7 @@ INTERNAL void user_update(void)
/* Draw menkowski */ /* Draw menkowski */
{ {
u32 color = collider_res.solved ? RGBA_32_F(0, 0, 0.25, 1) : RGBA_32_F(0, 0.25, 0.25, 1); u32 color = collider_res.solved ? RGBA_32F(0, 0, 0.25, 1) : RGBA_32F(0, 0.25, 0.25, 1);
f32 thickness = 2; f32 thickness = 2;
u32 detail = 512; u32 detail = 512;
(UNUSED)thickness; (UNUSED)thickness;
@ -1401,7 +1402,7 @@ INTERNAL void user_update(void)
/* Draw cloud */ /* Draw cloud */
{ {
u32 color = RGBA_32_F(1, 1, 1, 1); u32 color = RGBA_32F(1, 1, 1, 1);
f32 radius = 2; f32 radius = 2;
struct v2_array m = cloud(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf); struct v2_array m = cloud(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf);
@ -1412,21 +1413,10 @@ INTERNAL void user_update(void)
} }
} }
/* Draw normal */
{
u32 color = COLOR_WHITE;
f32 len = 0.1f;
f32 arrow_thickness = 2;
f32 arrow_height = 5;
struct v2 start = xform_mul_v2(G.world_to_ui_xf, V2(0, 0));
struct v2 end = xform_mul_v2(G.world_to_ui_xf, v2_mul(v2_norm(collider_res.normal), len));
draw_arrow_line(G.ui_cmd_buffer, start, end, arrow_thickness, arrow_height, color);
}
/* Draw prototype */ /* Draw prototype */
{ {
f32 thickness = 2; f32 thickness = 2;
u32 color = RGBA_32_F(1, 1, 1, 0.25); u32 color = RGBA_32F(1, 1, 1, 0.25);
struct v2_array m = { struct v2_array m = {
.points = collider_res.prototype.points, .points = collider_res.prototype.points,
@ -1441,9 +1431,9 @@ INTERNAL void user_update(void)
{ {
f32 thickness = 2; f32 thickness = 2;
u32 line_color = COLOR_YELLOW; u32 line_color = COLOR_YELLOW;
u32 color_first = RGBA_32_F(1, 0, 0, 0.75); u32 color_first = RGBA_32F(1, 0, 0, 0.75);
u32 color_second = RGBA_32_F(0, 1, 0, 0.75); u32 color_second = RGBA_32F(0, 1, 0, 0.75);
u32 color_third = RGBA_32_F(0, 0, 1, 0.75); u32 color_third = RGBA_32F(0, 0, 1, 0.75);
struct collider_menkowski_simplex simplex = collider_res.simplex; struct collider_menkowski_simplex simplex = collider_res.simplex;
struct v2 simplex_points[] = { simplex.a.p, simplex.b.p, simplex.c.p }; struct v2 simplex_points[] = { simplex.a.p, simplex.b.p, simplex.c.p };
@ -1466,6 +1456,17 @@ INTERNAL void user_update(void)
draw_poly_line(G.ui_cmd_buffer, simplex_array, simplex.len > 2, thickness, line_color); draw_poly_line(G.ui_cmd_buffer, simplex_array, simplex.len > 2, thickness, line_color);
} }
} }
/* Draw normal */
{
u32 color = COLOR_WHITE;
f32 len = 0.1f;
f32 arrow_thickness = 4;
f32 arrowhead_height = 10;
struct v2 start = xform_mul_v2(G.world_to_ui_xf, V2(0, 0));
struct v2 end = xform_mul_v2(G.world_to_ui_xf, v2_mul(v2_norm(collider_res.normal), len));
draw_arrow_line(G.ui_cmd_buffer, start, end, arrow_thickness, arrowhead_height, color);
}
} }
#endif #endif
} }
@ -1474,7 +1475,7 @@ INTERNAL void user_update(void)
/* Draw hierarchy */ /* Draw hierarchy */
if (sim_ent_has_prop(parent, SEPROP_ACTIVE) && !parent->is_root) { if (sim_ent_has_prop(parent, SEPROP_ACTIVE) && !parent->is_root) {
u32 color = RGBA_32_F(0.6, 0.6, 1, 0.75); u32 color = RGBA_32F(0.6, 0.6, 1, 0.75);
f32 thickness = 2; f32 thickness = 2;
f32 arrow_height = 15; f32 arrow_height = 15;
@ -1485,7 +1486,7 @@ INTERNAL void user_update(void)
/* Draw camera rect */ /* Draw camera rect */
if (sim_ent_has_prop(ent, SEPROP_CAMERA)) { if (sim_ent_has_prop(ent, SEPROP_CAMERA)) {
u32 color = ent == local_camera ? RGBA_32_F(1, 1, 1, 0.5) : RGBA_32_F(0, 0.75, 0, 0.5); u32 color = ent == local_camera ? RGBA_32F(1, 1, 1, 0.5) : RGBA_32F(0, 0.75, 0, 0.5);
f32 thickness = 3; f32 thickness = 3;
struct xform quad_xf = xform_mul(xf, ent->camera_quad_xform); struct xform quad_xf = xform_mul(xf, ent->camera_quad_xform);
@ -1504,7 +1505,7 @@ INTERNAL void user_update(void)
if (!G.debug_camera) { if (!G.debug_camera) {
__profscope(draw_crosshair); __profscope(draw_crosshair);
struct v2 crosshair_pos = G.ui_cursor; struct v2 crosshair_pos = G.ui_cursor;
u32 tint = RGBA_32_F(1, 1, 1, 1); u32 tint = RGBA_32F(1, 1, 1, 1);
struct sprite_tag crosshair_tag = sprite_tag_from_path(LIT("res/graphics/crosshair.ase")); struct sprite_tag crosshair_tag = sprite_tag_from_path(LIT("res/graphics/crosshair.ase"));
struct sprite_texture *t = sprite_texture_from_tag_async(sprite_frame_scope, crosshair_tag); struct sprite_texture *t = sprite_texture_from_tag_async(sprite_frame_scope, crosshair_tag);
@ -1593,7 +1594,8 @@ INTERNAL void user_update(void)
struct bind_state fire_state = G.bind_states[USER_BIND_KIND_FIRE]; struct bind_state fire_state = G.bind_states[USER_BIND_KIND_FIRE];
struct bind_state drag_state = G.bind_states[USER_BIND_KIND_DEBUG_DRAG]; struct bind_state drag_state = G.bind_states[USER_BIND_KIND_DEBUG_DRAG];
struct bind_state clear_state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR]; struct bind_state clear_state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
struct bind_state spawn_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN]; struct bind_state spawn1_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN1];
struct bind_state spawn2_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN2];
struct bind_state pause_state = G.bind_states[USER_BIND_KIND_DEBUG_PAUSE]; struct bind_state pause_state = G.bind_states[USER_BIND_KIND_DEBUG_PAUSE];
struct bind_state step_state = G.bind_states[USER_BIND_KIND_DEBUG_STEP]; struct bind_state step_state = G.bind_states[USER_BIND_KIND_DEBUG_STEP];
struct bind_state tile_state = G.bind_states[USER_BIND_KIND_TILE_TEST]; struct bind_state tile_state = G.bind_states[USER_BIND_KIND_TILE_TEST];
@ -1609,8 +1611,11 @@ INTERNAL void user_update(void)
if (clear_state.num_presses_and_repeats) { if (clear_state.num_presses_and_repeats) {
control.flags |= SIM_CONTROL_FLAG_CLEAR_ALL; control.flags |= SIM_CONTROL_FLAG_CLEAR_ALL;
} }
if (spawn_state.num_presses_and_repeats) { if (spawn1_state.num_presses_and_repeats) {
control.flags |= SIM_CONTROL_FLAG_SPAWN_TEST; control.flags |= SIM_CONTROL_FLAG_SPAWN1_TEST;
}
if (spawn2_state.num_presses_and_repeats) {
control.flags |= SIM_CONTROL_FLAG_SPAWN2_TEST;
} }
if (tile_state.num_presses_and_repeats) { if (tile_state.num_presses_and_repeats) {
control.flags |= SIM_CONTROL_FLAG_TILE_TEST; control.flags |= SIM_CONTROL_FLAG_TILE_TEST;
@ -1896,10 +1901,10 @@ INTERNAL void user_update(void)
/* Execute render cmds */ /* Execute render cmds */
{ {
/* Clear textures */ /* Clear textures */
renderer_texture_clear(G.world_texture, RGBA_32_F(0.2f, 0.2f, 0.2f, 1.f)); renderer_texture_clear(G.world_texture, RGBA_32F(0.2f, 0.2f, 0.2f, 1.f));
renderer_texture_clear(G.ui_texture, RGBA_32_F(0, 0, 0, 0)); renderer_texture_clear(G.ui_texture, RGBA_32F(0, 0, 0, 0));
renderer_texture_clear(G.final_texture, RGBA_32_F(0, 0, 0, 0)); renderer_texture_clear(G.final_texture, RGBA_32F(0, 0, 0, 0));
renderer_texture_clear(G.backbuffer_texture, RGBA_32_F(0, 0, 0, 1)); renderer_texture_clear(G.backbuffer_texture, RGBA_32F(0, 0, 0, 1));
/* Render to world texture */ /* Render to world texture */
renderer_texture_render(G.world_texture, G.world_cmd_buffer, G.world_to_ui_xf, ui_viewport, sprite_frame_scope); renderer_texture_render(G.world_texture, G.world_cmd_buffer, G.world_to_ui_xf, ui_viewport, sprite_frame_scope);

View File

@ -29,7 +29,8 @@ enum user_bind_kind {
USER_BIND_KIND_TILE_TEST, USER_BIND_KIND_TILE_TEST,
USER_BIND_KIND_DEBUG_CLEAR, USER_BIND_KIND_DEBUG_CLEAR,
USER_BIND_KIND_DEBUG_SPAWN, USER_BIND_KIND_DEBUG_SPAWN1,
USER_BIND_KIND_DEBUG_SPAWN2,
USER_BIND_KIND_DEBUG_FOLLOW, USER_BIND_KIND_DEBUG_FOLLOW,
USER_BIND_KIND_DEBUG_DRAW, USER_BIND_KIND_DEBUG_DRAW,
USER_BIND_KIND_DEBUG_CAMERA, USER_BIND_KIND_DEBUG_CAMERA,