Render animation fixes, vs code tasks

This commit is contained in:
2026-03-15 13:22:53 -04:00
parent bbfafd7331
commit a83dbd5b6c
6 changed files with 100 additions and 14 deletions

8
.vscode/launch.json vendored
View File

@@ -5,8 +5,12 @@
"name": "Debug", "name": "Debug",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
<<<<<<< HEAD
"preLaunchTask": "build-debug", "preLaunchTask": "build-debug",
"program": "${workspaceFolder}/out/build/linux-debug/bin/anm2ed", "program": "${workspaceFolder}/out/build/linux-debug/bin/anm2ed",
=======
"program": "${workspaceFolder}/out/build/linux-debug/anm2ed",
>>>>>>> f58d894 (Render animation fixes, vs code tasks)
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
@@ -29,8 +33,12 @@
"name": "Release", "name": "Release",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
<<<<<<< HEAD
"preLaunchTask": "build-release", "preLaunchTask": "build-release",
"program": "${workspaceFolder}/out/build/linux-release/bin/anm2ed", "program": "${workspaceFolder}/out/build/linux-release/bin/anm2ed",
=======
"program": "${workspaceFolder}/out/build/linux-release/anm2ed",
>>>>>>> f58d894 (Render animation fixes, vs code tasks)
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",

21
.vscode/tasks.json vendored
View File

@@ -3,6 +3,7 @@
"tasks": [ "tasks": [
{ {
"label": "run-debug", "label": "run-debug",
<<<<<<< HEAD
"type": "shell", "type": "shell",
"command": "cmake", "command": "cmake",
"args": [ "args": [
@@ -27,6 +28,18 @@
"anm2ed" "anm2ed"
], ],
"dependsOn": "run-debug", "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": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
@@ -38,6 +51,7 @@
{ {
"label": "run-release", "label": "run-release",
"type": "shell", "type": "shell",
<<<<<<< HEAD
"command": "cmake", "command": "cmake",
"args": [ "args": [
"-S", "-S",
@@ -46,6 +60,9 @@
"out/build/linux-release", "out/build/linux-release",
"-DCMAKE_BUILD_TYPE=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": [ "problemMatcher": [
"$gcc" "$gcc"
] ]
@@ -53,6 +70,7 @@
{ {
"label": "build-release", "label": "build-release",
"type": "shell", "type": "shell",
<<<<<<< HEAD
"command": "cmake", "command": "cmake",
"args": [ "args": [
"--build", "--build",
@@ -61,6 +79,9 @@
"anm2ed" "anm2ed"
], ],
"dependsOn": "run-release", "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", "group": "build",
"problemMatcher": [ "problemMatcher": [
"$gcc" "$gcc"

View File

@@ -18,6 +18,13 @@ using namespace glm;
namespace namespace
{ {
int remap_id(const std::unordered_map<int, int>& 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) void region_frames_sync(anm2ed::anm2::Anm2& anm2, bool clearInvalid)
{ {
for (auto& animation : anm2.animations.items) for (auto& animation : anm2.animations.items)
@@ -84,12 +91,13 @@ namespace anm2ed::anm2
XMLElement* Anm2::to_element(XMLDocument& document, Flags flags) 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"); auto element = document.NewElement("AnimatedActor");
info.serialize(document, element); normalized.info.serialize(document, element);
content.serialize(document, element, flags); normalized.content.serialize(document, element, flags);
animations.serialize(document, element, flags); normalized.animations.serialize(document, element, flags);
return element; return element;
} }
@@ -123,6 +131,46 @@ namespace anm2ed::anm2
uint64_t Anm2::hash() { return std::hash<std::string>{}(to_string()); } uint64_t Anm2::hash() { return std::hash<std::string>{}(to_string()); }
Anm2 Anm2::normalized_for_serialize() const
{
auto normalized = *this;
std::unordered_map<int, int> 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<int, Item> layerAnimations{};
std::vector<int> 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) Frame* Anm2::frame_get(int animationIndex, Type itemType, int frameIndex, int itemID)
{ {
if (auto item = item_get(animationIndex, itemType, itemID); item) if (auto item = item_get(animationIndex, itemType, itemID); item)
@@ -177,13 +225,6 @@ namespace anm2ed::anm2
return original; 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<int, int> spritesheetRemap{}; std::unordered_map<int, int> spritesheetRemap{};
std::unordered_map<int, int> layerRemap{}; std::unordered_map<int, int> layerRemap{};
std::unordered_map<int, int> nullRemap{}; std::unordered_map<int, int> nullRemap{};

View File

@@ -36,6 +36,7 @@ namespace anm2ed::anm2
std::string to_string(Flags = 0); std::string to_string(Flags = 0);
Anm2(const std::filesystem::path&, std::string* = nullptr); Anm2(const std::filesystem::path&, std::string* = nullptr);
uint64_t hash(); uint64_t hash();
Anm2 normalized_for_serialize() const;
Spritesheet* spritesheet_get(int); Spritesheet* spritesheet_get(int);
bool spritesheet_add(const std::filesystem::path&, const std::filesystem::path&, int&); bool spritesheet_add(const std::filesystem::path&, const std::filesystem::path&, int&);

View File

@@ -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); 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<int, anm2::Sound>& sounds, bool render_audio_stream_generate(AudioStream& audioStream, std::map<int, anm2::Sound>& sounds,
const std::vector<int>& frameSoundIDs, int fps) const std::vector<int>& frameSoundIDs, int fps)
@@ -150,6 +151,8 @@ namespace anm2ed::imgui
MIX_DestroyMixer(mixer); MIX_DestroyMixer(mixer);
return true; return true;
} }
=======
>>>>>>> f58d894 (Render animation fixes, vs code tasks)
} }
AnimationPreview::AnimationPreview() : Canvas(vec2()) {} AnimationPreview::AnimationPreview() : Canvas(vec2()) {}
@@ -368,7 +371,8 @@ namespace anm2ed::imgui
} }
else 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), logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString))); std::make_format_args(pathString)));
if (type != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames); if (type != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames);
@@ -649,7 +653,8 @@ namespace anm2ed::imgui
if (renderTempDirectory.empty()) if (renderTempDirectory.empty())
{ {
auto pathString = path::to_utf8(settings.renderPath); 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), logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString))); std::make_format_args(pathString)));
manager.isRecording = false; manager.isRecording = false;

View File

@@ -5,6 +5,7 @@
#include <format> #include <format>
<<<<<<< HEAD
#include "document.hpp" #include "document.hpp"
#include "log.hpp" #include "log.hpp"
#include "map_.hpp" #include "map_.hpp"
@@ -12,6 +13,15 @@
#include "strings.hpp" #include "strings.hpp"
#include "toast.hpp" #include "toast.hpp"
#include "vector_.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" #include "../../util/map_.hpp"