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