/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_ParticleContext.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_PARTICLECONTEXT_H_ #define NW_GFX_PARTICLECONTEXT_H_ #include #include #include #include #include namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @brief パーティクルの更新時の内容を保持させるためのクラスです。 //--------------------------------------------------------------------------- class ParticleContext : public GfxObject { private: NW_DISALLOW_COPY_AND_ASSIGN(ParticleContext); public: //! VEC3の Array の定義です。 typedef ut::MoveArray VEC3Array; //! F32の Array の定義です。 typedef ut::MoveArray F32Array; //! U16の Array の定義です。 typedef ut::MoveArray U16Array; //---------------------------------------- //! @name 作成 //@{ //! シーンコンテキストクラスを構築するためのクラスです。 //! //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 class Builder { public: //! @brief コンストラクタです。 Builder() : m_IsFixedSizeMemory(true), m_MaxEmission(1000), m_MaxStreamLength(1000), m_UseDoubleBuffer(false) {} //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 //! //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 //! //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 Builder& IsFixedSizeMemory(bool isFixedSizeMemory) { m_IsFixedSizeMemory = isFixedSizeMemory; return *this; } //! @brief 放出量の最大数を設定します。 //! @param[in] maxEmission 放出量の最大数です。 //! @return ビルダーを返します。 Builder& MaxEmission(int maxEmission) { m_MaxEmission = maxEmission; return *this; } //! @brief ストリーム長の最大数を設定します。 //! @param[in] maxStreamLength ストリーム長の最大数です。 //! @return ビルダーを返します。 Builder& MaxStreamLength(int maxStreamLength) { m_MaxStreamLength = maxStreamLength; return *this; } //! @brief ダブルバッファで複数回更新を有効にします。 //! @details ダブルバッファでUpdateを複数回実行するときに必要なバッファを確保します。 //! @param[in] maxRuntimeWork ランタイムワークサイズの最大値です。 //! @return ビルダーを返します。 Builder& UseDoubleBuffer(int useDoubleBuffer) { m_UseDoubleBuffer = useDoubleBuffer; return *this; } //! @brief シーンコンテキストを構築します。 //! @param[in] allocator メモリのアロケータです。 //! @return シーンコンテキストを返します。 ParticleContext* Create(os::IAllocator* allocator); private: bool m_IsFixedSizeMemory; int m_MaxEmission; int m_MaxStreamLength; bool m_UseDoubleBuffer; }; //@} //---------------------------------------- //! @name 取得/設定 //@{ //! @brief 放出時の位置のワークメモリの容量を取得します。 //! @return ワークメモリの容量を返します。 int GetEmissionWorkCapacity() const { return m_EmissionPositionWork.Capacity(); } //! @brief 放出時の位置のワークメモリを取得します。 //! @details requireSizeは、NW_MOVE_ARRAY_VARIABILITY_ENABLEDが有効な場合のみ機能します。 //! @param[in] requireSize 必要なサイズ //! @return 放出時の位置のワークメモリを返します。 VEC3Array::iterator GetEmissionPositionWork(int requireSize = 0) { #ifdef NW_MOVE_ARRAY_VARIABILITY_ENABLED if (m_EmissionPositionWork.GetArrayKind() == ut::ARRAY_VARIABILITY) { if (m_EmissionPositionWork.capacity() < requireSize) { m_EmissionPositionWork.resize(requireSize); } } #endif return m_EmissionPositionWork.Begin(); } //! @brief 放出時の親パーティクルのワークメモリを取得します。 //! @details requireSizeは、NW_MOVE_ARRAY_VARIABILITY_ENABLEDが有効な場合のみ機能します。 //! @param[in] requireSize 必要なサイズ //! @return 放出時の親パーティクルのワークメモリを返します。 U16Array::iterator GetEmissionParentWork(int requireSize = 0) { #ifdef NW_MOVE_ARRAY_VARIABILITY_ENABLED if (m_EmissionParentWork.GetArrayKind() == ut::ARRAY_VARIABILITY) { if (m_EmissionParentWork.capacity() < requireSize) { m_EmissionParentWork.resize(requireSize); } } #endif return m_EmissionParentWork.Begin(); } //! @brief パーティクルのストリーム処理用のワークメモリを取得します。 //! @return パーティクルのストリーム処理用のワークメモリを返します。 F32Array::iterator GetParticleWorkF32() { return m_ParticleWorkF32.Begin(); } //! @brief ダブルバッファ時の複数回アップデート用のワークメモリを取得します。 //! @details requireSizeは、NW_MOVE_ARRAY_VARIABILITY_ENABLEDが有効な場合のみ機能します。 //! @param[in] requireSize 必要なサイズ //! @return ダブルバッファ時の複数回アップデート用のワークメモリを返します。 VEC3Array::iterator GetPrevTranslateWork(int requireSize = 0) { #ifdef NW_MOVE_ARRAY_VARIABILITY_ENABLED if (m_PrevTranslateWork.GetArrayKind() == ut::ARRAY_VARIABILITY) { if (m_PrevTranslateWork.capacity() < requireSize) { m_PrevTranslateWork.resize(requireSize); } } #endif return m_PrevTranslateWork.Begin(); } //! @brief ダブルバッファ時の複数回アップデート用のワークメモリの容量を取得します。 //! @details :private //! @return ダブルバッファ時の複数回アップデート用のワークメモリの容量を返します。 int GetPrevTranslateWorkCapacity() const { return m_PrevTranslateWork.Capacity(); } //! @brief 乱数種を設定します。 //! //! @param[in] seed 乱数種です。 void Srand(u32 seed) { m_ParticleRandom.Srand(seed); } //! @details :private u16 GetRandom() { return m_ParticleRandom.Next(0xffff); } //@} private: ParticleContext( os::IAllocator* allocator, VEC3Array emissionPositionWork, U16Array emissionParentWork, F32Array particleWorkF32, VEC3Array prevTranslateWork) : GfxObject(allocator), m_EmissionPositionWork(emissionPositionWork), m_EmissionParentWork(emissionParentWork), m_ParticleWorkF32(particleWorkF32), m_PrevTranslateWork(prevTranslateWork) {} virtual ~ParticleContext() {} VEC3Array m_EmissionPositionWork; U16Array m_EmissionParentWork; F32Array m_ParticleWorkF32; VEC3Array m_PrevTranslateWork; ParticleRandom m_ParticleRandom; }; } // namespace gfx } // namespace nw #endif // NW_GFX_PARTICLECONTEXT_H_