1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_SceneEnvironmentSetting.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: 21233 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_GFX_SCENEENVIRONMENTSETTING_H_
17 #define NW_GFX_SCENEENVIRONMENTSETTING_H_
18 
19 #include <nw/gfx/res/gfx_ResSceneEnvironmentSetting.h>
20 #include <nw/ut/ut_MoveArray.h>
21 #include <nw/gfx/gfx_GfxObject.h>
22 #include <functional>
23 
24 namespace nw
25 {
26 namespace gfx
27 {
28 
29 class Fog;
30 class Camera;
31 class LightSet;
32 
33 //---------------------------------------------------------------------------
34 //! @brief        シーン環境設定を表すクラスです。
35 //---------------------------------------------------------------------------
36 class SceneEnvironmentSetting : public SceneObject
37 {
38 private:
39     NW_DISALLOW_COPY_AND_ASSIGN(SceneEnvironmentSetting);
40 
41 public:
42     NW_UT_RUNTIME_TYPEINFO;
43 
44     //! @brief ライトセットをバインドするための構造体です。
45     struct LightSetBinder
46     {
LightSetBinderLightSetBinder47         LightSetBinder()
48             : index(-1)
49         {}
50 
51         s32 index;
52         GfxPtr<LightSet> lightSet;
53     };
54 
55     //! @brief カメラをバインドするための構造体です。
56     struct CameraBinder
57     {
CameraBinderCameraBinder58         CameraBinder()
59             : index(-1),
60               camera(NULL)
61         {}
62 
63         s32 index;
64         Camera* camera;
65     };
66 
67     //! @brief フォグをバインドするための構造体です。
68     struct FogBinder
69     {
FogBinderFogBinder70         FogBinder()
71             : index(-1),
72               fog(NULL)
73         {}
74 
75         s32 index;
76         Fog* fog;
77     };
78 
79     typedef ut::MoveArray<LightSetBinder> LightSetBinderArray;
80     typedef ut::MoveArray<CameraBinder> CameraBinderArray;
81     typedef ut::MoveArray<FogBinder> FogBinderArray;
82 
83     //! @brief 設定内容です。
84     struct Description
85     {
86         //! @brief コンストラクタです。
DescriptionDescription87         Description(){}
88     };
89 
90     //----------------------------------------
91     //! @name 作成/破棄
92     //@{
93 
94     //! @brief        シーン環境設定を生成します。
95     //!
96     //! @param[in]    resource リソースです。
97     //! @param[in]    description 設定内容です。
98     //! @param[in]    allocator アロケータです。
99     //!
100     //! @return       生成したシーン環境設定です。
101     //!
102     static SceneEnvironmentSetting* Create(
103         ResSceneObject resource,
104         const SceneEnvironmentSetting::Description& description,
105         os::IAllocator* allocator);
106 
107     //@}
108 
109     //----------------------------------------
110     //! @name 更新
111     //@{
112 
113     //! @brief        シーンコンテキストを用いて参照解決を行います。
114     //!
115     //! @param[in]    sceneContext 参照解決に用いるシーンコンテキストです。
116     //!
117 
118     void ResolveReference(const SceneContext& sceneContext);
119 
120     //@}
121 
122     //----------------------------------------
123     //! @name 取得/設定
124     //@{
125 
126     //! リソースを取得します。
GetResSceneEnvironmentSetting()127     ResSceneEnvironmentSetting GetResSceneEnvironmentSetting()
128     {
129         return ResDynamicCast<ResSceneEnvironmentSetting>(this->GetResSceneObject());
130     }
131 
132     //! リソースを取得します。
GetResSceneEnvironmentSetting()133     const ResSceneEnvironmentSetting GetResSceneEnvironmentSetting() const
134     {
135         return ResDynamicCast<ResSceneEnvironmentSetting>(this->GetResSceneObject());
136     }
137 
138     //!  @brief        カメラの先頭を指すイテレータを取得します。
139     //!
140     //!  @return       カメラの先頭を指すイテレータです。
141     //!
GetCameraBegin()142     CameraBinderArray::iterator GetCameraBegin()
143     {
144         return m_Cameras.begin();
145     }
146 
147     //!  @brief        カメラの先頭を指すイテレータを取得します。
148     //!
149     //!  @return       カメラの先頭を指すイテレータです。
150     //!
GetCameraBegin()151     CameraBinderArray::const_iterator GetCameraBegin() const
152     {
153         return m_Cameras.begin();
154     }
155 
156     //!  @brief        カメラの終端を指すイテレータを取得します。
157     //!
158     //!  @return       カメラの終端を指すイテレータです。
159     //!
GetCameraEnd()160     CameraBinderArray::iterator GetCameraEnd()
161     {
162         return m_Cameras.end();
163     }
164 
165     //!  @brief        カメラの終端を指すイテレータを取得します。
166     //!
167     //!  @return       カメラの終端を指すイテレータです。
168     //!
GetCameraEnd()169     CameraBinderArray::const_iterator GetCameraEnd() const
170     {
171         return m_Cameras.end();
172     }
173 
174     //!  @brief        フォグの先頭を指すイテレータを取得します。
175     //!
176     //!  @return       フォグの先頭を指すイテレータです。
177     //!
GetFogBegin()178     FogBinderArray::iterator GetFogBegin()
179     {
180         return m_Fogs.begin();
181     }
182 
183     //!  @brief        フォグの先頭を指すイテレータを取得します。
184     //!
185     //!  @return       フォグの先頭を指すイテレータです。
186     //!
GetFogBegin()187     FogBinderArray::const_iterator GetFogBegin() const
188     {
189         return m_Fogs.begin();
190     }
191 
192     //!  @brief        フォグの終端を指すイテレータを取得します。
193     //!
194     //!  @return       フォグの終端を指すイテレータです。
195     //!
GetFogEnd()196     FogBinderArray::iterator GetFogEnd()
197     {
198         return m_Fogs.end();
199     }
200 
201     //!  @brief        フォグの終端を指すイテレータを取得します。
202     //!
203     //!  @return       フォグの終端を指すイテレータです。
204     //!
GetFogEnd()205     FogBinderArray::const_iterator GetFogEnd() const
206     {
207         return m_Fogs.end();
208     }
209 
210     //!  @brief        ライトセットの先頭を指すイテレータを取得します。
211     //!
212     //!  @return       ライトセットの先頭を指すイテレータです。
213     //!
GetLightSetBegin()214     LightSetBinderArray::iterator GetLightSetBegin()
215     {
216         return m_LightSets.begin();
217     }
218 
219     //!  @brief        ライトセットの先頭を指すイテレータを取得します。
220     //!
221     //!  @return       ライトセットの先頭を指すイテレータです。
222     //!
GetLightSetBegin()223     LightSetBinderArray::const_iterator GetLightSetBegin() const
224     {
225         return m_LightSets.begin();
226     }
227 
228     //!  @brief        ライトセットの終端を指すイテレータを取得します。
229     //!
230     //!  @return       ライトセットの終端を指すイテレータです。
231     //!
GetLightSetEnd()232     LightSetBinderArray::iterator GetLightSetEnd()
233     {
234         return m_LightSets.end();
235     }
236 
237     //!  @brief        ライトセットの終端を指すイテレータを取得します。
238     //!
239     //!  @return       ライトセットの終端を指すイテレータです。
240     //!
GetLightSetEnd()241     LightSetBinderArray::const_iterator GetLightSetEnd() const
242     {
243         return m_LightSets.end();
244     }
245 
246     //@}
247 
248 protected:
249     //----------------------------------------
250     //! @name コンストラクタ/デストラクタ
251     //@{
252 
253     //! コンストラクタです。
SceneEnvironmentSetting(os::IAllocator * allocator,ResSceneEnvironmentSetting resSetting,const SceneEnvironmentSetting::Description & description)254     SceneEnvironmentSetting(
255         os::IAllocator* allocator,
256         ResSceneEnvironmentSetting resSetting,
257         const SceneEnvironmentSetting::Description& description)
258         : SceneObject(allocator, resSetting)
259     {
260         NW_UNUSED_VARIABLE(description);
261         this->CreateEnvironmentArray(allocator, resSetting);
262     }
263 
264     //! デストラクタです。
~SceneEnvironmentSetting()265     virtual ~SceneEnvironmentSetting() {}
266 
267     //@}
268 
269 private:
270     //! シーン環境の配列を作成します。
271     void CreateEnvironmentArray(os::IAllocator* allocator, ResSceneEnvironmentSetting );
272 
273     //! @brief ResReferenceSceneObject の名前比較用構造体です。
274     template<typename TObject>
275     struct SceneObjectCompare: public std::unary_function<TObject, bool>
276     {
SceneObjectCompareSceneObjectCompare277         SceneObjectCompare(ResReferenceSceneObject referenceSceneObject): m_Object(referenceSceneObject){}
278         ResReferenceSceneObject m_Object;
operatorSceneObjectCompare279         bool operator()(TObject* lhs) const
280         {
281             if (lhs->GetName() != NULL &&
282                 m_Object.GetPath() != NULL &&
283                 std::strcmp(lhs->GetName(), m_Object.GetPath()) == 0)
284             {
285                 return true;
286             }
287             return false;
288         }
289     };
290 
291     LightSetBinderArray m_LightSets;
292     CameraBinderArray m_Cameras;
293     FogBinderArray m_Fogs;
294 };
295 
296 } // namespace gfx
297 } // namespace nw
298 
299 #endif // NW_GFX_SCENEENVIRONMENTSETTING_H_
300