persist struct region

This commit is contained in:
jacob 2025-10-24 06:46:34 -05:00
parent a8bc77fab3
commit fc9aff7f06
3 changed files with 27 additions and 29 deletions

View File

@ -424,15 +424,17 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define IsArray(a) (IsIndexable(a) && (((void *)&a) == ((void *)a))) #define IsArray(a) (IsIndexable(a) && (((void *)&a) == ((void *)a)))
//- offsetof //- offsetof
#if 0
#if !CompilerIsMsvc #if !CompilerIsMsvc
# if !defined _CRT_USE_BUILTIN_OFFSETOF # ifdef _CRT_USE_BUILTIN_OFFSETOF
# define offsetof(type, field) ((u64)&(((type *)0)->field))
# else
# define offsetof(type, field) __builtin_offsetof(type, field) # define offsetof(type, field) __builtin_offsetof(type, field)
# else
# define offsetof(type, field) ((u64)&(((type *)0)->field))
# endif # endif
#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 //- Packed
#if CompilerIsMsvc #if CompilerIsMsvc

View File

@ -30,9 +30,10 @@ void StartupUser(void)
g->local_to_user_client_store = AcquireClientStore(); g->local_to_user_client_store = AcquireClientStore();
g->local_to_user_client = AcquireClient(g->local_to_user_client_store); g->local_to_user_client = AcquireClient(g->local_to_user_client_store);
/* Init from swap */
g->world_to_ui_xf = XformIdentity; g->world_to_ui_xf = XformIdentity;
g->world_to_render_xf = XformIdentity; g->world_to_render_xf = XformIdentity;
/* Init from swap */
if (IsSwappingIn()); if (IsSwappingIn());
{ {
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
@ -41,22 +42,7 @@ void StartupUser(void)
{ {
SwappedUserState *swap = (SwappedUserState *)swap_str.text; SwappedUserState *swap = (SwappedUserState *)swap_str.text;
SharedUserState *old = &swap->s; SharedUserState *old = &swap->s;
g->debug_following = old->debug_following; CopyStructRegion(g, old, PERSIST_START, PERSIST_END);
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;
} }
EndScratch(scratch); EndScratch(scratch);
} }

View File

@ -194,13 +194,6 @@ Struct(SharedUserState)
//- Bind state //- Bind state
BindState bind_states[BindKind_Count]; 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 //- Debug console
Mutex console_logs_mutex; Mutex console_logs_mutex;
Arena *console_logs_arena; Arena *console_logs_arena;
@ -245,6 +238,18 @@ Struct(SharedUserState)
i64 real_dt_ns; i64 real_dt_ns;
i64 real_time_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 //- Per frame
Vec2I32 screen_size; Vec2I32 screen_size;
@ -262,6 +267,11 @@ Struct(SharedUserState)
Vec2 world_cursor; Vec2 world_cursor;
Vec2 focus_send; Vec2 focus_send;
StructRegion(PERSIST_END);
//- Persist end
//////////////////////////////
} extern shared_user_state; } extern shared_user_state;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////