Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "ParticleManager.h"
21 
22 #include "ps/Filesystem.h"
23 #include "ps/Profile.h"
24 #include "renderer/Scene.h"
25 
26 static Status ReloadChangedFileCB(void* param, const VfsPath& path)
27 {
28  return static_cast<CParticleManager*>(param)->ReloadChangedFile(path);
29 }
30 
32  m_CurrentTime(0.f)
33 {
35 }
36 
38 {
40 }
41 
43 {
44  boost::unordered_map<VfsPath, CParticleEmitterTypePtr>::iterator it = m_EmitterTypes.find(path);
45  if (it != m_EmitterTypes.end())
46  return it->second;
47 
48  CParticleEmitterTypePtr emitterType(new CParticleEmitterType(path, *this));
49  m_EmitterTypes[path] = emitterType;
50  return emitterType;
51 }
52 
54 {
55  m_UnattachedEmitters.push_back(emitter);
56 }
57 
59 {
60  m_UnattachedEmitters.clear();
61 }
62 
63 void CParticleManager::Interpolate(const float simFrameLength)
64 {
65  m_CurrentTime += simFrameLength;
66 }
67 
69 {
70  bool operator()(const CParticleEmitterPtr& emitterPtr)
71  {
72  CParticleEmitter& emitter = *emitterPtr.get();
73  for (size_t i = 0; i < emitter.m_Particles.size(); ++i)
74  {
75  SParticle& p = emitter.m_Particles[i];
76  if (p.age < p.maxAge)
77  return false;
78  }
79  return true;
80  }
81 };
82 
84 {
85  PROFILE("submit unattached particles");
86 
87  // Delete any unattached emitters that have no particles left
89 
90  // TODO: should do some frustum culling
91 
92  for (std::list<CParticleEmitterPtr>::iterator it = m_UnattachedEmitters.begin(); it != m_UnattachedEmitters.end(); ++it)
93  collector.Submit(it->get());
94 }
95 
97 {
98  m_EmitterTypes.erase(path);
99  return INFO::OK;
100 }
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Particle emitter.
Particle emitter type - stores the common state data for all emitters of that type, and uses that data to update the emitter states.
const Status OK
Definition: status.h:386
shared_ptr< CParticleEmitterType > CParticleEmitterTypePtr
std::vector< SParticle > m_Particles
shared_ptr< CParticleEmitter > CParticleEmitterPtr
This interface accepts renderable objects.
Definition: Scene.h:82
void UnregisterFileReloadFunc(FileReloadFunc func, void *obj)
delete a callback function registered with RegisterFileReloadFunc (removes any with the same func and...
Definition: Filesystem.cpp:44
Status ReloadChangedFile(const VfsPath &path)
void RegisterFileReloadFunc(FileReloadFunc func, void *obj)
register a callback function to be called by ReloadChangedFiles
Definition: Filesystem.cpp:39
Definition: path.h:75
bool operator()(const CParticleEmitterPtr &emitterPtr)
void AddUnattachedEmitter(const CParticleEmitterPtr &emitter)
Tell the manager to handle rendering of an emitter that is no longer attached to a unit...
#define PROFILE(name)
Definition: Profile.h:195
i64 Status
Error handling system.
Definition: status.h:171
void Interpolate(const float simFrameLength)
void ClearUnattachedEmitters()
Delete unattached emitters if we don&#39;t wish to see them anymore (like in actor viewer) ...
boost::unordered_map< VfsPath, CParticleEmitterTypePtr > m_EmitterTypes
CParticleEmitterTypePtr LoadEmitterType(const VfsPath &path)
static Status ReloadChangedFileCB(void *param, const VfsPath &path)
virtual void Submit(CPatch *patch)=0
Submit a terrain patch that is part of the scene.
std::list< CParticleEmitterPtr > m_UnattachedEmitters
Simulation state for a single particle.
void RenderSubmit(SceneCollector &collector, const CFrustum &frustum)