From 438333cf6f1dcd9f8d6a94fc702a952b070353b4 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 Jan 2026 09:45:18 +0100 Subject: refactor(assets): Optimize asset retrieval using array lookup This refactors the asset management system to be more efficient and cleaner. - Moved common GetAsset/DropAsset logic to src/util/asset_manager.cc. - Changed retrieval to use an array of records (AssetRecord) for O(1) lookups instead of a switch statement. - Updated asset_packer to generate only raw data and the record array. --- src/util/asset_manager.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/util/asset_manager.h (limited to 'src/util/asset_manager.h') diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h new file mode 100644 index 0000000..1b5e510 --- /dev/null +++ b/src/util/asset_manager.h @@ -0,0 +1,19 @@ +// 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. + +#pragma once +#include +#include + +// Forward declaration of the generated enum +enum class AssetId : uint16_t; + +struct AssetRecord { + const uint8_t *data; + size_t size; +}; + +// Generic interface +const uint8_t *GetAsset(AssetId asset_id, size_t *out_size = nullptr); +void DropAsset(AssetId asset_id, const uint8_t *asset); -- cgit v1.2.3