R-Type 0.1
Loading...
Searching...
No Matches
game.hpp
1#pragma once
2
3#include "GameEngine.hpp"
4#include "collision/collisionBuffer.hpp"
5#include "inputAction/InputAction.hpp"
6#include "inputAction/inputMapping.hpp"
7
8#include "factoryDataDriven/factoryDataDriven.hpp"
9#include "sceneManager/sceneManager.hpp"
10#include <array>
11#include <unordered_set>
12
13#include "rtkAudiManagerAdapter.hpp"
14#include "rtkWindowAdapter.hpp"
15
16#include "NetworkClient.hpp"
17#include "scene/gameScene.hpp"
18#include "scene/menuScene.hpp"
19#include "scene/networkConnectionScene.hpp"
20
21namespace rtype::events {
30struct PlayerShotEvent {};
31
33} // namespace rtype::events
34
35namespace rtype::client {
45class Game {
46public:
50 Game();
51 ~Game() = default;
52
58 void onLoad(rtk::EngineContext &context);
59
64 bool shouldContinue() const;
65
72 void onUpdate(rtk::EngineContext &context, float dt);
73
79 void onUnload(rtk::EngineContext &context);
80
81private:
82 void registerBuilders(rtk::EngineContext &context);
83 void registerComponents(rtk::EngineContext &context);
84 void createBindings();
85 void subscribeEvents(rtk::EngineContext &context, uint32_t shootSoundId);
86 void addSystems(rtk::EngineContext &context);
87 void loadEntityBluePrint(rtk::EngineContext &context);
88 void handleReplication(rtk::EngineContext &context);
89 void createReplicatedEntity(rtk::EngineContext &context,
90 const protocol::CreateEntityPayload &payload);
91 void destroyReplicatedEntity(rtk::EngineContext &context,
92 const protocol::DestroyEntityPayload &payload);
93 void applySnapshot(rtk::EngineContext &context,
94 const protocol::SnapshotPayload &payload);
95
96 std::unordered_map<protocol::NetworkEntityId, std::size_t> _networkEntities;
97 std::unordered_set<std::uint32_t> _pendingEntityQueries;
98 std::unordered_set<std::uint32_t> _destroyedEntities;
99 std::array<std::uint16_t, 4> _playerArchetypes{};
100 std::uint32_t _lastServerTick = 0;
101 rtk::RenderWindow _window;
102 RtkWindowAdapter _adapter;
103 RtkAudioAdapter _adapterAudioManager;
104 rtk::InputState _inputState{};
105 rtk::collision::CollisionBuffer _collisionBuffer;
106 rtk::Input::InputMapping _inputMapping;
107 rtype::client::NetworkClient _networkClient;
108
109 rtk::SceneManager<SceneType, rtk::RenderWindow, rtk::InputState, MenuScene,
110 NetworkConnectionScene, GameScene>
111 _sceneManager;
112};
113
115} // namespace rtype::client
Adapts the window of the graphical library to the IsRenderWindow concept.
Definition rtkWindowAdapter.hpp:20
Table binding up to four physical controls to each of 32 actions.
Definition inputMapping.hpp:54
Holds the active scene and switches between a fixed set of scenes.
Definition sceneManager.hpp:32
Collisions detected during the current frame.
Definition collisionBuffer.hpp:24
bool shouldContinue() const
Tells the engine whether to keep running.
Definition game.cpp:301
void onLoad(rtk::EngineContext &context)
Registers components, loads blueprints, binds inputs, adds the systems and starts the network client.
Definition game.cpp:56
void onUnload(rtk::EngineContext &context)
Destroys replicated entities, exits the scene and stops the network client.
Definition game.cpp:440
void onUpdate(rtk::EngineContext &context, float dt)
Applies network events and replication messages, then updates the active scene.
Definition game.cpp:303
Game()
Opens the 1280x720 window and creates the menu scene.
Definition game.cpp:53
UDP client that performs the handshake, sends inputs and decodes server messages.
Definition NetworkClient.hpp:71
SceneType
Identifiers of the client scenes.
Definition sceneType.hpp:12
Engine services handed to the game and its scenes.
Definition EngineContext.hpp:20
Player input sampled during the current frame.
Definition InputAction.hpp:14