summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-03 18:44:41 +0100
committerskal <pascal.massimino@gmail.com>2026-02-03 18:44:41 +0100
commitbf46e44e1cb6027a072819a2a3aa3be32651f6e1 (patch)
tree21267e7ef52fd91e7b99271ed87e275e91b3de3c /src/main.cc
parent815c428dea14a6a1ea5c421c400985d0c14d473d (diff)
refactor: Task #20 - Platform & Code Hygiene
- Consolidated all WebGPU shims and platform-specific logic into src/platform.h. - Refactored platform_init to return PlatformState by value and platform_poll to automatically refresh time and aspect_ratio. - Removed STL dependencies (std::map, std::vector, std::string) from AssetManager and Procedural subsystems. - Fixed Windows cross-compilation by adjusting include paths and linker flags in CMakeLists.txt and updating build_win.sh. - Removed redundant direct inclusions of GLFW/glfw3.h and WebGPU headers across the project. - Applied clang-format and updated documentation. handoff(Gemini): Completed Task #20 and 20.1. Platform abstraction is now unified, and core paths are STL-free. Windows build is stable.
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc55
1 files changed, 27 insertions, 28 deletions
diff --git a/src/main.cc b/src/main.cc
index 76e366a..aba8d4b 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -11,11 +11,10 @@
#include "gpu/gpu.h"
#include "platform.h"
#include "util/math.h"
-#include <GLFW/glfw3.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-#include <vector>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#define SPEC_FRAMES 16
@@ -47,12 +46,11 @@ float* generate_tone(float* buffer, float freq) {
}
int main(int argc, char** argv) {
- PlatformState platform_state = {};
+ PlatformState platform_state;
bool fullscreen_enabled = false;
float seek_time = 0.0f;
- int* width_ptr = nullptr;
- int* height_ptr = nullptr;
- int custom_width, custom_height;
+ int width = 1280;
+ int height = 720;
#if !defined(STRIP_ALL)
for (int i = 1; i < argc; ++i) {
@@ -63,9 +61,10 @@ int main(int argc, char** argv) {
++i;
} else if (strcmp(argv[i], "--resolution") == 0 && i + 1 < argc) {
const char* res_str = argv[++i];
- if (sscanf(res_str, "%dx%d", &custom_width, &custom_height) == 2) {
- width_ptr = &custom_width;
- height_ptr = &custom_height;
+ int w, h;
+ if (sscanf(res_str, "%dx%d", &w, &h) == 2) {
+ width = w;
+ height = h;
}
} else if (strcmp(argv[i], "--debug") == 0) {
Renderer3D::SetDebugEnabled(true);
@@ -77,7 +76,7 @@ int main(int argc, char** argv) {
fullscreen_enabled = true;
#endif /* STRIP_ALL */
- platform_init(&platform_state, fullscreen_enabled, width_ptr, height_ptr);
+ platform_state = platform_init(fullscreen_enabled, width, height);
gpu_init(&platform_state);
audio_init();
synth_init();
@@ -98,22 +97,22 @@ int main(int argc, char** argv) {
auto update_game_logic = [&](double t) {
if (t - last_beat_time > (60.0f / g_tracker_score.bpm) / 2.0) { // 8th notes
- last_beat_time = t; // Sync to t
+ last_beat_time = t; // Sync to t
const int step = beat_count % 16;
-/*
- // Bass pattern
- if (step % 4 == 0) {
- float* back_buffer = synth_begin_update(bass_id);
- if (back_buffer) {
- float bass_freq = (step < 8) ? 110.0f : 164.82f; // A3 then E3
- generate_tone(back_buffer, bass_freq);
- synth_commit_update(bass_id);
- }
- synth_trigger_voice(bass_id, 0.9f, 1.2f);
- }
-*/
+ /*
+ // Bass pattern
+ if (step % 4 == 0) {
+ float* back_buffer = synth_begin_update(bass_id);
+ if (back_buffer) {
+ float bass_freq = (step < 8) ? 110.0f : 164.82f; // A3 then E3
+ generate_tone(back_buffer, bass_freq);
+ synth_commit_update(bass_id);
+ }
+ synth_trigger_voice(bass_id, 0.9f, 1.2f);
+ }
+ */
++beat_count;
}
tracker_update((float)t);
@@ -152,11 +151,11 @@ int main(int argc, char** argv) {
gpu_resize(last_width, last_height);
}
- double current_time = platform_get_time() + seek_time; // Offset logic time
+ double current_time = platform_state.time + seek_time; // Offset logic time
update_game_logic(current_time);
- float aspect_ratio = platform_get_aspect_ratio(&platform_state);
+ float aspect_ratio = platform_state.aspect_ratio;
// Adjusted multiplier for visuals (preventing constant 1.0 saturation)
float raw_peak = synth_get_output_peak();