/*---------------------------------------------------------------------------* Project: NintendoWare File: lyt_Animation.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_LYT_ANIMATION_H_ #define NW_LYT_ANIMATION_H_ #include #include namespace nw { namespace lyt { namespace res { struct BinaryFileHeader; struct AnimationBlock; struct AnimationTagBlock; struct AnimationShareBlock; } // namespace res namespace internal { class AnimPaneTreeLink; } // namespace internal class Pane; class Layout; class Group; class Material; class ResourceAccessor; class TextureInfo; class AnimationLink; //--------------------------------------------------------------------------- //! :category アニメーション //! //! @brief アニメーションの基底クラスです。 //! //! @since 2009/09/18 初版。 //--------------------------------------------------------------------------- class AnimTransform { public: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! @brief コンストラクタです。 //! //! @since 2009/09/18 初版。 //! AnimTransform(); //! @brief デストラクタです。 //! //! @since 2009/09/18 初版。 //! virtual ~AnimTransform(); //@} //---------------------------------------- //! @name 設定/取得 //@{ //! @brief 現在のフレーム位置を取得します。 //! //! @return 現在のフレーム位置を返します。 //! //! @sa SetFrame //! //! @since 2009/09/18 初版。 //! f32 GetFrame() const { return m_Frame; } //! @brief フレーム位置を設定します。 //! //! @param frame フレーム位置です。 //! //! @sa GetFrame //! //! @since 2009/09/18 初版。 //! void SetFrame(f32 frame) { m_Frame = frame; } //! @brief フレームの長さを取得します。 //! //! @return フレームの長さを返します。 //! //! @since 2009/09/18 初版。 //! u16 GetFrameSize() const; //! @brief フレーム位置の最大値を取得します。 //! //! @return フレーム位置の最大値を返します。 //! //! @since 2009/09/18 初版。 //! f32 GetFrameMax() const { return GetFrameSize(); } //! @brief アニメーションブロックを取得します。 //! //! @return アニメーションブロックへのポインタを返します。 //! //! @sa SetResource //! //! @since 2009/09/18 初版。 //! const res::AnimationBlock* GetAnimResource() const { return m_pRes; } //@} //---------------------------------------- //! @name アニメーション //@{ //! @brief ループ用のアニメーションデータか判定します。 //! //! @details //! アニメーションデータがループ用としてマークされているかどうかを //! 判定します。 //! //! @return //! アニメーションデータがループ用としてマークされている場合は true を //! 返します。 //! //! @since 2009/09/18 初版。 //! bool IsLoopData() const; //! @brief アニメーションを再生します。 //! //! @details //! idx で指定されたアニメーションを pPane で指定したペインで再生します。 //! //! @param idx アニメーションのインデックスです。 //! @param pPane ペインです。 //! //! @sa Bind //! //! @since 2009/09/18 初版。 //! virtual void Animate(u32 idx, Pane* pPane) = 0; //! @brief アニメーションを再生します。 //! //! @details //! idx で指定されたアニメーションを pMaterial で指定したマテリアルで //! 再生します。 //! //! @param idx アニメーションのインデックスです。 //! @param pMaterial マテリアルです。 //! //! @sa Bind //! //! @since 2009/09/18 初版。 //! virtual void Animate(u32 idx, Material* pMaterial) = 0; //@} //---------------------------------------- //! @name リソース //@{ //! @brief アニメーションが使用するリソースを設定します。 //! //! @param pRes リソースのアニメーションブロックへのポインタです。 //! @param pResAccessor リソースアクセサです。 //! //! @details //! Bind() でアニメーションに関連付けるアニメーションブロックデータと //! アニメーションデータに必要なリソースを設定します。 //! //! また、 Bind() で必要になる AnimationLink を //! アニメーションブロックに含まれるアニメーション対象の個数分確保します。 //! //! AnimationLink は、バインドされるアニメーションの対象(ペインや //! マテリアル)毎に必要です。 //! //! この関数の実装では SetAnimResource() を使用して、アニメーション //! ブロックデータを登録しなければなりません。 //! //! @sa Bind //! @sa SetAnimResource //! @sa lyt::AnimationLink //! //! @since 2009/09/18 //! virtual void SetResource( const res::AnimationBlock* pRes, ResourceAccessor* pResAccessor) = 0; //! @brief アニメーションが使用するリソースを設定します。 //! //! @param pRes リソースのアニメーションブロックへのポインタです。 //! @param pResAccessor リソースアクセサです。 //! @param animNum 確保する AnimationLink 数です。 //! //! @details //! Bind() でアニメーションに関連付けるアニメーションブロックデータと //! アニメーションデータに必要なリソースを設定します。 //! //! また、 Bind() で必要になる AnimationLink を //! animNum で指定された個数、確保します。 //! //! AnimationLink は、バインドされるアニメーションの対象(ペインや //! マテリアル)毎に必要です。 //! //! 本関数の実装では SetAnimResource() を使用して、アニメーション //! ブロックデータを登録しなければなりません。 //! //! @sa Bind //! @sa SetAnimResource //! @sa lyt::AnimationLink //! //! @since 2009/09/18 //! virtual void SetResource( const res::AnimationBlock* pRes, ResourceAccessor* pResAccessor, u16 animNum) = 0; //! @brief アニメーションの関連付けを行います。 //! //! @details //! pPane で指定したペインにアニメーションを関連付けます。 //! //! bRecursive に true を渡して呼び出した場合は、ペインを pPane の子からも //! 検索します。 //! //! bDisable に true を渡して呼び出した場合は、アニメーションを無効状態で //! 関連付けます。 //! //! @param pPane ペインへのポインタです。 //! @param bRecursive 再帰的に検索する場合は true を指定します。 //! @param bDisable アニメーションを無効状態で関連付ける場合は true を //! 指定します。 //! //! @since 2009/09/18 初版。 //! virtual void Bind( Pane* pPane, bool bRecursive, bool bDisable = false) = 0; //! @brief アニメーションの関連付けを行います。 //! //! @details //! pMaterial で指定したマテリアルにアニメーションを関連付けます。 //! //! bDisable に true を渡して呼び出した場合は、アニメーションを無効状態で //! 関連付けます。 //! //! @param pMaterial マテリアルへのポインタです。 //! @param bDisable アニメーションを無効状態で関連付ける場合は true を //! 指定します。 //! //! @since 2009/09/18 初版。 //! virtual void Bind(Material* pMaterial, bool bDisable = false) = 0; //@} //! :private //! @brief リンク情報です。 ut::LinkListNode m_Link; protected: //---------------------------------------- //! @name 設定/取得 //@{ //! @brief アニメーションリソースへのポインタを設定します。 //! //! @details //! SetResource() の実装内で使用され、 GetAnimResource() の戻り値を設定します。 //! //! @param pRes アニメーションブロックへのポインタです。 //! //! @sa SetResource //! @sa GetAnimResource //! //! @since 2009/09/18 初版。 //! void SetAnimResource(const res::AnimationBlock* pRes) { m_pRes = pRes; } //@} protected: //! @details :private //! アニメーションリソースです。 const res::AnimationBlock* m_pRes; //! @details :private //! カレントフレーム値です。 f32 m_Frame; }; //--------------------------------------------------------------------------- //! :category アニメーション //! //! @brief アニメーションの基礎クラスです。 //! //! @since 2009/09/18 初版。 //--------------------------------------------------------------------------- class AnimTransformBasic : public AnimTransform { private: typedef AnimTransform Base; public: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! @brief コンストラクタです。 //! //! @since 2009/09/18 初版。 //! AnimTransformBasic(); //! @brief デストラクタです。 //! //! @since 2009/09/18 初版。 //! virtual ~AnimTransformBasic(); //@} //---------------------------------------- //! @name アニメーション //@{ virtual void Animate( u32 idx, Pane* pPane); virtual void Animate( u32 idx, Material* pMaterial); //@} //---------------------------------------- //! @name リソース //@{ virtual void SetResource( const res::AnimationBlock* pRes, ResourceAccessor* pResAccessor); virtual void SetResource( const res::AnimationBlock* pRes, ResourceAccessor* pResAccessor, u16 animNum); virtual void Bind( Pane* pPane, bool bRecursive, bool bDisable = false); virtual void Bind( Material* pMaterial, bool bDisable = false); //@} //! :private //! @brief アニメーションの関連付けを行います。 template AnimationLink* Bind( T* pTarget, AnimationLink* pAnimLink, u16 idx, bool bDisable) { NW_NULL_ASSERT(pTarget); pAnimLink = this->FindUnbindLink(pAnimLink); if (! pAnimLink) { NW_WARNING(false, "all AnimationLink used."); return 0; } pAnimLink->Set(this, idx, bDisable); pTarget->AddAnimationLink(pAnimLink); return ++pAnimLink; } protected: //! @details :private AnimationLink* FindUnbindLink(AnimationLink* pLink) const; //! @details :private //! テクスチャの情報です。 TextureInfo* m_pTexAry; //! @details :private //! アニメーションリンクです。 AnimationLink* m_pAnimLinkAry; //! @details :private //! アニメーションリンクの数です。 u16 m_AnimLinkNum; }; //--------------------------------------------------------------------------- //! :category アニメーション //! //! @brief アニメーションリソースクラスです。 //! //! @since 2009/09/18 初版。 //--------------------------------------------------------------------------- class AnimResource { public: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! @brief コンストラクタです。 //! //! @details //! リソースの関連付けは行われません。 //! 別途 Set() を使用して関連付けを行います。 //! //! @sa Set //! //! @since 2009/09/18 初版。 //! AnimResource(); //! @brief コンストラクタです。 //! //! @details //! anmResBuf で指定したアニメーションリソースが関連付けられます。 //! //! @param anmResBuf アニメーションリソースへのポインタです。 //! //! @since 2009/09/18 初版。 //! explicit AnimResource(const void* anmResBuf) { Set(anmResBuf); } //@} //---------------------------------------- //! @name 設定/取得 //@{ //! @brief アニメーションリソースを関連付けます。 //! //! @param anmResBuf アニメーションリソースへのポインタです。 //! //! @since 2009/09/18 初版。 //! void Set(const void* anmResBuf); //! @brief アニメーションリソースを取得します。 //! //! @return ファイルヘッダへのポインタを返します。 //! //! @since 2009/09/18 初版。 //! const ut::BinaryFileHeader* GetFileHeader() const { return m_pFileHeader; } //! @brief アニメーションブロックを取得します。 //! //! @return アニメーションブロックへのポインタを返します。 //! //! @since 2009/09/18 初版。 //! const res::AnimationBlock* GetResourceBlock() const { return m_pResBlock; } //! @brief アニメーション区間タグブロックを取得します。 //! //! @return アニメーション区間タグブロックへのポインタを返します。 //! //! @since 2009/09/18 初版。 //! const res::AnimationTagBlock* GetTagBlock() const { return m_pTagBlock; } //! @brief アニメーション区間タグの通し番号を取得します。 //! //! @return アニメーション区間タグの0から始まる通し番号を返します。 //! //! @since 2009/09/18 初版。 //! u16 GetTagOrder() const; //! @brief アニメーション区間タグの名前を取得します。 //! //! @return アニメーション区間タグの名前を返します。 //! //! @since 2009/09/18 初版。 //! const char* GetTagName() const; //! @brief アニメーション区間タグのグループ数を取得します。 //! //! @return アニメーション区間タグに設定されているグループ数を返します。 //! //! @since 2009/09/18 初版。 //! u16 GetGroupNum() const; //! @brief アニメーション区間タグのグループ配列を取得します。 //! //! @return //! アニメーション区間タグに設定されているグループ配列の //! 先頭ポインタを返します。 //! //! @since 2009/09/18 初版。 //! const AnimationGroupRef* GetGroupArray() const; //! @brief //! アニメーションをバインドするとき、ペインの子孫となるペインも対象に //! するかどうかを判定します。 //! //! @return //! アニメーションをバインドするとき、子孫のペインも対象にするときは //! true を返します。 //! //! @since 2009/09/18 初版。 //! bool IsDescendingBind() const; //! @brief アニメーション共有情報の個数を取得します。 //! //! @return アニメーション共有情報の個数を返します。 //! //! @since 2009/09/18 初版。 //! u16 GetAnimationShareInfoNum() const; //! @brief アニメーション共有情報の配列を取得します。 //! //! @return AnimationShareInfo オブジェクト配列の先頭ポインタを返します。 //! //! @since 2009/09/18 初版。 //! const AnimationShareInfo* GetAnimationShareInfoArray() const; //! @brief バインドされるアニメーションの個数を計算します。 //! //! @details //! pPane で指定したペインにバインドされるアニメーションの個数を計算します。 //! //! bRecursive に true を指定した場合は、関連付けるペインを子ペインからも //! 検索します。 //! //! @param pPane ペインへのポインタです。 //! @param bRecursive 子ペインも検索するか指定します。 //! //! @return バインドされるアニメーションの個数を返します。 //! //! @since 2009/09/18 初版。 //! u16 CalcAnimationNum(Pane* pPane, bool bRecursive) const; //! @brief バインドされるアニメーションの個数を計算します。 //! //! @details //! pMaterial で指定されたマテリアルにバインドされるアニメーションの //! 個数を計算します。 //! //! @param pMaterial マテリアルへのポインタです。 //! //! @return バインドされるアニメーションの個数を返します。 //! //! @since 2009/09/18 初版。 //! u16 CalcAnimationNum(Material* pMaterial) const; //! @brief バインドされるアニメーションの個数を計算します。 //! //! @details //! pGroup で指定されたグループに含まれるペインにバインドされる //! アニメーションの個数を計算します。 //! //! bRecursive に true を指定した場合は、関連付けるペインを子ペインからも //! 検索します。 //! //! @param pGroup グループへのポインタです。 //! @param bRecursive 子ペインも検索するか指定します。 //! //! @return バインドされるアニメーションの個数を返します。 //! //! @since 2009/09/18 初版。 //! u16 CalcAnimationNum(Group* pGroup, bool bRecursive) const; //@} protected: //! @details :private void Init(); //! :private //! //! @brief アニメーションリソースが設定されているか確認します。 //! //! @return 設定されていれば true を返します。 //! //! @since 2009/09/18 初版。 //! bool CheckResource() const; //! @details :private const ut::BinaryFileHeader* m_pFileHeader; //! @details :private const res::AnimationBlock* m_pResBlock; //! @details :private const res::AnimationTagBlock* m_pTagBlock; //! @details :private const res::AnimationShareBlock* m_pShareBlock; }; namespace internal { class AnimPaneTree { public: AnimPaneTree(); AnimPaneTree( Pane* pTargetPane, const AnimResource& animRes); void Set( Pane* pTargetPane, const AnimResource& animRes); AnimTransform* Bind( Layout* pLayout, Pane* pTargetPane, ResourceAccessor* pResAccessor) const; bool IsEnabled() const { return m_LinkNum > 0; } const AnimResource& GetAnimResource() const { return m_AnimRes; } protected: //! @details :private static u16 FindAnimContent( const res::AnimationBlock* pAnimBlock, const char* animContName, u8 animContType); //! @details :private void Init(); //! @details :private static const u16 NOBIND = u16(-1); //! @details :private static const int MATERIAL_NUM_MAX = 1 + 4 + 4; //! @details :private AnimResource m_AnimRes; //! @details :private u16 m_AnimPaneIdx; //! @details :private u16 m_LinkNum; //! @details :private u16 m_AnimMatIdxs[MATERIAL_NUM_MAX]; //! @details :private u8 m_AnimMatCnt; }; AnimationLink* FindAnimationLink( AnimationList* pAnimList, AnimTransform* pAnimTrans); AnimationLink* FindAnimationLink( AnimationList* pAnimList, const AnimResource& animRes); void UnbindAnimationLink( AnimationList* pAnimList, AnimTransform* pAnimTrans); } // namespace nw::lyt::internal } // namespace nw::lyt } // namespace nw #endif // NW_LYT_ANIMATION_H_