Stage 5: content-hash AssetStore; undo records asset keys, not pixels

- resource::AssetStore (core) keeps immutable images and sounds keyed by content
  hash for the life of the document; nothing is purged until it closes.
- Undo state holds spritesheet/sound id -> asset key maps (always tracked), so
  every edit can undo texture changes; the textures-only snapshot flag
  (edit_begin(label, true) / push(message, isTextures)) and the pixel/audio
  equality helpers are gone.
- Document::texture_get/sound_get read through the store; texture_set/sound_set
  add assets; texture_edit gives the pencil a private draft that becomes a new
  asset on the next change().
- Spritesheet dirty state compares path + asset key instead of hashing pixels.
- Preview audio reads sounds through the store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 15:53:34 -04:00
1 parent 65a3546c3b
commit 9f43a210c5
13 files changed
+195 -130

No files matched your search

+13 -9
View File
@@ -210,7 +210,13 @@ namespace anm2ed::imgui
return document.sound_get(soundID) ? soundID : -1;
}
bool render_audio_stream_generate(AudioStream& audioStream, std::map<int, AudioData>& sounds,
void sounds_detach(const Document& document, MIX_Mixer* mixer)
{
for (auto& [id, _] : document.sounds)
if (auto sound = document.sound_get(id)) audio::track_detach(*sound, mixer);
}
bool render_audio_stream_generate(AudioStream& audioStream, const Document& document,
const std::vector<int>& frameSoundIDs, int fps)
{
audioStream.stream.clear();
@@ -229,7 +235,7 @@ namespace anm2ed::imgui
for (auto soundID : frameSoundIDs)
{
if (soundID != -1 && sounds.contains(soundID)) audio::play(sounds.at(soundID), false, mixer);
if (auto sound = document.sound_get(soundID)) audio::play(*sound, false, mixer);
sampleFrameAccumulator += framesPerStep;
auto sampleFramesToGenerate = (int)std::floor(sampleFrameAccumulator);
@@ -239,8 +245,7 @@ namespace anm2ed::imgui
frameBuffer.resize((std::size_t)sampleFramesToGenerate * (std::size_t)channels);
if (!MIX_Generate(mixer, frameBuffer.data(), (int)(frameBuffer.size() * sizeof(float))))
{
for (auto& [_, sound] : sounds)
audio::track_detach(sound, mixer);
sounds_detach(document, mixer);
MIX_DestroyMixer(mixer);
audioStream.stream.clear();
return false;
@@ -249,8 +254,7 @@ namespace anm2ed::imgui
audioStream.stream.insert(audioStream.stream.end(), frameBuffer.begin(), frameBuffer.end());
}
for (auto& [_, sound] : sounds)
audio::track_detach(sound, mixer);
sounds_detach(document, mixer);
MIX_DestroyMixer(mixer);
return true;
}
@@ -268,8 +272,8 @@ namespace anm2ed::imgui
auto stop_all_sounds = [&]()
{
for (auto& [_, sound] : document.sounds)
audio::stop(sound, mixer);
for (auto& [id, _] : document.sounds)
if (auto sound = document.sound_get(id)) audio::stop(*sound, mixer);
};
if (manager.isRecording)
@@ -367,7 +371,7 @@ namespace anm2ed::imgui
{
if (settings.timelineIsSound && type != render::GIF)
{
if (!render_audio_stream_generate(audioStream, document.sounds, renderFrameSoundIDs, renderFrameRate))
if (!render_audio_stream_generate(audioStream, document, renderFrameSoundIDs, renderFrameRate))
{
toasts.push(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED));
logger.error("Failed to generate deterministic render audio stream; exporting without audio.");
+2 -2
View File
@@ -133,7 +133,7 @@ namespace anm2ed::imgui
if (options.isMakeSpritesheet || options.isRemoveCurrent)
{
document.edit_begin(EDIT_EXPORT_REGION, true);
document.edit_begin(EDIT_EXPORT_REGION);
if (options.isMakeSpritesheet)
{
@@ -150,7 +150,7 @@ namespace anm2ed::imgui
exported.children.push_back(exportedRegion);
spritesheets->children.push_back(exported);
document.textures[exported.id] = Image(pixels.data(), exportSize);
document.texture_set(exported.id, Image(pixels.data(), exportSize));
document.texturePaths[exported.id] = exported.path;
document.spritesheet.reference = exported.id;
document.spritesheet.selection = {exported.id};
+6 -7
View File
@@ -359,10 +359,10 @@ namespace anm2ed::imgui
auto fraction = current - glm::floor(current);
return glm::floor(value) + fraction;
};
auto edit_begin_push = [&](StringType label, bool isTextures = false)
auto edit_begin_push = [&](StringType label)
{
manager.command_push({manager.selected, [label, isTextures](Manager&, Document& document)
{ document.edit_begin(label, isTextures); }});
manager.command_push(
{manager.selected, [label](Manager&, Document& document) { document.edit_begin(label); }});
};
auto document_change_push = [&](Document::ChangeType changeType)
{
@@ -542,9 +542,8 @@ namespace anm2ed::imgui
auto queuedSpritesheet = referenceSpritesheet;
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
auto texture = document.texture_get(queuedSpritesheet);
if (!texture) return;
texture->pixel_line(start, end, color);
if (auto texture = document.texture_edit(queuedSpritesheet))
texture->pixel_line(start, end, color);
}});
};
auto texture_change_push = [&]()
@@ -819,7 +818,7 @@ namespace anm2ed::imgui
{
if (!texture) break;
auto color = useTool == tool::DRAW ? toolColor : vec4();
if (isMouseClicked) edit_begin_push(useTool == tool::DRAW ? EDIT_DRAW : EDIT_ERASE, true);
if (isMouseClicked) edit_begin_push(useTool == tool::DRAW ? EDIT_DRAW : EDIT_ERASE);
if (isMouseDown) texture_line_apply(ivec2(previousTextureMousePos), ivec2(textureMousePos), color);
if (isMouseReleased) texture_change_push();
break;
+1 -1
View File
@@ -80,7 +80,7 @@ namespace anm2ed::imgui
void spritesheet_textures_edit(Document& document, StringType edit, Document::ChangeType changeType,
const std::function<bool()>& behavior, StringType successToast, StringType failToast)
{
document.edit_begin(edit, true);
document.edit_begin(edit);
auto isSuccess = behavior();
toast_log(isSuccess ? Level::INFO : Level::ERROR, isSuccess ? successToast : failToast);
document.change(changeType);
+1 -1
View File
@@ -66,7 +66,7 @@ namespace anm2ed::imgui
struct WindowCardImage
{
resource::Image* texture{};
const resource::Image* texture{};
glm::vec2 size{};
glm::vec2 uvMin{};
glm::vec2 uvMax{1.0f};