group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Game.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
10#include "debug/DebugUI.hpp"
14#include "network/Client.hpp"
18#include "sfx/SfxSystem.hpp"
19#ifdef USE_HYBRID_RENDERER
21#else
22#include "renderer/Renderer.hpp"
23#endif
24
25#include <SDL3/SDL.h>
26
27#include <entt/entt.hpp>
28#include <glm/glm.hpp>
29
34class Game
35{
36public:
39 bool init();
40
44 SDL_AppResult event(SDL_Event* event);
45
48 SDL_AppResult iterate();
49
51 void quit();
54
55private:
56 static constexpr int k_physicsHz = 128;
57 static constexpr float k_physicsDt = 1.0f / static_cast<float>(k_physicsHz);
58 static constexpr int k_maxTicksPerFrame = 8;
59 static constexpr int k_fpsHistorySize = 512;
60
61 NetworkConfig netCfg;
62 SDL_Window* window = nullptr;
63 DebugUI debugUI;
64#ifdef USE_HYBRID_RENDERER
65 HybridRenderer renderer;
66#else
67 Renderer renderer;
68#endif
69 Registry registry;
70 Client client;
71 ParticleSystem particleSystem;
72 SfxSystem sfxSystem;
73 entt::dispatcher dispatcher;
74
75 Uint64 prevTime = 0;
76 float accumulator = 0.0f;
77 int tickCount = 0;
78 bool mouseCaptured = true;
79
80 // Runtime-tunable loop settings (exposed via ImGui)
81 float mouseSensitivity = 0.001f;
82 bool renderSeparateFromPhysics = true;
84 bool inputSyncedWithPhysics = true;
86 bool limitFPSToMonitor = true;
87
88 Uint64 softLimitPeriod = 0;
89 Uint64 softLimitNextFrame = 0;
90
94 void applyFrameRateLimit();
95
96 FrameRecorder recorder;
97 uint64_t frameCount = 0;
98
99 // Cached camera state — updated each iterate(), used by event() key shortcuts.
100 glm::vec3 cachedEye_{0.f, 100.f, 0.f};
101 glm::vec3 cachedCamFwd_{0.f, 0.f, 1.f};
102 float currentCameraRoll_{0.0f};
103
104 // Model indices for entity rendering (loaded at init).
105 int wraithModelIdx = -1;
106 int glowSphereModelIdx_ = -1;
107 int movableSphereModelIdx_ = -1;
108 int weaponModelIndices_[4] = {-1, -1, -1, -1};
109
110 // Dynamic lighting test controls (ImGui-tunable)
111 bool showDynLightUI_ = false;
112 bool flashlightEnabled_ = false;
113 float flashlightIntensity_ = 8.0f;
114 float flashlightRange_ = 800.0f;
115 float flashlightOffset_ = 30.0f;
116 bool movableSphereEnabled_ = false;
117 float sphereFollowDist_ = 150.0f;
118 float sphereIntensity_ = 5.0f;
119 float sphereRange_ = 500.0f;
120 int glowCylinderModelIdx_ = -1;
121 bool beamEnabled_ = false;
122 glm::vec3 beamStartOff_{30.0f, -5.0f, 10.0f};
123 glm::vec3 beamEndOff_{200.0f, -5.0f, 10.0f};
124 float beamRadius_ = 3.0f;
125 glm::vec3 beamColor_{0.6f, 0.1f, 1.0f};
126 float beamLightIntensity_ = 4.0f;
127 float beamLightRange_ = 300.0f;
128 float beamLightSpacing_ = 60.0f;
129 WeaponType currentEquippedType_ = WeaponType::Rifle;
130 WeaponType lastEquippedType_ = WeaponType::Rifle;
131
132 // Sound state tracking
133 bool wasChargingRailgun_ = false;
134 bool wasBeamActive_ = false;
135
136 // Hitmarker
137 float hitmarkerTimer_ = 0.0f;
138
139 // Viewmodel tuning (live-adjustable via ImGui)
140 float vmScale = 0.03f;
141 float vmForward = 21.0f;
142 float vmRight = 5.5f;
143 float vmDown = 22.5f;
144 float vmYawOffset = 58.0f;
145 float vmPitchOffset = 12.0f;
146 float vmRollOffset = 2.0f;
147 bool showViewmodelUI = false;
148
149 // Weapon sway state (CoD-style barrel lead)
150 float prevSwayYaw_ = 0.0f;
151 float prevSwayPitch_ = 0.0f;
152 float swayOffsetX_ = 0.0f;
153 float swayOffsetY_ = 0.0f;
154 bool swayInitialized_ = false;
155
156 // Sway tuning (ImGui-adjustable)
157 float swayAmplitudeYaw_ = 3.0f;
158 float swayAmplitudePitch_ = 2.0f;
159 float swayDecayRate_ = 8.0f;
160 float swaySmoothing_ = 0.15f;
161
162 // Visual recoil state (viewmodel-only, does not affect aim)
163 float recoilPitch_ = 0.0f;
164 float recoilPushBack_ = 0.0f;
165 float recoilRoll_ = 0.0f;
166
167 // Local weapon fire cooldown (mirrors server's per-weapon cooldown for VFX)
168 float localFireCooldown_ = 0.0f;
169
170 // Crosshair settings (ImGui-adjustable)
171 float crosshairSize_ = 6.0f;
172 float crosshairThickness_ = 2.0f;
173 float crosshairGap_ = 3.0f;
174 glm::vec4 crosshairColor_ = {0.0f, 1.0f, 0.0f, 0.85f};
175 bool crosshairDot_ = true;
176 bool showCrosshair_ = true;
177
178 // Scroll-wheel weapon switching
179 int pendingScrollSwitch_ = 0;
180
181 // Third-person weapon tuning (per weapon type, live-adjustable via ImGui)
182 ThirdPersonWeaponParams tpWeaponParams_[4];
183 int tpTuneWeaponIdx_ = 0;
184 bool showTPWeaponUI_ = false;
185
186 // Animation subsystem — shared rig + clip library + skinning backend.
187 // CharacterAnimators (one per animated entity) hold non-owning refs.
188 CharacterRig charRig_;
189 AnimationLibrary animLibrary_;
190 CpuLbsSkinningBackend skinBackend_;
191 AnimationTesterState animUI_;
192 float kRigScale_ = 1.0f;
193 float kRigVerticalOffset_ =
194 -90.0f;
195 float rigMeshMinY_ = 0.0f;
196
197 // FPS ring buffer -- inter-render deltas, newest at (head-1) % size
198 float fpsHistory[k_fpsHistorySize] = {};
199 int fpsHistoryHead = 0;
200 int fpsHistoryCount = 0;
201 Uint64 prevRenderTime = 0;
202
203 // Network ping timer
204 float pingTimer = 0.0f;
205
206 // Performance stats -- refreshed every 0.5 s
207 Uint64 statsPrevTime = 0;
208 int statsPhysTicks = 0;
209 float measuredPhysicsHz = 0.0f;
210 float statsFPSCurrent = 0.0f;
211 float statsFPSMin = 0.0f;
212 float statsFPSMax = 0.0f;
213 float statsFPS1pLow = 0.0f;
214 float statsFPS5pLow = 0.0f;
215
222 void attachAnimatedCharacter(entt::entity e);
223
224 // Match State
225 MatchPhase currentMatchPhase = MatchPhase::WARMUP;
226 float countdownTimer = 0.0f;
227};
Catalog of ozz animation clips shared across all animated entities.
ImGui panel for driving the animation state machine in development.
Shared skinned-character rig: skeleton, bind-pose mesh, skin weights.
TCP client for connecting to the game server.
Live ECS inspector overlay and debug windows powered by Dear ImGui.
Per-frame state recorder for diagnosing camera jitter and position glitches.
Routing layer between the legacy renderer and the new (in-progress) renderer.
Shared definitions for match status and state synchronization between server and clients.
MatchPhase
Definition MatchStatus.hpp:6
Network configuration loaded from config.toml at startup.
Top-level particle system orchestrator owning all effect sub-systems.
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
Client-side sound effects system.
Pluggable skinning interface — phase-1 CPU LBS; GPU backend slots in later.
Per-weapon viewmodel, third-person, and recoil tuning parameters (header-only).
WeaponType
Weapon type — determines tracer style, damage, sound, and impact effects.
Definition WeaponState.hpp:10
@ Rifle
Fast hitscan/projectile (R301-style capsule tracer)
Collection of animation clips loaded on top of a shared skeleton.
Definition AnimationLibrary.hpp:55
Shared skinned rig — skeleton + bind-pose meshes + joint map.
Definition CharacterRig.hpp:42
TCP stream client — sends input to the server and receives state updates.
Definition Client.hpp:34
CPU Linear Blend Skinning — pure function; no state between calls.
Definition SkinningBackend.hpp:37
Forward-declared to avoid pulling in heavy particle headers.
Definition DebugUI.hpp:31
Records per-frame state to a timestamped directory on disk.
Definition FrameRecorder.hpp:56
Top-level client game object.
Definition Game.hpp:35
SDL_AppResult event(SDL_Event *event)
Forward an SDL event to ImGui and handle application-level keys.
Definition Game.cpp:337
void refreshRemoteProjectileRenderables()
Definition Game.cpp:1656
void quit()
Shut down all subsystems in reverse-init order.
Definition Game.cpp:1603
bool init()
Initialise all subsystems and spawn the local player entity.
Definition Game.cpp:44
void refreshRemotePlayerRenderables()
Definition Game.cpp:1617
SDL_AppResult iterate()
Advance one frame: sample input, step physics, render.
Definition Game.cpp:525
Definition HybridRenderer.hpp:18
Top-level particle system orchestrator.
Definition ParticleSystem.hpp:35
Forward-declared to avoid circular includes.
Definition Renderer.hpp:35
Client-side sound effects system.
Definition SfxSystem.hpp:28
SDL3 GPU forward PBR renderer with HDR pipeline and post-processing.
Persistent UI state for the Animation Tester panel.
Definition AnimationTesterUI.hpp:13
Runtime network connection parameters.
Definition NetworkConfig.hpp:21
Third-person weapon attachment params for remote players.
Definition ViewmodelConfig.hpp:22