diff --git a/.vscode/launch.json b/.vscode/launch.json index cdfd141..dcdee9f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,8 +5,12 @@ "name": "Debug", "type": "cppdbg", "request": "launch", +<<<<<<< HEAD "preLaunchTask": "build-debug", "program": "${workspaceFolder}/out/build/linux-debug/bin/anm2ed", +======= + "program": "${workspaceFolder}/out/build/linux-debug/anm2ed", +>>>>>>> f58d894 (Render animation fixes, vs code tasks) "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", @@ -29,8 +33,12 @@ "name": "Release", "type": "cppdbg", "request": "launch", +<<<<<<< HEAD "preLaunchTask": "build-release", "program": "${workspaceFolder}/out/build/linux-release/bin/anm2ed", +======= + "program": "${workspaceFolder}/out/build/linux-release/anm2ed", +>>>>>>> f58d894 (Render animation fixes, vs code tasks) "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 87f59fa..546a48d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,6 +3,7 @@ "tasks": [ { "label": "run-debug", +<<<<<<< HEAD "type": "shell", "command": "cmake", "args": [ @@ -27,6 +28,18 @@ "anm2ed" ], "dependsOn": "run-debug", +======= + "type": "shell", + "command": "cmake -S . -B out/build/linux-debug -DCMAKE_BUILD_TYPE=Debug && cmake --build out/build/linux-debug --parallel 8 --target anm2ed && ./out/build/linux-debug/anm2ed", + "problemMatcher": [ + "$gcc" + ] + }, + { + "label": "build", + "type": "shell", + "command": "cmake -S . -B out/build/linux-debug -DCMAKE_BUILD_TYPE=Debug && cmake --build out/build/linux-debug --parallel 8 --target anm2ed", +>>>>>>> f58d894 (Render animation fixes, vs code tasks) "group": { "kind": "build", "isDefault": true @@ -38,6 +51,7 @@ { "label": "run-release", "type": "shell", +<<<<<<< HEAD "command": "cmake", "args": [ "-S", @@ -46,6 +60,9 @@ "out/build/linux-release", "-DCMAKE_BUILD_TYPE=Release" ], +======= + "command": "cmake -S . -B out/build/linux-release -DCMAKE_BUILD_TYPE=Release && cmake --build out/build/linux-release --parallel 8 --target anm2ed && ./out/build/linux-release/anm2ed", +>>>>>>> f58d894 (Render animation fixes, vs code tasks) "problemMatcher": [ "$gcc" ] @@ -53,6 +70,7 @@ { "label": "build-release", "type": "shell", +<<<<<<< HEAD "command": "cmake", "args": [ "--build", @@ -61,6 +79,9 @@ "anm2ed" ], "dependsOn": "run-release", +======= + "command": "cmake -S . -B out/build/linux-release -DCMAKE_BUILD_TYPE=Release && cmake --build out/build/linux-release --parallel 8 --target anm2ed", +>>>>>>> f58d894 (Render animation fixes, vs code tasks) "group": "build", "problemMatcher": [ "$gcc" @@ -73,4 +94,4 @@ "problemMatcher": [] } ] -} +} \ No newline at end of file diff --git a/src/anm2/anm2.cpp b/src/anm2/anm2.cpp index c9e9585..f72cea4 100644 --- a/src/anm2/anm2.cpp +++ b/src/anm2/anm2.cpp @@ -18,6 +18,13 @@ using namespace glm; namespace { + int remap_id(const std::unordered_map& table, int value) + { + if (value < 0) return value; + if (auto it = table.find(value); it != table.end()) return it->second; + return value; + } + void region_frames_sync(anm2ed::anm2::Anm2& anm2, bool clearInvalid) { for (auto& animation : anm2.animations.items) @@ -84,12 +91,13 @@ namespace anm2ed::anm2 XMLElement* Anm2::to_element(XMLDocument& document, Flags flags) { - region_frames_sync(*this, true); + auto normalized = normalized_for_serialize(); + region_frames_sync(normalized, true); auto element = document.NewElement("AnimatedActor"); - info.serialize(document, element); - content.serialize(document, element, flags); - animations.serialize(document, element, flags); + normalized.info.serialize(document, element); + normalized.content.serialize(document, element, flags); + normalized.animations.serialize(document, element, flags); return element; } @@ -123,6 +131,46 @@ namespace anm2ed::anm2 uint64_t Anm2::hash() { return std::hash{}(to_string()); } + Anm2 Anm2::normalized_for_serialize() const + { + auto normalized = *this; + std::unordered_map layerRemap{}; + + int normalizedID = 0; + for (auto& [layerID, layer] : content.layers) + { + layerRemap[layerID] = normalizedID; + ++normalizedID; + } + + normalized.content.layers.clear(); + for (auto& [layerID, layer] : content.layers) + normalized.content.layers[remap_id(layerRemap, layerID)] = layer; + + for (auto& animation : normalized.animations.items) + { + std::unordered_map layerAnimations{}; + std::vector layerOrder{}; + + for (auto layerID : animation.layerOrder) + { + auto mappedID = remap_id(layerRemap, layerID); + if (mappedID >= 0) layerOrder.push_back(mappedID); + } + + for (auto& [layerID, item] : animation.layerAnimations) + { + auto mappedID = remap_id(layerRemap, layerID); + if (mappedID >= 0) layerAnimations[mappedID] = item; + } + + animation.layerAnimations = std::move(layerAnimations); + animation.layerOrder = std::move(layerOrder); + } + + return normalized; + } + Frame* Anm2::frame_get(int animationIndex, Type itemType, int frameIndex, int itemID) { if (auto item = item_get(animationIndex, itemType, itemID); item) @@ -177,13 +225,6 @@ namespace anm2ed::anm2 return original; }; - auto remap_id = [](const auto& table, int value) - { - if (value < 0) return value; - if (auto it = table.find(value); it != table.end()) return it->second; - return value; - }; - std::unordered_map spritesheetRemap{}; std::unordered_map layerRemap{}; std::unordered_map nullRemap{}; diff --git a/src/anm2/anm2.hpp b/src/anm2/anm2.hpp index 4ac11ad..12c0b41 100644 --- a/src/anm2/anm2.hpp +++ b/src/anm2/anm2.hpp @@ -36,6 +36,7 @@ namespace anm2ed::anm2 std::string to_string(Flags = 0); Anm2(const std::filesystem::path&, std::string* = nullptr); uint64_t hash(); + Anm2 normalized_for_serialize() const; Spritesheet* spritesheet_get(int); bool spritesheet_add(const std::filesystem::path&, const std::filesystem::path&, int&); diff --git a/src/imgui/window/animation_preview.cpp b/src/imgui/window/animation_preview.cpp index 6167df7..b6602c5 100644 --- a/src/imgui/window/animation_preview.cpp +++ b/src/imgui/window/animation_preview.cpp @@ -105,6 +105,7 @@ namespace anm2ed::imgui pixels[index + 2] = (uint8_t)glm::clamp((float)std::round((float)pixels[index + 2] / alphaUnit), 0.0f, 255.0f); } } +<<<<<<< HEAD bool render_audio_stream_generate(AudioStream& audioStream, std::map& sounds, const std::vector& frameSoundIDs, int fps) @@ -150,6 +151,8 @@ namespace anm2ed::imgui MIX_DestroyMixer(mixer); return true; } +======= +>>>>>>> f58d894 (Render animation fixes, vs code tasks) } AnimationPreview::AnimationPreview() : Canvas(vec2()) {} @@ -368,7 +371,8 @@ namespace anm2ed::imgui } else { - toasts.push(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString))); + toasts.push( + std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString))); logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH), std::make_format_args(pathString))); if (type != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames); @@ -649,7 +653,8 @@ namespace anm2ed::imgui if (renderTempDirectory.empty()) { auto pathString = path::to_utf8(settings.renderPath); - toasts.push(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString))); + toasts.push( + std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString))); logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH), std::make_format_args(pathString))); manager.isRecording = false; diff --git a/src/imgui/window/regions.cpp b/src/imgui/window/regions.cpp index 261c3fb..e125644 100644 --- a/src/imgui/window/regions.cpp +++ b/src/imgui/window/regions.cpp @@ -5,6 +5,7 @@ #include +<<<<<<< HEAD #include "document.hpp" #include "log.hpp" #include "map_.hpp" @@ -12,6 +13,15 @@ #include "strings.hpp" #include "toast.hpp" #include "vector_.hpp" +======= +#include "document.h" +#include "log.h" +#include "map_.h" +#include "math_.h" +#include "strings.h" +#include "toast.h" +#include "vector_.h" +>>>>>>> f58d894 (Render animation fixes, vs code tasks) #include "../../util/map_.hpp"