/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_AnimBlender.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_GFX_ANIMBLENDER_H_ #define NW_GFX_ANIMBLENDER_H_ #include #include #include namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @brief 汎用アニメーションブレンドの基底クラスです。 //! 抽象クラスですのでインスタンス化して使用することはできません。 //! //! AnimBlender は複数の AnimEvaluator のアニメーション評価結果をブレンドします。 //! AnimBlender で他の AnimBlender のアニメーション評価結果をブレンドすることも可能です。 //--------------------------------------------------------------------------- class AnimBlender : public AnimObject { public: NW_UT_RUNTIME_TYPEINFO; //! アニメーションオブジェクトの MoveArray の定義です。 //! //! :private typedef ut::MoveArray AnimObjectArray; //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 AnimBlender( os::IAllocator* allocator) : AnimObject(allocator, ANIMTYPE_BLENDER) { } //! デストラクタです。 virtual ~AnimBlender() {} //@} //---------------------------------------- //! @name 基本操作 //@{ //! @brief アニメーションを関連付けます。 //! //! Bind よりも詳細なバインド結果を得ることができます。 //! //! @param[in] animGroup アニメーショングループです。 //! //! @return バインドの結果を返します。 //! //! @sa Bind //! @sa TryBindResult virtual Result TryBind(AnimGroup* animGroup) { NW_NULL_ASSERT(animGroup); NW_ASSERT(m_AnimGroup == NULL); m_AnimGroup = animGroup; return Result(BIND_RESULT_OK); } //! アニメーションの関連付けを解除します。 virtual void Release() { m_AnimGroup = NULL; } //! フレームを更新します。 virtual void UpdateFrame() { for (int animObjIdx = 0; animObjIdx < m_AnimObjects.Size(); ++animObjIdx) { if (m_AnimObjects[animObjIdx] != NULL) { m_AnimObjects[animObjIdx]->UpdateFrame(); } } } //@} //---------------------------------------- //! @name 取得/設定 //@{ //! @brief メンバに関連付けられたアニメーションが存在するかどうかを取得します。 //! //! @param[in] memberIdx メンバインデックスです。 //! //! @return アニメーションが存在すれば true を返します。 //! virtual bool HasMemberAnim(int memberIdx) const { for (int animObjIdx = 0; animObjIdx < m_AnimObjects.Size(); ++animObjIdx) { if (m_AnimObjects[animObjIdx] != NULL && m_AnimObjects[animObjIdx]->HasMemberAnim(memberIdx)) { return true; } } return false; } //@} //---------------------------------------- //! @name アニメーションオブジェクト //@{ //! @brief アニメーションオブジェクトを追加します。 //! //! @param[in] animObj 追加するアニメーションオブジェクトです。 //! NULL を指定しておいて、後で ReplaceAnimObject() で置き換えることも可能です。 //! void AddAnimObject(AnimObject* animObj) { NW_ASSERT(m_AnimObjects.Size() < m_AnimObjects.Capacity()); m_AnimObjects.PushBack(animObj); } //! @brief アニメーションオブジェクトを取得します。 //! //! @param[in] animObjIdx アニメーションオブジェクトのインデックスです。 //! //! @return アニメーションオブジェクトです。 //! const AnimObject* GetAnimObject(int animObjIdx) const { NW_MINMAXLT_ASSERT(animObjIdx, 0, m_AnimObjects.Size()); return m_AnimObjects[animObjIdx]; } //! @brief アニメーションオブジェクトを取得します。 //! //! @param[in] animObjIdx アニメーションオブジェクトのインデックスです。 //! //! @return アニメーションオブジェクトです。 //! AnimObject* GetAnimObject(int animObjIdx) { NW_MINMAXLT_ASSERT(animObjIdx, 0, m_AnimObjects.Size()); return m_AnimObjects[animObjIdx]; } //! @brief アニメーションオブジェクトを置き替えます。 //! //! @param[in] animObjIdx 置き替えるアニメーションオブジェクトのインデックスです。 //! @param[in] animObj アニメーションオブジェクトです。 //! NULL を指定した場合、アニメーションオブジェクトがない状態になります。 //! //! @return 置き替える前のアニメーションオブジェクトです。 //! AnimObject* ReplaceAnimObject(int animObjIdx, AnimObject* animObj) { NW_MINMAXLT_ASSERT(animObjIdx, 0, m_AnimObjects.Size()); AnimObject* oldObj = m_AnimObjects[animObjIdx]; m_AnimObjects[animObjIdx] = animObj; return oldObj; } //! アニメーションオブジェクトをクリアします。 void ClearAnimObjects() { m_AnimObjects.Clear(); } //! 追加されているアニメーションオブジェクト数を取得します。 int GetAnimObjectCount() const { return m_AnimObjects.Size(); } //! アニメーションオブジェクトの最大数を取得します。 int GetMaxAnimObjects() const { return m_AnimObjects.Capacity(); } //@} //---------------------------------------- //! @name キャッシュ //@{ //! アニメーション評価結果の内部キャッシュが古ければ更新します。 virtual void UpdateCache() { for (int animObjIdx = 0; animObjIdx < m_AnimObjects.Size(); ++animObjIdx) { if (m_AnimObjects[animObjIdx] != NULL) { m_AnimObjects[animObjIdx]->UpdateCache(); } } } //@} protected: //! Initialize() の実行に必要なメモリサイズを取得します。 //! //! :private static void GetMemorySizeForInitialize(os::MemorySizeCalculator* pSize, int maxAnimObjects) { os::MemorySizeCalculator& size = *pSize; size += sizeof(AnimObject*) * maxAnimObjects; } //! @details :private Result Initialize(int maxAnimObjects) { Result result = INITIALIZE_RESULT_OK; void* memory = GetAllocator().Alloc(sizeof(AnimObject*) * maxAnimObjects); if (memory == NULL) { result |= Result::MASK_FAIL_BIT; } NW_ENSURE_AND_RETURN(result); m_AnimObjects = AnimObjectArray(memory, maxAnimObjects, &GetAllocator()); return result; } AnimObjectArray m_AnimObjects; //!< @details :private }; } // namespace gfx } // namespace nw #endif // NW_GFX_ANIMBLENDER_H_