1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_ParticleContext.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 28118 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_GFX_PARTICLECONTEXT_H_ 17 #define NW_GFX_PARTICLECONTEXT_H_ 18 19 #include <nw/math.h> 20 #include <nw/ut/ut_Preprocessor.h> 21 #include <nw/ut/ut_MoveArray.h> 22 #include <nw/gfx/gfx_GfxObject.h> 23 #include <nw/gfx/gfx_ParticleRandom.h> 24 25 namespace nw 26 { 27 namespace gfx 28 { 29 30 //--------------------------------------------------------------------------- 31 //! @brief パーティクルの更新時の内容を保持させるためのクラスです。 32 //--------------------------------------------------------------------------- 33 class ParticleContext : public GfxObject 34 { 35 private: 36 NW_DISALLOW_COPY_AND_ASSIGN(ParticleContext); 37 38 public: 39 //! VEC3の Array の定義です。 40 typedef ut::MoveArray<nw::math::VEC3> VEC3Array; 41 42 //! F32の Array の定義です。 43 typedef ut::MoveArray<f32> F32Array; 44 45 //! U16の Array の定義です。 46 typedef ut::MoveArray<u16> U16Array; 47 48 //---------------------------------------- 49 //! @name 作成 50 //@{ 51 52 //! シーンコンテキストクラスを構築するためのクラスです。 53 //! 54 //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 55 class Builder 56 { 57 public: 58 //! @brief コンストラクタです。 Builder()59 Builder() 60 : m_IsFixedSizeMemory(true), 61 m_MaxEmission(1000), 62 m_MaxStreamLength(10000){} 63 64 //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 65 //! 66 //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 67 //! 68 //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 IsFixedSizeMemory(bool isFixedSizeMemory)69 Builder& IsFixedSizeMemory(bool isFixedSizeMemory) 70 { 71 m_IsFixedSizeMemory = isFixedSizeMemory; 72 return *this; 73 } 74 75 //! @brief 放出量の最大数を設定します。 76 //! @param[in] maxEmission 放出量の最大数です。 77 //! @return ビルダーを返します。 MaxEmission(int maxEmission)78 Builder& MaxEmission(int maxEmission) { m_MaxEmission = maxEmission; return *this; } 79 80 //! @brief ストリーム長の最大数を設定します。 81 //! @param[in] maxStreamLength ストリーム長の最大数です。 82 //! @return ビルダーを返します。 MaxStreamLength(int maxStreamLength)83 Builder& MaxStreamLength(int maxStreamLength) { m_MaxStreamLength = maxStreamLength; return *this; } 84 85 //! @brief シーンコンテキストを構築します。 86 //! @param[in] allocator メモリのアロケータです。 87 //! @return シーンコンテキストを返します。 88 ParticleContext* Create(os::IAllocator* allocator); 89 90 private: 91 bool m_IsFixedSizeMemory; 92 int m_MaxEmission; 93 int m_MaxStreamLength; 94 }; 95 96 //@} 97 98 //---------------------------------------- 99 //! @name 取得/設定 100 //@{ 101 102 //! @brief 放出時の位置のワークメモリの容量を取得します。 103 //! @return ワークメモリの容量を返します。 GetEmissionWorkCapacity()104 int GetEmissionWorkCapacity() const 105 { 106 return m_EmissionPositionWork.Capacity(); 107 } 108 109 //! @brief 放出時の位置のワークメモリを取得します。 110 //! @return 放出時の位置のワークメモリを返します。 111 VEC3Array::iterator GetEmissionPositionWork(int requireSize = 0) 112 { 113 #ifdef NW_MOVE_ARRAY_VARIABILITY_ENABLED 114 if (m_EmissionPositionWork.GetArrayKind() == ut::ARRAY_VARIABILITY) 115 { 116 if (m_EmissionPositionWork.capacity() < requireSize) 117 { 118 m_EmissionPositionWork.resize(requireSize); 119 } 120 } 121 #endif 122 123 return m_EmissionPositionWork.Begin(); 124 } 125 126 //! @brief 放出時の親パーティクルのワークメモリを取得します。 127 //! @return 放出時の親パーティクルのワークメモリを返します。 128 U16Array::iterator GetEmissionParentWork(int requireSize = 0) 129 { 130 #ifdef NW_MOVE_ARRAY_VARIABILITY_ENABLED 131 if (m_EmissionParentWork.GetArrayKind() == ut::ARRAY_VARIABILITY) 132 { 133 if (m_EmissionParentWork.capacity() < requireSize) 134 { 135 m_EmissionParentWork.resize(requireSize); 136 } 137 } 138 #endif 139 140 return m_EmissionParentWork.Begin(); 141 } 142 143 //! @brief パーティクルのストリーム処理用のワークメモリを取得します。 144 //! @return パーティクルのストリーム処理用のワークメモリを返します。 GetParticleWorkF32()145 F32Array::iterator GetParticleWorkF32() 146 { 147 return m_ParticleWorkF32.Begin(); 148 } 149 150 //! @brief 乱数種を設定します。 151 //! 152 //! @param[in] seed 乱数種です。 Srand(u32 seed)153 void Srand(u32 seed) 154 { 155 m_ParticleRandom.Srand(seed); 156 } 157 158 //! @details :private GetRandom()159 u16 GetRandom() 160 { 161 return m_ParticleRandom.Next(0xffff); 162 } 163 164 //@} 165 166 private: ParticleContext(os::IAllocator * allocator,VEC3Array emissionPositionWork,U16Array emissionParentWork,F32Array particleWorkF32)167 ParticleContext( 168 os::IAllocator* allocator, 169 VEC3Array emissionPositionWork, 170 U16Array emissionParentWork, 171 F32Array particleWorkF32) 172 : GfxObject(allocator), 173 m_EmissionPositionWork(emissionPositionWork), 174 m_EmissionParentWork(emissionParentWork), 175 m_ParticleWorkF32(particleWorkF32) 176 {} ~ParticleContext()177 virtual ~ParticleContext() {} 178 179 VEC3Array m_EmissionPositionWork; 180 U16Array m_EmissionParentWork; 181 F32Array m_ParticleWorkF32; 182 183 ParticleRandom m_ParticleRandom; 184 }; 185 186 } // namespace gfx 187 } // namespace nw 188 189 #endif // NW_GFX_PARTICLECONTEXT_H_ 190