Pyrogenesis  trunk
MessageTypes.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 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(const ScriptInterface& scriptInterface) const; \
39  static CMessage* FromJSVal(const ScriptInterface&, JS::HandleValue val);
40 
41 class SceneCollector;
42 class CFrustum;
43 
44 class CMessageTurnStart final : public CMessage
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 final : 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  */
94 class CMessageUpdate_MotionUnit final : public CMessage
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  */
110 class CMessageUpdate_Final final : public CMessage
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  */
126 class CMessageInterpolate final : public CMessage
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  */
149 class CMessageRenderSubmit final : public CMessage
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  */
175 class CMessageProgressiveLoad final : public CMessage
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  */
198 class CMessageDeserialized final : public CMessage
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 final : 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 final : public CMessage
234 {
235 public:
237 
239  entity(entity)
240  {
241  }
242 
244 };
245 
246 class CMessageOwnershipChanged final : public CMessage
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  */
268 class CMessagePositionChanged final : public CMessage
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 if an event happened that might interest other components.
321  */
322 class CMessageMotionUpdate final : public CMessage
323 {
324 public:
325  DEFAULT_MESSAGE_IMPL(MotionUpdate)
326 
327  enum UpdateType {
328  LIKELY_SUCCESS, // UnitMotion considers it is arrived at destination.
329  LIKELY_FAILURE, // UnitMotion says it cannot reach the destination.
330  OBSTRUCTED, // UnitMotion was obstructed. This does not mean stuck, but can be a hint to run range checks.
331  VERY_OBSTRUCTED, // Sent when obstructed several time in a row.
332  LENGTH
333  };
334 
335  static const std::array<const char*, UpdateType::LENGTH> UpdateTypeStr;
336 
337  CMessageMotionUpdate(UpdateType ut) : updateType(ut)
338  {
339  }
340 
342 };
343 
344 /**
345  * Sent when water height has been changed.
346  */
347 class CMessageWaterChanged final : public CMessage
348 {
349 public:
350  DEFAULT_MESSAGE_IMPL(WaterChanged)
351 
353  {
354  }
355 };
356 
357 /**
358  * Sent when terrain (texture or elevation) has been changed.
359  */
360 class CMessageTerrainChanged final : public CMessage
361 {
362 public:
363  DEFAULT_MESSAGE_IMPL(TerrainChanged)
364 
365  CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) :
366  i0(i0), j0(j0), i1(i1), j1(j1)
367  {
368  }
369 
370  int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
371 };
372 
373 /**
374  * Sent, at most once per turn, when the visibility of an entity changed
375  */
377 {
378 public:
379  DEFAULT_MESSAGE_IMPL(VisibilityChanged)
380 
381  CMessageVisibilityChanged(player_id_t player, entity_id_t ent, int oldVisibility, int newVisibility) :
382  player(player), ent(ent), oldVisibility(oldVisibility), newVisibility(newVisibility)
383  {
384  }
385 
390 };
391 
392 /**
393  * Sent when then obstruction of an entity has changed in a manner
394  * that changes 'block movement' properties.
395  */
397 {
398 public:
399  DEFAULT_MESSAGE_IMPL(MovementObstructionChanged)
400 
402  {
403  }
404 };
405 
406 /**
407  * Sent when ObstructionManager's view of the shape of the world has changed
408  * (changing the TILE_OUTOFBOUNDS tiles returned by Rasterise).
409  */
411 {
412 public:
413  DEFAULT_MESSAGE_IMPL(ObstructionMapShapeChanged)
414 
416  {
417  }
418 };
419 
420 /**
421  * Sent when territory assignments have changed.
422  */
424 {
425 public:
426  DEFAULT_MESSAGE_IMPL(TerritoriesChanged)
427 
429  {
430  }
431 };
432 
433 /**
434  * Sent by CCmpRangeManager at most once per turn, when an active range query
435  * has had matching units enter/leave the range since the last RangeUpdate.
436  */
437 class CMessageRangeUpdate final : public CMessage
438 {
439 public:
440  DEFAULT_MESSAGE_IMPL(RangeUpdate)
441 
442 
443 
444  u32 tag;
445  std::vector<entity_id_t> added;
446  std::vector<entity_id_t> removed;
447 
448  // CCmpRangeManager wants to store a vector of messages and wants to
449  // swap vectors instead of copying (to save on memory allocations),
450  // so add some constructors for it:
451 
452  // don't init tag in empty ctor
454  {
455  }
456  CMessageRangeUpdate(u32 tag) : tag(tag)
457  {
458  }
459  CMessageRangeUpdate(u32 tag, const std::vector<entity_id_t>& added, const std::vector<entity_id_t>& removed)
460  : tag(tag), added(added), removed(removed)
461  {
462  }
464  : CMessage(), tag(other.tag), added(other.added), removed(other.removed)
465  {
466  }
468  {
469  tag = other.tag;
470  added = other.added;
471  removed = other.removed;
472  return *this;
473  }
474 };
475 
476 /**
477  * Sent by CCmpPathfinder after async path requests.
478  */
479 class CMessagePathResult final : public CMessage
480 {
481 public:
483 
484  CMessagePathResult(u32 ticket, const WaypointPath& path) :
485  ticket(ticket), path(path)
486  {
487  }
488 
491 };
492 
493 /**
494  * Sent by aura manager when a value of a certain entity's component is changed
495  */
497 {
498 public:
499  DEFAULT_MESSAGE_IMPL(ValueModification)
500 
501  CMessageValueModification(const std::vector<entity_id_t>& entities, std::wstring component, const std::vector<std::wstring>& valueNames) :
502  entities(entities),
503  component(component),
504  valueNames(valueNames)
505  {
506  }
507 
508  std::vector<entity_id_t> entities;
509  std::wstring component;
510  std::vector<std::wstring> valueNames;
511 };
512 
513 /**
514  * Sent by atlas if the playercolor has been changed.
515  */
517 {
518 public:
519  DEFAULT_MESSAGE_IMPL(PlayerColorChanged)
520 
522  player(player)
523  {
524  }
525 
527 };
528 
529 /**
530  * Sent by aura and tech managers when a value of a certain template's component is changed
531  */
533 {
534 public:
535  DEFAULT_MESSAGE_IMPL(TemplateModification)
536 
537  CMessageTemplateModification(player_id_t player, std::wstring component, const std::vector<std::wstring>& valueNames) :
538  player(player),
539  component(component),
540  valueNames(valueNames)
541  {
542  }
543 
545  std::wstring component;
546  std::vector<std::wstring> valueNames;
547 };
548 
549 /**
550  * Sent by CCmpVision when an entity's vision range changes.
551  */
553 {
554 public:
555  DEFAULT_MESSAGE_IMPL(VisionRangeChanged)
556 
558  entity(entity), oldRange(oldRange), newRange(newRange)
559  {
560  }
561 
565 };
566 
567 /**
568  * Sent by CCmpVision when an entity's vision sharing changes.
569  */
571 {
572 public:
573  DEFAULT_MESSAGE_IMPL(VisionSharingChanged)
574 
576  entity(entity), player(player), add(add)
577  {
578  }
579 
582  bool add;
583 };
584 
585 /**
586  * Sent when an entity pings the minimap
587  */
588 class CMessageMinimapPing final : public CMessage
589 {
590 public:
591  DEFAULT_MESSAGE_IMPL(MinimapPing)
592 
594  {
595  }
596 };
597 
598 /**
599 * Cinematics events
600 */
601 
602 class CMessageCinemaPathEnded final : public CMessage
603 {
604 public:
605  DEFAULT_MESSAGE_IMPL(CinemaPathEnded)
606 
608  name(name)
609  {
610  }
611 
612  CStrW name;
613 };
614 
615 class CMessageCinemaQueueEnded final : public CMessage
616 {
617 public:
618  DEFAULT_MESSAGE_IMPL(CinemaQueueEnded)
619 };
620 
621 #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:119
bool inWorld
Definition: MessageTypes.h:299
int * progress
Definition: MessageTypes.h:187
entity_id_t entity
Definition: MessageTypes.h:580
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:508
Definition: ICmpPathfinder.h:36
const CFrustum & frustum
Definition: MessageTypes.h:160
std::wstring component
Definition: MessageTypes.h:545
Sent by CCmpUnitMotion during Update if an event happened that might interest other components...
Definition: MessageTypes.h:322
Sent when ObstructionManager&#39;s view of the shape of the world has changed (changing the TILE_OUTOFBOU...
Definition: MessageTypes.h:410
CMessageRangeUpdate(u32 tag, const std::vector< entity_id_t > &added, const std::vector< entity_id_t > &removed)
Definition: MessageTypes.h:459
entity_id_t entity
Definition: MessageTypes.h:243
Sent by CCmpVision when an entity&#39;s vision range changes.
Definition: MessageTypes.h:552
player_id_t player
Definition: MessageTypes.h:526
Returned path.
Definition: Pathfinding.h:66
static int ProgressiveLoad()
Definition: main.cpp:296
fixed turnLength
Definition: MessageTypes.h:104
CVector3D pos0
Definition: MessageTypes.h:300
Sent when then obstruction of an entity has changed in a manner that changes &#39;block movement&#39; propert...
Definition: MessageTypes.h:396
bool * progressed
Definition: MessageTypes.h:185
std::vector< entity_id_t > removed
Definition: MessageTypes.h:446
Sent by CCmpVision when an entity&#39;s vision sharing changes.
Definition: MessageTypes.h:570
Add renderable objects to the scene collector.
Definition: MessageTypes.h:149
bool add
Definition: MessageTypes.h:582
Sent when terrain (texture or elevation) has been changed.
Definition: MessageTypes.h:360
Sent by CCmpRangeManager at most once per turn, when an active range query has had matching units ent...
Definition: MessageTypes.h:437
Definition: Vector3D.h:30
Definition: Frustum.h:36
fixed turnLength
Definition: MessageTypes.h:71
Sent when water height has been changed.
Definition: MessageTypes.h:347
Definition: MessageTypes.h:615
Definition: ShaderDefines.cpp:30
Update phase for non-formation-controller unit movement.
Definition: MessageTypes.h:94
int32_t j1
Definition: MessageTypes.h:370
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
Sent by atlas if the playercolor has been changed.
Definition: MessageTypes.h:516
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:510
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:142
This interface accepts renderable objects.
Definition: Scene.h:89
T Interpolate(const T &a, const T &b, float t)
Definition: MathUtil.h:26
UpdateType updateType
Definition: MessageTypes.h:341
entity_pos_t oldRange
Definition: MessageTypes.h:563
uint32_t u32
Definition: types.h:39
int oldVisibility
Definition: MessageTypes.h:388
Final update phase, after all other updates.
Definition: MessageTypes.h:110
CStrW name
Definition: MessageTypes.h:612
CVector3D pos1
Definition: MessageTypes.h:301
bool culling
Definition: MessageTypes.h:161
u32 tag
Definition: MessageTypes.h:444
player_id_t player
Definition: MessageTypes.h:544
This is sent immediately before a destroyed entity is flushed and really destroyed.
Definition: MessageTypes.h:233
entity_id_t ent
Definition: MessageTypes.h:387
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
Definition: MessageTypes.h:328
Sent when an entity pings the minimap.
Definition: MessageTypes.h:588
Definition: MessageTypes.h:329
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:496
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:376
static const std::array< const char *, UpdateType::LENGTH > UpdateTypeStr
Definition: MessageTypes.h:335
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:546
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:456
CMessageRangeUpdate(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:463
int * total
Definition: MessageTypes.h:186
entity_id_t entity
Definition: MessageTypes.h:223
u32 ticket
Definition: MessageTypes.h:489
WaypointPath path
Definition: MessageTypes.h:490
player_id_t player
Definition: MessageTypes.h:386
entity_pos_t newRange
Definition: MessageTypes.h:564
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:532
Definition: MessageTypes.h:305
CMessageMotionUpdate(UpdateType ut)
Definition: MessageTypes.h:337
UpdateType
Definition: MessageTypes.h:327
Handle progressive loading of resources.
Definition: MessageTypes.h:175
Sent by CCmpPathfinder after async path requests.
Definition: MessageTypes.h:479
SceneCollector & collector
Definition: MessageTypes.h:159
player_id_t newTerritory
Definition: MessageTypes.h:316
Definition: MessageTypes.h:331
#define DEFAULT_MESSAGE_IMPL(name)
Definition: MessageTypes.h:34
Definition: MessageTypes.h:330
CMessageRangeUpdate & operator=(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:467
Sent when territory assignments have changed.
Definition: MessageTypes.h:423
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:126
int newVisibility
Definition: MessageTypes.h:389
fixed turnLength
Definition: MessageTypes.h:120
Entity coordinate types.
Cinematics events.
Definition: MessageTypes.h:602
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
bool inWorld
Definition: MessageTypes.h:279
std::wstring component
Definition: MessageTypes.h:509
player_id_t player
Definition: MessageTypes.h:581
Definition: Message.h:23
entity_pos_t z
Definition: MessageTypes.h:280
entity_id_t entity
Definition: MessageTypes.h:562
entity_id_t entity
Definition: MessageTypes.h:315
std::vector< entity_id_t > added
Definition: MessageTypes.h:445