Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
Game.h
1#ifndef _BOMBERMAN_GAME_H_
2#define _BOMBERMAN_GAME_H_
3
4#include <SDL.h>
5#include <chrono>
6#include <memory>
7
8#include "Managers/AssetManager.h"
9#include "Managers/SceneManager.h"
10#include "Net/NetCommon.h"
11
12namespace bomberman
13{
14 namespace net { class NetClient; }
15
17 {
18 bool predictionEnabled = true;
19 bool remoteSmoothingEnabled = true;
20 };
21
22 class Game
23 {
24 public:
36 Game(const std::string& windowName, int windowWidth, int windowHeight,
37 net::NetClient* inNetClient = nullptr, uint16_t serverPort = net::kDefaultServerPort, bool mute = false,
38 MultiplayerClientConfig multiplayerConfig = {});
39
41 ~Game();
42
44 void run();
45
47 void stop();
48
50 [[nodiscard]]
51 int getWindowWidth() const;
52
54 [[nodiscard]]
55 int getWindowHeight() const;
56
58 [[nodiscard]]
59 SDL_Renderer* getRenderer() const;
60
62 [[nodiscard]]
64
66 [[nodiscard]]
68
70 [[nodiscard]]
72
78 [[nodiscard]]
80
82 [[nodiscard]]
83 uint16_t getServerPort() const;
84
86 [[nodiscard]]
88
90 [[nodiscard]]
91 bool isPredictionEnabled() const;
92
94 [[nodiscard]]
95 bool isRemoteSmoothingEnabled() const;
96
99
101 void disconnectNetClientIfActive(bool blockUntilComplete = true);
102
103 private:
104 // SDL pointers.
105 SDL_Window* window = nullptr;
106 SDL_Renderer* renderer = nullptr;
107
108 std::unique_ptr<SceneManager> sceneManager = nullptr;
109 std::unique_ptr<AssetManager> assetManager = nullptr;
110
111 // Screen parameters.
112 int windowWidth = 0;
113 int windowHeight = 0;
114
115 bool isRunning = false;
116 bool isInitialized = false;
117 std::chrono::steady_clock::time_point lastTickTime{};
118 std::chrono::duration<double> accumulator{};
119
120 net::NetClient* netClient_ = nullptr;
121 uint16_t serverPort_ = net::kDefaultServerPort;
122 bool mute_ = false;
123 bool hasKeyboardFocus_ = true;
124 bool renderVsyncEnabled_ = true;
125 MultiplayerClientConfig multiplayerConfig_{};
126 bool suppressBombInputUntilRelease_ = false;
127
128
130 void handleWindowFocusChanged(bool hasFocus);
131
133 void pollNetInput();
134 };
135} // namespace bomberman
136
137#endif // _BOMBERMAN_GAME_H_
Shared client/server wire contract for the multiplayer protocol.
Asset Manager.
Definition AssetManager.h:73
Definition Game.h:23
bool tryGetLatestSnapshot(net::MsgSnapshot &out) const
Fills out with the most recent server snapshot and returns true.
Definition Game.cpp:392
void suppressBombInputUntilReleased()
Suppresses bomb input until the space key is released once.
Definition Game.cpp:313
int getWindowWidth() const
Returns current window width in pixels.
Definition Game.cpp:362
SceneManager * getSceneManager() const
Returns the scene manager.
Definition Game.cpp:377
bool isRemoteSmoothingEnabled() const
Returns true when remote smoothing/interpolation is enabled.
Definition Game.cpp:414
void disconnectNetClientIfActive(bool blockUntilComplete=true)
Disconnects the multiplayer client if one is active.
Definition Game.cpp:335
void run()
Runs the main loop until stop() is requested.
Definition Game.cpp:142
void stop()
Requests the main loop to stop.
Definition Game.cpp:330
net::NetClient * getNetClient() const
Returns the network client, or nullptr if not in multiplayer mode.
Definition Game.cpp:387
uint16_t getServerPort() const
Returns the server port (from CLI or default).
Definition Game.cpp:399
AssetManager * getAssetManager() const
Returns the asset manager.
Definition Game.cpp:382
SDL_Renderer * getRenderer() const
Returns the SDL renderer.
Definition Game.cpp:372
~Game()
Releases runtime resources and shuts down SDL subsystems.
Definition Game.cpp:121
bool isPredictionEnabled() const
Returns true when local multiplayer prediction is enabled.
Definition Game.cpp:409
int getWindowHeight() const
Returns current window height in pixels.
Definition Game.cpp:367
const MultiplayerClientConfig & getMultiplayerClientConfig() const
Returns the multiplayer client configuration used for this run.
Definition Game.cpp:404
Scene Manager.
Definition SceneManager.h:18
ENet client connection and protocol endpoint.
Definition NetClient.h:75
constexpr uint16_t kDefaultServerPort
Default server port used by both client and server.
Definition NetCommon.h:43
Snapshot payload broadcast by the server to all clients.
Definition NetCommon.h:673