Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# AnimationManager.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * アニメーションマネージャ実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Animation/System/AnimationManager.h"
    00027 #include "Core/Renamer/CountRenamer.h"
    00028 #include "Animation/System/AnimationSet.h"
    00029 #include "Animation/Camera/CameraAnimation.h"
    00030 #include "Animation/SceneNode/SceneNodeAnimation.h"
    00031 #include "Animation/Model/CharacterModelAnimation.h"
    00032
    00033 namespace Lamp{
    00034
    00035 //------------------------------------------------------------------------------
    00036 // コンストラクタ
    00037 AnimationManager::AnimationManager() :
    00038     animationHash_(256, 0.75f), animationArray_(256),
    00039     animationDataHash_(256, 0.75f), animationDataArray_(256){
    00040     animationRenamer_ = new CountRenamer();
    00041     animationDataRenamer_ = new CountRenamer();
    00042 }
    00043 //------------------------------------------------------------------------------
    00044 // デストラクタ
    00045 AnimationManager::~AnimationManager(){
    00046     Assert(animationHash_.getCount() == 0);
    00047     Assert(animationArray_.getCount() == 0);
    00048     Assert(animationDataHash_.getCount() == 0);
    00049     Assert(animationDataArray_.getCount() == 0);
    00050     if(getCount() != 0){ clear(); }
    00051     if(getDataCount() != 0){ clear(); }
    00052     SafeDelete(animationDataRenamer_);
    00053     SafeDelete(animationRenamer_);
    00054 }
    00055 //------------------------------------------------------------------------------
    00056 // アニメーションセット
    00057 //------------------------------------------------------------------------------
    00058 // アニメーションセットの作成
    00059 AnimationSet* AnimationManager::createAnimationSet(const String& name){
    00060     AnimationSet* animation = new AnimationSet(rename(name), this);
    00061     animationHash_.put(animation->getName(), animation);
    00062     animationArray_.add(animation);
    00063     return animation;
    00064 }
    00065 //------------------------------------------------------------------------------
    00066 // カメラアニメーション
    00067 //------------------------------------------------------------------------------
    00068 // カメラアニメーションの作成
    00069 CameraAnimation* AnimationManager::createCamera(
    00070     const String& name){
    00071     CameraAnimation* animation = new CameraAnimation(rename(name), this);
    00072     animationHash_.put(animation->getName(), animation);
    00073     animationArray_.add(animation);
    00074     return animation;
    00075 }
    00076 //------------------------------------------------------------------------------
    00077 // カメラアニメーションデータの作成
    00078 CameraAnimationData* AnimationManager::createCameraData(
    00079     const String& name){
    00080     CameraAnimationData* animationData =
    00081         new CameraAnimationData(renameData(name), this);
    00082     animationDataHash_.put(animationData->getName(), animationData);
    00083     animationDataArray_.add(animationData);
    00084     return animationData;
    00085 }
    00086 //------------------------------------------------------------------------------
    00087 // シーンノードアニメーション
    00088 //------------------------------------------------------------------------------
    00089 // シーンノードアニメーションの作成
    00090 SceneNodeAnimation* AnimationManager::createSceneNode(
    00091     const String& name){
    00092     SceneNodeAnimation* animation = new SceneNodeAnimation(rename(name), this);
    00093     animationHash_.put(animation->getName(), animation);
    00094     animationArray_.add(animation);
    00095     return animation;
    00096 }
    00097 //------------------------------------------------------------------------------
    00098 // シーンノードアニメーションデータの作成
    00099 SceneNodeAnimationData* AnimationManager::createSceneNodeData(
    00100     const String& name){
    00101     SceneNodeAnimationData* animationData =
    00102         new SceneNodeAnimationData(renameData(name), this);
    00103     animationDataHash_.put(animationData->getName(), animationData);
    00104     animationDataArray_.add(animationData);
    00105     return animationData;
    00106 }
    00107 //------------------------------------------------------------------------------
    00108 // モデルアニメーション
    00109 //------------------------------------------------------------------------------
    00110 // キャラクタモデルアニメーションの作成
    00111 CharacterModelAnimation* AnimationManager::createCharacterModel(
    00112     const String& name){
    00113     CharacterModelAnimation* animation =
    00114         new CharacterModelAnimation(rename(name), this);
    00115     animationHash_.put(animation->getName(), animation);
    00116     animationArray_.add(animation);
    00117     return animation;
    00118 }
    00119 //------------------------------------------------------------------------------
    00120 // キャラクタモデルアニメーションデータの作成
    00121 CharacterModelAnimationData* AnimationManager::createCharacterModelData(
    00122     const String& name){
    00123     CharacterModelAnimationData* animationData =
    00124         new CharacterModelAnimationData(renameData(name), this);
    00125     animationDataHash_.put(animationData->getName(), animationData);
    00126     animationDataArray_.add(animationData);
    00127     return animationData;
    00128 }
    00129 //------------------------------------------------------------------------------
    00130 // 破棄、クリア
    00131 //------------------------------------------------------------------------------
    00132 // アニメーションの破棄
    00133 void AnimationManager::destroy(Animation* animation){
    00134     // アニメーションセットの場合は下位のアニメーションも削除する
    00135 /*
    00136     if(animation->isAnimationSet()){
    00137         AnimationSet* animationSet = animation->castAnimationSet();
    00138         int animationCount = animationSet->getAnimationCount();
    00139         for(int i = animationCount - 1; i >= 0; i--){
    00140             Animation* child = animationSet->getAnimation(i);
    00141             animationSet->removeAnimation(child);
    00142             destroy(child);
    00143         }
    00144     }
    00145 */
    00146     // データベースから検索して削除
    00147     if(animationArray_.removeByValue(animation) == -1){
    00148         ErrorOut("AnimationManager::destroy() "
    00149             "Not found object in array");
    00150     }
    00151     if(animationHash_.remove(animation->getName()) == NULL){
    00152         ErrorOut("AnimationManager::destroy() "
    00153             "Not found object in hashmap");
    00154     }
    00155     delete animation;
    00156 }
    00157 //------------------------------------------------------------------------------
    00158 // アニメーションデータの破棄
    00159 int AnimationManager::destroyData(AnimationData* animationData){
    00160     // 参照が残っていれば削除しない
    00161     int referenceCount = animationData->getReferenceCount();
    00162     Assert(referenceCount >= 0);
    00163     if(referenceCount != 0){ return referenceCount; }
    00164     // データベースから検索して削除
    00165     if(animationDataArray_.removeByValue(animationData) == -1){
    00166         ErrorOut("AnimationManager::destroyData() "
    00167             "Not found object in array");
    00168     }
    00169     if(animationDataHash_.remove(animationData->getName()) == NULL){
    00170         ErrorOut("AnimationManager::destroyData() "
    00171             "Not found object in hashmap");
    00172     }
    00173     delete animationData;
    00174     return 0;
    00175 }
    00176 //------------------------------------------------------------------------------
    00177 // クリア
    00178 int AnimationManager::clear(){
    00179     int result = 0;
    00180     // アニメーションの削除
    00181     int count = getCount();
    00182     for(int i = 0; i < count; i++){ delete get(i); }
    00183     result += count;
    00184     // アニメーションデータの削除
    00185     int dataCount = getDataCount();
    00186     for(int i = 0; i < dataCount; i++){ delete getData(i); }
    00187     result += dataCount;
    00188     // コンテナの削除
    00189     animationArray_.clear();
    00190     animationHash_.clear();
    00191     animationDataArray_.clear();
    00192     animationDataHash_.clear();
    00193     return result;
    00194 }
    00195 //------------------------------------------------------------------------------
    00196 // リネーマ
    00197 //------------------------------------------------------------------------------
    00198 // アニメーションリネーマの設定
    00199 void AnimationManager::setRenamer(Renamer* renamer){
    00200     Assert(renamer != NULL);
    00201     SafeDelete(animationRenamer_);
    00202     animationRenamer_ = renamer;
    00203 }
    00204 //------------------------------------------------------------------------------
    00205 // アニメーションデータリネーマの設定
    00206 void AnimationManager::setDataRenamer(Renamer* renamer){
    00207     Assert(renamer != NULL);
    00208     SafeDelete(animationDataRenamer_);
    00209     animationDataRenamer_ = renamer;
    00210 }
    00211 //------------------------------------------------------------------------------
    00212 } // End of namespace Lamp
    00213 //------------------------------------------------------------------------------