summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-03-08 09:33:17 +0100
committerskal <pascal.massimino@gmail.com>2026-03-08 09:33:17 +0100
commita2f0f7c7a45ba8b30984fb135b8b54f11fb119f8 (patch)
tree794527d25368227320e5f6aebe409178296db391 /src
parent9d114ae4fec465baed381de7782ef42ca77e734b (diff)
feat: Implement dual-mode asset loading and update documentation
This commit introduces a dual-mode asset loading system to enhance developer workflow and optimize release builds. Key changes include: - **Dual-Mode Asset Loading:** Assets are now loaded from disk during development (when is OFF) for faster iteration, particularly for heavy assets like and files. For release builds ( ON), all assets are embedded directly into the binary, ensuring a single, self-contained executable. - **Explicit Asset Typing:** Replaced generic asset type with specific types (, , , , ) in and the enum in for clearer categorization and more robust processing. - **Build System Integration:** Modified to pass a flag to in development builds. - **Asset Packer Updates:** now generates file paths for disk-loaded assets and embeds data for others based on the build mode. - **Asset Manager Enhancements:** includes new logic in for loading and caching disk-based assets and updates to for proper memory deallocation. - **Documentation:** Updated to reflect the new asset nomenclature and dual-mode loading strategy. - **Project Rules:** Added a concise rule to mandating top-level documentation updates for medium/large sub-system changes. handoff(Gemini): Implemented dual-mode asset loading and updated documentation.
Diffstat (limited to 'src')
-rw-r--r--src/effects/ntsc.wgsl22
-rw-r--r--src/util/asset_manager.cc41
-rw-r--r--src/util/asset_manager.h8
3 files changed, 57 insertions, 14 deletions
diff --git a/src/effects/ntsc.wgsl b/src/effects/ntsc.wgsl
index 31d4e0d..6c9fa37 100644
--- a/src/effects/ntsc.wgsl
+++ b/src/effects/ntsc.wgsl
@@ -3,9 +3,8 @@
#include "render/fullscreen_uv_vs"
#include "math/noise"
-const f32 vignetteRounding = 160.0f;
-const f32 vignetteSmoothness = 0.7f;
-
+const vignetteRounding = 160.0f;
+const vignetteSmoothness = 0.7f;
@group(0) @binding(0) var input_sampler: sampler;
@group(0) @binding(1) var input_texture: texture_2d<f32>;
@@ -13,15 +12,14 @@ const f32 vignetteSmoothness = 0.7f;
// Barrel (fisheye) distortion: strength > 0 = barrel, < 0 = pincushion
fn fisheye(uv: vec2f, strength: f32) -> vec2f {
- let c = uv * 2.0 - 1.0;
- let r2 = c * c;
- return uv * 1.03 * (1.0 + vec2f(.1, .24) * strength * r2);
+ let r2 = uv * uv;
+ return uv * 1.05 * (1.0 + vec2f(.1, .24) * strength * r2);
}
-fn vignette(vec2f uv) -> f32 {
- uv *= 1.99;
- f32 amount = 1.0 - sqrt(pow(abs(uv.x), vignetteRounding) + pow(abs(uv.y), vignetteRounding));
- f32 vhard = smoothstep(0., vignetteSmoothness, amount);
+fn vignette(uv: vec2f) -> f32 {
+ let uv2 = uv * 1.99;
+ let amount = 1.0 - sqrt(pow(abs(uv2.x), vignetteRounding) + pow(abs(uv2.y), vignetteRounding));
+ let vhard = smoothstep(0., vignetteSmoothness, amount);
return vhard;
}
@@ -29,8 +27,8 @@ fn vignette(vec2f uv) -> f32 {
let t = uniforms.time;
// Fisheye/barrel distortion
- let uv = fisheye(in.uv, 0.18);
- uv = vignette(uv);
+ let uv = (fisheye(in.st, 0.18) + 1.) * .5;
+// uv = vignette(uv);
// Black outside screen edges
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc
index 2285f3a..52a60ee 100644
--- a/src/util/asset_manager.cc
+++ b/src/util/asset_manager.cc
@@ -76,6 +76,39 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
AssetRecord source_record = assets[index];
+#if !defined(DEMO_STRIP_ALL)
+ if (source_record.type == AssetType::SPEC ||
+ source_record.type == AssetType::MP3) {
+ const char* path = (const char*)source_record.data;
+ FILE* f = fopen(path, "rb");
+ if (!f) {
+ if (out_size)
+ *out_size = 0;
+ return nullptr;
+ }
+ fseek(f, 0, SEEK_END);
+ long size = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ uint8_t* buffer = new (std::nothrow) uint8_t[size + 1];
+ if (!buffer) {
+ fclose(f);
+ if (out_size)
+ *out_size = 0;
+ return nullptr;
+ }
+ fread(buffer, 1, size, f);
+ fclose(f);
+ buffer[size] = 0; // Null-terminate
+
+ g_asset_cache[index].data = buffer;
+ g_asset_cache[index].size = size;
+ g_asset_cache[index].type = source_record.type;
+ if (out_size)
+ *out_size = size;
+ return buffer;
+ }
+#endif
+
AssetRecord cached_record = source_record;
if (source_record.type == AssetType::PROC ||
@@ -188,6 +221,14 @@ void DropAsset(AssetId asset_id, const uint8_t* asset) {
delete[] g_asset_cache[index].data;
g_asset_cache[index] = {}; // Zero out the struct to force re-generation
}
+#if !defined(DEMO_STRIP_ALL)
+ if (g_asset_cache[index].data == asset &&
+ (g_asset_cache[index].type == AssetType::SPEC ||
+ g_asset_cache[index].type == AssetType::MP3)) {
+ delete[] g_asset_cache[index].data;
+ g_asset_cache[index] = {};
+ }
+#endif
// For static assets, no dynamic memory to free.
}
diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h
index 5380257..786a8db 100644
--- a/src/util/asset_manager.h
+++ b/src/util/asset_manager.h
@@ -6,10 +6,14 @@
#include "asset_manager_dcl.h"
enum class AssetType : uint8_t {
- STATIC,
+ WGSL,
+ SPEC,
+ TEXTURE,
+ MESH,
+ BINARY,
+ MP3,
PROC,
PROC_GPU,
- MP3
};
struct AssetRecord {