#include "user.h" #include "sim.h" #include "sim_ent.h" #include "sim_step.h" #include "renderer.h" #include "font.h" #include "sprite.h" #include "draw.h" #include "intrinsics.h" #include "asset_cache.h" #include "string.h" #include "scratch.h" #include "math.h" #include "sys.h" #include "mixer.h" #include "atomic.h" #include "collider.h" #include "rand.h" #include "log.h" #include "sock.h" #include "host.h" #include "bitbuff.h" #include "gstat.h" #include "app.h" struct bind_state { b32 is_held; /* Is this bind held down this frame */ u32 num_presses; /* How many times was this bind pressed 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 second_stat { u64 last_second_start; u64 last_second_end; u64 last_second; }; GLOBAL struct { struct atomic_i32 user_thread_shutdown; struct sys_thread user_thread; struct atomic_i32 local_sim_thread_shutdown; struct sys_thread local_sim_thread; struct sim_ctx *local_sim_ctx; struct arena arena; struct sys_window *window; struct string connect_address_str; struct sim_client_store *user_client_store; struct sim_client *user_unblended_client; /* Contains snapshots received from local sim */ struct sim_client *user_blended_client; /* Contains single snapshot from result of blending local sim snapshots */ struct sim_snapshot *ss_blended; /* Points to blended snapshot contained in blended client */ /* Usage stats */ i64 last_second_reset_ns; struct second_stat net_bytes_read; struct second_stat net_bytes_sent; /* Render targets */ struct renderer_texture final_texture; struct renderer_texture world_texture; struct renderer_texture ui_texture; struct renderer_texture backbuffer_texture; struct renderer_cmd_buffer *world_cmd_buffer; struct renderer_cmd_buffer *ui_cmd_buffer; struct renderer_cmd_buffer *final_cmd_buffer; struct renderer_cmd_buffer *backbuffer_cmd_buffer; struct xform world_to_ui_xf; struct bind_state bind_states[USER_BIND_KIND_COUNT]; b32 debug_camera; b32 debug_camera_panning; struct v2 debug_camera_pan_start; b32 debug_draw; /* Window -> user */ struct sys_mutex sys_events_mutex; struct arena sys_events_arena; /* User -> local sim */ struct sys_mutex user_sim_cmd_mutex; struct sim_control user_sim_cmd_control; struct sim_ent_id user_hovered_ent; u64 last_user_sim_cmd_gen; u64 user_sim_cmd_gen; /* Local sim -> user */ struct sys_mutex local_to_user_client_mutex; struct sim_client_store *local_to_user_client_store; struct sim_client *local_to_user_client; /* Rolling window of local sim -> user publish time deltas */ i64 last_local_to_user_snapshot_published_at_ns; i64 local_to_user_snapshot_publish_dts_ns[10]; i64 local_to_user_snapshot_publish_dts_index; i64 average_local_to_user_snapshot_publish_dt_ns; i64 local_sim_predicted_time_ns; /* Calculated from +