Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CCmpParticleManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 
21 #include "ICmpParticleManager.h"
22 
24 
26 #include "renderer/Renderer.h"
27 
29 {
30 public:
31  static void ClassInit(CComponentManager& componentManager)
32  {
33  componentManager.SubscribeToMessageType(MT_Interpolate);
34  }
35 
36  DEFAULT_COMPONENT_ALLOCATOR(ParticleManager)
37 
38  bool useSimTime;
39 
40  static std::string GetSchema()
41  {
42  return "<a:component type='system'/><empty/>";
43  }
44 
45  virtual void Init(const CParamNode& UNUSED(paramNode))
46  {
47  useSimTime = true;
48  }
49 
50  virtual void Deinit()
51  {
52  }
53 
54  virtual void Serialize(ISerializer& UNUSED(serialize))
55  {
56  }
57 
58  virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize))
59  {
60  Init(paramNode);
61  }
62 
63  virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
64  {
65  switch (msg.GetType())
66  {
67  case MT_Interpolate:
68  {
69  const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
71  {
72  float time = useSimTime ? msgData.deltaSimTime : msgData.deltaRealTime;
73  g_Renderer.GetParticleManager().Interpolate(time);
74  }
75  break;
76  }
77  }
78  }
79 
80  virtual void SetUseSimTime(bool flag)
81  {
82  useSimTime = flag;
83  }
84 };
85 
86 REGISTER_COMPONENT_TYPE(ParticleManager)
An entity initialisation parameter node.
Definition: ParamNode.h:112
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
#define REGISTER_COMPONENT_TYPE(cname)
Definition: Component.h:30
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
static void ClassInit(CComponentManager &componentManager)
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
Definition: MessageTypes.h:134
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:138
#define g_Renderer
Definition: Renderer.h:61
virtual void Init(const CParamNode &paramNode)
virtual int GetType() const =0
virtual void Deserialize(const CParamNode &paramNode, IDeserializer &deserialize)
virtual void SetUseSimTime(bool flag)
Set whether particle rendering should use sim time If false, it uses real time and updates even durin...
virtual void HandleMessage(const CMessage &msg, bool global)
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
Definition: Component.h:44
static bool IsInitialised()
Definition: Singleton.h:63
static std::string GetSchema()
Minimal interface for particle rendering.
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:122
virtual void Serialize(ISerializer &serialize)
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34