Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MessageTypes.h
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 #ifndef INCLUDED_MESSAGETYPES
19 #define INCLUDED_MESSAGETYPES
20 
24 
27 
29 
30 #define DEFAULT_MESSAGE_IMPL(name) \
31  virtual int GetType() const { return MT_##name; } \
32  virtual const char* GetScriptHandlerName() const { return "On" #name; } \
33  virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \
34  virtual jsval ToJSVal(ScriptInterface& scriptInterface) const; \
35  static CMessage* FromJSVal(ScriptInterface&, jsval val);
36 
37 class SceneCollector;
38 class CFrustum;
39 
41 {
42 public:
44 
46  {
47  }
48 };
49 
50 // The update process is split into a number of phases, in an attempt
51 // to cope with dependencies between components. Each phase is implemented
52 // as a separate message. Simulation2.cpp sends them in sequence.
53 
54 /**
55  * Generic per-turn update message, for things that don't care much about ordering.
56  */
57 class CMessageUpdate : public CMessage
58 {
59 public:
61 
64  {
65  }
66 
68 };
69 
70 /**
71  * Update phase for formation controller movement (must happen before individual
72  * units move to follow their formation).
73  */
75 {
76 public:
77  DEFAULT_MESSAGE_IMPL(Update_MotionFormation)
78 
81  {
82  }
83 
85 };
86 
87 /**
88  * Update phase for non-formation-controller unit movement.
89  */
91 {
92 public:
93  DEFAULT_MESSAGE_IMPL(Update_MotionUnit)
94 
97  {
98  }
99 
101 };
102 
103 /**
104  * Final update phase, after all other updates.
105  */
107 {
108 public:
109  DEFAULT_MESSAGE_IMPL(Update_Final)
110 
113  {
114  }
115 
117 };
118 
119 /**
120  * Prepare for rendering a new frame (set up model positions etc).
121  */
123 {
124 public:
126 
128  deltaSimTime(deltaSimTime), offset(offset), deltaRealTime(deltaRealTime)
129  {
130  }
131 
132  /// Elapsed simulation time since previous interpolate, in seconds. This is similar to the elapsed real time, except
133  /// it is scaled by the current simulation rate (and might indeed be zero).
135  /// Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns.
136  float offset;
137  /// Elapsed real time since previous interpolate, in seconds.
139 };
140 
141 /**
142  * Add renderable objects to the scene collector.
143  * Called after CMessageInterpolate.
144  */
146 {
147 public:
148  DEFAULT_MESSAGE_IMPL(RenderSubmit)
149 
151  collector(collector), frustum(frustum), culling(culling)
152  {
153  }
154 
157  bool culling;
158 };
159 
160 /**
161  * Handle progressive loading of resources.
162  * A component that listens to this message must do the following:
163  * - Increase *msg.total by the non-zero number of loading tasks this component can perform.
164  * - If *msg.progressed == true, return and do nothing.
165  * - If you've loaded everything, increase *msg.progress by the value you added to .total
166  * - Otherwise do some loading, set *msg.progressed = true, and increase *msg.progress by a
167  * value indicating how much progress you've made in total (0 <= p <= what you added to .total)
168  * In some situations these messages will never be sent - components must ensure they
169  * load all their data themselves before using it in that case.
170  */
172 {
173 public:
175 
177  progressed(progressed), total(total), progress(progress)
178  {
179  }
180 
181  bool* progressed;
182  int* total;
183  int* progress;
184 };
185 
186 
187 /**
188  * This is sent immediately after a new entity's components have all been created
189  * and initialised.
190  */
191 class CMessageCreate : public CMessage
192 {
193 public:
195 
197  entity(entity)
198  {
199  }
200 
202 };
203 
204 /**
205  * This is sent immediately before a destroyed entity is flushed and really destroyed.
206  * (That is, after CComponentManager::DestroyComponentsSoon and inside FlushDestroyedComponents).
207  * The entity will still exist at the time this message is sent.
208  * It's possible for this message to be sent multiple times for one entity, but all its components
209  * will have been deleted after the first time.
210  */
211 class CMessageDestroy : public CMessage
212 {
213 public:
215 
217  entity(entity)
218  {
219  }
220 
222 };
223 
225 {
226 public:
227  DEFAULT_MESSAGE_IMPL(OwnershipChanged)
228 
230  entity(entity), from(from), to(to)
231  {
232  }
233 
237 };
238 
239 /**
240  * Sent during TurnStart.
241  *
242  * If @c inWorld is false, then the other fields are invalid and meaningless.
243  * Otherwise they represent the current position.
244  */
246 {
247 public:
248  DEFAULT_MESSAGE_IMPL(PositionChanged)
249 
251  entity(entity), inWorld(inWorld), x(x), z(z), a(a)
252  {
253  }
254 
256  bool inWorld;
259 };
260 
261 /**
262  * Sent by CCmpUnitMotion during Update, whenever the motion status has changed
263  * since the previous update.
264  */
266 {
267 public:
268  DEFAULT_MESSAGE_IMPL(MotionChanged)
269 
271  starting(starting), error(error)
272  {
273  }
274 
275  bool starting; // whether this is a start or end of movement
276  bool error; // whether we failed to start moving (couldn't find any path)
277 };
278 
279 /**
280  * Sent when terrain (texture or elevation) has been changed.
281  */
283 {
284 public:
285  DEFAULT_MESSAGE_IMPL(TerrainChanged)
286 
287  CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) :
288  i0(i0), j0(j0), i1(i1), j1(j1)
289  {
290  }
291 
292  int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
293 };
294 
295 /**
296  * Sent when territory assignments have changed.
297  */
299 {
300 public:
301  DEFAULT_MESSAGE_IMPL(TerritoriesChanged)
302 
304  {
305  }
306 };
307 
308 /**
309  * Sent by CCmpRangeManager at most once per turn, when an active range query
310  * has had matching units enter/leave the range since the last RangeUpdate.
311  */
313 {
314 public:
315  DEFAULT_MESSAGE_IMPL(RangeUpdate)
316 
317 
318 
320  std::vector<entity_id_t> added;
321  std::vector<entity_id_t> removed;
322 
323  // CCmpRangeManager wants to store a vector of messages and wants to
324  // swap vectors instead of copying (to save on memory allocations),
325  // so add some constructors for it:
326 
327  // don't init tag in empty ctor
329  {
330  }
332  {
333  }
334  CMessageRangeUpdate(u32 tag, const std::vector<entity_id_t>& added, const std::vector<entity_id_t>& removed)
335  : tag(tag), added(added), removed(removed)
336  {
337  }
339  : CMessage(), tag(other.tag), added(other.added), removed(other.removed)
340  {
341  }
343  {
344  tag = other.tag;
345  added = other.added;
346  removed = other.removed;
347  return *this;
348  }
349 };
350 
351 /**
352  * Sent by CCmpPathfinder after async path requests.
353  */
355 {
356 public:
358 
360  ticket(ticket), path(path)
361  {
362  }
363 
366 };
367 
368 /**
369  * Sent by technology manager when a technology is researched that modifies a component.
370  */
372 {
373 public:
374  DEFAULT_MESSAGE_IMPL(TechnologyModification)
375 
377  component(component), player(player)
378  {
379  }
380 
381  std::wstring component;
383 };
384 
385 /**
386  * Sent by CCmpVision when an entity's vision range changes.
387  */
389 {
390 public:
391  DEFAULT_MESSAGE_IMPL(VisionRangeChanged)
392 
394  entity(entity), oldRange(oldRange), newRange(newRange)
395  {
396  }
397 
401 };
402 
403 /**
404  * Sent when an entity pings the minimap
405  */
407 {
408 public:
409  DEFAULT_MESSAGE_IMPL(MinimapPing)
410 
412  {
413  }
414 };
415 
416 #endif // INCLUDED_MESSAGETYPES
Update phase for formation controller movement (must happen before individual units move to follow th...
Definition: MessageTypes.h:74
A simple fixed-point number class.
Definition: Fixed.h:115
Generic per-turn update message, for things that don&#39;t care much about ordering.
Definition: MessageTypes.h:57
This is sent immediately after a new entity&#39;s components have all been created and initialised...
Definition: MessageTypes.h:191
const CFrustum & frustum
Definition: MessageTypes.h:156
CMessageRangeUpdate(u32 tag, const std::vector< entity_id_t > &added, const std::vector< entity_id_t > &removed)
Definition: MessageTypes.h:334
T Interpolate(const T &a, const T &b, float l)
Definition: MathUtil.h:26
entity_id_t entity
Definition: MessageTypes.h:221
Sent by CCmpVision when an entity&#39;s vision range changes.
Definition: MessageTypes.h:388
static int ProgressiveLoad()
Definition: main.cpp:229
std::vector< entity_id_t > removed
Definition: MessageTypes.h:321
Add renderable objects to the scene collector.
Definition: MessageTypes.h:145
Sent by CCmpUnitMotion during Update, whenever the motion status has changed since the previous updat...
Definition: MessageTypes.h:265
Sent when terrain (texture or elevation) has been changed.
Definition: MessageTypes.h:282
Sent by CCmpRangeManager at most once per turn, when an active range query has had matching units ent...
Definition: MessageTypes.h:312
Returned path.
Update phase for non-formation-controller unit movement.
Definition: MessageTypes.h:90
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
Definition: MessageTypes.h:134
Pathfinder algorithms.
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:24
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:138
This interface accepts renderable objects.
Definition: Scene.h:82
Final update phase, after all other updates.
Definition: MessageTypes.h:106
Definition: path.h:75
This is sent immediately before a destroyed entity is flushed and really destroyed.
Definition: MessageTypes.h:211
Sent when an entity pings the minimap.
Definition: MessageTypes.h:406
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns...
Definition: MessageTypes.h:136
Sent during TurnStart.
Definition: MessageTypes.h:245
CMessageRangeUpdate(u32 tag)
Definition: MessageTypes.h:331
CMessageRangeUpdate(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:338
entity_id_t entity
Definition: MessageTypes.h:201
#define u32
Definition: types.h:41
Handle progressive loading of resources.
Definition: MessageTypes.h:171
Sent by CCmpPathfinder after async path requests.
Definition: MessageTypes.h:354
SceneCollector & collector
Definition: MessageTypes.h:155
Sent by technology manager when a technology is researched that modifies a component.
Definition: MessageTypes.h:371
#define DEFAULT_MESSAGE_IMPL(name)
Definition: MessageTypes.h:30
CMessageRangeUpdate & operator=(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:342
ICmpPathfinder::Path path
Definition: MessageTypes.h:365
Sent when territory assignments have changed.
Definition: MessageTypes.h:298
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:122
Entity coordinate types.
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
std::vector< entity_id_t > added
Definition: MessageTypes.h:320