1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_ParticleUtil.h
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 #ifndef NW_GFX_PARTICLE_UTIL_H_
18 #define NW_GFX_PARTICLE_UTIL_H_
19 
20 #include <nw/types.h>
21 #include <nw/ut.h>
22 
23 #include <nw/gfx/res/gfx_ResParticleModel.h>
24 #include <nw/gfx/res/gfx_ResParticleSet.h>
25 
26 namespace nw {
27 namespace gfx {
28 
29 class SceneNode;
30 class ParticleContext;
31 
32 namespace res {
33 class ResParticleInitializer;
34 struct ResParticleInitializerData;
35 class ResParticleUpdater;
36 struct ResParticleUpdaterData;
37 } // namespace res
38 
39 //--------------------------------------------------------------------------
40 //! @brief        パーティクルの各種ユーティリティです。
41 //---------------------------------------------------------------------------
42 class ParticleUtil
43 {
44 public:
45     //! @brief        パーティクルのオブジェクトの初期設定を行います。
46     //!   内部でResolveParticleObjectを呼びます。
47     //!
48     //! @param[in]    sceneNodeArray シーンノードのアレイです。
49     static void SetupParticleObject(
50         ut::MoveArray<SceneNode*>* sceneNodeArray,
51         ParticleContext* context);
52 
53     //! @brief        パーティクルのオブジェクトの参照を解決します。
54     //!
55     //! @param[in]    sceneNodeArray シーンノードのアレイです。
56     static void ResolveParticleObject(ut::MoveArray<SceneNode*>* sceneNodeArray);
57 
58     //! @details :private
59     static ResParticleInitializerData* DuplicateResParticleInitializer(
60         const ResParticleInitializer* src,
61         os::IAllocator* allocator);
62 
63     //! @details :private
64     static void GetMemorySizeForDuplicateResParticleInitializerInternal(
65         os::MemorySizeCalculator* pSize,
66         const ResParticleInitializer* src);
67 
68     //! @details :private
69     static ResParticleUpdaterData* DuplicateResParticleUpdater(
70         const ResParticleUpdater* src,
71         os::IAllocator* allocator);
72 
73     //! @details :private
74     static void GetMemorySizeForDuplicateResParticleUpdaterInternal(
75         os::MemorySizeCalculator* pSize,
76         const ResParticleUpdater* src);
77 };
78 
79 //! @brief パーティクルセットの依存関係でソートするための関数オブジェクトです。
80 struct ParticleSetCompare
81     : public std::binary_function<ParticleSet*, ParticleSet*, bool>
82 {
83     //! @brief パーティクルセットの依存関係でソートするための比較関数です。
84     //! @param[in] lhs 左辺値です。
85     //! @param[in] rhs 右辺値です。
86     //! @return 比較結果を返します。
87     bool operator() (
88         const ParticleSet* lhs,
89         const ParticleSet* rhs);
90 };
91 
92 //---------------------------------------------------------------------------
93 //! @brief        パーティクルのVBOフラッシュを設定する関数オブジェクトです。
94 //---------------------------------------------------------------------------
95 class ParticleSetIsBufferFlushEnabledSetter
96 {
97 public:
98     //! @brief コンストラクタです
99     //! @param[in] flat 設定するフラッシュの有無のフラグです。
ParticleSetIsBufferFlushEnabledSetter(bool flag)100     ParticleSetIsBufferFlushEnabledSetter(bool flag) : m_Flag(flag) {}
101 
102     //! @brief ResModelを引数とするオペレータです
103     //! @param[in] resModel 対象のResParticleModelです。
operator()104     void operator()(ResModel resModel) const
105     {
106         ResParticleModel resParticleModel = ResDynamicCast<ResParticleModel>(resModel);
107         if (resParticleModel.IsValid())
108         {
109             resParticleModel.ForeachParticleSet(ParticleSetIsBufferFlushEnabledSetter(m_Flag));
110         }
111     }
112 
113     //! @brief ResParticleModelを引数とするオペレータです
114     //! @param[in] resParticleModel 対象のResParticleModelです。
operator()115     void operator()(ResParticleModel resParticleModel) const
116     {
117         if (resParticleModel.IsValid())
118         {
119             resParticleModel.ForeachParticleSet(ParticleSetIsBufferFlushEnabledSetter(m_Flag));
120         }
121     }
122 
123     //! @brief ResParticleSetを引数とするオペレータです
124     //! @param[in] resParticleSet 対象のResParticleSetです。
operator()125     void operator()(ResParticleSet resParticleSet) const
126     {
127         resParticleSet.SetIsBufferFlushEnabled(m_Flag);
128     }
129 
130 private:
131     bool m_Flag;
132 };
133 
134 } // namespace gfx
135 } // namespace nw
136 
137 #endif // NW_GFX_PARTICLE_UTIL_H_
138