summaryrefslogtreecommitdiff
path: root/src/procedural/generator.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/procedural/generator.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/procedural/generator.cc')
-rw-r--r--src/procedural/generator.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/procedural/generator.cc b/src/procedural/generator.cc
index 12dcb56..5ae83e4 100644
--- a/src/procedural/generator.cc
+++ b/src/procedural/generator.cc
@@ -8,8 +8,12 @@
namespace procedural {
// Smoothstep
-constexpr float smooth(float x) { return x * x * (3.f - 2.f * x); }
-constexpr float mix(float a, float b, float t) { return (a * (1.0f - t) + b * t); }
+constexpr float smooth(float x) {
+ return x * x * (3.f - 2.f * x);
+}
+constexpr float mix(float a, float b, float t) {
+ return (a * (1.0f - t) + b * t);
+}
// Simple smooth noise generator (Value Noise-ish)
// Params[0]: Seed
@@ -24,9 +28,13 @@ void gen_noise(uint8_t* buffer, int w, int h, const float* params,
// Create a small lattice of random values
const int lattice_w = (int)ceil(freq);
const int lattice_h = (int)ceil(freq);
- std::vector<float> lattice(lattice_w * lattice_h);
- for (float& v : lattice) {
- v = (float)rand() / RAND_MAX;
+ float* lattice =
+ (float*)malloc((size_t)lattice_w * lattice_h * sizeof(float));
+ if (!lattice)
+ return;
+
+ for (int i = 0; i < lattice_w * lattice_h; ++i) {
+ lattice[i] = (float)rand() / RAND_MAX;
}
const float scale_u = 1.f * (lattice_w - 1) / w;
const float scale_v = 1.f * (lattice_h - 1) / h;
@@ -59,6 +67,7 @@ void gen_noise(uint8_t* buffer, int w, int h, const float* params,
dst[4 * x + 3] = 255; // A
}
}
+ free(lattice);
}
// Simple grid generator