From a9712944edf853b11db425e2f9ab17ed1eec9ea7 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 28 Dec 2013 04:42:02 +0100 Subject: [PATCH] Fix animation editor problems: Undo buffer memory hoarding, add warning if saving failed. Thanks to Peri for finally making me fix this. --- Aquaria/AnimationEditor.cpp | 10 ++++++++-- Aquaria/States.h | 2 +- BBGE/SkeletalSprite.cpp | 9 +++++++-- BBGE/SkeletalSprite.h | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 110fea3..5539380 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -516,6 +516,10 @@ void AnimationEditor::pushUndo() SkeletalSprite sk; sk.animations = editSprite->animations; undoHistory.push_back(sk); + + if(undoHistory.size() > 50) + undoHistory.pop_front(); + undoEntry = undoHistory.size()-1; } @@ -1328,8 +1332,10 @@ void AnimationEditor::cloneBoneAhead() void AnimationEditor::saveFile() { - editSprite->saveSkeletal(editingFile); - dsq->screenMessage("Saved anim: " + editingFile); + if(editSprite->saveSkeletal(editingFile)) + dsq->screenMessage("Saved anim: " + editingFile); + else + dsq->screenMessage("FAILED TO SAVE: " + editingFile); } void AnimationEditor::loadFile() diff --git a/Aquaria/States.h b/Aquaria/States.h index a662a53..1216a19 100644 --- a/Aquaria/States.h +++ b/Aquaria/States.h @@ -204,7 +204,7 @@ public: void moveNextWidgets(float dt); - std::vector undoHistory; + std::deque undoHistory; int undoEntry; diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index d7abec1..8fe3263 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -846,15 +846,20 @@ void AnimationLayer::update(float dt) } } -void SkeletalSprite::saveSkeletal(const std::string &fn) +bool SkeletalSprite::saveSkeletal(const std::string &fn) { std::string file, filename=fn; stringToLower(filename); if (!secondaryAnimationPath.empty()) + { + createDir(secondaryAnimationPath); file = secondaryAnimationPath + filename + ".xml"; + } else + { file = animationPath + filename + ".xml"; + } int i = 0; TiXmlDocument& xml = _retrieveSkeletalXML(file); @@ -1032,7 +1037,7 @@ void SkeletalSprite::saveSkeletal(const std::string &fn) animations.InsertEndChild(animation); } xml.InsertEndChild(animations); - xml.SaveFile(file); + return xml.SaveFile(file); } int SkeletalSprite::getBoneIdx(Bone *b) diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index 570c4bf..8e66a64 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -203,7 +203,7 @@ public: SkeletalSprite(); void loadSkeletal(const std::string &fn); - void saveSkeletal(const std::string &fn); + bool saveSkeletal(const std::string &fn); void loadSkin(const std::string &fn); Bone *getBoneByIdx(int idx);