From 82f587f2f3795898ed4fb7b125bf34b7e13de7cd Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 14 Nov 2006 21:40:40 +0000 Subject: Separated Action class to its own module. --- ChangeLog | 6 ++++ src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/action.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/action.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/animatedsprite.cpp | 1 + src/animation.cpp | 47 ---------------------------- src/animation.h | 47 ---------------------------- 8 files changed, 172 insertions(+), 94 deletions(-) create mode 100644 src/action.cpp create mode 100644 src/action.h diff --git a/ChangeLog b/ChangeLog index 674fd3d6..d81e426f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-11-14 Bjørn Lindeijer + + * src/action.h, src/action.cpp, src/animation.h, src/CMakeLists.txt, + src/animatedsprite.cpp, src/animation.cpp, src/Makefile.am: Separated + Action class to its own module. + 2006-11-12 Bjørn Lindeijer * src/map.cpp, src/map.h: Made pathfinding algorithm cope better with diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 009f4fc3..35b01931 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -227,6 +227,8 @@ SET(SRCS resources/buddylist.cpp utils/dtor.h utils/tostring.h + action.cpp + action.h animatedsprite.cpp animatedsprite.h animation.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 7d37edf8..8166efed 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -189,6 +189,8 @@ tmw_SOURCES = graphic/imagerect.h \ resources/buddylist.cpp \ utils/dtor.h \ utils/tostring.h \ + action.cpp \ + action.h \ animatedsprite.cpp \ animatedsprite.h \ animation.cpp \ diff --git a/src/action.cpp b/src/action.cpp new file mode 100644 index 00000000..4abfa229 --- /dev/null +++ b/src/action.cpp @@ -0,0 +1,77 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: animation.cpp 2822 2006-11-05 14:30:53Z b_lindeijer $ + */ + +#include "action.h" + +#include + +#include "animation.h" +#include "utils/dtor.h" + + +Action::Action(): + mSpriteset(NULL) +{ +} + +Action::~Action() +{ + std::for_each(mAnimations.begin(), mAnimations.end(), make_dtor(mAnimations)); + mAnimations.clear(); +} + +Animation* +Action::getAnimation(int direction) const +{ + Animations::const_iterator i = mAnimations.find(direction); + + // When the direction isn't defined, try the default + if (i == mAnimations.end()) + { + i = mAnimations.find(0); + } + + return (i == mAnimations.end()) ? NULL : i->second; +} + +void +Action::setAnimation(int direction, Animation *animation) +{ + // Set first direction as default direction + if (mAnimations.empty()) + { + mAnimations[0] = animation; + } + + mAnimations[direction] = animation; +} + +void +Action::reset() +{ + for (AnimationIterator i = mAnimations.begin(); + i != mAnimations.end(); ++i) + { + i->second->reset(); + } +} diff --git a/src/action.h b/src/action.h new file mode 100644 index 00000000..a686e722 --- /dev/null +++ b/src/action.h @@ -0,0 +1,84 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: animation.h 2822 2006-11-05 14:30:53Z b_lindeijer $ + */ + +#ifndef _TMW_ACTION_H +#define _TMW_ACTION_H + +#include + +#include + +class Image; +class Spriteset; + +struct AnimationPhase; +class Animation; + +/** + * An action consists of several animations, one for each direction. + */ +class Action +{ + public: + /** + * Constructor. + */ + Action(); + + /** + * Destructor. + */ + ~Action(); + + /** + * Sets the spriteset used by this action. + */ + void + setSpriteset(Spriteset *spriteset) { mSpriteset = spriteset; } + + /** + * Returns the spriteset used by this action. + */ + Spriteset* + getSpriteset() const { return mSpriteset; } + + void + setAnimation(int direction, Animation *animation); + + /** + * Resets all animations associated with this action. + */ + void + reset(); + + Animation* + getAnimation(int direction) const; + + protected: + Spriteset *mSpriteset; + typedef std::map Animations; + typedef Animations::iterator AnimationIterator; + Animations mAnimations; +}; + +#endif diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index e7439644..e5a4df15 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -24,6 +24,7 @@ #include "animatedsprite.h" #include "animation.h" +#include "action.h" #include "graphics.h" #include "log.h" diff --git a/src/animation.cpp b/src/animation.cpp index 98a4abb8..bca4bb58 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -115,50 +115,3 @@ Animation::getLength() } return length; } - -Action::Action(): - mSpriteset(NULL) -{ -} - -Action::~Action() -{ - std::for_each(mAnimations.begin(), mAnimations.end(), make_dtor(mAnimations)); - mAnimations.clear(); -} - -Animation* -Action::getAnimation(int direction) const -{ - Animations::const_iterator i = mAnimations.find(direction); - - // When the direction isn't defined, try the default - if (i == mAnimations.end()) - { - i = mAnimations.find(0); - } - - return (i == mAnimations.end()) ? NULL : i->second; -} - -void -Action::setAnimation(int direction, Animation *animation) -{ - // Set first direction as default direction - if (mAnimations.empty()) - { - mAnimations[0] = animation; - } - - mAnimations[direction] = animation; -} - -void -Action::reset() -{ - for (AnimationIterator i = mAnimations.begin(); - i != mAnimations.end(); ++i) - { - i->second->reset(); - } -} diff --git a/src/animation.h b/src/animation.h index 605d8cb1..8f62b9c4 100644 --- a/src/animation.h +++ b/src/animation.h @@ -110,51 +110,4 @@ class Animation unsigned int mTime; }; -/** - * An action consists of several animations, one for each direction. - */ -class Action -{ - public: - /** - * Constructor. - */ - Action(); - - /** - * Destructor. - */ - ~Action(); - - /** - * Sets the spriteset used by this action. - */ - void - setSpriteset(Spriteset *spriteset) { mSpriteset = spriteset; } - - /** - * Returns the spriteset used by this action. - */ - Spriteset* - getSpriteset() const { return mSpriteset; } - - void - setAnimation(int direction, Animation *animation); - - /** - * Resets all animations associated with this action. - */ - void - reset(); - - Animation* - getAnimation(int direction) const; - - protected: - Spriteset *mSpriteset; - typedef std::map Animations; - typedef Animations::iterator AnimationIterator; - Animations mAnimations; -}; - #endif -- cgit v1.2.3-60-g2f50