/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_AnimAdder.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_ANIMADDER_H_ #define NW_GFX_ANIMADDER_H_ #include #include #include namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @details :private //! @brief 汎用アニメーション評価結果を加算ブレンドするクラスです。 //--------------------------------------------------------------------------- class AnimAdder : public AnimBlender { public: NW_UT_RUNTIME_TYPEINFO; //---------------------------------------- //! @name 作成 //@{ //! 汎用アニメーション加算を構築するクラスです。 class Builder { public: //! コンストラクタです。 Builder() : m_MaxAnimObjects(2) {} //! 最大アニメーションオブジェクト数を設定します。 Builder& MaxAnimObjects(int maxAnimObjects) { NW_ASSERT(maxAnimObjects > 0); m_MaxAnimObjects = maxAnimObjects; return *this; } //! @brief 生成時に必要なメモリサイズを取得します。 //! //! メモリサイズは Builder の設定によって変化します。 //! すべての設定が終わった後にこの関数を呼び出してください。 //! //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const { os::MemorySizeCalculator size(alignment); GetMemorySizeInternal(&size); return size.GetSizeWithPadding(alignment); } //! @details :private void GetMemorySizeInternal(os::MemorySizeCalculator* pSize) const { os::MemorySizeCalculator& size = *pSize; size += sizeof(AnimAdder); AnimAdder::GetMemorySizeForInitialize(pSize, m_MaxAnimObjects); } //! @brief 汎用アニメーション加算を生成します。 //! //! @param[in] allocator アロケータです。 //! //! @return 生成された汎用アニメーション加算です。 //! AnimAdder* Create(os::IAllocator* allocator) { void* buf = allocator->Alloc(sizeof(AnimAdder)); if (buf == NULL) { return NULL; } AnimAdder* animAdder = new(buf) AnimAdder(allocator); Result result = animAdder->Initialize(m_MaxAnimObjects); NW_ASSERT(result.IsSuccess()); return animAdder; } private: int m_MaxAnimObjects; }; //@} //---------------------------------------- //! @name 評価 //@{ //! @brief メンバ単位でアニメーション結果を取得します。 //! //! @param[out] target アニメーション結果を書き込む対象です。 //! @param[in] memberIdx メンバインデックスです。 //! //! @return アニメーション結果を返します。 //! ブレンドオペレーションを使用する場合は、返り値のアニメーション結果を使用してください。 //! virtual const anim::AnimResult* GetResult( void* target, int memberIdx) const; //@} //---------------------------------------- //! @name 取得/設定 //@{ //! @brief アニメーションのブレンド重みを取得します。 //! //! @param[in] animObjIdx アニメーションオブジェクトのインデックスです。 //! //! @return 重みです。 //! float GetWeight(int animObjIdx) const { NW_MINMAXLT_ASSERT(animObjIdx, 0, m_Weights.Size()); return m_Weights[animObjIdx]; } //! @brief アニメーションのブレンド重みを設定します。 //! //! @param[in] animObjIdx アニメーションオブジェクトのインデックスです。 //! @param[in] weight 重みです。 //! void SetWeight(int animObjIdx, float weight) { NW_MINMAXLT_ASSERT(animObjIdx, 0, m_Weights.Size()); m_Weights[animObjIdx] = weight; } //@} protected: //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 AnimAdder( os::IAllocator* allocator) : AnimBlender(allocator) { } //! デストラクタです。 virtual ~AnimAdder() {} //@} //! Initialize() の実行に必要なメモリサイズを取得します。 //! //! :private static void GetMemorySizeForInitialize(os::MemorySizeCalculator* pSize, int maxAnimObjects) { os::MemorySizeCalculator& size = *pSize; AnimBlender::GetMemorySizeForInitialize(pSize, maxAnimObjects); size += sizeof(float) * maxAnimObjects; } Result Initialize(int maxAnimObjects) { Result result = AnimBlender::Initialize(maxAnimObjects); NW_ENSURE_AND_RETURN(result); void* memory = GetAllocator().Alloc(sizeof(float) * maxAnimObjects); if (memory == NULL) { result |= Result::MASK_FAIL_BIT; } NW_ENSURE_AND_RETURN(result); m_Weights = ut::MoveArray(memory, maxAnimObjects, &GetAllocator()); for (int animObjIdx = 0; animObjIdx < maxAnimObjects; ++animObjIdx) { m_Weights.PushBackFast(1.0f); } return result; } ut::MoveArray m_Weights; }; } // namespace gfx } // namespace nw #endif // NW_GFX_ANIMADDER_H_