diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/asset_packer.cc | 70 | ||||
| -rw-r--r-- | tools/seq_compiler.cc | 8 | ||||
| -rw-r--r-- | tools/spectool.cc | 17 | ||||
| -rw-r--r-- | tools/tracker_compiler.cc | 5 |
4 files changed, 62 insertions, 38 deletions
diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc index 42dfa7a..0d26cf6 100644 --- a/tools/asset_packer.cc +++ b/tools/asset_packer.cc @@ -2,16 +2,16 @@ // It implements the asset packer tool for demoscene resource management. // Converts external files into embedded C++ byte arrays and look-up records. -#include <cstdio> // for simplicity, use fprintf() for output generation +#include <algorithm> // For std::count +#include <cmath> +#include <cstdio> // for simplicity, use fprintf() for output generation +#include <cstring> // For std::memcpy #include <fstream> #include <map> -#include <algorithm> // For std::count -#include <cstring> // For std::memcpy #include <regex> // For std::regex #include <stdexcept> // For std::stof exceptions #include <string> #include <vector> -#include <cmath> #define STB_IMAGE_IMPLEMENTATION #define STBI_NO_LINEAR // Don't apply gamma correction, we want raw bytes @@ -63,16 +63,29 @@ struct AssetBuildInfo { struct Vec3 { float x, y, z; - Vec3 operator+(const Vec3& o) const { return {x + o.x, y + o.y, z + o.z}; } - Vec3 operator+=(const Vec3& o) { x += o.x; y += o.y; z += o.z; return *this; } - Vec3 operator-(const Vec3& o) const { return {x - o.x, y - o.y, z - o.z}; } - Vec3 operator*(float s) const { return {x * s, y * s, z * s}; } + Vec3 operator+(const Vec3& o) const { + return {x + o.x, y + o.y, z + o.z}; + } + Vec3 operator+=(const Vec3& o) { + x += o.x; + y += o.y; + z += o.z; + return *this; + } + Vec3 operator-(const Vec3& o) const { + return {x - o.x, y - o.y, z - o.z}; + } + Vec3 operator*(float s) const { + return {x * s, y * s, z * s}; + } static Vec3 cross(const Vec3& a, const Vec3& b) { - return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; + return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x}; } Vec3 normalize() const { float len = std::sqrt(x * x + y * y + z * z); - if (len > 1e-6f) return {x / len, y / len, z / len}; + if (len > 1e-6f) + return {x / len, y / len, z / len}; return {0, 0, 0}; } }; @@ -359,26 +372,29 @@ int main(int argc, char* argv[]) { int idx0 = face.v[0] - 1; int idx1 = face.v[1] - 1; int idx2 = face.v[2] - 1; - + if (idx0 >= 0 && idx1 >= 0 && idx2 >= 0) { - Vec3 p0 = {v_pos[idx0 * 3], v_pos[idx0 * 3 + 1], v_pos[idx0 * 3 + 2]}; - Vec3 p1 = {v_pos[idx1 * 3], v_pos[idx1 * 3 + 1], v_pos[idx1 * 3 + 2]}; - Vec3 p2 = {v_pos[idx2 * 3], v_pos[idx2 * 3 + 1], v_pos[idx2 * 3 + 2]}; - + Vec3 p0 = {v_pos[idx0 * 3], v_pos[idx0 * 3 + 1], + v_pos[idx0 * 3 + 2]}; + Vec3 p1 = {v_pos[idx1 * 3], v_pos[idx1 * 3 + 1], + v_pos[idx1 * 3 + 2]}; + Vec3 p2 = {v_pos[idx2 * 3], v_pos[idx2 * 3 + 1], + v_pos[idx2 * 3 + 2]}; + Vec3 normal = Vec3::cross(p1 - p0, p2 - p0).normalize(); temp_normals[idx0] += normal; temp_normals[idx1] += normal; temp_normals[idx2] += normal; } } - + for (const auto& n : temp_normals) { Vec3 normalized = n.normalize(); v_norm.push_back(normalized.x); v_norm.push_back(normalized.y); v_norm.push_back(normalized.z); } - + // Assign generated normals to faces for (auto& face : raw_faces) { face.vn[0] = face.v[0]; @@ -392,12 +408,13 @@ int main(int argc, char* argv[]) { for (int i = 0; i < 3; ++i) { // Reconstruct key string for uniqueness check char key_buf[128]; - std::snprintf(key_buf, sizeof(key_buf), "%d/%d/%d", face.v[i], face.vt[i], face.vn[i]); + std::snprintf(key_buf, sizeof(key_buf), "%d/%d/%d", face.v[i], + face.vt[i], face.vn[i]); std::string key = key_buf; if (vertex_map.find(key) == vertex_map.end()) { vertex_map[key] = (uint32_t)final_vertices.size(); - + Vertex v = {}; if (face.v[i] > 0) { v.p[0] = v_pos[(face.v[i] - 1) * 3]; @@ -419,11 +436,12 @@ int main(int argc, char* argv[]) { } } - // Format: [num_vertices(u32)][Vertex * num_vertices][num_indices(u32)][uint32_t + // Format: [num_vertices(u32)][Vertex * + // num_vertices][num_indices(u32)][uint32_t // * num_indices] - buffer.resize(sizeof(uint32_t) + final_vertices.size() * sizeof(Vertex) + - sizeof(uint32_t) + - final_indices.size() * sizeof(uint32_t)); + buffer.resize( + sizeof(uint32_t) + final_vertices.size() * sizeof(Vertex) + + sizeof(uint32_t) + final_indices.size() * sizeof(uint32_t)); uint8_t* out_ptr = buffer.data(); *reinterpret_cast<uint32_t*>(out_ptr) = (uint32_t)final_vertices.size(); out_ptr += sizeof(uint32_t); @@ -500,9 +518,11 @@ int main(int argc, char* argv[]) { fprintf(assets_data_cc_file, " return %zu;\n", asset_build_infos.size()); fprintf(assets_data_cc_file, "}\n\n"); - fprintf(assets_data_cc_file, "AssetId GetAssetIdByName(const char* name) {\n"); + fprintf(assets_data_cc_file, + "AssetId GetAssetIdByName(const char* name) {\n"); for (const auto& info : asset_build_infos) { - fprintf(assets_data_cc_file, " if (std::strcmp(name, \"%s\") == 0) return AssetId::ASSET_%s;\n", + fprintf(assets_data_cc_file, + " if (std::strcmp(name, \"%s\") == 0) return AssetId::ASSET_%s;\n", info.name.c_str(), info.name.c_str()); } fprintf(assets_data_cc_file, " return AssetId::ASSET_LAST_ID;\n"); diff --git a/tools/seq_compiler.cc b/tools/seq_compiler.cc index 784bb80..f9409de 100644 --- a/tools/seq_compiler.cc +++ b/tools/seq_compiler.cc @@ -700,7 +700,8 @@ int main(int argc, char* argv[]) { out_file << "}\n\n"; } - out_file << "void LoadTimeline(MainSequence& main_seq, const GpuContext& ctx) {\n"; + out_file << "void LoadTimeline(MainSequence& main_seq, const GpuContext& " + "ctx) {\n"; for (const SequenceEntry& seq : sequences) { out_file << " {\n"; @@ -711,9 +712,8 @@ int main(int argc, char* argv[]) { } for (const EffectEntry& eff : seq.effects) { out_file << " seq->add_effect(std::make_shared<" << eff.class_name - << ">(ctx" << eff.extra_args << "), " - << eff.start << "f, " << eff.end << "f, " << eff.priority - << ");\n"; + << ">(ctx" << eff.extra_args << "), " << eff.start << "f, " + << eff.end << "f, " << eff.priority << ");\n"; } out_file << " main_seq.add_sequence(seq, " << seq.start_time << "f, " << seq.priority << ");\n"; diff --git a/tools/spectool.cc b/tools/spectool.cc index 1c6411e..bd17dfc 100644 --- a/tools/spectool.cc +++ b/tools/spectool.cc @@ -119,16 +119,17 @@ int analyze_audio(const char* in_path, const char* out_path, bool normalize, const size_t num_chunks = (pcm_data.size() + DCT_SIZE - 1) / DCT_SIZE; for (size_t chunk_idx = 0; chunk_idx < num_chunks; ++chunk_idx) { const size_t chunk_start = chunk_idx * DCT_SIZE; - const size_t chunk_end = - (chunk_start + DCT_SIZE < pcm_data.size()) ? chunk_start + DCT_SIZE - : pcm_data.size(); + const size_t chunk_end = (chunk_start + DCT_SIZE < pcm_data.size()) + ? chunk_start + DCT_SIZE + : pcm_data.size(); const size_t chunk_size = chunk_end - chunk_start; // Copy chunk (with zero-padding if needed) memcpy(pcm_chunk, pcm_data.data() + chunk_start, chunk_size * sizeof(float)); if (chunk_size < DCT_SIZE) { - memset(pcm_chunk + chunk_size, 0, (DCT_SIZE - chunk_size) * sizeof(float)); + memset(pcm_chunk + chunk_size, 0, + (DCT_SIZE - chunk_size) * sizeof(float)); } // Apply window @@ -327,10 +328,12 @@ void print_usage() { " test_gen <output.spec> Generate a test " "spectrogram.\n"); printf("\nOptions for 'analyze':\n"); - printf(" --normalize [rms] Normalize audio to target RMS level (default: " - "0.15)\n"); printf( - " Ensures consistent loudness across all samples.\n"); + " --normalize [rms] Normalize audio to target RMS level (default: " + "0.15)\n"); + printf( + " Ensures consistent loudness across all " + "samples.\n"); } int main(int argc, char** argv) { diff --git a/tools/tracker_compiler.cc b/tools/tracker_compiler.cc index 314099d..6784209 100644 --- a/tools/tracker_compiler.cc +++ b/tools/tracker_compiler.cc @@ -99,7 +99,7 @@ struct Sample { }; struct Event { - float unit_time; // Unit-less time within pattern + float unit_time; // Unit-less time within pattern std::string sample_name; float volume, pan; }; @@ -107,7 +107,8 @@ struct Event { struct Pattern { std::string name; std::vector<Event> events; - float unit_length; // Pattern duration in units (default 1.0 for 4-beat patterns) + float unit_length; // Pattern duration in units (default 1.0 for 4-beat + // patterns) }; struct Trigger { |
