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: 25276 $ 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 放出時の位置のワークメモリを返します。 GetEmissionPositionWork()111 VEC3Array::iterator GetEmissionPositionWork() 112 { 113 return m_EmissionPositionWork.Begin(); 114 } 115 116 //! @brief 放出時の親パーティクルのワークメモリを取得します。 117 //! @return 放出時の親パーティクルのワークメモリを返します。 GetEmissionParentWork()118 U16Array::iterator GetEmissionParentWork() 119 { 120 return m_EmissionParentWork.Begin(); 121 } 122 123 //! @brief パーティクルのストリーム処理用のワークメモリを取得します。 124 //! @return パーティクルのストリーム処理用のワークメモリを返します。 GetParticleWorkF32()125 F32Array::iterator GetParticleWorkF32() 126 { 127 return m_ParticleWorkF32.Begin(); 128 } 129 130 //! @brief 乱数種を設定します。 131 //! 132 //! @param[in] seed 乱数種です。 Srand(u32 seed)133 void Srand(u32 seed) 134 { 135 m_ParticleRandom.Srand(seed); 136 } 137 138 //! @details :private GetRandom()139 u16 GetRandom() 140 { 141 return m_ParticleRandom.Next(0xffff); 142 } 143 144 //@} 145 146 private: ParticleContext(os::IAllocator * allocator,VEC3Array emissionPositionWork,U16Array emissionParentWork,F32Array particleWorkF32)147 ParticleContext( 148 os::IAllocator* allocator, 149 VEC3Array emissionPositionWork, 150 U16Array emissionParentWork, 151 F32Array particleWorkF32) 152 : GfxObject(allocator), 153 m_EmissionPositionWork(emissionPositionWork), 154 m_EmissionParentWork(emissionParentWork), 155 m_ParticleWorkF32(particleWorkF32) 156 {} ~ParticleContext()157 virtual ~ParticleContext() {} 158 159 VEC3Array m_EmissionPositionWork; 160 U16Array m_EmissionParentWork; 161 F32Array m_ParticleWorkF32; 162 163 ParticleRandom m_ParticleRandom; 164 }; 165 166 } // namespace gfx 167 } // namespace nw 168 169 #endif // NW_GFX_PARTICLECONTEXT_H_ 170