Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
MessageTypes.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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
21#include "maths/Fixed.h"
22#include "maths/Vector3D.h"
23#include "ps/CStr.h"
30
31#include <array>
32#include <cstdint>
33#include <js/TypeDecls.h>
34#include <string>
35#include <vector>
36
37namespace Script { class Request; }
38
39#define DEFAULT_MESSAGE_IMPL(name) \
40 virtual int GetType() const { return MT_##name; } \
41 virtual const char* GetScriptHandlerName() const { return "On" #name; } \
42 virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \
43 virtual JS::Value ToJSVal(const Script::Request& rq) const; \
44 static CMessage* FromJSVal(const Script::Request&, JS::HandleValue val);
45
46class SceneCollector;
47class CFrustum;
48
49class CMessageTurnStart final : public CMessage
50{
51public:
53
55 {
56 }
57};
58
59// The update process is split into a number of phases, in an attempt
60// to cope with dependencies between components. Each phase is implemented
61// as a separate message. Simulation2.cpp sends them in sequence.
62
63/**
64 * Generic per-turn update message, for things that don't care much about ordering.
65 */
66class CMessageUpdate final : public CMessage
67{
68public:
70
73 {
74 }
75
77};
78
79/**
80 * Update phase for formation controller movement (must happen before individual
81 * units move to follow their formation).
82 */
84{
85public:
86 DEFAULT_MESSAGE_IMPL(Update_MotionFormation)
87
90 {
91 }
92
94};
95
96/**
97 * Update phase for non-formation-controller unit movement.
98 */
100{
101public:
102 DEFAULT_MESSAGE_IMPL(Update_MotionUnit)
103
106 {
107 }
108
110};
111
112/**
113 * Final update phase, after all other updates.
114 */
115class CMessageUpdate_Final final : public CMessage
116{
117public:
119
122 {
123 }
124
126};
127
128/**
129 * Prepare for rendering a new frame (set up model positions etc).
130 */
131class CMessageInterpolate final : public CMessage
132{
133public:
135
138 {
139 }
140
141 /// Elapsed simulation time since previous interpolate, in seconds. This is similar to the elapsed real time, except
142 /// it is scaled by the current simulation rate (and might indeed be zero).
144 /// Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns.
145 float offset;
146 /// Elapsed real time since previous interpolate, in seconds.
148};
149
150/**
151 * Add renderable objects to the scene collector.
152 * Called after CMessageInterpolate.
153 */
154class CMessageRenderSubmit final : public CMessage
155{
156public:
158
161 {
162 }
163
167};
168
169/**
170 * Handle progressive loading of resources.
171 * A component that listens to this message must do the following:
172 * - Increase *msg.total by the non-zero number of loading tasks this component can perform.
173 * - If *msg.progressed == true, return and do nothing.
174 * - If you've loaded everything, increase *msg.progress by the value you added to .total
175 * - Otherwise do some loading, set *msg.progressed = true, and increase *msg.progress by a
176 * value indicating how much progress you've made in total (0 <= p <= what you added to .total)
177 * In some situations these messages will never be sent - components must ensure they
178 * load all their data themselves before using it in that case.
179 */
181{
182public:
184
187 {
188 }
189
191 int* total;
193};
194
195/**
196 * Broadcast after the entire simulation state has been deserialized.
197 * Components should do all their self-contained work in their Deserialize
198 * function when possible. But any reinitialisation that depends on other
199 * components or other entities, that might not be constructed until later
200 * in the deserialization process, may be done in response to this message
201 * instead.
202 */
203class CMessageDeserialized final : public CMessage
204{
205public:
207
209 {
210 }
211};
212
213
214/**
215 * This is sent immediately after a new entity's components have all been created
216 * and initialised.
217 */
218class CMessageCreate final : public CMessage
219{
220public:
222
225 {
226 }
227
229};
230
231/**
232 * This is sent immediately before a destroyed entity is flushed and really destroyed.
233 * (That is, after CComponentManager::DestroyComponentsSoon and inside FlushDestroyedComponents).
234 * The entity will still exist at the time this message is sent.
235 * It's possible for this message to be sent multiple times for one entity, but all its components
236 * will have been deleted after the first time.
237 */
238class CMessageDestroy final : public CMessage
239{
240public:
242
245 {
246 }
247
249};
250
252{
253public:
254 DEFAULT_MESSAGE_IMPL(OwnershipChanged)
255
258 {
259 }
260
264};
265
266/**
267 * Sent by CCmpPosition whenever anything has changed that will affect the
268 * return value of GetPosition2D() or GetRotation().Y
269 *
270 * If @c inWorld is false, then the other fields are invalid and meaningless.
271 * Otherwise they represent the current position.
272 */
274{
275public:
276 DEFAULT_MESSAGE_IMPL(PositionChanged)
277
279 entity(entity), inWorld(inWorld), x(x), z(z), a(a)
280 {
281 }
282
287};
288
289/**
290 * Sent by CCmpPosition whenever anything has changed that will affect the
291 * return value of GetInterpolatedTransform()
292 */
294{
295public:
296 DEFAULT_MESSAGE_IMPL(InterpolatedPositionChanged)
297
300 {
301 }
302
307};
308
309/**
310 * Sent by CCmpUnitMotion during Update if an event happened that might interest other components.
311 */
312class CMessageMotionUpdate final : public CMessage
313{
314public:
316
318 LIKELY_SUCCESS, // UnitMotion considers it is arrived at destination.
319 LIKELY_FAILURE, // UnitMotion says it cannot reach the destination.
320 OBSTRUCTED, // UnitMotion was obstructed. This does not mean stuck, but can be a hint to run range checks.
321 VERY_OBSTRUCTED, // Sent when obstructed several time in a row.
322 LENGTH
323 };
324
325 static const std::array<const char*, UpdateType::LENGTH> UpdateTypeStr;
326
328 {
329 }
330
332};
333
334/**
335 * Sent when water height has been changed.
336 */
337class CMessageWaterChanged final : public CMessage
338{
339public:
341
343 {
344 }
345};
346
347/**
348 * Sent when terrain (texture or elevation) has been changed.
349 */
351{
352public:
353 DEFAULT_MESSAGE_IMPL(TerrainChanged)
354
355 CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) :
356 i0(i0), j0(j0), i1(i1), j1(j1)
357 {
358 }
359
360 int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
361};
362
363/**
364 * Sent, at most once per turn, when the visibility of an entity changed
365 */
367{
368public:
369 DEFAULT_MESSAGE_IMPL(VisibilityChanged)
370
373 {
374 }
375
380};
381
382/**
383 * Sent when then obstruction of an entity has changed in a manner
384 * that changes 'block movement' properties.
385 */
387{
388public:
389 DEFAULT_MESSAGE_IMPL(MovementObstructionChanged)
390
392 {
393 }
394};
395
396/**
397 * Sent when ObstructionManager's view of the shape of the world has changed
398 * (changing the TILE_OUTOFBOUNDS tiles returned by Rasterise).
399 */
401{
402public:
403 DEFAULT_MESSAGE_IMPL(ObstructionMapShapeChanged)
404
406 {
407 }
408};
409
410/**
411 * Sent when territory assignments have changed.
412 */
414{
415public:
416 DEFAULT_MESSAGE_IMPL(TerritoriesChanged)
417
419 {
420 }
421};
422
423/**
424 * Sent by CCmpRangeManager at most once per turn, when an active range query
425 * has had matching units enter/leave the range since the last RangeUpdate.
426 */
427class CMessageRangeUpdate final : public CMessage
428{
429public:
431
432
433
434 std::uint32_t tag;
437
438 // CCmpRangeManager wants to store a vector of messages and wants to
439 // swap vectors instead of copying (to save on memory allocations),
440 // so add some constructors for it:
441
442 // don't init tag in empty ctor
444 {
445 }
446 CMessageRangeUpdate(std::uint32_t tag) : tag(tag)
447 {
448 }
449 CMessageRangeUpdate(std::uint32_t tag, const std::vector<entity_id_t>& added, const std::vector<entity_id_t>& removed)
451 {
452 }
454 : CMessage(), tag(other.tag), added(other.added), removed(other.removed)
455 {
456 }
458 {
459 tag = other.tag;
460 added = other.added;
461 removed = other.removed;
462 return *this;
463 }
464};
465
466/**
467 * Sent by CCmpPathfinder after async path requests.
468 */
469class CMessagePathResult final : public CMessage
470{
471public:
473
476 {
477 }
478
479 std::uint32_t ticket;
481};
482
483/**
484 * Sent by aura manager when a value of a certain entity's component is changed
485 */
487{
488public:
489 DEFAULT_MESSAGE_IMPL(ValueModification)
490
491 CMessageValueModification(const std::vector<entity_id_t>& entities, std::wstring component, const std::vector<std::wstring>& valueNames) :
495 {
496 }
497
498 std::vector<entity_id_t> entities;
499 std::wstring component;
500 std::vector<std::wstring> valueNames;
501};
502
503/**
504 * Sent by atlas if the playercolor has been changed.
505 */
507{
508public:
509 DEFAULT_MESSAGE_IMPL(PlayerColorChanged)
510
513 {
514 }
515
517};
518
519/**
520 * Sent by the Player component when a specific player has won.
521 */
522class CMessagePlayerWon final : public CMessage
523{
524public:
526
529 {
530 }
531
533};
534
535/**
536 * Sent by the Player component when an specific player has been defeated.
537 */
539{
540public:
541 DEFAULT_MESSAGE_IMPL(PlayerDefeated)
542
545 {
546 }
547
549};
550
551/**
552 * Sent by aura and tech managers when a value of a certain template's component is changed
553 */
555{
556public:
557 DEFAULT_MESSAGE_IMPL(TemplateModification)
558
560 player(player),
563 {
564 }
565
567 std::wstring component;
568 std::vector<std::wstring> valueNames;
569};
570
571/**
572 * Sent by CCmpVision when an entity's vision range changes.
573 */
575{
576public:
577 DEFAULT_MESSAGE_IMPL(VisionRangeChanged)
578
581 {
582 }
583
587};
588
589/**
590 * Sent by CCmpVision when an entity's vision sharing changes.
591 */
593{
594public:
595 DEFAULT_MESSAGE_IMPL(VisionSharingChanged)
596
599 {
600 }
601
604 bool add;
605};
606
607/**
608 * Sent when an entity pings the minimap
609 */
610class CMessageMinimapPing final : public CMessage
611{
612public:
614
616 {
617 }
618};
619
620/**
621* Cinematics events
622*/
623
625{
626public:
627 DEFAULT_MESSAGE_IMPL(CinemaPathEnded)
628
630 name(name)
631 {
632 }
633
634 CStrW name;
635};
636
638{
639public:
640 DEFAULT_MESSAGE_IMPL(CinemaQueueEnded)
641};
642
643#endif // INCLUDED_MESSAGETYPES
T Interpolate(const T &a, const T &b, float t)
Definition: MathUtil.h:28
#define DEFAULT_MESSAGE_IMPL(name)
Definition: MessageTypes.h:39
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:26
Entity coordinate types.
A simple fixed-point number class.
Definition: Fixed.h:129
Definition: Frustum.h:40
Cinematics events.
Definition: MessageTypes.h:625
CStrW name
Definition: MessageTypes.h:634
Definition: MessageTypes.h:638
This is sent immediately after a new entity's components have all been created and initialised.
Definition: MessageTypes.h:219
entity_id_t entity
Definition: MessageTypes.h:228
Broadcast after the entire simulation state has been deserialized.
Definition: MessageTypes.h:204
This is sent immediately before a destroyed entity is flushed and really destroyed.
Definition: MessageTypes.h:239
entity_id_t entity
Definition: MessageTypes.h:248
Prepare for rendering a new frame (set up model positions etc).
Definition: MessageTypes.h:132
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
Definition: MessageTypes.h:147
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
Definition: MessageTypes.h:143
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns.
Definition: MessageTypes.h:145
Sent by CCmpPosition whenever anything has changed that will affect the return value of GetInterpolat...
Definition: MessageTypes.h:294
entity_id_t entity
Definition: MessageTypes.h:303
CVector3D pos0
Definition: MessageTypes.h:305
CVector3D pos1
Definition: MessageTypes.h:306
bool inWorld
Definition: MessageTypes.h:304
Sent when an entity pings the minimap.
Definition: MessageTypes.h:611
Sent by CCmpUnitMotion during Update if an event happened that might interest other components.
Definition: MessageTypes.h:313
CMessageMotionUpdate(UpdateType ut)
Definition: MessageTypes.h:327
UpdateType updateType
Definition: MessageTypes.h:331
UpdateType
Definition: MessageTypes.h:317
@ LENGTH
Definition: MessageTypes.h:322
@ LIKELY_FAILURE
Definition: MessageTypes.h:319
@ VERY_OBSTRUCTED
Definition: MessageTypes.h:321
@ LIKELY_SUCCESS
Definition: MessageTypes.h:318
@ OBSTRUCTED
Definition: MessageTypes.h:320
static const std::array< const char *, UpdateType::LENGTH > UpdateTypeStr
Definition: MessageTypes.h:325
Sent when then obstruction of an entity has changed in a manner that changes 'block movement' propert...
Definition: MessageTypes.h:387
Sent when ObstructionManager's view of the shape of the world has changed (changing the TILE_OUTOFBOU...
Definition: MessageTypes.h:401
Definition: MessageTypes.h:252
player_id_t to
Definition: MessageTypes.h:263
entity_id_t entity
Definition: MessageTypes.h:261
player_id_t from
Definition: MessageTypes.h:262
Sent by CCmpPathfinder after async path requests.
Definition: MessageTypes.h:470
WaypointPath path
Definition: MessageTypes.h:480
std::uint32_t ticket
Definition: MessageTypes.h:479
Sent by atlas if the playercolor has been changed.
Definition: MessageTypes.h:507
player_id_t player
Definition: MessageTypes.h:516
Sent by the Player component when an specific player has been defeated.
Definition: MessageTypes.h:539
player_id_t playerId
Definition: MessageTypes.h:548
Sent by the Player component when a specific player has won.
Definition: MessageTypes.h:523
player_id_t playerId
Definition: MessageTypes.h:532
Sent by CCmpPosition whenever anything has changed that will affect the return value of GetPosition2D...
Definition: MessageTypes.h:274
bool inWorld
Definition: MessageTypes.h:284
entity_id_t entity
Definition: MessageTypes.h:283
entity_pos_t x
Definition: MessageTypes.h:285
entity_angle_t a
Definition: MessageTypes.h:286
entity_pos_t z
Definition: MessageTypes.h:285
Handle progressive loading of resources.
Definition: MessageTypes.h:181
int * progress
Definition: MessageTypes.h:192
bool * progressed
Definition: MessageTypes.h:190
int * total
Definition: MessageTypes.h:191
Sent by CCmpRangeManager at most once per turn, when an active range query has had matching units ent...
Definition: MessageTypes.h:428
CMessageRangeUpdate(std::uint32_t tag)
Definition: MessageTypes.h:446
CMessageRangeUpdate & operator=(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:457
std::vector< entity_id_t > removed
Definition: MessageTypes.h:436
std::uint32_t tag
Definition: MessageTypes.h:434
CMessageRangeUpdate(const CMessageRangeUpdate &other)
Definition: MessageTypes.h:453
std::vector< entity_id_t > added
Definition: MessageTypes.h:435
CMessageRangeUpdate(std::uint32_t tag, const std::vector< entity_id_t > &added, const std::vector< entity_id_t > &removed)
Definition: MessageTypes.h:449
Add renderable objects to the scene collector.
Definition: MessageTypes.h:155
bool culling
Definition: MessageTypes.h:166
SceneCollector & collector
Definition: MessageTypes.h:164
const CFrustum & frustum
Definition: MessageTypes.h:165
Sent by aura and tech managers when a value of a certain template's component is changed.
Definition: MessageTypes.h:555
std::vector< std::wstring > valueNames
Definition: MessageTypes.h:568
std::wstring component
Definition: MessageTypes.h:567
player_id_t player
Definition: MessageTypes.h:566
Sent when terrain (texture or elevation) has been changed.
Definition: MessageTypes.h:351
int32_t i1
Definition: MessageTypes.h:360
int32_t j0
Definition: MessageTypes.h:360
int32_t i0
Definition: MessageTypes.h:360
int32_t j1
Definition: MessageTypes.h:360
Sent when territory assignments have changed.
Definition: MessageTypes.h:414
Definition: MessageTypes.h:50
Final update phase, after all other updates.
Definition: MessageTypes.h:116
fixed turnLength
Definition: MessageTypes.h:125
Update phase for formation controller movement (must happen before individual units move to follow th...
Definition: MessageTypes.h:84
fixed turnLength
Definition: MessageTypes.h:93
Update phase for non-formation-controller unit movement.
Definition: MessageTypes.h:100
fixed turnLength
Definition: MessageTypes.h:109
Generic per-turn update message, for things that don't care much about ordering.
Definition: MessageTypes.h:67
fixed turnLength
Definition: MessageTypes.h:76
Sent by aura manager when a value of a certain entity's component is changed.
Definition: MessageTypes.h:487
std::vector< entity_id_t > entities
Definition: MessageTypes.h:498
std::vector< std::wstring > valueNames
Definition: MessageTypes.h:500
std::wstring component
Definition: MessageTypes.h:499
Sent, at most once per turn, when the visibility of an entity changed.
Definition: MessageTypes.h:367
int oldVisibility
Definition: MessageTypes.h:378
player_id_t player
Definition: MessageTypes.h:376
entity_id_t ent
Definition: MessageTypes.h:377
int newVisibility
Definition: MessageTypes.h:379
Sent by CCmpVision when an entity's vision range changes.
Definition: MessageTypes.h:575
entity_pos_t oldRange
Definition: MessageTypes.h:585
entity_pos_t newRange
Definition: MessageTypes.h:586
entity_id_t entity
Definition: MessageTypes.h:584
Sent by CCmpVision when an entity's vision sharing changes.
Definition: MessageTypes.h:593
player_id_t player
Definition: MessageTypes.h:603
entity_id_t entity
Definition: MessageTypes.h:602
bool add
Definition: MessageTypes.h:604
Sent when water height has been changed.
Definition: MessageTypes.h:338
Definition: Message.h:31
Definition: Vector3D.h:32
This interface accepts renderable objects.
Definition: Scene.h:90
static int ProgressiveLoad()
Definition: main.cpp:290
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32
Definition: ShaderDefines.cpp:43
std::uint32_t entity_id_t
Entity ID type.
Definition: Entity.h:29
Definition: ICmpPathfinder.h:40
Returned path.
Definition: Pathfinding.h:69