1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_AnimAdder.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_GFX_ANIMADDER_H_ 19 #define NW_GFX_ANIMADDER_H_ 20 21 #include <nw/gfx/gfx_AnimBlender.h> 22 #include <nw/ut/ut_MoveArray.h> 23 #include <nw/ut/ut_RuntimeTypeInfo.h> 24 25 namespace nw { 26 namespace gfx { 27 28 //--------------------------------------------------------------------------- 29 //! @details :private 30 //! @brief 汎用アニメーション評価結果を加算ブレンドするクラスです。 31 //--------------------------------------------------------------------------- 32 class AnimAdder : public AnimBlender 33 { 34 public: 35 NW_UT_RUNTIME_TYPEINFO; 36 37 //---------------------------------------- 38 //! @name 作成 39 //@{ 40 41 //! 汎用アニメーション加算を構築するクラスです。 42 class Builder 43 { 44 public: 45 //! コンストラクタです。 Builder()46 Builder() 47 : m_MaxAnimObjects(2) {} 48 49 //! 最大アニメーションオブジェクト数を設定します。 MaxAnimObjects(int maxAnimObjects)50 Builder& MaxAnimObjects(int maxAnimObjects) 51 { 52 NW_ASSERT(maxAnimObjects > 0); 53 m_MaxAnimObjects = maxAnimObjects; 54 return *this; 55 } 56 57 //! @brief 生成時に必要なメモリサイズを取得します。 58 //! 59 //! メモリサイズは Builder の設定によって変化します。 60 //! すべての設定が終わった後にこの関数を呼び出してください。 61 //! 62 //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 63 size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const 64 { 65 os::MemorySizeCalculator size(alignment); 66 67 GetMemorySizeInternal(&size); 68 69 return size.GetSizeWithPadding(alignment); 70 } 71 72 //! @details :private GetMemorySizeInternal(os::MemorySizeCalculator * pSize)73 void GetMemorySizeInternal(os::MemorySizeCalculator* pSize) const 74 { 75 os::MemorySizeCalculator& size = *pSize; 76 77 size += sizeof(AnimAdder); 78 AnimAdder::GetMemorySizeForInitialize(pSize, m_MaxAnimObjects); 79 } 80 81 //! @brief 汎用アニメーション加算を生成します。 82 //! 83 //! @param[in] allocator アロケータです。 84 //! 85 //! @return 生成された汎用アニメーション加算です。 86 //! Create(os::IAllocator * allocator)87 AnimAdder* Create(os::IAllocator* allocator) 88 { 89 void* buf = allocator->Alloc(sizeof(AnimAdder)); 90 91 if (buf == NULL) 92 { 93 return NULL; 94 } 95 96 AnimAdder* animAdder = new(buf) AnimAdder(allocator); 97 98 Result result = animAdder->Initialize(m_MaxAnimObjects); 99 NW_ASSERT(result.IsSuccess()); 100 101 return animAdder; 102 } 103 104 private: 105 int m_MaxAnimObjects; 106 }; 107 108 //@} 109 110 //---------------------------------------- 111 //! @name 評価 112 //@{ 113 114 //! @brief メンバ単位でアニメーション結果を取得します。 115 //! 116 //! @param[out] target アニメーション結果を書き込む対象です。 117 //! @param[in] memberIdx メンバインデックスです。 118 //! 119 //! @return アニメーション結果を返します。 120 //! ブレンドオペレーションを使用する場合は、返り値のアニメーション結果を使用してください。 121 //! 122 virtual const anim::AnimResult* GetResult( 123 void* target, 124 int memberIdx) const; 125 126 //@} 127 128 //---------------------------------------- 129 //! @name 取得/設定 130 //@{ 131 132 //! @brief アニメーションのブレンド重みを取得します。 133 //! 134 //! @param[in] animObjIdx アニメーションオブジェクトのインデックスです。 135 //! 136 //! @return 重みです。 137 //! GetWeight(int animObjIdx)138 float GetWeight(int animObjIdx) const 139 { 140 NW_MINMAXLT_ASSERT(animObjIdx, 0, m_Weights.Size()); 141 return m_Weights[animObjIdx]; 142 } 143 144 //! @brief アニメーションのブレンド重みを設定します。 145 //! 146 //! @param[in] animObjIdx アニメーションオブジェクトのインデックスです。 147 //! @param[in] weight 重みです。 148 //! SetWeight(int animObjIdx,float weight)149 void SetWeight(int animObjIdx, float weight) 150 { 151 NW_MINMAXLT_ASSERT(animObjIdx, 0, m_Weights.Size()); 152 m_Weights[animObjIdx] = weight; 153 } 154 155 //@} 156 157 protected: 158 //---------------------------------------- 159 //! @name コンストラクタ/デストラクタ 160 //@{ 161 162 //! コンストラクタです。 AnimAdder(os::IAllocator * allocator)163 AnimAdder( 164 os::IAllocator* allocator) 165 : AnimBlender(allocator) 166 { 167 } 168 169 //! デストラクタです。 ~AnimAdder()170 virtual ~AnimAdder() {} 171 172 //@} 173 174 //! Initialize() の実行に必要なメモリサイズを取得します。 175 //! 176 //! :private GetMemorySizeForInitialize(os::MemorySizeCalculator * pSize,int maxAnimObjects)177 static void GetMemorySizeForInitialize(os::MemorySizeCalculator* pSize, int maxAnimObjects) 178 { 179 os::MemorySizeCalculator& size = *pSize; 180 181 AnimBlender::GetMemorySizeForInitialize(pSize, maxAnimObjects); 182 size += sizeof(float) * maxAnimObjects; 183 } 184 Initialize(int maxAnimObjects)185 Result Initialize(int maxAnimObjects) 186 { 187 Result result = AnimBlender::Initialize(maxAnimObjects); 188 NW_ENSURE_AND_RETURN(result); 189 190 void* memory = GetAllocator().Alloc(sizeof(float) * maxAnimObjects); 191 if (memory == NULL) 192 { 193 result |= Result::MASK_FAIL_BIT; 194 } 195 NW_ENSURE_AND_RETURN(result); 196 197 m_Weights = ut::MoveArray<float>(memory, maxAnimObjects, &GetAllocator()); 198 for (int animObjIdx = 0; animObjIdx < maxAnimObjects; ++animObjIdx) 199 { 200 m_Weights.PushBackFast(1.0f); 201 } 202 203 return result; 204 } 205 206 ut::MoveArray<float> m_Weights; 207 }; 208 209 } // namespace gfx 210 } // namespace nw 211 212 #endif // NW_GFX_ANIMADDER_H_ 213