1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: gfx_AmbientLight.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: 24209 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_GFX_AMBIENTLIGHT_H_ 17 #define NW_GFX_AMBIENTLIGHT_H_ 18 19 #include <nw/gfx/gfx_Light.h> 20 #include <nw/gfx/res/gfx_ResLight.h> 21 22 #include <nw/ut/ut_MovePtr.h> 23 #include <functional> 24 25 namespace nw 26 { 27 namespace gfx 28 { 29 30 //--------------------------------------------------------------------------- 31 //! @brief アンビエントライトを表すクラスです。 32 //--------------------------------------------------------------------------- 33 class AmbientLight : public Light 34 { 35 private: 36 NW_DISALLOW_COPY_AND_ASSIGN(AmbientLight); 37 38 public: 39 NW_UT_RUNTIME_TYPEINFO; 40 41 //! @brief 設定内容です。 42 struct Description : public Light::Description 43 { 44 //! @brief コンストラクタです。 DescriptionDescription45 Description(){} 46 }; 47 48 //---------------------------------------- 49 //! @name 作成/破棄 50 //@{ 51 52 //! @brief アンビエントライトを動的に構築するためのクラスです。 53 //! 54 //! IsFixedSizeMemory の初期値は true です。false に変更すると、各種最大数の設定は無視されます。 55 class DynamicBuilder 56 { 57 public: 58 //! コンストラクタです。 DynamicBuilder()59 DynamicBuilder() {} 60 //! デストラクタです。 ~DynamicBuilder()61 ~DynamicBuilder() {} 62 63 //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。 64 //! 65 //! true を指定すると、生成時のみ固定サイズのメモリ確保を行います。 66 //! 67 //! false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。 IsFixedSizeMemory(bool isFixedSizeMemory)68 DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory) 69 { 70 m_Description.isFixedSizeMemory = isFixedSizeMemory; 71 return *this; 72 } 73 74 //! 子の最大数を設定します。 MaxChildren(int maxChildren)75 DynamicBuilder& MaxChildren(int maxChildren) 76 { 77 m_Description.maxChildren = maxChildren; 78 return *this; 79 } 80 81 //! 管理できるコールバックの最大数を設定します。 MaxCallbacks(int maxCallbacks)82 DynamicBuilder& MaxCallbacks(int maxCallbacks) 83 { 84 m_Description.maxCallbacks = maxCallbacks; 85 return *this; 86 } 87 88 //! @brief アンビエントライトを生成します。 89 //! 90 //! @param[in] allocator アロケータです。 91 //! 92 //! @return 生成したアンビエントライトを返します。 93 //! 94 AmbientLight* Create(os::IAllocator* allocator); 95 96 private: 97 AmbientLight::Description m_Description; 98 }; 99 100 //! @brief アンビエントライトを生成します。 101 //! 102 //! @param[in] parent 親のノードです。 103 //! @param[in] resource リソースです。 104 //! @param[in] description 設定内容です。 105 //! @param[in] allocator アロケータです。 106 //! 107 //! @return 生成されたアンビエントライトです。 108 //! 109 static AmbientLight* Create( 110 SceneNode* parent, 111 ResSceneObject resource, 112 const AmbientLight::Description& description, 113 os::IAllocator* allocator); 114 115 //@} 116 117 //---------------------------------------- 118 //! @name シーンツリー 119 //@{ 120 121 //! @brief ビジターを受け付けます。 122 //! 123 //! @param[in] visitor ビジターです。 124 //! 125 virtual void Accept(ISceneVisitor* visitor); 126 127 //@} 128 129 //---------------------------------------- 130 //! @name リソース 131 //@{ 132 133 //! アンビエントライトのリソースを取得します。 GetResAmbientLight()134 ResAmbientLight GetResAmbientLight() 135 { 136 return ResStaticCast<ResAmbientLight>(this->GetResSceneObject()); 137 } 138 139 //! アンビエントライトのリソースを取得します。 GetResAmbientLight()140 const ResAmbientLight GetResAmbientLight() const 141 { 142 return ResStaticCast<ResAmbientLight>(this->GetResSceneObject()); 143 } 144 145 //@} 146 147 protected: 148 struct ResAmbientLightDataDestroyer : public std::unary_function<ResAmbientLightData*, void> 149 { m_AllocatorResAmbientLightDataDestroyer150 ResAmbientLightDataDestroyer(os::IAllocator* allocator = 0) : m_Allocator(allocator) 151 {} operatorResAmbientLightDataDestroyer152 result_type operator()(argument_type data) 153 { 154 DestroyResAmbientLight(m_Allocator, data); 155 } 156 157 os::IAllocator* m_Allocator; 158 }; 159 160 //! 動的生成したライトリソースを破棄するための MovePtr の定義です。 161 typedef ut::MovePtr<ResAmbientLightData, ResAmbientLightDataDestroyer> ResPtr; 162 163 //---------------------------------------- 164 //! @name コンストラクタ/デストラクタ 165 //@{ 166 167 //! コンストラクタです。 AmbientLight(os::IAllocator * allocator,ResAmbientLight resObj,const AmbientLight::Description & description)168 AmbientLight( 169 os::IAllocator* allocator, 170 ResAmbientLight resObj, 171 const AmbientLight::Description& description) 172 : Light( 173 allocator, 174 resObj, 175 description) 176 {} 177 178 //! コンストラクタです。 AmbientLight(os::IAllocator * allocator,ResPtr resource,const AmbientLight::Description & description)179 AmbientLight( 180 os::IAllocator* allocator, 181 ResPtr resource, 182 const AmbientLight::Description& description) 183 : Light( 184 allocator, 185 ResAmbientLight(resource.Get()), 186 description), 187 m_Resource(resource) 188 {} 189 190 //! デストラクタです。 ~AmbientLight()191 virtual ~AmbientLight() 192 { 193 DestroyOriginalValue(); 194 } 195 196 //@} 197 198 private: 199 200 virtual Result Initialize(os::IAllocator* allocator); 201 202 //--------------------------------------------------------------------------- 203 //! @brief ResAmbientLightData のリソースを生成します。 204 //! 205 //! @param[in] allocator リソース用のメモリを確保するアロケータです。 206 //! @param[in] name リソースにつける名前へのポインタです。名前が必要ない場合には NULL を指定してください。 207 //! 208 //! @return ResAmbientLightData へのポインタです。 209 //--------------------------------------------------------------------------- 210 static ResAmbientLightData* CreateResAmbientLight(os::IAllocator* allocator, const char* name = NULL); 211 212 //--------------------------------------------------------------------------- 213 //! @brief ResAmbientLightData のリソースを破棄します。 214 //! 215 //! @param[in] resAmbientLight ResAmbientLightData へのポインタです。 216 //! @param[in] allocator リソース用のメモリを開放するアロケータです。 217 //--------------------------------------------------------------------------- 218 static void DestroyResAmbientLight(os::IAllocator* allocator, ResAmbientLightData* resAmbientLight); 219 220 //! アニメーションを初期状態に戻すため、初期化時の状態を保存します。 221 Result CreateOriginalValue(os::IAllocator* allocator); 222 223 ResPtr m_Resource; 224 }; 225 226 } // namespace gfx 227 } // namespace nw 228 229 #endif // NW_GFX_AMBIENTLIGHT_H_ 230