From eb1a4cd64682b00f6b709879974cbc8538fc0541 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 13 Nov 2025 20:14:31 -0600 Subject: [PATCH] zero held buttons when window loses focus --- src/proto/pp_sim/pp_sim_core.c | 33 ++++++++++++++++++++++------ src/proto/pp_sim/pp_sim_core.h | 11 +++++++--- src/proto/pp_vis/pp_vis_core.c | 39 ++++++++++++++++------------------ 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/proto/pp_sim/pp_sim_core.c b/src/proto/pp_sim/pp_sim_core.c index d0314807..42a1698d 100644 --- a/src/proto/pp_sim/pp_sim_core.c +++ b/src/proto/pp_sim/pp_sim_core.c @@ -1,8 +1,8 @@ S_SharedState S_shared_state = ZI; Readonly S_Ent S_nil_ent = { - .local_to_parent_xf = CompXformIdentity, - .final_local_to_world_xf = CompXformIdentity, + .local_xf = CompXformIdentity, + .final_xf = CompXformIdentity, .tint = { 0.5, 0.5, 0.5, 1 }, }; @@ -77,7 +77,7 @@ S_Shape S_MulXformShape(Xform xf, S_Shape shape) S_Shape result = shape; for (i32 i = 0; i < shape.points_count; ++i) { - shape.points[i] = MulXformV2(xf, shape.points[i]); + result.points[i] = MulXformV2(xf, shape.points[i]); } Vec2 scale = ScaleFromXform(xf); result.radius *= MaxF32(scale.x, scale.y); @@ -366,11 +366,12 @@ JobDef(S_SimWorker, _, __) ++world->ents_count; } *dst = *src; + dst->shape.points_count = MaxI32(dst->shape.points_count, 1); + dst->active = 1; } - - LogInfoF("RAAAH %F", FmtSint(world->ents_count)); } + LogInfoF("Received spawn cmd containing %F ents. New count: %F", FmtSint(cmd.ents.count), FmtSint(world->ents_count)); } } lookup = S_LookupFromWorld(frame_arena, world); @@ -460,17 +461,35 @@ JobDef(S_SimWorker, _, __) { if (!S_IsKeyNil(ent->camera)) { - ent->local_to_parent_xf.og.x += 1; + Xform xf = ent->local_xf; + xf = RotateXform(xf, 0.1); + xf.og.x += 1; + xf.og.y += 1; + ent->local_xf = xf; } } + ////////////////////////////// + //- Compute shape centers + + for (S_Ent *ent = S_FirstEnt(frame_arena, &iter, &lookup); !S_IsEntNil(ent); ent = S_NextEnt(frame_arena, &iter)) + { + S_Shape shape = ent->shape; + Vec2 accum = ZI; + for (i32 p_idx = 0; p_idx < shape.points_count; ++p_idx) + { + accum = AddVec2(accum, shape.points[p_idx]); + } + ent->center = DivVec2(accum, shape.points_count); + } + ////////////////////////////// //- Compute final world transforms for (S_Ent *ent = S_FirstEnt(frame_arena, &iter, &lookup); !S_IsEntNil(ent); ent = S_NextEnt(frame_arena, &iter)) { S_Ent *parent = S_EntFromKey(&lookup, ent->parent); - ent->final_local_to_world_xf = MulXform(parent->final_local_to_world_xf, ent->local_to_parent_xf); + ent->final_xf = MulXform(parent->final_xf, ent->local_xf); } ////////////////////////////// diff --git a/src/proto/pp_sim/pp_sim_core.h b/src/proto/pp_sim/pp_sim_core.h index bddb2959..922a7688 100644 --- a/src/proto/pp_sim/pp_sim_core.h +++ b/src/proto/pp_sim/pp_sim_core.h @@ -50,13 +50,18 @@ Struct(S_Ent) S_Key follow; S_Key camera; - S_Shape local_shape; - Xform local_to_parent_xf; + S_Shape shape; + Xform local_xf; + + ////////////////////////////// + //- Pre-solve data + + Vec2 center; ////////////////////////////// //- Post-solve data - Xform final_local_to_world_xf; + Xform final_xf; ////////////////////////////// //- Internal sim data diff --git a/src/proto/pp_vis/pp_vis_core.c b/src/proto/pp_vis/pp_vis_core.c index cdf94758..05edfd41 100644 --- a/src/proto/pp_vis/pp_vis_core.c +++ b/src/proto/pp_vis/pp_vis_core.c @@ -48,13 +48,9 @@ void V_PushTestEnts(Arena *arena, S_EntList *list) ent->key = player_key; ent->camera = camera_key; { - S_Shape *shape = &ent->local_shape; - shape->points_count = 4; - shape->points[0] = VEC2(100, 100); - shape->points[1] = VEC2(200, 100); - shape->points[2] = VEC2(200, 200); - shape->points[3] = VEC2(100, 200); - shape->radius = 0; + S_Shape *shape = &ent->shape; + shape->points_count = 1; + shape->radius = 50; } } break; @@ -65,14 +61,13 @@ void V_PushTestEnts(Arena *arena, S_EntList *list) ent->key = child_key; ent->parent = player_key; { - S_Shape *shape = &ent->local_shape; - shape->points_count = 1; - shape->points[0] = VEC2(100, 100); - // shape->points[1] = VEC2(200, 100); - // shape->points[2] = VEC2(150, 200); - // shape->points[3] = VEC2(125, 200); - shape->radius = 20; - // ent->local_to_parent_xf = XformFromPos(VEC2(500, 500)); + S_Shape *shape = &ent->shape; + shape->points_count = 4; + shape->points[0] = VEC2(-15, -15); + shape->points[1] = VEC2(15, -15); + shape->points[2] = VEC2(15, 15); + shape->points[3] = VEC2(-15, 15); + shape->radius = 0; } } break; @@ -259,6 +254,10 @@ JobDef(V_VisWorker, _, __) V_CmdNode *first_cmd_node = 0; V_CmdNode *last_cmd_node = 0; + if (!window_frame.has_focus) + { + ZeroStructs(held_buttons, countof(held_buttons)); + } for (u64 i = 0; i < window_frame.controller_events.count; ++i) { ControllerEvent cev = window_frame.controller_events.events[i]; @@ -392,9 +391,7 @@ JobDef(V_VisWorker, _, __) case V_CmdKind_spawn: { - S_EntListNode *n = PushStruct(frame_arena, S_EntListNode); - ++spawn_ents.count; - SllQueuePush(spawn_ents.first, spawn_ents.last, n); + V_PushTestEnts(frame_arena, &spawn_ents); } break; } } @@ -441,10 +438,10 @@ JobDef(V_VisWorker, _, __) b32 is_visible = ent->tint.w != 0; if (is_visible) { - Xform xf = ent->final_local_to_world_xf; - S_Shape shape = S_MulXformShape(ent->final_local_to_world_xf, ent->local_shape); + Xform xf = ent->final_xf; + S_Shape shape = S_MulXformShape(ent->final_xf, ent->shape); Vec4 color = ent->tint; - V_DrawShape(dverts_arena, dvert_idx_arena, shape, LinearFromSrgb(color), 16, V_DrawFlag_Line); + V_DrawShape(dverts_arena, dvert_idx_arena, shape, LinearFromSrgb(color), 32, V_DrawFlag_Line); } }