1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ParticleUtil.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: 25777 $
14  *---------------------------------------------------------------------------*/
15 #ifndef NW_GFX_PARTICLE_UTIL_H_
16 #define NW_GFX_PARTICLE_UTIL_H_
17 
18 #include <nw/types.h>
19 #include <nw/ut.h>
20 
21 #include <nw/gfx/res/gfx_ResParticleModel.h>
22 #include <nw/gfx/res/gfx_ResParticleSet.h>
23 
24 namespace nw {
25 namespace gfx {
26 
27 class SceneNode;
28 class ParticleContext;
29 
30 namespace res {
31 class ResParticleInitializer;
32 struct ResParticleInitializerData;
33 class ResParticleUpdater;
34 struct ResParticleUpdaterData;
35 } // namespace res
36 
37 //--------------------------------------------------------------------------
38 //! @brief        パーティクルの各種ユーティリティです。
39 //---------------------------------------------------------------------------
40 class ParticleUtil
41 {
42 public:
43     //! @brief        パーティクルのオブジェクトの初期設定を行います。
44     //!   内部でResolveParticleObjectを呼びます。
45     //!
46     //! @param[in]    sceneNodeArray シーンノードのアレイです。
47     static void SetupParticleObject(
48         ut::MoveArray<SceneNode*>* sceneNodeArray,
49         ParticleContext* context);
50 
51     //! @brief        パーティクルのオブジェクトの参照を解決します。
52     //!
53     //! @param[in]    sceneNodeArray シーンノードのアレイです。
54     static void ResolveParticleObject(ut::MoveArray<SceneNode*>* sceneNodeArray);
55 
56     //! @details :private
57     static ResParticleInitializerData* DuplicateResParticleInitializer(
58         const ResParticleInitializer* src,
59         os::IAllocator* allocator);
60 
61     //! @details :private
62     static void GetMemorySizeForDuplicateResParticleInitializerInternal(
63         os::MemorySizeCalculator* pSize,
64         const ResParticleInitializer* src);
65 
66     //! @details :private
67     static ResParticleUpdaterData* DuplicateResParticleUpdater(
68         const ResParticleUpdater* src,
69         os::IAllocator* allocator);
70 
71     //! @details :private
72     static void GetMemorySizeForDuplicateResParticleUpdaterInternal(
73         os::MemorySizeCalculator* pSize,
74         const ResParticleUpdater* src);
75 };
76 
77 //! @brief パーティクルセットの依存関係でソートするための関数オブジェクトです。
78 struct ParticleSetCompare
79     : public std::binary_function<ParticleSet*, ParticleSet*, bool>
80 {
81     //! @brief パーティクルセットの依存関係でソートするための比較関数です。
82     //! @param[in] lhs 左辺値です。
83     //! @param[in] rhs 右辺値です。
84     //! @return 比較結果を返します。
85     bool operator() (
86         const ParticleSet* lhs,
87         const ParticleSet* rhs);
88 };
89 
90 //---------------------------------------------------------------------------
91 //! @brief        パーティクルのVBOフラッシュを設定する関数オブジェクトです。
92 //---------------------------------------------------------------------------
93 class ParticleSetIsBufferFlushEnabledSetter
94 {
95 public:
96     //! @brief コンストラクタです
97     //! @param[in] flat 設定するフラッシュの有無のフラグです。
ParticleSetIsBufferFlushEnabledSetter(bool flag)98     ParticleSetIsBufferFlushEnabledSetter(bool flag) : m_Flag(flag) {}
99 
100     //! @brief ResModelを引数とするオペレータです
101     //! @param[in] resModel 対象のResParticleModelです。
operator()102     void operator()(ResModel resModel) const
103     {
104         ResParticleModel resParticleModel = ResDynamicCast<ResParticleModel>(resModel);
105         if (resParticleModel.IsValid())
106         {
107             resParticleModel.ForeachParticleSet(ParticleSetIsBufferFlushEnabledSetter(m_Flag));
108         }
109     }
110 
111     //! @brief ResParticleModelを引数とするオペレータです
112     //! @param[in] resParticleModel 対象のResParticleModelです。
operator()113     void operator()(ResParticleModel resParticleModel) const
114     {
115         if (resParticleModel.IsValid())
116         {
117             resParticleModel.ForeachParticleSet(ParticleSetIsBufferFlushEnabledSetter(m_Flag));
118         }
119     }
120 
121     //! @brief ResParticleSetを引数とするオペレータです
122     //! @param[in] resParticleSet 対象のResParticleSetです。
operator()123     void operator()(ResParticleSet resParticleSet) const
124     {
125         resParticleSet.SetIsBufferFlushEnabled(m_Flag);
126     }
127 
128 private:
129     bool m_Flag;
130 };
131 
132 } // namespace gfx
133 } // namespace nw
134 
135 #endif // NW_GFX_PARTICLE_UTIL_H_
136