R-Type  2
Doom but in better
Loading...
Searching...
No Matches
SyncingSystem.cpp
Go to the documentation of this file.
1#include "SyncingSystem.hpp"
2#include "Registry.hpp"
3#include "Components.hpp"
4#include "IndexedZipper.hpp"
5
6std::vector<GameMessage> syncGameState(Registry &r)
7{
8 std::vector<GameMessage> state;
9 auto &&[positions, types, teams] = r.get_component_array<Position, Type, Team>();
10 for (auto &&[idx, pos, type] : IndexedZipper(positions, types)) {
11 // if killed or not created continue
12 if (!pos || !type) continue;
13
14 // need to spawn
15 GameMessage msg;
16 msg.type = P_SPAWN;
17 msg.id = idx;
18
19 // get position
20 msg.msg.coords.x = pos->X;
21 msg.msg.coords.y = pos->Y;
22
23 // check type and assign asseet
24 if (type->type == PLAYER) {
26 } else if (type->type == MONSTER) {
28 } else {
29 if (teams[idx]->team == ENEMY)
31 else
33 }
34
35 // done
36 state.push_back(msg);
37 }
38 return state;
39}
@ P_SPAWN
Represents a spawn event.
@ PLAYER_MISSILE_ASSET
Definition Image.hpp:14
@ PLAYER_ASSET
Definition Image.hpp:11
@ MONSTER_MISSILE_ASSET
Definition Image.hpp:13
@ MONSTER1_ASSET
Definition Image.hpp:12
std::vector< GameMessage > syncGameState(Registry &r)
Creates the.
@ ENEMY
Definition Team.hpp:12
Registry * r
Definition Tests.cpp:4
@ PLAYER
Definition Type.hpp:12
@ MONSTER
Definition Type.hpp:13
Combines multiple containers into a single iterable unit, iterating over corresponding elements from ...
Manages entities and their associated components, enabling the creation, deletion,...
Definition Registry.hpp:23
std::tuple< ComponentContainer< Components > &... > get_component_array()
Retrieves component containers for multiple component types.
Definition Registry.hpp:110
A structure representing a game message.
messageType type
The type of message (e.g., SPAWN, MOVE, etc.).
messageInfo msg
Additional information about the event (status, asset ID, and coordinates).
std::size_t id
The unique identifier for the entity or object involved in the event.
Represents the position of an entity in a 2D space.
Definition Position.hpp:10
Represents the team affiliation of an entity.
Definition Team.hpp:22
Represents the type of an entity in the game.
Definition Type.hpp:26
float x
The X coordinate.
float y
The Y coordinate.
coord coords
Coordinates associated with the event, such as the position of an entity.
int asset_id
ID representing the game asset related to the event (e.g., entity or object).