1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: gfx_ParticleSceneUpdater.cpp
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
18 #include "precompiled.h"
19
20 #include <nw/gfx/gfx_ParticleSceneUpdater.h>
21
22 #include <nw/gfx/gfx_SceneContext.h>
23 #include <nw/gfx/gfx_ParticleContext.h>
24 #include <nw/gfx/gfx_SkeletalModel.h>
25 #include <nw/gfx/gfx_ParticleModel.h>
26 #include <nw/gfx/gfx_ParticleSet.h>
27 #include <nw/gfx/gfx_ParticleEmitter.h>
28
29 #include <nw/ut/ut_Foreach.h>
30
31
32 namespace nw
33 {
34 namespace gfx
35 {
36
37 NW_UT_RUNTIME_TYPEINFO_ROOT_DEFINITION(ParticleSceneUpdater);
38
39 //----------------------------------------
40 ParticleSceneUpdater*
Create(os::IAllocator * allocator)41 ParticleSceneUpdater::Builder::Create(
42 os::IAllocator* allocator
43 )
44 {
45 NW_NULL_ASSERT(allocator);
46
47 void* memory = allocator->Alloc(sizeof(ParticleSceneUpdater));
48 if (memory == NULL)
49 {
50 return NULL;
51 }
52
53 return new(memory) ParticleSceneUpdater(
54 allocator);
55 }
56
57 //----------------------------------------
58 void
SetStepFrame(SceneContext * sceneContext,f32 stepFrame)59 ParticleSceneUpdater::SetStepFrame(
60 SceneContext* sceneContext,
61 f32 stepFrame
62 )
63 {
64 NW_PROFILE("ParticleSceneUpdater::SetStepFrame");
65
66 {
67 ParticleModelArray::iterator end = sceneContext->GetParticleModelEnd();
68 for (ParticleModelArray::iterator i = sceneContext->GetParticleModelBegin(); i != end;)
69 {
70 ParticleModel* model = *i++;
71 NW_NULL_ASSERT(model);
72
73 model->ParticleAnimFrameController().SetStepFrame(stepFrame);
74 }
75 }
76
77 {
78 ParticleEmitterArray::iterator end = sceneContext->GetParticleEmitterEnd();
79 for (ParticleEmitterArray::iterator i = sceneContext->GetParticleEmitterBegin(); i != end;)
80 {
81 ParticleEmitter* emitter = *i++;
82 NW_NULL_ASSERT(emitter);
83
84 emitter->ParticleAnimFrameController().SetStepFrame(stepFrame);
85 }
86 }
87 }
88
89 //----------------------------------------
90 void
UpdateNode(SceneContext * sceneContext,ParticleContext * particleContext,bool enableSwapBuffer)91 ParticleSceneUpdater::UpdateNode(
92 SceneContext* sceneContext,
93 ParticleContext* particleContext,
94 bool enableSwapBuffer
95 )
96 {
97 NW_PROFILE("ParticleSceneUpdater::UpdateNode");
98
99 // Frame更新 -> Emission -> UpdateParticlesの順で処理する
100 // Emitter間の依存関係は無いので
101 // emitterのUpdateFrameとEmissionは一緒に行っている(本来はUpdateFrameを完了してからEmission)
102
103 {
104 ParticleModelArray::iterator end = sceneContext->GetParticleModelEnd();
105 for (ParticleModelArray::iterator i = sceneContext->GetParticleModelBegin(); i != end;)
106 {
107 ParticleModel* model = *i++;
108 NW_NULL_ASSERT(model);
109
110 model->UpdateParticleFrame();
111 }
112 }
113
114 {
115 ParticleEmitterArray::iterator end = sceneContext->GetParticleEmitterEnd();
116 for (ParticleEmitterArray::iterator i = sceneContext->GetParticleEmitterBegin(); i != end;)
117 {
118 ParticleEmitter* emitter = *i++;
119 NW_NULL_ASSERT(emitter);
120
121 emitter->UpdateParticleFrame();
122 emitter->Emission(particleContext);
123 }
124 }
125
126 {
127 ParticleSetArray::iterator end = sceneContext->GetParticleSetEnd();
128 for (ParticleSetArray::iterator i = sceneContext->GetParticleSetBegin(); i != end;)
129 {
130 ParticleSet* particleSet = *i++;
131 particleSet->UpdateParticles(particleContext, enableSwapBuffer);
132 }
133 }
134 }
135
136 } // namespace gfx
137 } // namespace nw
138