/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_HemiSphereLight.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_HEMISPHERELIGHT_H_ #define NW_GFX_HEMISPHERELIGHT_H_ #include #include #include #include namespace nw { namespace gfx { //--------------------------------------------------------------------------- //! @brief 半球ライトを表すクラスです。 //--------------------------------------------------------------------------- class HemiSphereLight : public Light { private: NW_DISALLOW_COPY_AND_ASSIGN(HemiSphereLight); public: NW_UT_RUNTIME_TYPEINFO; //! @brief 設定内容です。 struct Description : public Light::Description { //! @brief コンストラクタです。 Description(){} }; //---------------------------------------- //! @name 作成/破棄 //@{ //! @brief 半球ライトを動的に構築するためのクラスです。 //! //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 class DynamicBuilder { public: //! コンストラクタです。 DynamicBuilder() {} //! デストラクタです。 ~DynamicBuilder() {} //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 //! //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 //! //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) { m_Description.isFixedSizeMemory = isFixedSizeMemory; return *this; } //! 子の最大数を設定します。 DynamicBuilder& MaxChildren(int maxChildren) { m_Description.maxChildren = maxChildren; return *this; } //! 管理できるコールバックの最大数を設定します。 DynamicBuilder& MaxCallbacks(int maxCallbacks) { m_Description.maxCallbacks = maxCallbacks; return *this; } //! @brief 半球ライトを生成します。 //! //! @param[in] allocator アロケータです。 //! //! @return 生成した半球ライトを返します。 //! HemiSphereLight* Create(os::IAllocator* allocator); //! @brief 生成時に必要なメモリサイズを取得します。 //! //! メモリサイズは Builder の設定によって変化します。 //! すべての設定が終わった後にこの関数を呼び出してください。 //! //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 size_t GetMemorySize(size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT) const; private: HemiSphereLight::Description m_Description; }; //! @brief 半球ライトを生成します。 //! //! @param[in] parent 親のノードです。 //! @param[in] resource リソースです。 //! @param[in] description 設定内容です。 //! @param[in] allocator アロケータです。 //! //! @return 生成された半球ライトです。 //! static HemiSphereLight* Create( SceneNode* parent, ResSceneObject resource, const HemiSphereLight::Description& description, os::IAllocator* allocator); //! @brief 生成時に必要なメモリサイズを取得します。 //! //! @param[in] resource リソースです。 //! @param[in] description 設定内容です。 //! @param[in] alignment 計算に用いるアライメントです。2 のべき乗である必要があります。 static size_t GetMemorySize( ResHemiSphereLight resource, Description description, size_t alignment = os::IAllocator::DEFAULT_ALIGNMENT ) { os::MemorySizeCalculator size(alignment); GetMemorySizeInternal(&size, resource, description); return size.GetSizeWithPadding(alignment); } //! @details :private static void GetMemorySizeInternal( os::MemorySizeCalculator* pSize, ResHemiSphereLight resource, Description description); //@} //---------------------------------------- //! @name シーンツリー //@{ //! @brief ビジターを受け付けます。 //! //! @param[in] visitor ビジターです。 //! virtual void Accept(ISceneVisitor* visitor); //@} //---------------------------------------- //! @name リソース //@{ //! 半球ライトのリソースを取得します。 ResHemiSphereLight GetResHemiSphereLight() { return ResStaticCast(this->GetResSceneObject()); } //! 半球ライトのリソースを取得します。 const ResHemiSphereLight GetResHemiSphereLight() const { return ResStaticCast(this->GetResSceneObject()); } //@} protected: struct ResHemiSphereLightDataDestroyer : public std::unary_function { ResHemiSphereLightDataDestroyer(os::IAllocator* allocator = 0) : m_Allocator(allocator) {} result_type operator()(argument_type data) { DestroyResHemiSphereLight(m_Allocator, data); } os::IAllocator* m_Allocator; }; //! 動的生成したライトリソースを破棄するための MovePtr の定義です。 typedef ut::MovePtr ResPtr; //---------------------------------------- //! @name コンストラクタ/デストラクタ //@{ //! コンストラクタです。 HemiSphereLight( os::IAllocator* allocator, ResHemiSphereLight resObj, const HemiSphereLight::Description& description) : Light( allocator, resObj, description) {} //! コンストラクタです。 HemiSphereLight( os::IAllocator* allocator, ResPtr resource, const HemiSphereLight::Description& description) : Light( allocator, ResHemiSphereLight(resource.Get()), description), m_Resource(resource) {} //! デストラクタです。 virtual ~HemiSphereLight() { DestroyOriginalValue(); } //@} private: virtual Result Initialize(os::IAllocator* allocator); //--------------------------------------------------------------------------- //! @brief ResHemiSphereLightData のリソースを生成します。 //! //! @param[in] allocator リソース用のメモリを確保するアロケータです。 //! @param[in] name リソースにつける名前へのポインタです。名前が必要ない場合には NULL を指定してください。 //! //! @return ResHemiSphereLightData へのポインタです。 //--------------------------------------------------------------------------- static ResHemiSphereLightData* CreateResHemiSphereLight(os::IAllocator* allocator, const char* name = NULL); //--------------------------------------------------------------------------- //! @brief ResHemiSphereLightData のリソースを破棄します。 //! //! @param[in] resHemiSphereLight ResHemiSphereLightData へのポインタです。 //! @param[in] allocator リソース用のメモリを開放するアロケータです。 //--------------------------------------------------------------------------- static void DestroyResHemiSphereLight(os::IAllocator* allocator, ResHemiSphereLightData* resHemiSphereLight); //! アニメーションを初期状態に戻すため、初期化時の状態を保存します。 Result CreateOriginalValue(os::IAllocator* allocator); //! :private virtual u32 GetLightType() const { return anim::ResLightAnimData::LIGHT_TYPE_HEMISPHERE; } //! :private virtual u32 GetLightKind() const { // hemisphereでは光源の種類は考慮しない return ResLight::KIND_UNUSED; } ResPtr m_Resource; }; } // namespace gfx } // namespace nw #endif // NW_GFX_HEMISPHERELIGHT_H_