Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
MessageTypes.h
Go to the documentation of this file.
1/* Copyright (C) 2023 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 ScriptRequest& rq) const; \
39 static CMessage* FromJSVal(const ScriptRequest&, JS::HandleValue val);
40
41class SceneCollector;
42class CFrustum;
43
44class CMessageTurnStart final : public CMessage
45{
46public:
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 */
61class CMessageUpdate final : public CMessage
62{
63public:
65
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{
80public:
81 DEFAULT_MESSAGE_IMPL(Update_MotionFormation)
82
85 {
86 }
87
89};
90
91/**
92 * Update phase for non-formation-controller unit movement.
93 */
95{
96public:
97 DEFAULT_MESSAGE_IMPL(Update_MotionUnit)
98
101 {
102 }
103
105};
106
107/**
108 * Final update phase, after all other updates.
109 */
110class CMessageUpdate_Final final : public CMessage
111{
112public:
114
117 {
118 }
119
121};
122
123/**
124 * Prepare for rendering a new frame (set up model positions etc).
125 */
126class CMessageInterpolate final : public CMessage
127{
128public:
130
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 */
149class CMessageRenderSubmit final : public CMessage
150{
151public:
153
156 {
157 }
158
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{
177public:
179
182 {
183 }
184
186 int* total;
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 */
198class CMessageDeserialized final : public CMessage
199{
200public:
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 */
213class CMessageCreate final : public CMessage
214{
215public:
217
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 */
233class CMessageDestroy final : public CMessage
234{
235public:
237
240 {
241 }
242
244};
245
247{
248public:
249 DEFAULT_MESSAGE_IMPL(OwnershipChanged)
250
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{
270public:
271 DEFAULT_MESSAGE_IMPL(PositionChanged)
272
274 entity(entity), inWorld(inWorld), x(x), z(z), a(a)
275 {
276 }
277
282};
283
284/**
285 * Sent by CCmpPosition whenever anything has changed that will affect the
286 * return value of GetInterpolatedTransform()
287 */
289{
290public:
291 DEFAULT_MESSAGE_IMPL(InterpolatedPositionChanged)
292
295 {
296 }
297
302};
303
304/**
305 * Sent by CCmpUnitMotion during Update if an event happened that might interest other components.
306 */
307class CMessageMotionUpdate final : public CMessage
308{
309public:
311
313 LIKELY_SUCCESS, // UnitMotion considers it is arrived at destination.
314 LIKELY_FAILURE, // UnitMotion says it cannot reach the destination.
315 OBSTRUCTED, // UnitMotion was obstructed. This does not mean stuck, but can be a hint to run range checks.
316 VERY_OBSTRUCTED, // Sent when obstructed several time in a row.
317 LENGTH
318 };
319
320 static const std::array<const char*, UpdateType::LENGTH> UpdateTypeStr;
321
323 {
324 }
325
327};
328
329/**
330 * Sent when water height has been changed.
331 */
332class CMessageWaterChanged final : public CMessage
333{
334public:
336
338 {
339 }
340};
341
342/**
343 * Sent when terrain (texture or elevation) has been changed.
344 */
346{
347public:
348 DEFAULT_MESSAGE_IMPL(TerrainChanged)
349
350 CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) :
351 i0(i0), j0(j0), i1(i1), j1(j1)
352 {
353 }
354
355 int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
356};
357
358/**
359 * Sent, at most once per turn, when the visibility of an entity changed
360 */
362{
363public:
364 DEFAULT_MESSAGE_IMPL(VisibilityChanged)
365
368 {
369 }
370
375};
376
377/**
378 * Sent when then obstruction of an entity has changed in a manner
379 * that changes 'block movement' properties.
380 */
382{
383public:
384 DEFAULT_MESSAGE_IMPL(MovementObstructionChanged)
385
387 {
388 }
389};
390
391/**
392 * Sent when ObstructionManager's view of the shape of the world has changed
393 * (changing the TILE_OUTOFBOUNDS tiles returned by Rasterise).
394 */
396{
397public:
398 DEFAULT_MESSAGE_IMPL(ObstructionMapShapeChanged)
399
401 {
402 }
403};
404
405/**
406 * Sent when territory assignments have changed.
407 */
409{
410public:
411 DEFAULT_MESSAGE_IMPL(TerritoriesChanged)
412
414 {
415 }
416};
417
418/**
419 * Sent by CCmpRangeManager at most once per turn, when an active range query
420 * has had matching units enter/leave the range since the last RangeUpdate.
421 */
422class CMessageRangeUpdate final : public CMessage
423{
424public:
426
427
428
432
433 // CCmpRangeManager wants to store a vector of messages and wants to
434 // swap vectors instead of copying (to save on memory allocations),
435 // so add some constructors for it:
436
437 // don't init tag in empty ctor
439 {
440 }
442 {
443 }
444 CMessageRangeUpdate(u32 tag, const std::vector<entity_id_t>& added, const std::vector<entity_id_t>& removed)
446 {
447 }
449 : CMessage(), tag(other.tag), added(other.added), removed(other.removed)
450 {
451 }
453 {
454 tag = other.tag;
455 added = other.added;
456 removed = other.removed;
457 return *this;
458 }
459};
460
461/**
462 * Sent by CCmpPathfinder after async path requests.
463 */
464class CMessagePathResult final : public CMessage
465{
466public:
468
471 {
472 }
473
476};
477
478/**
479 * Sent by aura manager when a value of a certain entity's component is changed
480 */
482{
483public:
484 DEFAULT_MESSAGE_IMPL(ValueModification)
485
486 CMessageValueModification(const std::vector<entity_id_t>& entities, std::wstring component, const std::vector<std::wstring>& valueNames) :
490 {
491 }
492
493 std::vector<entity_id_t> entities;
494 std::wstring component;
495 std::vector<std::wstring> valueNames;
496};
497
498/**
499 * Sent by atlas if the playercolor has been changed.
500 */
502{
503public:
504 DEFAULT_MESSAGE_IMPL(PlayerColorChanged)
505
508 {
509 }
510
512};
513
514/**
515 * Sent by aura and tech managers when a value of a certain template's component is changed
516 */
518{
519public:
520 DEFAULT_MESSAGE_IMPL(TemplateModification)
521
523 player(player),
526 {
527 }
528
530 std::wstring component;
531 std::vector<std::wstring> valueNames;
532};
533
534/**
535 * Sent by CCmpVision when an entity's vision range changes.
536 */
538{
539public:
540 DEFAULT_MESSAGE_IMPL(VisionRangeChanged)
541
544 {
545 }
546
550};
551
552/**
553 * Sent by CCmpVision when an entity's vision sharing changes.
554 */
556{
557public:
558 DEFAULT_MESSAGE_IMPL(VisionSharingChanged)
559
562 {
563 }
564
567 bool add;
568};
569
570/**
571 * Sent when an entity pings the minimap
572 */
573class CMessageMinimapPing final : public CMessage
574{
575public:
577
579 {
580 }
581};
582
583/**
584* Cinematics events
585*/
586
588{
589public:
590 DEFAULT_MESSAGE_IMPL(CinemaPathEnded)
591
593 name(name)
594 {
595 }
596
597 CStrW name;
598};
599
601{
602public:
603 DEFAULT_MESSAGE_IMPL(CinemaQueueEnded)
604};
605
606#endif // INCLUDED_MESSAGETYPES
T Interpolate(const T &a, const T &b, float t)
Definition: MathUtil.h:26
#define DEFAULT_MESSAGE_IMPL(name)
Definition: MessageTypes.h:34
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:24
Entity coordinate types.
A simple fixed-point number class.
Definition: Fixed.h:120
Definition: Frustum.h:37
Cinematics events.
Definition: MessageTypes.h:588
CStrW name
Definition: MessageTypes.h:597
Definition: MessageTypes.h:601
This is sent immediately after a new entity's components have all been created and initialised.
Definition: MessageTypes.h:214
entity_id_t entity
Definition: MessageTypes.h:223
Broadcast after the entire simulation state has been deserialized.
Definition: MessageTypes.h:199
This is sent immediately before a destroyed entity is flushed and really destroyed.
Definition: MessageTypes.h:234
entity_id_t entity
Definition: MessageTypes.h:243
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:127
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:142
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
Definition: MessageTypes.h:138
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns.
Definition: MessageTypes.h:140
Sent by CCmpPosition whenever anything has changed that will affect the return value of GetInterpolat...
Definition: MessageTypes.h:289
entity_id_t entity
Definition: MessageTypes.h:298
CVector3D pos0
Definition: MessageTypes.h:300
CVector3D pos1
Definition: MessageTypes.h:301
bool inWorld
Definition: MessageTypes.h:299
Sent when an entity pings the minimap.
Definition: MessageTypes.h:574
Sent by CCmpUnitMotion during Update if an event happened that might interest other components.
Definition: MessageTypes.h:308
CMessageMotionUpdate(UpdateType ut)
Definition: MessageTypes.h:322
UpdateType updateType
Definition: MessageTypes.h:326
UpdateType
Definition: MessageTypes.h:312
@ LENGTH
Definition: MessageTypes.h:317
@ LIKELY_FAILURE
Definition: MessageTypes.h:314
@ VERY_OBSTRUCTED
Definition: MessageTypes.h:316
@ LIKELY_SUCCESS
Definition: MessageTypes.h:313
@ OBSTRUCTED
Definition: MessageTypes.h:315
static const std::array< const char *, UpdateType::LENGTH > UpdateTypeStr
Definition: MessageTypes.h:320
Sent when then obstruction of an entity has changed in a manner that changes 'block movement' propert...
Definition: MessageTypes.h:382
Sent when ObstructionManager's view of the shape of the world has changed (changing the TILE_OUTOFBOU...
Definition: MessageTypes.h:396
Definition: MessageTypes.h:247
player_id_t to
Definition: MessageTypes.h:258
entity_id_t entity
Definition: MessageTypes.h:256
player_id_t from
Definition: MessageTypes.h:257
Sent by CCmpPathfinder after async path requests.
Definition: MessageTypes.h:465
WaypointPath path
Definition: MessageTypes.h:475
u32 ticket
Definition: MessageTypes.h:474
Sent by atlas if the playercolor has been changed.
Definition: MessageTypes.h:502
player_id_t player
Definition: MessageTypes.h:511
Sent by CCmpPosition whenever anything has changed that will affect the return value of GetPosition2D...
Definition: MessageTypes.h:269
bool inWorld
Definition: MessageTypes.h:279
entity_id_t entity
Definition: MessageTypes.h:278
entity_pos_t x
Definition: MessageTypes.h:280
entity_angle_t a
Definition: MessageTypes.h:281
entity_pos_t z
Definition: MessageTypes.h:280
Handle progressive loading of resources.
Definition: MessageTypes.h:176
int * progress
Definition: MessageTypes.h:187
bool * progressed
Definition: MessageTypes.h:185
int * total
Definition: MessageTypes.h:186
Sent by CCmpRangeManager at most once per turn, when an active range query has had matching units ent...
Definition: MessageTypes.h:423
CMessageRangeUpdate(u32 tag)
Definition: MessageTypes.h:441
CMessageRangeUpdate & operator=(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:452
std::vector< entity_id_t > removed
Definition: MessageTypes.h:431
CMessageRangeUpdate(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:448
std::vector< entity_id_t > added
Definition: MessageTypes.h:430
CMessageRangeUpdate(u32 tag, const std::vector< entity_id_t > &added, const std::vector< entity_id_t > &removed)
Definition: MessageTypes.h:444
u32 tag
Definition: MessageTypes.h:429
Add renderable objects to the scene collector.
Definition: MessageTypes.h:150
bool culling
Definition: MessageTypes.h:161
SceneCollector & collector
Definition: MessageTypes.h:159
const CFrustum & frustum
Definition: MessageTypes.h:160
Sent by aura and tech managers when a value of a certain template's component is changed.
Definition: MessageTypes.h:518
std::vector< std::wstring > valueNames
Definition: MessageTypes.h:531
std::wstring component
Definition: MessageTypes.h:530
player_id_t player
Definition: MessageTypes.h:529
Sent when terrain (texture or elevation) has been changed.
Definition: MessageTypes.h:346
int32_t i1
Definition: MessageTypes.h:355
int32_t j0
Definition: MessageTypes.h:355
int32_t i0
Definition: MessageTypes.h:355
int32_t j1
Definition: MessageTypes.h:355
Sent when territory assignments have changed.
Definition: MessageTypes.h:409
Definition: MessageTypes.h:45
Final update phase, after all other updates.
Definition: MessageTypes.h:111
fixed turnLength
Definition: MessageTypes.h:120
Update phase for formation controller movement (must happen before individual units move to follow th...
Definition: MessageTypes.h:79
fixed turnLength
Definition: MessageTypes.h:88
Update phase for non-formation-controller unit movement.
Definition: MessageTypes.h:95
fixed turnLength
Definition: MessageTypes.h:104
Generic per-turn update message, for things that don't care much about ordering.
Definition: MessageTypes.h:62
fixed turnLength
Definition: MessageTypes.h:71
Sent by aura manager when a value of a certain entity's component is changed.
Definition: MessageTypes.h:482
std::vector< entity_id_t > entities
Definition: MessageTypes.h:493
std::vector< std::wstring > valueNames
Definition: MessageTypes.h:495
std::wstring component
Definition: MessageTypes.h:494
Sent, at most once per turn, when the visibility of an entity changed.
Definition: MessageTypes.h:362
int oldVisibility
Definition: MessageTypes.h:373
player_id_t player
Definition: MessageTypes.h:371
entity_id_t ent
Definition: MessageTypes.h:372
int newVisibility
Definition: MessageTypes.h:374
Sent by CCmpVision when an entity's vision range changes.
Definition: MessageTypes.h:538
entity_pos_t oldRange
Definition: MessageTypes.h:548
entity_pos_t newRange
Definition: MessageTypes.h:549
entity_id_t entity
Definition: MessageTypes.h:547
Sent by CCmpVision when an entity's vision sharing changes.
Definition: MessageTypes.h:556
player_id_t player
Definition: MessageTypes.h:566
entity_id_t entity
Definition: MessageTypes.h:565
bool add
Definition: MessageTypes.h:567
Sent when water height has been changed.
Definition: MessageTypes.h:333
Definition: Message.h:26
Definition: Vector3D.h:31
This interface accepts renderable objects.
Definition: Scene.h:90
static int ProgressiveLoad()
Definition: main.cpp:303
Definition: ShaderDefines.cpp:31
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
Definition: ICmpPathfinder.h:37
Returned path.
Definition: Pathfinding.h:67
uint32_t u32
Definition: types.h:39