From 110e28119c18e1e608bb83b6d22fc62bb0ae8e72 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 9 Feb 2025 15:36:46 -0600 Subject: [PATCH] fix dbg drag local point --- src/sim.c | 14 +++++++++++--- src/sim.h | 1 + src/user.c | 31 ++++++++++++++----------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/sim.c b/src/sim.c index b73db5bd..16217c81 100644 --- a/src/sim.c +++ b/src/sim.c @@ -393,6 +393,12 @@ void sim_update(struct sim_ctx *ctx, i64 target_dt_ns) { __prof; + { + __profscope(sim_update_sleep); + sleep_frame(ctx->last_tick_ns, target_dt_ns); + ctx->last_tick_ns = sys_time_ns(); + } + struct temp_arena scratch = scratch_begin_no_conflict(); /* ========================== * @@ -542,8 +548,8 @@ void sim_update(struct sim_ctx *ctx, i64 target_dt_ns) struct sim_control *control = &client->control; client->dbg_drag_start = false; - client->dbg_drag_stop = false; + client->dbg_drag_stop = false; for (struct sim_cmd *cmd = cmds.first; cmd; cmd = cmd->next) { enum sim_cmd_kind kind = cmd->kind; b32 start = cmd->state == SIM_CMD_STATE_START; @@ -1087,7 +1093,7 @@ void sim_update(struct sim_ctx *ctx, i64 target_dt_ns) if (sim_ent_is_valid_and_active(target_ent)) { if (!sim_ent_is_valid_and_active(joint_ent)) { - /* FIXME: Joint ent never released */ + /* FIXME: Joint ent may never release */ joint_ent = sim_ent_alloc(root); joint_ent->mass_unscaled = F32_INFINITY; joint_ent->inertia_unscaled = F32_INFINITY; @@ -1100,7 +1106,9 @@ void sim_update(struct sim_ctx *ctx, i64 target_dt_ns) struct phys_mouse_joint_def def = ZI; def.target = target_ent->handle; - if (!sim_ent_handle_eq(joint_ent->mouse_joint_data.target, target_ent->handle)) { + if (sim_ent_handle_eq(joint_ent->mouse_joint_data.target, target_ent->handle)) { + def.point_local_start = joint_ent->mouse_joint_data.point_local_start; + } else { def.point_local_start = xform_invert_mul_v2(xf, cursor); } def.point_local_end = xform_invert_mul_v2(xf, cursor); diff --git a/src/sim.h b/src/sim.h index 8e172635..1594cb79 100644 --- a/src/sim.h +++ b/src/sim.h @@ -21,6 +21,7 @@ struct host_startup_receipt; struct sim_ctx { struct arena arena; + i64 last_tick_ns; u64 last_phys_iteration; struct sprite_scope *sprite_frame_scope; diff --git a/src/user.c b/src/user.c index d2184b8e..475e85e4 100644 --- a/src/user.c +++ b/src/user.c @@ -129,29 +129,13 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = { #endif }; -/* ========================== * - * Sim thread - * ========================== */ - -INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_sim_thread_entry_point, arg) -{ - struct sim_ctx *ctx = (struct sim_ctx *)arg; - i64 last_frame_ns = 0; - i64 target_dt_ns = NS_FROM_SECONDS(1) / SIM_FPS;; - while (!atomic_i32_eval(&G.sim_thread_shutdown)) { - __profscope(sim_update_w_sleep); - sleep_frame(last_frame_ns, target_dt_ns); - last_frame_ns = sys_time_ns(); - sim_update(ctx, target_dt_ns); - } -} - /* ========================== * * Startup * ========================== */ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(user_shutdown); INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_thread_entry_point, arg); +INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_sim_thread_entry_point, arg); INTERNAL SYS_WINDOW_EVENT_CALLBACK_FUNC_DEF(window_event_callback, event); struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr, @@ -1862,3 +1846,16 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_thread_entry_point, arg) user_update(); } } + +/* ========================== * + * Sim thread entry point + * ========================== */ + +INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_sim_thread_entry_point, arg) +{ + struct sim_ctx *ctx = (struct sim_ctx *)arg; + i64 target_dt_ns = NS_FROM_SECONDS(1) / SIM_FPS;; + while (!atomic_i32_eval(&G.sim_thread_shutdown)) { + sim_update(ctx, target_dt_ns); + } +}