From fc9aff7f068dcef4bbaee9b15d66a54f31ce167e Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 24 Oct 2025 06:46:34 -0500 Subject: [PATCH] persist struct region --- src/base/base.h | 12 +++++++----- src/pp/pp.c | 20 +++----------------- src/pp/pp.h | 24 +++++++++++++++++------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/base/base.h b/src/base/base.h index b53f551e..89e13adc 100644 --- a/src/base/base.h +++ b/src/base/base.h @@ -424,15 +424,17 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); #define IsArray(a) (IsIndexable(a) && (((void *)&a) == ((void *)a))) //- offsetof -#if 0 #if !CompilerIsMsvc -# if !defined _CRT_USE_BUILTIN_OFFSETOF -# define offsetof(type, field) ((u64)&(((type *)0)->field)) -# else +# ifdef _CRT_USE_BUILTIN_OFFSETOF # define offsetof(type, field) __builtin_offsetof(type, field) +# else +# define offsetof(type, field) ((u64)&(((type *)0)->field)) # endif #endif -#endif + +//- struct region +#define StructRegion(name) i8 name +#define CopyStructRegion(dst, src, r0, r1) CopyBytes(&dst->r0, &src->r0, (u8 *)&dst->r1 - (u8 *)&dst->r0) //- Packed #if CompilerIsMsvc diff --git a/src/pp/pp.c b/src/pp/pp.c index 1f4a40d9..78a1fe5b 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -30,9 +30,10 @@ void StartupUser(void) g->local_to_user_client_store = AcquireClientStore(); g->local_to_user_client = AcquireClient(g->local_to_user_client_store); - /* Init from swap */ g->world_to_ui_xf = XformIdentity; g->world_to_render_xf = XformIdentity; + + /* Init from swap */ if (IsSwappingIn()); { TempArena scratch = BeginScratchNoConflict(); @@ -41,22 +42,7 @@ void StartupUser(void) { SwappedUserState *swap = (SwappedUserState *)swap_str.text; SharedUserState *old = &swap->s; - g->debug_following = old->debug_following; - g->debug_camera = old->debug_camera; - g->debug_camera_panning = old->debug_camera_panning; - g->debug_camera_pan_start = old->debug_camera_pan_start; - g->debug_draw = old->debug_draw; - g->screen_size = old->screen_size; - g->screen_cursor = old->screen_cursor; - g->ui_to_screen_xf = old->ui_to_screen_xf; - g->ui_size = old->ui_size; - g->ui_cursor = old->ui_cursor; - g->render_to_ui_xf = old->render_to_ui_xf; - g->render_size = old->render_size; - g->world_to_render_xf = old->world_to_render_xf; - g->world_to_ui_xf = old->world_to_ui_xf; - g->world_cursor = old->world_cursor; - g->focus_send = old->focus_send; + CopyStructRegion(g, old, PERSIST_START, PERSIST_END); } EndScratch(scratch); } diff --git a/src/pp/pp.h b/src/pp/pp.h index 153c6465..32287d1e 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -194,13 +194,6 @@ Struct(SharedUserState) //- Bind state BindState bind_states[BindKind_Count]; - //- Debug camera - EntityId debug_following; - b32 debug_camera; - b32 debug_camera_panning; - Vec2 debug_camera_pan_start; - b32 debug_draw; - //- Debug console Mutex console_logs_mutex; Arena *console_logs_arena; @@ -245,6 +238,18 @@ Struct(SharedUserState) i64 real_dt_ns; i64 real_time_ns; + ////////////////////////////// + //- Persist start + StructRegion(PERSIST_START); + + //- Debug camera + + EntityId debug_following; + b32 debug_camera; + b32 debug_camera_panning; + Vec2 debug_camera_pan_start; + b32 debug_draw; + //- Per frame Vec2I32 screen_size; @@ -262,6 +267,11 @@ Struct(SharedUserState) Vec2 world_cursor; Vec2 focus_send; + + StructRegion(PERSIST_END); + //- Persist end + ////////////////////////////// + } extern shared_user_state; ////////////////////////////////////////////////////////////