Pyrogenesis  trunk
MessageTypes.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 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 #include "maths/Vector3D.h"
31 
32 #include "ps/CStr.h"
33 
34 #define DEFAULT_MESSAGE_IMPL(name) \
35  virtual int GetType() const { return MT_##name; } \
36  virtual const char* GetScriptHandlerName() const { return "On" #name; } \
37  virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \
38  virtual JS::Value ToJSVal(ScriptInterface& scriptInterface) const; \
39  static CMessage* FromJSVal(ScriptInterface&, JS::HandleValue val);
40 
41 class SceneCollector;
42 class CFrustum;
43 
45 {
46 public:
48 
50  {
51  }
52 };
53 
54 // The update process is split into a number of phases, in an attempt
55 // to cope with dependencies between components. Each phase is implemented
56 // as a separate message. Simulation2.cpp sends them in sequence.
57 
58 /**
59  * Generic per-turn update message, for things that don't care much about ordering.
60  */
61 class CMessageUpdate : public CMessage
62 {
63 public:
65 
66  CMessageUpdate(fixed turnLength) :
67  turnLength(turnLength)
68  {
69  }
70 
72 };
73 
74 /**
75  * Update phase for formation controller movement (must happen before individual
76  * units move to follow their formation).
77  */
79 {
80 public:
81  DEFAULT_MESSAGE_IMPL(Update_MotionFormation)
82 
84  turnLength(turnLength)
85  {
86  }
87 
89 };
90 
91 /**
92  * Update phase for non-formation-controller unit movement.
93  */
95 {
96 public:
97  DEFAULT_MESSAGE_IMPL(Update_MotionUnit)
98 
100  turnLength(turnLength)
101  {
102  }
103 
105 };
106 
107 /**
108  * Final update phase, after all other updates.
109  */
111 {
112 public:
113  DEFAULT_MESSAGE_IMPL(Update_Final)
114 
116  turnLength(turnLength)
117  {
118  }
119 
121 };
122 
123 /**
124  * Prepare for rendering a new frame (set up model positions etc).
125  */
127 {
128 public:
130 
131  CMessageInterpolate(float deltaSimTime, float offset, float deltaRealTime) :
132  deltaSimTime(deltaSimTime), offset(offset), deltaRealTime(deltaRealTime)
133  {
134  }
135 
136  /// Elapsed simulation time since previous interpolate, in seconds. This is similar to the elapsed real time, except
137  /// it is scaled by the current simulation rate (and might indeed be zero).
139  /// Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns.
140  float offset;
141  /// Elapsed real time since previous interpolate, in seconds.
143 };
144 
145 /**
146  * Add renderable objects to the scene collector.
147  * Called after CMessageInterpolate.
148  */
150 {
151 public:
152  DEFAULT_MESSAGE_IMPL(RenderSubmit)
153 
154  CMessageRenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling) :
155  collector(collector), frustum(frustum), culling(culling)
156  {
157  }
158 
161  bool culling;
162 };
163 
164 /**
165  * Handle progressive loading of resources.
166  * A component that listens to this message must do the following:
167  * - Increase *msg.total by the non-zero number of loading tasks this component can perform.
168  * - If *msg.progressed == true, return and do nothing.
169  * - If you've loaded everything, increase *msg.progress by the value you added to .total
170  * - Otherwise do some loading, set *msg.progressed = true, and increase *msg.progress by a
171  * value indicating how much progress you've made in total (0 <= p <= what you added to .total)
172  * In some situations these messages will never be sent - components must ensure they
173  * load all their data themselves before using it in that case.
174  */
176 {
177 public:
179 
180  CMessageProgressiveLoad(bool* progressed, int* total, int* progress) :
181  progressed(progressed), total(total), progress(progress)
182  {
183  }
184 
185  bool* progressed;
186  int* total;
187  int* progress;
188 };
189 
190 /**
191  * Broadcast after the entire simulation state has been deserialized.
192  * Components should do all their self-contained work in their Deserialize
193  * function when possible. But any reinitialisation that depends on other
194  * components or other entities, that might not be constructed until later
195  * in the deserialization process, may be done in response to this message
196  * instead.
197  */
199 {
200 public:
201  DEFAULT_MESSAGE_IMPL(Deserialized)
202 
204  {
205  }
206 };
207 
208 
209 /**
210  * This is sent immediately after a new entity's components have all been created
211  * and initialised.
212  */
213 class CMessageCreate : public CMessage
214 {
215 public:
217 
219  entity(entity)
220  {
221  }
222 
224 };
225 
226 /**
227  * This is sent immediately before a destroyed entity is flushed and really destroyed.
228  * (That is, after CComponentManager::DestroyComponentsSoon and inside FlushDestroyedComponents).
229  * The entity will still exist at the time this message is sent.
230  * It's possible for this message to be sent multiple times for one entity, but all its components
231  * will have been deleted after the first time.
232  */
233 class CMessageDestroy : public CMessage
234 {
235 public:
237 
239  entity(entity)
240  {
241  }
242 
244 };
245 
247 {
248 public:
249  DEFAULT_MESSAGE_IMPL(OwnershipChanged)
250 
252  entity(entity), from(from), to(to)
253  {
254  }
255 
259 };
260 
261 /**
262  * Sent by CCmpPosition whenever anything has changed that will affect the
263  * return value of GetPosition2D() or GetRotation().Y
264  *
265  * If @c inWorld is false, then the other fields are invalid and meaningless.
266  * Otherwise they represent the current position.
267  */
269 {
270 public:
271  DEFAULT_MESSAGE_IMPL(PositionChanged)
272 
274  entity(entity), inWorld(inWorld), x(x), z(z), a(a)
275  {
276  }
277 
279  bool inWorld;
282 };
283 
284 /**
285  * Sent by CCmpPosition whenever anything has changed that will affect the
286  * return value of GetInterpolatedTransform()
287  */
289 {
290 public:
291  DEFAULT_MESSAGE_IMPL(InterpolatedPositionChanged)
292 
293  CMessageInterpolatedPositionChanged(entity_id_t entity, bool inWorld, const CVector3D& pos0, const CVector3D& pos1) :
294  entity(entity), inWorld(inWorld), pos0(pos0), pos1(pos1)
295  {
296  }
297 
299  bool inWorld;
302 };
303 
304 /*Sent whenever the territory type (neutral,own,enemy) differs from the former type*/
306 {
307 public:
308  DEFAULT_MESSAGE_IMPL(TerritoryPositionChanged)
309 
311  entity(entity), newTerritory(newTerritory)
312  {
313  }
314 
317 };
318 
319 /**
320  * Sent by CCmpUnitMotion during Update, whenever the motion status has changed
321  * since the previous update.
322  */
324 {
325 public:
326  DEFAULT_MESSAGE_IMPL(MotionChanged)
327 
328  CMessageMotionChanged(bool starting, bool error) :
329  starting(starting), error(error)
330  {
331  }
332 
333  bool starting; // whether this is a start or end of movement
334  bool error; // whether we failed to start moving (couldn't find any path)
335 };
336 
337 /**
338  * Sent when water height has been changed.
339  */
341 {
342 public:
343  DEFAULT_MESSAGE_IMPL(WaterChanged)
344 
346  {
347  }
348 };
349 
350 /**
351  * Sent when terrain (texture or elevation) has been changed.
352  */
354 {
355 public:
356  DEFAULT_MESSAGE_IMPL(TerrainChanged)
357 
358  CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) :
359  i0(i0), j0(j0), i1(i1), j1(j1)
360  {
361  }
362 
363  int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
364 };
365 
366 /**
367  * Sent, at most once per turn, when the visibility of an entity changed
368  */
370 {
371 public:
372  DEFAULT_MESSAGE_IMPL(VisibilityChanged)
373 
374  CMessageVisibilityChanged(player_id_t player, entity_id_t ent, int oldVisibility, int newVisibility) :
375  player(player), ent(ent), oldVisibility(oldVisibility), newVisibility(newVisibility)
376  {
377  }
378 
383 };
384 
385 /**
386  * Sent when ObstructionManager's view of the shape of the world has changed
387  * (changing the TILE_OUTOFBOUNDS tiles returned by Rasterise).
388  */
390 {
391 public:
392  DEFAULT_MESSAGE_IMPL(ObstructionMapShapeChanged)
393 
395  {
396  }
397 };
398 
399 /**
400  * Sent when territory assignments have changed.
401  */
403 {
404 public:
405  DEFAULT_MESSAGE_IMPL(TerritoriesChanged)
406 
408  {
409  }
410 };
411 
412 /**
413  * Sent by CCmpRangeManager at most once per turn, when an active range query
414  * has had matching units enter/leave the range since the last RangeUpdate.
415  */
417 {
418 public:
419  DEFAULT_MESSAGE_IMPL(RangeUpdate)
420 
421 
422 
423  u32 tag;
424  std::vector<entity_id_t> added;
425  std::vector<entity_id_t> removed;
426 
427  // CCmpRangeManager wants to store a vector of messages and wants to
428  // swap vectors instead of copying (to save on memory allocations),
429  // so add some constructors for it:
430 
431  // don't init tag in empty ctor
433  {
434  }
435  CMessageRangeUpdate(u32 tag) : tag(tag)
436  {
437  }
438  CMessageRangeUpdate(u32 tag, const std::vector<entity_id_t>& added, const std::vector<entity_id_t>& removed)
439  : tag(tag), added(added), removed(removed)
440  {
441  }
443  : CMessage(), tag(other.tag), added(other.added), removed(other.removed)
444  {
445  }
447  {
448  tag = other.tag;
449  added = other.added;
450  removed = other.removed;
451  return *this;
452  }
453 };
454 
455 /**
456  * Sent by CCmpPathfinder after async path requests.
457  */
459 {
460 public:
462 
463  CMessagePathResult(u32 ticket, const WaypointPath& path) :
464  ticket(ticket), path(path)
465  {
466  }
467 
470 };
471 
472 /**
473  * Sent by aura manager when a value of a certain entity's component is changed
474  */
476 {
477 public:
478  DEFAULT_MESSAGE_IMPL(ValueModification)
479 
480  CMessageValueModification(const std::vector<entity_id_t>& entities, std::wstring component, const std::vector<std::wstring>& valueNames) :
481  entities(entities),
482  component(component),
483  valueNames(valueNames)
484  {
485  }
486 
487  std::vector<entity_id_t> entities;
488  std::wstring component;
489  std::vector<std::wstring> valueNames;
490 };
491 
492 /**
493  * Sent by aura and tech managers when a value of a certain template's component is changed
494  */
496 {
497 public:
498  DEFAULT_MESSAGE_IMPL(TemplateModification)
499 
500  CMessageTemplateModification(player_id_t player, std::wstring component, const std::vector<std::wstring>& valueNames) :
501  player(player),
502  component(component),
503  valueNames(valueNames)
504  {
505  }
506 
508  std::wstring component;
509  std::vector<std::wstring> valueNames;
510 };
511 
512 /**
513  * Sent by CCmpVision when an entity's vision range changes.
514  */
516 {
517 public:
518  DEFAULT_MESSAGE_IMPL(VisionRangeChanged)
519 
521  entity(entity), oldRange(oldRange), newRange(newRange)
522  {
523  }
524 
528 };
529 
530 /**
531  * Sent by CCmpVision when an entity's vision sharing changes.
532  */
534 {
535 public:
536  DEFAULT_MESSAGE_IMPL(VisionSharingChanged)
537 
539  entity(entity), player(player), add(add)
540  {
541  }
542 
545  bool add;
546 };
547 
548 /**
549  * Sent when an entity pings the minimap
550  */
552 {
553 public:
554  DEFAULT_MESSAGE_IMPL(MinimapPing)
555 
557  {
558  }
559 };
560 
561 /**
562 * Cinematics events
563 */
564 
566 {
567 public:
568  DEFAULT_MESSAGE_IMPL(CinemaPathEnded)
569 
571  name(name)
572  {
573  }
574 
575  CStrW name;
576 };
577 
579 {
580 public:
581  DEFAULT_MESSAGE_IMPL(CinemaQueueEnded)
582 };
583 
584 #endif // INCLUDED_MESSAGETYPES
Update phase for formation controller movement (must happen before individual units move to follow th...
Definition: MessageTypes.h:78
A simple fixed-point number class.
Definition: Fixed.h:115
bool inWorld
Definition: MessageTypes.h:299
int * progress
Definition: MessageTypes.h:187
entity_id_t entity
Definition: MessageTypes.h:543
Generic per-turn update message, for things that don&#39;t care much about ordering.
Definition: MessageTypes.h:61
Definition: MessageTypes.h:44
This is sent immediately after a new entity&#39;s components have all been created and initialised...
Definition: MessageTypes.h:213
std::vector< entity_id_t > entities
Definition: MessageTypes.h:487
const CFrustum & frustum
Definition: MessageTypes.h:160
std::wstring component
Definition: MessageTypes.h:508
Sent when ObstructionManager&#39;s view of the shape of the world has changed (changing the TILE_OUTOFBOU...
Definition: MessageTypes.h:389
CMessageRangeUpdate(u32 tag, const std::vector< entity_id_t > &added, const std::vector< entity_id_t > &removed)
Definition: MessageTypes.h:438
bool error(JSContext *cx, uint argc, jsval *vp)
Definition: ScriptInterface.cpp:190
T Interpolate(const T &a, const T &b, float l)
Definition: MathUtil.h:26
entity_id_t entity
Definition: MessageTypes.h:243
Sent by CCmpVision when an entity&#39;s vision range changes.
Definition: MessageTypes.h:515
Returned path.
Definition: Pathfinding.h:40
static int ProgressiveLoad()
Definition: main.cpp:182
fixed turnLength
Definition: MessageTypes.h:104
CVector3D pos0
Definition: MessageTypes.h:300
bool * progressed
Definition: MessageTypes.h:185
std::vector< entity_id_t > removed
Definition: MessageTypes.h:425
Sent by CCmpVision when an entity&#39;s vision sharing changes.
Definition: MessageTypes.h:533
Add renderable objects to the scene collector.
Definition: MessageTypes.h:149
Sent by CCmpUnitMotion during Update, whenever the motion status has changed since the previous updat...
Definition: MessageTypes.h:323
bool add
Definition: MessageTypes.h:545
Sent when terrain (texture or elevation) has been changed.
Definition: MessageTypes.h:353
Sent by CCmpRangeManager at most once per turn, when an active range query has had matching units ent...
Definition: MessageTypes.h:416
Definition: Vector3D.h:28
Definition: Frustum.h:39
fixed turnLength
Definition: MessageTypes.h:71
Sent when water height has been changed.
Definition: MessageTypes.h:340
Definition: MessageTypes.h:578
Definition: unique_range.h:196
bool error
Definition: MessageTypes.h:334
Update phase for non-formation-controller unit movement.
Definition: MessageTypes.h:94
bool starting
Definition: MessageTypes.h:333
int32_t j1
Definition: MessageTypes.h:363
entity_angle_t a
Definition: MessageTypes.h:281
entity_id_t entity
Definition: MessageTypes.h:256
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
Definition: MessageTypes.h:138
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:24
std::vector< std::wstring > valueNames
Definition: MessageTypes.h:489
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:142
This interface accepts renderable objects.
Definition: Scene.h:83
entity_pos_t oldRange
Definition: MessageTypes.h:526
uint32_t u32
Definition: types.h:39
int oldVisibility
Definition: MessageTypes.h:381
Final update phase, after all other updates.
Definition: MessageTypes.h:110
CStrW name
Definition: MessageTypes.h:575
CVector3D pos1
Definition: MessageTypes.h:301
bool culling
Definition: MessageTypes.h:161
u32 tag
Definition: MessageTypes.h:423
player_id_t player
Definition: MessageTypes.h:507
This is sent immediately before a destroyed entity is flushed and really destroyed.
Definition: MessageTypes.h:233
entity_id_t ent
Definition: MessageTypes.h:380
fixed turnLength
Definition: MessageTypes.h:88
player_id_t from
Definition: MessageTypes.h:257
Definition: MessageTypes.h:246
Broadcast after the entire simulation state has been deserialized.
Definition: MessageTypes.h:198
Sent when an entity pings the minimap.
Definition: MessageTypes.h:551
player_id_t to
Definition: MessageTypes.h:258
Sent by aura manager when a value of a certain entity&#39;s component is changed.
Definition: MessageTypes.h:475
Sent by CCmpPosition whenever anything has changed that will affect the return value of GetInterpolat...
Definition: MessageTypes.h:288
Sent, at most once per turn, when the visibility of an entity changed.
Definition: MessageTypes.h:369
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns...
Definition: MessageTypes.h:140
std::vector< std::wstring > valueNames
Definition: MessageTypes.h:509
entity_id_t entity
Definition: MessageTypes.h:298
Sent by CCmpPosition whenever anything has changed that will affect the return value of GetPosition2D...
Definition: MessageTypes.h:268
CMessageRangeUpdate(u32 tag)
Definition: MessageTypes.h:435
CMessageRangeUpdate(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:442
int * total
Definition: MessageTypes.h:186
entity_id_t entity
Definition: MessageTypes.h:223
u32 ticket
Definition: MessageTypes.h:468
WaypointPath path
Definition: MessageTypes.h:469
player_id_t player
Definition: MessageTypes.h:379
entity_pos_t newRange
Definition: MessageTypes.h:527
entity_id_t entity
Definition: MessageTypes.h:278
Sent by aura and tech managers when a value of a certain template&#39;s component is changed.
Definition: MessageTypes.h:495
Definition: MessageTypes.h:305
Handle progressive loading of resources.
Definition: MessageTypes.h:175
Sent by CCmpPathfinder after async path requests.
Definition: MessageTypes.h:458
SceneCollector & collector
Definition: MessageTypes.h:159
player_id_t newTerritory
Definition: MessageTypes.h:316
#define DEFAULT_MESSAGE_IMPL(name)
Definition: MessageTypes.h:34
CMessageRangeUpdate & operator=(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:446
Sent when territory assignments have changed.
Definition: MessageTypes.h:402
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:126
int newVisibility
Definition: MessageTypes.h:382
fixed turnLength
Definition: MessageTypes.h:120
Entity coordinate types.
Cinematics events.
Definition: MessageTypes.h:565
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
bool inWorld
Definition: MessageTypes.h:279
std::wstring component
Definition: MessageTypes.h:488
player_id_t player
Definition: MessageTypes.h:544
Definition: Message.h:24
entity_pos_t z
Definition: MessageTypes.h:280
entity_id_t entity
Definition: MessageTypes.h:525
entity_id_t entity
Definition: MessageTypes.h:315
std::vector< entity_id_t > added
Definition: MessageTypes.h:424