From 1522b95c838fc3e567066fd96dede3dca25cbc95 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 16:18:19 +0100 Subject: feat(gpu): Integrate bumpy 3D renderer into main demo - Added depth buffer support to MainSequence. - Implemented Hybrid3DEffect for the main timeline. - Fixed effect initialization order in MainSequence. - Ensured depth-stencil compatibility for all scene effects. - Updated demo sequence with 3D elements and post-processing. --- tools/asset_packer.cc | 108 +++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 55 deletions(-) (limited to 'tools/asset_packer.cc') diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc index 8ae4742..a91552a 100644 --- a/tools/asset_packer.cc +++ b/tools/asset_packer.cc @@ -2,8 +2,8 @@ // It implements the asset packer tool for demoscene resource management. // Converts external files into embedded C++ byte arrays and look-up records. +#include // for simplicity, use fprintf() for output generation #include -#include #include #include #include @@ -36,9 +36,7 @@ struct AssetBuildInfo { int main(int argc, char* argv[]) { if (argc != 4) { - std::cerr << "Usage: " << argv[0] - << " " - "\n"; + fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } @@ -48,44 +46,39 @@ int main(int argc, char* argv[]) { std::ifstream assets_txt_file(assets_txt_path); if (!assets_txt_file.is_open()) { - std::cerr << "Error: Could not open assets.txt at " << assets_txt_path - << "\n"; + fprintf(stderr, "Error: Could not open assets.txt at %s\n", assets_txt_path.c_str()); return 1; } - std::ofstream assets_h_file(output_assets_h_path); - if (!assets_h_file.is_open()) { - std::cerr << "Error: Could not open output assets.h at " - << output_assets_h_path << "\n"; + FILE* assets_h_file = std::fopen(output_assets_h_path.c_str(), "w"); + if (!assets_h_file) { + fprintf(stderr, "Error: Could not open output assets.h at %s\n", output_assets_h_path.c_str()); return 1; } - std::ofstream assets_data_cc_file(output_assets_data_cc_path); - if (!assets_data_cc_file.is_open()) { - std::cerr << "Error: Could not open output assets_data.cc at " - << output_assets_data_cc_path << "\n"; + FILE* assets_data_cc_file = std::fopen(output_assets_data_cc_path.c_str(), "w"); + if (!assets_data_cc_file) { + fprintf(stderr, "Error: Could not open output assets_data.cc at %s\n", output_assets_data_cc_path.c_str()); return 1; } // Generate assets.h header - assets_h_file - << "// This file is auto-generated by asset_packer.cc. Do not edit.\n\n" - << "#pragma once\n" - << "#include \n\n" - << "enum class AssetId : uint16_t {\n"; + fprintf(assets_h_file, "// This file is auto-generated by asset_packer.cc. Do not edit.\n\n"); + fprintf(assets_h_file, "#pragma once\n"); + fprintf(assets_h_file, "#include \n\n"); + fprintf(assets_h_file, "enum class AssetId : uint16_t {\n"); std::string generated_header_name = output_assets_h_path.substr(output_assets_h_path.find_last_of("/\\") + 1); // Generate assets_data.cc header - assets_data_cc_file - << "// This file is auto-generated by asset_packer.cc. Do not edit.\n\n" - << "#include \"util/asset_manager.h\"\n" - << "#include \"generated/" << generated_header_name << "\"\n\n"; + fprintf(assets_data_cc_file, "// This file is auto-generated by asset_packer.cc. Do not edit.\n\n"); + fprintf(assets_data_cc_file, "#include \"util/asset_manager.h\"\n"); + fprintf(assets_data_cc_file, "#include \"generated/%s\"\n\n", generated_header_name.c_str()); // Forward declare procedural functions for AssetRecord initialization - assets_data_cc_file << "namespace procedural { void gen_noise(uint8_t*, int, int, const float*, int); }\n" - << "namespace procedural { void gen_grid(uint8_t*, int, int, const float*, int); }\n" - << "namespace procedural { void make_periodic(uint8_t*, int, int, const float*, int); }\n\n"; + fprintf(assets_data_cc_file, "namespace procedural { void gen_noise(uint8_t*, int, int, const float*, int); }\n"); + fprintf(assets_data_cc_file, "namespace procedural { void gen_grid(uint8_t*, int, int, const float*, int); }\n"); + fprintf(assets_data_cc_file, "namespace procedural { void make_periodic(uint8_t*, int, int, const float*, int); }\n\n"); std::vector asset_build_infos; int asset_id_counter = 0; @@ -115,7 +108,7 @@ int main(int argc, char* argv[]) { size_t open_paren = compression_type_str.find('('); size_t close_paren = compression_type_str.rfind(')'); if (open_paren == std::string::npos || close_paren == std::string::npos) { - std::cerr << "Error: Invalid PROC() syntax for asset: " << info.name << ", string: [" << compression_type_str << "]\n"; + fprintf(stderr, "Error: Invalid PROC() syntax for asset: %s, string: [%s]\n", info.name.c_str(), compression_type_str.c_str()); return 1; } std::string func_and_params_str = compression_type_str.substr(open_paren + 1, close_paren - open_paren - 1); @@ -134,7 +127,7 @@ int main(int argc, char* argv[]) { try { info.proc_params.push_back(std::stof(param_val_str)); } catch (...) { - std::cerr << "Error: Invalid proc param for " << info.name << ": " << param_val_str << "\n"; + fprintf(stderr, "Error: Invalid proc param for %s: %s\n", info.name.c_str(), param_val_str.c_str()); return 1; } if (comma_pos == std::string::npos) break; @@ -147,67 +140,72 @@ int main(int argc, char* argv[]) { // Validate procedural function name // kAssetPackerProcGenFuncMap is defined globally for validation if (kAssetPackerProcGenFuncMap.find(info.proc_func_name) == kAssetPackerProcGenFuncMap.end()) { - std::cerr << "Error: Unknown procedural function: " << info.proc_func_name << " for asset: " << info.name << "\n"; + fprintf(stderr, "Error: Unknown procedural function: %s for asset: %s\n", info.proc_func_name.c_str(), info.name.c_str()); return 1; } } asset_build_infos.push_back(info); - assets_h_file << " ASSET_" << info.name << " = " << asset_id_counter++ << ",\n"; + fprintf(assets_h_file, " ASSET_%s = %d,\n", info.name.c_str(), asset_id_counter++); } else { - std::cerr << "Warning: Skipping malformed line in assets.txt: " << line << "\n"; + fprintf(stderr, "Warning: Skipping malformed line in assets.txt: %s\n", line.c_str()); } } - assets_h_file << " ASSET_LAST_ID = " << asset_id_counter << ",\n"; - assets_h_file << "};\n"; + fprintf(assets_h_file, " ASSET_LAST_ID = %d,\n", asset_id_counter); + fprintf(assets_h_file, "};\n"); - assets_h_file << "#include \"util/asset_manager.h\"\n"; // Include here AFTER enum definition - assets_h_file.close(); + fprintf(assets_h_file, "#include \"util/asset_manager.h\"\n"); // Include here AFTER enum definition + std::fclose(assets_h_file); for (const auto& info : asset_build_infos) { if (!info.is_procedural) { std::string base_dir = assets_txt_path.substr(0, assets_txt_path.find_last_of("/\\") + 1); std::ifstream asset_file(base_dir + info.filename, std::ios::binary); if (!asset_file.is_open()) { - std::cerr << "Error: Could not open asset file: " << base_dir + info.filename << "\n"; + fprintf(stderr, "Error: Could not open asset file: %s\n", (base_dir + info.filename).c_str()); return 1; } std::vector buffer((std::istreambuf_iterator(asset_file)), std::istreambuf_iterator()); - assets_data_cc_file << "static const uint8_t " << info.data_array_name << "[] = {\n "; + fprintf(assets_data_cc_file, "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) assets_data_cc_file << "\n "; - assets_data_cc_file << "0x" << std::hex << (int)buffer[i] << std::dec << (i == buffer.size() - 1 ? "" : ", "); + if (i > 0 && i % 12 == 0) fprintf(assets_data_cc_file, "\n "); + fprintf(assets_data_cc_file, "0x%02x%s", buffer[i], (i == buffer.size() - 1 ? "" : ", ")); } - assets_data_cc_file << "\n};\n"; + fprintf(assets_data_cc_file, "\n};\n"); } else { - assets_data_cc_file << "static const float " << info.params_array_name << "[] = {"; + fprintf(assets_data_cc_file, "static const float %s[] = {", info.params_array_name.c_str()); for (size_t i = 0; i < info.proc_params.size(); ++i) { - if (i > 0) assets_data_cc_file << ", "; - assets_data_cc_file << info.proc_params[i]; + if (i > 0) fprintf(assets_data_cc_file, ", "); + fprintf(assets_data_cc_file, "%f", info.proc_params[i]); } - assets_data_cc_file << "};\n\n"; - assets_data_cc_file << "static const char* " << info.func_name_str_name << " = \"" << info.proc_func_name << "\";\n\n"; + fprintf(assets_data_cc_file, "};\n\n"); + fprintf(assets_data_cc_file, "static const char* %s = \"%s\";\n\n", info.func_name_str_name.c_str(), info.proc_func_name.c_str()); } } - assets_data_cc_file << "extern const AssetRecord g_assets[] = {\n"; + fprintf(assets_data_cc_file, "extern const AssetRecord g_assets[] = {\n"); for (const auto& info : asset_build_infos) { - assets_data_cc_file << " {"; + fprintf(assets_data_cc_file, " { "); if (info.is_procedural) { - assets_data_cc_file << " nullptr, 0, true, " << info.func_name_str_name << ", " << info.params_array_name << ", " << info.proc_params.size(); + fprintf(assets_data_cc_file, "nullptr, 0, true, %s, %s, %zu", + info.func_name_str_name.c_str(), + info.params_array_name.c_str(), + info.proc_params.size()); } else { - assets_data_cc_file << " " << info.data_array_name << ", sizeof(" << info.data_array_name << "), false, nullptr, nullptr, 0"; + fprintf(assets_data_cc_file, "%s, sizeof(%s), false, nullptr, nullptr, 0", + info.data_array_name.c_str(), + info.data_array_name.c_str()); } - assets_data_cc_file << " },\n"; + fprintf(assets_data_cc_file, " },\n"); } - assets_data_cc_file << "};\n"; - assets_data_cc_file << "extern const size_t g_assets_count = sizeof(g_assets) / sizeof(g_assets[0]);\n"; + fprintf(assets_data_cc_file, "};\n"); + fprintf(assets_data_cc_file, "extern const size_t g_assets_count = sizeof(g_assets) / sizeof(g_assets[0]);\n"); - assets_data_cc_file.close(); + std::fclose(assets_data_cc_file); - std::cout << "Asset packer successfully generated records for " - << asset_build_infos.size() << " assets.\n"; + printf("Asset packer successfully generated records for %zu assets.\n", + asset_build_infos.size()); return 0; } -- cgit v1.2.3