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

# AnimationSet.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/AnimationSet.h"
    00027 #include "Animation/System/AnimationManager.h"
    00028
    00029 namespace Lamp{
    00030
    00031 //------------------------------------------------------------------------------
    00032 // コンストラクタ
    00033 AnimationSet::AnimationSet(String name, AnimationManager* manager) :
    00034     Animation(name, manager){
    00035 }
    00036 //------------------------------------------------------------------------------
    00037 // デストラクタ
    00038 AnimationSet::~AnimationSet(){
    00039 }
    00040 //------------------------------------------------------------------------------
    00041 // バインド
    00042 bool AnimationSet::bind(Scene* scene){
    00043     // 全てのバインドが成功すれば成功
    00044     bool result = true;
    00045     int animationCount = getAnimationCount();
    00046     for(int i = 0; i < animationCount; i++){
    00047         if(!getAnimation(i)->bind(scene)){ result = false; }
    00048     }
    00049     return result;
    00050 }
    00051 //------------------------------------------------------------------------------
    00052 // バインド解除
    00053 void AnimationSet::unbind(){
    00054     int animationCount = getAnimationCount();
    00055     for(int i = 0; i < animationCount; i++){
    00056         getAnimation(i)->unbind();
    00057     }
    00058 }
    00059 //------------------------------------------------------------------------------
    00060 // シーケンス数の取得
    00061 int AnimationSet::getSequenceCount() const{
    00062     // 一番小さいシーケンス数を取り出す
    00063     int animationCount = getAnimationCount();
    00064     if(animationCount == 0){ return 0; }
    00065     int result = getAnimation(0)->getSequenceCount();
    00066     for(int i = 1; i < animationCount; i++){
    00067         int count = getAnimation(i)->getSequenceCount();
    00068         if(count < result){ result = count; }
    00069     }
    00070     return result;
    00071 }
    00072 //------------------------------------------------------------------------------
    00073 // シーケンスの設定
    00074 void AnimationSet::setSequence(int sequence, float time){
    00075     Assert(sequence >= 0);
    00076     Assert(sequence < getSequenceCount());
    00077     int animationCount = getAnimationCount();
    00078     for(int i = 0; i < animationCount; i++){
    00079         getAnimation(i)->setSequence(sequence, time);
    00080     }
    00081 }
    00082 //------------------------------------------------------------------------------
    00083 // シーケンスの取得
    00084 int AnimationSet::getSequence() const{
    00085     // 一番小さいシーケンスを取り出す
    00086     int animationCount = getAnimationCount();
    00087     if(animationCount == 0){ return 0; }
    00088     int result = getAnimation(0)->getSequence();
    00089     for(int i = 1; i < animationCount; i++){
    00090         int sequence = getAnimation(i)->getSequence();
    00091         if(sequence < result){ result = sequence; }
    00092     }
    00093     return result;
    00094 }
    00095 //------------------------------------------------------------------------------
    00096 // 時間の設定
    00097 void AnimationSet::setTime(float time){
    00098     int animationCount = getAnimationCount();
    00099     for(int i = 0; i < animationCount; i++){ getAnimation(i)->setTime(time); }
    00100 }
    00101 //------------------------------------------------------------------------------
    00102 // 時間の取得
    00103 float AnimationSet::getTime() const{
    00104     // 一番小さい時間を取り出す
    00105     int animationCount = getAnimationCount();
    00106     if(animationCount == 0){ return 0.f; }
    00107     float result = getAnimation(0)->getTime();
    00108     for(int i = 1; i < animationCount; i++){
    00109         float time = getAnimation(i)->getTime();
    00110         if(time < result){ result = time; }
    00111     }
    00112     return result;
    00113 }
    00114 //------------------------------------------------------------------------------
    00115 // アニメーション
    00116 bool AnimationSet::animate(float deltaTime, AnimationMask mask){
    00117     // 有効でなければアニメーションしない
    00118     if(!isEnabled()){ return true; }
    00119     // 全てのアニメーションが終了していればtrue
    00120     bool result = true;
    00121     int animationCount = getAnimationCount();
    00122     for(int i = 0; i < animationCount; i++){
    00123         if(!getAnimation(i)->animate(deltaTime, mask)){ result = false; }
    00124     }
    00125     return result;
    00126 }
    00127 //------------------------------------------------------------------------------
    00128 // 長さの取得
    00129 float AnimationSet::getLength() const{
    00130     // 一番長い長さを取得
    00131     int animationCount = getAnimationCount();
    00132     if(animationCount == 0){ return 0.f; }
    00133     float result = getAnimation(0)->getLength();
    00134     for(int i = 1; i < animationCount; i++){
    00135         float length = getAnimation(i)->getLength();
    00136         if(length > result){ result = length; }
    00137     }
    00138     return result;
    00139 }
    00140 //------------------------------------------------------------------------------
    00141 // 終了しているか
    00142 bool AnimationSet::isFinished() const{
    00143     // 全てが終了していればtrue
    00144     bool result = true;
    00145     int animationCount = getAnimationCount();
    00146     for(int i = 0; i < animationCount; i++){
    00147         if(!getAnimation(i)->isFinished()){ result = false; }
    00148     }
    00149     return result;
    00150 }
    00151 //------------------------------------------------------------------------------
    00152 // ループしているか
    00153 bool AnimationSet::isLooped() const{
    00154     // 一つでもループしていればtrue;
    00155     int animationCount = getAnimationCount();
    00156     for(int i = 0; i < animationCount; i++){
    00157         if(getAnimation(i)->isLooped()){ return true; }
    00158     }
    00159     return false;
    00160 }
    00161 //------------------------------------------------------------------------------
    00162 // アニメーションセットのコピー
    00163 AnimationSet* AnimationSet::copyAnimationSet(DataCopyMask dataCopyMask) const{
    00164     AnimationSet* animation = getManager()->createAnimationSet(getName());
    00165     animation->setEnabled(isEnabled());
    00166     int animationCount = getAnimationCount();
    00167     for(int i = 0; i < animationCount; i++){
    00168         animation->addAnimation(getAnimation(i)->copy(dataCopyMask));
    00169     }
    00170     return animation;
    00171 }
    00172 //------------------------------------------------------------------------------
    00173 } // End of namespace Lamp
    00174 //------------------------------------------------------------------------------