diff options
| -rw-r--r-- | src/util/asset_manager.h | 4 | ||||
| -rw-r--r-- | tools/asset_packer.cc | 11 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h index b9cd778..062cd0f 100644 --- a/src/util/asset_manager.h +++ b/src/util/asset_manager.h @@ -25,5 +25,9 @@ struct AssetRecord { }; // Generic interface +// Retrieves a pointer to the asset data. +// - Static assets are guaranteed to be 16-byte aligned. +// - Static assets are guaranteed to be null-terminated (safe as C-strings). +// - '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); diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc index 2b90ecc..d86e29b 100644 --- a/tools/asset_packer.cc +++ b/tools/asset_packer.cc @@ -210,7 +210,12 @@ int main(int argc, char* argv[]) { } std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(asset_file)), std::istreambuf_iterator<char>()); - fprintf(assets_data_cc_file, "static const uint8_t %s[] = {\n ", + size_t original_size = buffer.size(); + buffer.push_back(0); // Null terminator for safety + + fprintf(assets_data_cc_file, "const size_t ASSET_SIZE_%s = %zu;\n", + info.name.c_str(), original_size); + fprintf(assets_data_cc_file, "alignas(16) static const uint8_t %s[] = {\n ", info.data_array_name.c_str()); for (size_t i = 0; i < buffer.size(); ++i) { if (i > 0 && i % 12 == 0) @@ -241,8 +246,8 @@ int main(int argc, char* argv[]) { info.func_name_str_name.c_str(), info.params_array_name.c_str(), info.proc_params.size()); } else { - fprintf(assets_data_cc_file, "%s, sizeof(%s), false, nullptr, nullptr, 0", - info.data_array_name.c_str(), info.data_array_name.c_str()); + fprintf(assets_data_cc_file, "%s, ASSET_SIZE_%s, false, nullptr, nullptr, 0", + info.data_array_name.c_str(), info.name.c_str()); } fprintf(assets_data_cc_file, " },\n"); } |
