summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-02 09:28:28 +0100
committerskal <pascal.massimino@gmail.com>2026-02-02 09:28:28 +0100
commit61139c8d9d655e07964d63ec1f5a091a7e8ab7d0 (patch)
tree4cf3694702f24e96c1c76a339f7b3e4d4fdf5e70 /src/main.cc
parent0b0067cb0a8db5ea5178501a12aacdef436a9845 (diff)
refactor(platform): Encapsulate state in PlatformState struct
- Replaced all global static variables in the platform layer with a single PlatformState struct. - Updated all platform function signatures to accept a pointer to this struct, making the implementation stateless and more modular. - Refactored main.cc, tests, and tools to instantiate and pass the PlatformState struct. - This improves code organization and removes scattered global state.
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main.cc b/src/main.cc
index f7136ef..2ece549 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -129,6 +129,7 @@ float* generate_tone(float* buffer, float freq) {
}
int main(int argc, char** argv) {
+ PlatformState platform_state = {};
bool fullscreen_enabled = false;
float seek_time = 0.0f;
int* width_ptr = nullptr;
@@ -156,8 +157,8 @@ int main(int argc, char** argv) {
fullscreen_enabled = true;
#endif /* STRIP_ALL */
- platform_init_window(fullscreen_enabled, width_ptr, height_ptr);
- gpu_init(platform_get_window(), platform_get_width(), platform_get_height());
+ platform_init(&platform_state, fullscreen_enabled, width_ptr, height_ptr);
+ gpu_init(&platform_state);
audio_init();
// Register drum assets
@@ -234,14 +235,14 @@ int main(int argc, char** argv) {
// Start real audio
audio_start();
- while (!platform_should_close()) {
- platform_poll();
+ while (!platform_should_close(&platform_state)) {
+ platform_poll(&platform_state);
double current_time = platform_get_time() + seek_time; // Offset logic time
update_game_logic(current_time);
- float aspect_ratio = platform_get_aspect_ratio();
+ float aspect_ratio = platform_get_aspect_ratio(&platform_state);
// Adjusted multiplier for visuals (preventing constant 1.0 saturation)
float raw_peak = synth_get_output_peak();
@@ -254,6 +255,6 @@ int main(int argc, char** argv) {
audio_shutdown();
gpu_shutdown();
- platform_shutdown();
+ platform_shutdown(&platform_state);
return 0;
}