From e281b6ff0884a5b4af8aa2ca79fd01141bc2005b Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 10:16:50 +0100 Subject: refactor(build): Split asset_manager.h into dcl/core/utils headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split monolithic asset_manager.h (61 lines) into 3 focused headers: - asset_manager_dcl.h: Forward declarations (AssetId, ProcGenFunc) - asset_manager.h: Core API (GetAsset, DropAsset, AssetRecord) - asset_manager_utils.h: Typed helpers (TextureAsset, MeshAsset) Updated 17 source files to use appropriate headers: - object.h: Uses dcl.h (only needs AssetId forward declaration) - 7 files using TextureAsset/MeshAsset: Use utils.h - 10 files using only GetAsset(): Keep asset_manager.h Performance improvement: - Before: Touch asset_manager.h → 4.82s (35 files rebuild) - After: Touch asset_manager_utils.h → 2.01s (24 files rebuild) - Improvement: 58% faster for common workflow (tweaking mesh/texture helpers) Note: Touching base headers (dcl/core) still triggers ~33 file rebuilds due to object.h dependency chain. Further optimization would require reducing object.h's footprint (separate task). Files changed: - Created: asset_manager_dcl.h, asset_manager_utils.h - Modified: asset_manager.h (removed structs), asset_manager.cc - Updated: object.h, visual_debug.h, renderer_mesh.cc, flash_cube_effect.cc, hybrid_3d_effect.cc, test files --- src/util/asset_manager.cc | 1 + src/util/asset_manager.h | 40 +++------------------------------------- src/util/asset_manager_dcl.h | 16 ++++++++++++++++ src/util/asset_manager_utils.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 src/util/asset_manager_dcl.h create mode 100644 src/util/asset_manager_utils.h (limited to 'src/util') diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc index c12331c..650f220 100644 --- a/src/util/asset_manager.cc +++ b/src/util/asset_manager.cc @@ -2,6 +2,7 @@ // It implements the generic asset retrieval logic with runtime caching. #include "util/asset_manager.h" +#include "util/asset_manager_utils.h" #if defined(USE_TEST_ASSETS) #include "test_assets.h" #else diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h index 0c2cc63..ed7f1aa 100644 --- a/src/util/asset_manager.h +++ b/src/util/asset_manager.h @@ -1,17 +1,9 @@ // This file is part of the 64k demo project. -// It defines the core structures and interface for asset management. -// Used for efficient retrieval of embedded binary resources. +// Core asset management interface for basic asset retrieval. +// For typed helpers (TextureAsset, MeshAsset), include asset_manager_utils.h #pragma once -#include -#include - -enum class AssetId : uint16_t; // Forward declaration - -// Type for procedural generation functions: (buffer, width, height, params, -// num_params) -// Returns true on success, false on failure. -typedef bool (*ProcGenFunc)(uint8_t*, int, int, const float*, int); +#include "asset_manager_dcl.h" struct AssetRecord { const uint8_t* data; // Pointer to asset data (static or dynamic) @@ -32,29 +24,3 @@ struct AssetRecord { // - 'out_size' returns the original asset size (excluding the null terminator). const uint8_t* GetAsset(AssetId asset_id, size_t* out_size = nullptr); void DropAsset(AssetId asset_id, const uint8_t* asset); - -struct TextureAsset { - int width; - int height; - const uint8_t* pixels; -}; - -struct MeshVertex { - float p[3]; - float n[3]; - float u[2]; -}; - -struct MeshAsset { - uint32_t num_vertices; - const MeshVertex* vertices; - uint32_t num_indices; - const uint32_t* indices; -}; - -// Helper to retrieve and parse a simple texture asset (from packer's -// [w][h][pixels] format) -TextureAsset GetTextureAsset(AssetId asset_id); - -// Helper to retrieve and parse a mesh asset (from packer's binary format) -MeshAsset GetMeshAsset(AssetId asset_id); diff --git a/src/util/asset_manager_dcl.h b/src/util/asset_manager_dcl.h new file mode 100644 index 0000000..bf618f0 --- /dev/null +++ b/src/util/asset_manager_dcl.h @@ -0,0 +1,16 @@ +// This file is part of the 64k demo project. +// Forward declarations for asset management system. +// Use this header when you only need AssetId type. + +#pragma once +#include +#include + +enum class AssetId : uint16_t; // Forward declaration + +// Type for procedural generation functions: (buffer, width, height, params, +// num_params) +// Returns true on success, false on failure. +typedef bool (*ProcGenFunc)(uint8_t*, int, int, const float*, int); + +struct AssetRecord; // Forward declaration (opaque) diff --git a/src/util/asset_manager_utils.h b/src/util/asset_manager_utils.h new file mode 100644 index 0000000..b738692 --- /dev/null +++ b/src/util/asset_manager_utils.h @@ -0,0 +1,32 @@ +// This file is part of the 64k demo project. +// Typed asset helpers for specialized asset retrieval. +// Only include this if you need TextureAsset or MeshAsset structs. + +#pragma once +#include "asset_manager.h" + +struct TextureAsset { + int width; + int height; + const uint8_t* pixels; +}; + +struct MeshVertex { + float p[3]; + float n[3]; + float u[2]; +}; + +struct MeshAsset { + uint32_t num_vertices; + const MeshVertex* vertices; + uint32_t num_indices; + const uint32_t* indices; +}; + +// Helper to retrieve and parse a simple texture asset (from packer's +// [w][h][pixels] format) +TextureAsset GetTextureAsset(AssetId asset_id); + +// Helper to retrieve and parse a mesh asset (from packer's binary format) +MeshAsset GetMeshAsset(AssetId asset_id); -- cgit v1.2.3