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 */
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)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,
USER_BIND_KIND_MOVE_DOWN,
USER_BIND_KIND_MOVE_LEFT,
USER_BIND_KIND_MOVE_RIGHT,
USER_BIND_KIND_WALK,
USER_BIND_KIND_FIRE,
USER_BIND_KIND_FIRE_ALT,
//- Bind kinds
typedef i32 BindKind; enum
{
BindKind_None,
/* Testing */
BindKind_MoveUp,
BindKind_MoveDown,
BindKind_MoveLeft,
BindKind_MoveRight,
BindKind_Walk,
BindKind_Fire,
BindKind_AltFire,
USER_BIND_KIND_TILE_TEST,
USER_BIND_KIND_DEBUG_CLEAR,
USER_BIND_KIND_DEBUG_SPAWN1,
USER_BIND_KIND_DEBUG_SPAWN2,
USER_BIND_KIND_DEBUG_SPAWN3,
USER_BIND_KIND_DEBUG_SPAWN4,
USER_BIND_KIND_DEBUG_WALLS,
USER_BIND_KIND_DEBUG_FOLLOW,
USER_BIND_KIND_DEBUG_DRAW,
USER_BIND_KIND_DEBUG_CONSOLE,
USER_BIND_KIND_DEBUG_CAMERA,
USER_BIND_KIND_DEBUG_PAUSE,
USER_BIND_KIND_DEBUG_STEP,
USER_BIND_KIND_DEBUG_DRAG,
USER_BIND_KIND_DEBUG_DELETE,
USER_BIND_KIND_DEBUG_TELEPORT,
USER_BIND_KIND_DEBUG_EXPLODE,
USER_BIND_KIND_DEBUG_TOGGLE_TOPMOST,
USER_BIND_KIND_FULLSCREEN_MOD,
USER_BIND_KIND_FULLSCREEN,
USER_BIND_KIND_ZOOM_IN,
USER_BIND_KIND_ZOOM_OUT,
USER_BIND_KIND_PAN,
BindKind_TestTile,
BindKind_DebugClear,
BindKind_DebugSpawn1,
BindKind_DebugSpawn2,
BindKind_DebugSpawn3,
BindKind_DebugSpawn4,
BindKind_DebugWalls,
BindKind_DebugFollow,
BindKind_DebugDraw,
BindKind_DebugConsole,
BindKind_DebugCamera,
BindKind_DebugPause,
BindKind_DebugStep,
BindKind_DebugDrag,
BindKind_DebugDelete,
BindKind_DebugTeleport,
BindKind_DebugExplode,
BindKind_DebugToggleTopmost,
BindKind_FullscreenMod,
BindKind_Fullscreen,
BindKind_ZoomIn,
BindKind_ZoomOut,
BindKind_Pan,
#if RtcIsEnabled
/* Debug */
USER_BIND_KIND_RESET_DEBUG_STEPS,
USER_BIND_KIND_INCR_DEBUG_STEPS,
USER_BIND_KIND_DECR_DEBUG_STEPS,
BindKind_ResetDebugSteps,
BindKind_IncrementDebugSteps,
BindKind_DecrementDebugSteps,
#endif
USER_BIND_KIND_COUNT
BindKind_Count
};
struct user_startup_receipt { i32 _; };
struct bind_state
//- 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)
{
b32 is_held; /* Is this bind held down this 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 */
};
struct second_stat
{
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
Struct(SharedUserState)
{
Atomic32 shutdown;
P_Counter shutdown_job_counters;
@ -230,13 +169,13 @@ Global struct
/* Usage stats */
i64 last_second_reset_ns;
struct second_stat net_bytes_read;
struct second_stat net_bytes_sent;
SecondsStat net_bytes_read;
SecondsStat net_bytes_sent;
/* Gpu resources */
GPU_RenderSig *render_sig;
struct bind_state bind_states[USER_BIND_KIND_COUNT];
BindState bind_states[BindKind_Count];
/* Debug camera */
EntityId debug_following;
@ -248,8 +187,8 @@ Global struct
/* Debug console */
P_Mutex console_logs_mutex;
Arena *console_logs_arena;
struct console_log *first_console_log;
struct console_log *last_console_log;
ConsoleLog *first_console_log;
ConsoleLog *last_console_log;
i32 console_log_color_indices[P_LogLevel_Count];
f32 console_logs_height;
b32 debug_console;
@ -306,136 +245,58 @@ Global struct
Vec2 world_cursor;
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
};
/* ========================== *
* Startup
* ========================== */
extern SharedUserState shared_user_state;
struct user_startup_receipt user_startup(F_StartupReceipt *font_sr,
////////////////////////////////
//~ Startup
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)
String connect_address_str);
internal P_ExitFuncDef(user_shutdown)
////////////////////////////////
//~ Shutdown
/* ========================== *
* Debug draw
* ========================== */
P_ExitFuncDef(ShutdownUser);
/* TODO: remove this (testing) */
internal void debug_draw_xform(Xform xf, u32 color_x, u32 color_y)
////////////////////////////////
//~ Debug draw operations
internal void debug_draw_movement(Entity *ent)
void DebugDrawXform(Xform xf, u32 color_x, u32 color_y);
void DebugDrawMovement(Entity *ent);
String DebugStringFromEntity(Arena *arena, Entity *ent);
internal String get_ent_debug_text(Arena *arena, Entity *ent)
////////////////////////////////
//~ Console draw operations
/* ========================== *
* Debug console
* ========================== */
P_LogEventCallbackFuncDef(ConsoleLogCallback, log);
void DebugDrawConsole(i32 level, b32 minimized);
internal P_LogEventCallbackFuncDef(debug_console_log_callback, log)
////////////////////////////////
//~ Entity sortign
internal void draw_debug_console(i32 level, b32 minimized)
MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _);
/* ========================== *
* Sort entities
* ========================== */
////////////////////////////////
//~ User update
internal MergesortCompareFuncDef(ent_draw_order_cmp, arg_a, arg_b, _)
void UpdateUser(P_Window *window);
P_JobDef(UpdateUserJob, _);
/* ========================== *
* Update
* ========================== */
////////////////////////////////
//~ User input cmds
internal void user_update(P_Window *window)
void GenerateuserInputCmds(Client *user_input_client, u64 tick);
internal P_JobDef(user_update_job, _)
////////////////////////////////
//~ Sim update
/* ========================== *
* Local sim thread
* ========================== */
internal void generate_user_input_cmds(Client *user_input_client, u64 tick)
internal P_JobDef(local_sim_job, _)
P_JobDef(SimJob, _);