337 lines
8.6 KiB
C
337 lines
8.6 KiB
C
////////////////////////////////////////////////////////////
|
|
//~ Binds
|
|
|
|
//- Bind kinds
|
|
Enum(PP_BindKind)
|
|
{
|
|
PP_BindKind_None,
|
|
|
|
PP_BindKind_MoveUp,
|
|
PP_BindKind_MoveDown,
|
|
PP_BindKind_MoveLeft,
|
|
PP_BindKind_MoveRight,
|
|
PP_BindKind_Walk,
|
|
PP_BindKind_Fire,
|
|
PP_BindKind_AltFire,
|
|
|
|
PP_BindKind_TestTile,
|
|
PP_BindKind_DebugClear,
|
|
PP_BindKind_DebugSpawn1,
|
|
PP_BindKind_DebugSpawn2,
|
|
PP_BindKind_DebugSpawn3,
|
|
PP_BindKind_DebugSpawn4,
|
|
PP_BindKind_DebugWalls,
|
|
PP_BindKind_DebugFollow,
|
|
PP_BindKind_DebugDraw,
|
|
PP_BindKind_DebugConsole,
|
|
PP_BindKind_DebugCamera,
|
|
PP_BindKind_DebugLister,
|
|
PP_BindKind_DebugPause,
|
|
PP_BindKind_DebugStep,
|
|
PP_BindKind_DebugDrag,
|
|
PP_BindKind_DebugDelete,
|
|
PP_BindKind_DebugTeleport,
|
|
PP_BindKind_DebugExplode,
|
|
PP_BindKind_DebugToggleTopmost,
|
|
PP_BindKind_DebugUi,
|
|
PP_BindKind_FullscreenMod,
|
|
PP_BindKind_Fullscreen,
|
|
PP_BindKind_ZoomIn,
|
|
PP_BindKind_ZoomOut,
|
|
PP_BindKind_Pan,
|
|
|
|
#if IsRtcEnabled
|
|
/* Debug */
|
|
|
|
PP_BindKind_ResetDebugSteps,
|
|
PP_BindKind_IncrementDebugSteps,
|
|
PP_BindKind_DecrementDebugSteps,
|
|
#endif
|
|
|
|
PP_BindKind_COUNT
|
|
};
|
|
|
|
//- Test bindings
|
|
|
|
/* TODO: Remove this */
|
|
Global Readonly PP_BindKind g_binds[Btn_COUNT] = {
|
|
[Btn_W] = PP_BindKind_MoveUp,
|
|
[Btn_S] = PP_BindKind_MoveDown,
|
|
[Btn_A] = PP_BindKind_MoveLeft,
|
|
[Btn_D] = PP_BindKind_MoveRight,
|
|
[Btn_M1] = PP_BindKind_Fire,
|
|
[Btn_M2] = PP_BindKind_AltFire,
|
|
#if 0
|
|
[Btn_Alt] = PP_BindKind_Walk,
|
|
#endif
|
|
|
|
/* Testing */
|
|
[Btn_Z] = PP_BindKind_TestTile,
|
|
[Btn_M5] = PP_BindKind_DebugDrag,
|
|
[Btn_M4] = PP_BindKind_DebugDelete,
|
|
[Btn_F] = PP_BindKind_DebugExplode,
|
|
[Btn_T] = PP_BindKind_DebugTeleport,
|
|
[Btn_C] = PP_BindKind_DebugClear,
|
|
[Btn_1] = PP_BindKind_DebugSpawn1,
|
|
[Btn_2] = PP_BindKind_DebugSpawn2,
|
|
[Btn_3] = PP_BindKind_DebugSpawn3,
|
|
[Btn_4] = PP_BindKind_DebugSpawn4,
|
|
[Btn_G] = PP_BindKind_DebugWalls,
|
|
[Btn_N] = PP_BindKind_DebugStep,
|
|
[Btn_Q] = PP_BindKind_DebugFollow,
|
|
[Btn_F1] = PP_BindKind_DebugPause,
|
|
[Btn_F2] = PP_BindKind_DebugCamera,
|
|
[Btn_F3] = PP_BindKind_DebugDraw,
|
|
[Btn_Tab] = PP_BindKind_DebugLister,
|
|
[Btn_F4] = PP_BindKind_DebugToggleTopmost,
|
|
[Btn_F5] = PP_BindKind_DebugUi,
|
|
[Btn_GraveAccent] = PP_BindKind_DebugConsole,
|
|
[Btn_Alt] = PP_BindKind_FullscreenMod,
|
|
[Btn_Enter] = PP_BindKind_Fullscreen,
|
|
[Btn_MWheelUp] = PP_BindKind_ZoomIn,
|
|
[Btn_MWheelDown] = PP_BindKind_ZoomOut,
|
|
[Btn_M3] = PP_BindKind_Pan,
|
|
|
|
#if IsRtcEnabled
|
|
[Btn_ForwardSlash] = PP_BindKind_ResetDebugSteps,
|
|
[Btn_Comma] = PP_BindKind_DecrementDebugSteps,
|
|
[Btn_Period] = PP_BindKind_IncrementDebugSteps
|
|
#endif
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Stats
|
|
|
|
Struct(PP_SecondsStat)
|
|
{
|
|
u64 last_second_start;
|
|
u64 last_second_end;
|
|
u64 last_second;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Console log
|
|
|
|
Struct(PP_ConsoleLog)
|
|
{
|
|
String msg;
|
|
i32 level;
|
|
i32 color_index;
|
|
DateTime datetime;
|
|
PP_ConsoleLog *prev;
|
|
PP_ConsoleLog *next;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Sim decode queue
|
|
|
|
Struct(PP_DecodeQueueNode)
|
|
{
|
|
PP_Client *client;
|
|
u64 tick;
|
|
u64 base_tick;
|
|
String tmp_encoded;
|
|
PP_DecodeQueueNode *next;
|
|
};
|
|
|
|
Struct(PP_DecodeQueue)
|
|
{
|
|
PP_DecodeQueueNode *first;
|
|
PP_DecodeQueueNode *last;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ State types
|
|
|
|
Struct(PP_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 */
|
|
u32 num_repeats; /* How many times was this bind's key repeated since last frame */
|
|
u32 num_presses_and_repeats; /* Same as `num_presses` but includes key repeats as well */
|
|
u32 num_releases; /* How many times was this bind released since last frame */
|
|
};
|
|
|
|
Struct(PP_SharedUserState)
|
|
{
|
|
Atomic32 shutdown;
|
|
|
|
Fence shutdown_jobs_fence;
|
|
u64 shutdown_jobs_count;
|
|
|
|
Arena *arena;
|
|
String connect_address_str;
|
|
|
|
PP_ClientStore *user_client_store;
|
|
PP_Client *user_unblended_client; /* Contains snapshots received from local sim */
|
|
PP_Client *user_blended_client; /* Contains single snapshot from result of blending local sim snapshots */
|
|
PP_Snapshot *ss_blended; /* Points to blended snapshot contained in blended client */
|
|
|
|
u64 user_tick;
|
|
u64 window_os_gen;
|
|
|
|
//- Usage stats
|
|
i64 last_second_reset_ns;
|
|
PP_SecondsStat net_bytes_read;
|
|
PP_SecondsStat net_bytes_sent;
|
|
|
|
//- Renderer gbuffers
|
|
GPU_Resource *albedo;
|
|
GPU_Resource *emittance;
|
|
GPU_Resource *emittance_flood_read;
|
|
GPU_Resource *emittance_flood_target;
|
|
GPU_Resource *shade_read;
|
|
GPU_Resource *shade_target;
|
|
|
|
//- Renderer transient buffers
|
|
GPU_TransientBuffer material_instances_tbuff;
|
|
GPU_TransientBuffer grids_tbuff;
|
|
Arena *material_instances_arena;
|
|
Arena *grids_arena;
|
|
|
|
//- Renderer state
|
|
RandState frame_rand;
|
|
u64 frame_index;
|
|
i64 gpu_submit_fence_target;
|
|
|
|
//- Bind state
|
|
PP_BindState bind_states[PP_BindKind_COUNT];
|
|
|
|
//- Window -> user
|
|
Mutex sys_window_events_mutex;
|
|
Arena *sys_window_events_arena;
|
|
|
|
//- User -> sim
|
|
Mutex user_sim_cmd_mutex;
|
|
PP_ControlData user_sim_cmd_control;
|
|
PP_EntKey user_hovered_ent;
|
|
u64 last_user_sim_cmd_gen;
|
|
u64 user_sim_cmd_gen;
|
|
|
|
Atomic32 user_paused;
|
|
Atomic32 user_paused_steps;
|
|
|
|
//- Sim -> user
|
|
Mutex local_to_user_client_mutex;
|
|
PP_ClientStore *local_to_user_client_store;
|
|
PP_Client *local_to_user_client;
|
|
i64 local_to_user_client_publish_dt_ns;
|
|
i64 local_to_user_client_publish_time_ns;
|
|
|
|
//- Local sim -> user rolling window of publish time deltas
|
|
i64 last_local_to_user_snapshot_published_at_ns;
|
|
i64 average_local_to_user_snapshot_publish_dt_ns;
|
|
|
|
i64 local_sim_predicted_time_ns; /* Calculated from <last local sim to user pubilsh time> + <time since last local sim to user publish> */
|
|
i64 render_time_target_ns; /* Claculated from <local_sim_rpedicted_time_ns> - <render interp delay> */
|
|
i64 render_time_ns; /* Incremented at a constant rate based on average local to user publish delta, but snaps to render_time_target_ns if it gets too distant */
|
|
|
|
u64 local_sim_last_known_tick;
|
|
i64 local_sim_last_known_time_ns;
|
|
|
|
i64 real_dt_ns;
|
|
i64 real_time_ns;
|
|
|
|
//- Window
|
|
|
|
String window_restore;
|
|
|
|
//////////////////////////////
|
|
//- Persist start
|
|
StructRegion(AUTO_PERSIST_START);
|
|
|
|
//- Debug ui
|
|
|
|
b32 ui_debug;
|
|
|
|
PP_EntKey debug_following;
|
|
Vec2 debug_camera_pan_start;
|
|
b32 debug_camera_panning;
|
|
b32 debug_camera;
|
|
|
|
b32 lister_active;
|
|
Vec2 lister_pos;
|
|
|
|
b32 debug_draw;
|
|
b32 debug_console;
|
|
|
|
//- Per frame
|
|
|
|
Vec2I32 screen_size;
|
|
Vec2 screen_cursor;
|
|
|
|
Xform ui_to_screen_xf;
|
|
Vec2I32 ui_size;
|
|
Vec2 ui_cursor;
|
|
|
|
Xform render_to_ui_xf;
|
|
Vec2I32 render_size;
|
|
|
|
Xform world_to_render_xf;
|
|
Xform world_to_ui_xf;
|
|
Vec2 world_cursor;
|
|
|
|
Vec2 focus_send;
|
|
|
|
StructRegion(AUTO_PERSIST_END);
|
|
//- Persist end
|
|
//////////////////////////////
|
|
|
|
} extern PP_shared_user_state;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Swap types
|
|
|
|
Struct(PP_SwappedUserState)
|
|
{
|
|
PP_SharedUserState s;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Startup
|
|
|
|
void PP_StartupUser(void);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Shutdown
|
|
|
|
ExitFuncDef(PP_ShutdownUser);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Ui helpers
|
|
|
|
void PP_PushGameUiStyle(void);
|
|
void PP_DrawDebugXform(Xform xf, u32 color_x, u32 color_y);
|
|
void PP_DrawDebugMovement(PP_Ent *ent);
|
|
String PP_DebugStringFromEnt(Arena *arena, PP_Ent *ent);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Gpu buffer helpers
|
|
|
|
GPU_Resource *PP_AcquireGbuffer(GPU_Format format, Vec2I32 size);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Ent sorting
|
|
|
|
MergesortCompareFuncDef(PP_EntSortCmp, arg_a, arg_b, _);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ User update
|
|
|
|
void PP_UpdateUser(void);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ User update job
|
|
|
|
JobDecl(PP_UpdateUserOrSleep, EmptySig);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ User input cmds
|
|
|
|
void PP_GenerateuserInputCmds(PP_Client *user_input_client, u64 tick);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Sim update job
|
|
|
|
JobDecl(PP_UpdateSim, EmptySig);
|