#include "user.h" #include "sim.h" #include "sim_ent.h" #include "sim_step.h" #include "gpu.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'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 second_stat { u64 last_second_start; u64 last_second_end; u64 last_second; }; struct console_log { struct string msg; i32 level; i32 color_index; struct sys_datetime datetime; i64 time_ns; struct rect bounds; struct console_log *prev; struct console_log *next; }; 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; /* Gpu handles */ struct gpu_handle user_texture; struct gpu_handle backbuffer_texture; struct gpu_handle world_gpu_cmd_list; struct gpu_handle user_gpu_cmd_list; struct gpu_handle backbuffer_gpu_cmd_list; struct gpu_handle user_dispatch_state; struct gpu_handle backbuffer_dispatch_state; struct xform world_to_user_xf; struct bind_state bind_states[USER_BIND_KIND_COUNT]; /* Debug camera */ struct sim_ent_id debug_following; b32 debug_camera; b32 debug_camera_panning; struct v2 debug_camera_pan_start; b32 debug_draw; /* Debug console */ struct sys_mutex console_logs_mutex; struct arena console_logs_arena; struct console_log *first_console_log; struct console_log *last_console_log; i32 console_log_color_indices[LOG_LEVEL_COUNT]; f32 console_logs_height; b32 debug_console; /* 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; struct atomic_i32 user_paused; struct atomic_i32 user_paused_steps; /* 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; i64 local_to_user_client_publish_dt_ns; i64 local_to_user_client_publish_time_ns; /* Rolling window of local sim -> user 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 +