1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_HemiSphereLight.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_HEMISPHERELIGHT_H_
17 #define NW_GFX_HEMISPHERELIGHT_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 HemiSphereLight : public Light
34 {
35 private:
36     NW_DISALLOW_COPY_AND_ASSIGN(HemiSphereLight);
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 
61         //! デストラクタです。
~DynamicBuilder()62         ~DynamicBuilder() {}
63 
64         //! @brief 生成時以外にもメモリを確保するかどうかのフラグを設定します。
65         //!
66         //!        true を指定すると、生成時のみ固定サイズのメモリ確保を行います。
67         //!
68         //!        false を指定すると、生成時以外にも必要に応じて動的にメモリ確保が行われます。
IsFixedSizeMemory(bool isFixedSizeMemory)69         DynamicBuilder& IsFixedSizeMemory(bool isFixedSizeMemory)
70         {
71             m_Description.isFixedSizeMemory = isFixedSizeMemory;
72             return *this;
73         }
74 
75         //! 子の最大数を設定します。
MaxChildren(int maxChildren)76         DynamicBuilder& MaxChildren(int maxChildren)
77         {
78             m_Description.maxChildren = maxChildren;
79             return *this;
80         }
81 
82         //! 管理できるコールバックの最大数を設定します。
MaxCallbacks(int maxCallbacks)83         DynamicBuilder& MaxCallbacks(int maxCallbacks)
84         {
85             m_Description.maxCallbacks = maxCallbacks;
86             return *this;
87         }
88 
89         //! @brief        半球ライトを生成します。
90         //!
91         //! @param[in]    allocator アロケータです。
92         //!
93         //! @return       生成した半球ライトを返します。
94         //!
95         HemiSphereLight* Create(os::IAllocator* allocator);
96 
97     private:
98         HemiSphereLight::Description m_Description;
99     };
100 
101     //! @brief        半球ライトを生成します。
102     //!
103     //! @param[in]    parent 親のノードです。
104     //! @param[in]    resource リソースです。
105     //! @param[in]    description 設定内容です。
106     //! @param[in]    allocator アロケータです。
107     //!
108     //! @return       生成された半球ライトです。
109     //!
110     static HemiSphereLight* Create(
111         SceneNode* parent,
112         ResSceneObject resource,
113         const HemiSphereLight::Description& description,
114         os::IAllocator* allocator);
115 
116     //@}
117 
118     //----------------------------------------
119     //! @name シーンツリー
120     //@{
121 
122     //! @brief        ビジターを受け付けます。
123     //!
124     //! @param[in]    visitor ビジターです。
125     //!
126     virtual void Accept(ISceneVisitor* visitor);
127 
128     //@}
129 
130     //----------------------------------------
131     //! @name リソース
132     //@{
133 
134     //! 半球ライトのリソースを取得します。
GetResHemiSphereLight()135     ResHemiSphereLight GetResHemiSphereLight()
136     {
137         return ResStaticCast<ResHemiSphereLight>(this->GetResSceneObject());
138     }
139 
140     //! 半球ライトのリソースを取得します。
GetResHemiSphereLight()141     const ResHemiSphereLight GetResHemiSphereLight() const
142     {
143         return ResStaticCast<ResHemiSphereLight>(this->GetResSceneObject());
144     }
145 
146     //@}
147 
148 protected:
149     struct ResHemiSphereLightDataDestroyer : public std::unary_function<ResHemiSphereLightData*, void>
150     {
m_AllocatorResHemiSphereLightDataDestroyer151         ResHemiSphereLightDataDestroyer(os::IAllocator* allocator = 0) : m_Allocator(allocator)
152         {}
operatorResHemiSphereLightDataDestroyer153         result_type operator()(argument_type data)
154         {
155             DestroyResHemiSphereLight(m_Allocator, data);
156         }
157 
158         os::IAllocator* m_Allocator;
159     };
160 
161     //! 動的生成したライトリソースを破棄するための MovePtr の定義です。
162     typedef ut::MovePtr<ResHemiSphereLightData, ResHemiSphereLightDataDestroyer> ResPtr;
163 
164     //----------------------------------------
165     //! @name コンストラクタ/デストラクタ
166     //@{
167 
168     //! コンストラクタです。
HemiSphereLight(os::IAllocator * allocator,ResHemiSphereLight resObj,const HemiSphereLight::Description & description)169     HemiSphereLight(
170         os::IAllocator* allocator,
171         ResHemiSphereLight resObj,
172         const HemiSphereLight::Description& description)
173     : Light(
174         allocator,
175         resObj,
176         description)
177     {}
178 
179     //! コンストラクタです。
HemiSphereLight(os::IAllocator * allocator,ResPtr resource,const HemiSphereLight::Description & description)180     HemiSphereLight(
181         os::IAllocator* allocator,
182         ResPtr resource,
183         const HemiSphereLight::Description& description)
184     : Light(
185         allocator,
186         ResHemiSphereLight(resource.Get()),
187         description),
188       m_Resource(resource)
189     {}
190 
191     //! デストラクタです。
~HemiSphereLight()192     virtual ~HemiSphereLight()
193     {
194         DestroyOriginalValue();
195     }
196 
197     //@}
198 
199 private:
200     virtual Result Initialize(os::IAllocator* allocator);
201 
202     //---------------------------------------------------------------------------
203     //! @brief        ResHemiSphereLightData のリソースを生成します。
204     //!
205     //! @param[in]    allocator   リソース用のメモリを確保するアロケータです。
206     //! @param[in]    name        リソースにつける名前へのポインタです。名前が必要ない場合には NULL を指定してください。
207     //!
208     //! @return       ResHemiSphereLightData へのポインタです。
209     //---------------------------------------------------------------------------
210     static ResHemiSphereLightData*    CreateResHemiSphereLight(os::IAllocator* allocator, const char* name = NULL);
211 
212     //---------------------------------------------------------------------------
213     //! @brief        ResHemiSphereLightData のリソースを破棄します。
214     //!
215     //! @param[in]    resHemiSphereLight ResHemiSphereLightData へのポインタです。
216     //! @param[in]    allocator        リソース用のメモリを開放するアロケータです。
217     //---------------------------------------------------------------------------
218     static void DestroyResHemiSphereLight(os::IAllocator* allocator, ResHemiSphereLightData* resHemiSphereLight);
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_HEMISPHERELIGHT_H_
230