user layer refactor

This commit is contained in:
jacob 2025-08-01 01:15:48 -05:00
parent d93bed029e
commit db5db23426
3 changed files with 1209 additions and 1115 deletions

View File

@ -247,7 +247,7 @@ void P_AppStartup(String args_str)
/* Interface systems */ /* Interface systems */
PB_StartupReceipt playback_sr = PB_Startup(&mixer_sr); PB_StartupReceipt playback_sr = PB_Startup(&mixer_sr);
struct user_startup_receipt user_sr = user_startup(&font_sr, &sprite_sr, &draw_sr, &asset_cache_sr, &sound_sr, &mixer_sr, &sim_sr, connect_address); UserStartupReceipt user_sr = StartupUser(&font_sr, &sprite_sr, &draw_sr, &asset_cache_sr, &sound_sr, &mixer_sr, &sim_sr, connect_address);
(UNUSED)user_sr; (UNUSED)user_sr;
(UNUSED)playback_sr; (UNUSED)playback_sr;

File diff suppressed because it is too large Load Diff

View File

@ -1,153 +1,147 @@
enum user_bind_kind { ////////////////////////////////
USER_BIND_KIND_NONE, //~ Binds
USER_BIND_KIND_MOVE_UP, //- Bind kinds
USER_BIND_KIND_MOVE_DOWN, typedef i32 BindKind; enum
USER_BIND_KIND_MOVE_LEFT, {
USER_BIND_KIND_MOVE_RIGHT, BindKind_None,
USER_BIND_KIND_WALK,
USER_BIND_KIND_FIRE,
USER_BIND_KIND_FIRE_ALT,
/* Testing */ BindKind_MoveUp,
BindKind_MoveDown,
BindKind_MoveLeft,
BindKind_MoveRight,
BindKind_Walk,
BindKind_Fire,
BindKind_AltFire,
USER_BIND_KIND_TILE_TEST, BindKind_TestTile,
BindKind_DebugClear,
USER_BIND_KIND_DEBUG_CLEAR, BindKind_DebugSpawn1,
USER_BIND_KIND_DEBUG_SPAWN1, BindKind_DebugSpawn2,
USER_BIND_KIND_DEBUG_SPAWN2, BindKind_DebugSpawn3,
USER_BIND_KIND_DEBUG_SPAWN3, BindKind_DebugSpawn4,
USER_BIND_KIND_DEBUG_SPAWN4, BindKind_DebugWalls,
USER_BIND_KIND_DEBUG_WALLS, BindKind_DebugFollow,
USER_BIND_KIND_DEBUG_FOLLOW, BindKind_DebugDraw,
USER_BIND_KIND_DEBUG_DRAW, BindKind_DebugConsole,
USER_BIND_KIND_DEBUG_CONSOLE, BindKind_DebugCamera,
USER_BIND_KIND_DEBUG_CAMERA, BindKind_DebugPause,
USER_BIND_KIND_DEBUG_PAUSE, BindKind_DebugStep,
USER_BIND_KIND_DEBUG_STEP, BindKind_DebugDrag,
USER_BIND_KIND_DEBUG_DRAG, BindKind_DebugDelete,
USER_BIND_KIND_DEBUG_DELETE, BindKind_DebugTeleport,
USER_BIND_KIND_DEBUG_TELEPORT, BindKind_DebugExplode,
USER_BIND_KIND_DEBUG_EXPLODE, BindKind_DebugToggleTopmost,
USER_BIND_KIND_DEBUG_TOGGLE_TOPMOST, BindKind_FullscreenMod,
USER_BIND_KIND_FULLSCREEN_MOD, BindKind_Fullscreen,
USER_BIND_KIND_FULLSCREEN, BindKind_ZoomIn,
USER_BIND_KIND_ZOOM_IN, BindKind_ZoomOut,
USER_BIND_KIND_ZOOM_OUT, BindKind_Pan,
USER_BIND_KIND_PAN,
#if RtcIsEnabled #if RtcIsEnabled
/* Debug */ /* Debug */
USER_BIND_KIND_RESET_DEBUG_STEPS, BindKind_ResetDebugSteps,
USER_BIND_KIND_INCR_DEBUG_STEPS, BindKind_IncrementDebugSteps,
USER_BIND_KIND_DECR_DEBUG_STEPS, BindKind_DecrementDebugSteps,
#endif #endif
USER_BIND_KIND_COUNT BindKind_Count
}; };
struct user_startup_receipt { i32 _; }; //- Test bindings
/* TODO: Remove this */
Global Readonly BindKind g_binds[P_Btn_Count] = {
[P_Btn_W] = BindKind_MoveUp,
[P_Btn_S] = BindKind_MoveDown,
[P_Btn_A] = BindKind_MoveLeft,
[P_Btn_D] = BindKind_MoveRight,
[P_Btn_M1] = BindKind_Fire,
[P_Btn_M2] = BindKind_AltFire,
#if 0
[P_Btn_Alt] = BindKind_Walk,
#endif
/* Testing */
[P_Btn_Z] = BindKind_TestTile,
[P_Btn_M5] = BindKind_DebugDrag,
[P_Btn_M4] = BindKind_DebugDelete,
[P_Btn_F] = BindKind_DebugExplode,
[P_Btn_T] = BindKind_DebugTeleport,
[P_Btn_C] = BindKind_DebugClear,
[P_Btn_1] = BindKind_DebugSpawn1,
[P_Btn_2] = BindKind_DebugSpawn2,
[P_Btn_3] = BindKind_DebugSpawn3,
[P_Btn_4] = BindKind_DebugSpawn4,
[P_Btn_G] = BindKind_DebugWalls,
[P_Btn_N] = BindKind_DebugStep,
[P_Btn_Q] = BindKind_DebugFollow,
[P_Btn_F1] = BindKind_DebugPause,
[P_Btn_F2] = BindKind_DebugCamera,
[P_Btn_F3] = BindKind_DebugDraw,
[P_Btn_F4] = BindKind_DebugToggleTopmost,
[P_Btn_GraveAccent] = BindKind_DebugConsole,
[P_Btn_Alt] = BindKind_FullscreenMod,
[P_Btn_Enter] = BindKind_Fullscreen,
[P_Btn_MWheelUp] = BindKind_ZoomIn,
[P_Btn_MWheelDown] = BindKind_ZoomOut,
[P_Btn_M3] = BindKind_Pan,
#if RtcIsEnabled
[P_Btn_ForwardSlash] = BindKind_ResetDebugSteps,
[P_Btn_Comma] = BindKind_DecrementDebugSteps,
[P_Btn_Period] = BindKind_IncrementDebugSteps
#endif
};
////////////////////////////////
//~ Stats
Struct(SecondsStat)
{
u64 last_second_start;
u64 last_second_end;
u64 last_second;
};
////////////////////////////////
//~ Console log
Struct(ConsoleLog)
{
String msg;
i32 level;
i32 color_index;
P_DateTime datetime;
i64 time_ns;
Rect bounds;
ConsoleLog *prev;
ConsoleLog *next;
};
////////////////////////////////
//~ Sim decode queue
Struct(DecodeQueueNode)
{
Client *client;
u64 tick;
u64 base_tick;
String tmp_encoded;
DecodeQueueNode *next;
};
Struct(DecodeQueue)
{
DecodeQueueNode *first;
DecodeQueueNode *last;
};
////////////////////////////////
//~ Shared state
Struct(BindState)
struct bind_state
{ {
b32 is_held; /* Is this bind held down this frame */ b32 is_held; /* Is this bind held down this frame */
u32 num_presses; /* How many times was this bind's pressed since last frame */ u32 num_presses; /* How many times was this bind's pressed since last frame */
@ -156,62 +150,7 @@ struct bind_state
u32 num_releases; /* How many times was this bind released since last frame */ u32 num_releases; /* How many times was this bind released since last frame */
}; };
struct second_stat Struct(SharedUserState)
{
u64 last_second_start;
u64 last_second_end;
u64 last_second;
};
struct console_log
{
String msg;
i32 level;
i32 color_index;
P_DateTime datetime;
i64 time_ns;
Rect bounds;
struct console_log *prev;
struct console_log *next;
};
struct sim_ss_decode_node
{
Client *client;
u64 tick;
u64 base_tick;
String tmp_encoded;
struct sim_ss_decode_node *next;
};
struct sim_decode_queue
{
struct sim_ss_decode_node *first;
struct sim_ss_decode_node *last;
};
Global struct
{ {
Atomic32 shutdown; Atomic32 shutdown;
P_Counter shutdown_job_counters; P_Counter shutdown_job_counters;
@ -230,13 +169,13 @@ Global struct
/* Usage stats */ /* Usage stats */
i64 last_second_reset_ns; i64 last_second_reset_ns;
struct second_stat net_bytes_read; SecondsStat net_bytes_read;
struct second_stat net_bytes_sent; SecondsStat net_bytes_sent;
/* Gpu resources */ /* Gpu resources */
GPU_RenderSig *render_sig; GPU_RenderSig *render_sig;
struct bind_state bind_states[USER_BIND_KIND_COUNT]; BindState bind_states[BindKind_Count];
/* Debug camera */ /* Debug camera */
EntityId debug_following; EntityId debug_following;
@ -248,8 +187,8 @@ Global struct
/* Debug console */ /* Debug console */
P_Mutex console_logs_mutex; P_Mutex console_logs_mutex;
Arena *console_logs_arena; Arena *console_logs_arena;
struct console_log *first_console_log; ConsoleLog *first_console_log;
struct console_log *last_console_log; ConsoleLog *last_console_log;
i32 console_log_color_indices[P_LogLevel_Count]; i32 console_log_color_indices[P_LogLevel_Count];
f32 console_logs_height; f32 console_logs_height;
b32 debug_console; b32 debug_console;
@ -306,136 +245,58 @@ Global struct
Vec2 world_cursor; Vec2 world_cursor;
Vec2 focus_send; Vec2 focus_send;
} G = ZI, DebugAlias(G, G_user);
/* ========================== *
* Bind state
* ========================== */
/* TODO: Remove this */
Global Readonly enum user_bind_kind g_binds[P_Btn_Count] = {
[P_Btn_W] = USER_BIND_KIND_MOVE_UP,
[P_Btn_S] = USER_BIND_KIND_MOVE_DOWN,
[P_Btn_A] = USER_BIND_KIND_MOVE_LEFT,
[P_Btn_D] = USER_BIND_KIND_MOVE_RIGHT,
//[P_Btn_Alt] = USER_BIND_KIND_WALK,
[P_Btn_M1] = USER_BIND_KIND_FIRE,
[P_Btn_M2] = USER_BIND_KIND_FIRE_ALT,
/* Testing */
[P_Btn_Z] = USER_BIND_KIND_TILE_TEST,
[P_Btn_M5] = USER_BIND_KIND_DEBUG_DRAG,
[P_Btn_M4] = USER_BIND_KIND_DEBUG_DELETE,
[P_Btn_F] = USER_BIND_KIND_DEBUG_EXPLODE,
[P_Btn_T] = USER_BIND_KIND_DEBUG_TELEPORT,
[P_Btn_C] = USER_BIND_KIND_DEBUG_CLEAR,
[P_Btn_1] = USER_BIND_KIND_DEBUG_SPAWN1,
[P_Btn_2] = USER_BIND_KIND_DEBUG_SPAWN2,
[P_Btn_3] = USER_BIND_KIND_DEBUG_SPAWN3,
[P_Btn_4] = USER_BIND_KIND_DEBUG_SPAWN4,
[P_Btn_G] = USER_BIND_KIND_DEBUG_WALLS,
[P_Btn_N] = USER_BIND_KIND_DEBUG_STEP,
[P_Btn_Q] = USER_BIND_KIND_DEBUG_FOLLOW,
[P_Btn_F1] = USER_BIND_KIND_DEBUG_PAUSE,
[P_Btn_F2] = USER_BIND_KIND_DEBUG_CAMERA,
[P_Btn_F3] = USER_BIND_KIND_DEBUG_DRAW,
[P_Btn_F4] = USER_BIND_KIND_DEBUG_TOGGLE_TOPMOST,
[P_Btn_GraveAccent] = USER_BIND_KIND_DEBUG_CONSOLE,
[P_Btn_Alt] = USER_BIND_KIND_FULLSCREEN_MOD,
[P_Btn_Enter] = USER_BIND_KIND_FULLSCREEN,
[P_Btn_MWheelUp] = USER_BIND_KIND_ZOOM_IN,
[P_Btn_MWheelDown] = USER_BIND_KIND_ZOOM_OUT,
[P_Btn_M3] = USER_BIND_KIND_PAN,
#if RtcIsEnabled
/* Debug */
[P_Btn_ForwardSlash] = USER_BIND_KIND_RESET_DEBUG_STEPS,
[P_Btn_Comma] = USER_BIND_KIND_DECR_DEBUG_STEPS,
[P_Btn_Period] = USER_BIND_KIND_INCR_DEBUG_STEPS
#endif
}; };
/* ========================== * extern SharedUserState shared_user_state;
* Startup
* ========================== */
struct user_startup_receipt user_startup(F_StartupReceipt *font_sr, ////////////////////////////////
S_StartupReceipt *sprite_sr, //~ Startup
D_StartupReceipt *draw_sr,
AC_StartupReceipt *asset_cache_sr,
SND_StartupReceipt *sound_sr,
MIX_StartupReceipt *mixer_sr,
SimStartupReceipt *sim_sr,
String connect_address_str)
internal P_ExitFuncDef(user_shutdown) Struct(UserStartupReceipt) { i32 _; };
UserStartupReceipt StartupUser(F_StartupReceipt *font_sr,
S_StartupReceipt *sprite_sr,
D_StartupReceipt *draw_sr,
AC_StartupReceipt *asset_cache_sr,
SND_StartupReceipt *sound_sr,
MIX_StartupReceipt *mixer_sr,
SimStartupReceipt *sim_sr,
String connect_address_str);
/* ========================== * ////////////////////////////////
* Debug draw //~ Shutdown
* ========================== */
/* TODO: remove this (testing) */ P_ExitFuncDef(ShutdownUser);
internal void debug_draw_xform(Xform xf, u32 color_x, u32 color_y)
internal void debug_draw_movement(Entity *ent) ////////////////////////////////
//~ Debug draw operations
internal String get_ent_debug_text(Arena *arena, Entity *ent) void DebugDrawXform(Xform xf, u32 color_x, u32 color_y);
void DebugDrawMovement(Entity *ent);
String DebugStringFromEntity(Arena *arena, Entity *ent);
/* ========================== * ////////////////////////////////
* Debug console //~ Console draw operations
* ========================== */
internal P_LogEventCallbackFuncDef(debug_console_log_callback, log) P_LogEventCallbackFuncDef(ConsoleLogCallback, log);
void DebugDrawConsole(i32 level, b32 minimized);
internal void draw_debug_console(i32 level, b32 minimized) ////////////////////////////////
//~ Entity sortign
/* ========================== * MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _);
* Sort entities
* ========================== */
internal MergesortCompareFuncDef(ent_draw_order_cmp, arg_a, arg_b, _) ////////////////////////////////
//~ User update
/* ========================== * void UpdateUser(P_Window *window);
* Update P_JobDef(UpdateUserJob, _);
* ========================== */
internal void user_update(P_Window *window) ////////////////////////////////
//~ User input cmds
internal P_JobDef(user_update_job, _) void GenerateuserInputCmds(Client *user_input_client, u64 tick);
////////////////////////////////
//~ Sim update
P_JobDef(SimJob, _);
/* ========================== *
* Local sim thread
* ========================== */
internal void generate_user_input_cmds(Client *user_input_client, u64 tick)
internal P_JobDef(local_sim_job, _)