Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
App.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <memory>
5
6#include "../audio/IAudioManager.hpp"
7#include "Args.hpp"
8#include "EventQueue.hpp"
9#include "GameState.hpp"
10#include "network/TcpSocket.hpp"
11
17class App {
18 public:
19 App(int argc, char** argv);
20
25 bool shouldRun() const;
26
31 int exitCode() const;
32
37 void run();
38
39 protected: // <- Protected for testing purposes, acts as private in practice
42 bool _rendererActive = false;
43
49 void pollAndEnqueue(TcpSocket& socket, EventQueue& queue);
50
52 bool _connectWithRetry(TcpSocket& socket, const std::string& host, int port);
53
55 void _trySendStu(TcpSocket& socket);
56
58 void _resetStuState();
59
60 std::chrono::steady_clock::time_point _lastStuSent{};
62 bool _stuSilenced = false;
63
64 std::unique_ptr<IAudioManager> _audioManager;
65};
The main application class that manages the game state, network communication, and rendering....
Definition App.hpp:17
bool _connectWithRetry(TcpSocket &socket, const std::string &host, int port)
Attempts to connect with exponential backoff. Returns true on success.
Definition App.cpp:134
std::unique_ptr< IAudioManager > _audioManager
Definition App.hpp:64
std::chrono::steady_clock::time_point _lastStuSent
Definition App.hpp:60
void _trySendStu(TcpSocket &socket)
Sends stu once per real second and silences it after 3 consecutive non-responses.
Definition App.cpp:105
bool shouldRun() const
Checks if the application should run based on the parsed arguments.
Definition App.cpp:24
bool _stuSilenced
Definition App.hpp:62
GameState state
Definition App.hpp:41
int exitCode() const
Gets the exit code to return if the application should not run.
Definition App.cpp:26
void _resetStuState()
Resets stu polling state, called on reconnect.
Definition App.cpp:127
void pollAndEnqueue(TcpSocket &socket, EventQueue &queue)
Polls the socket for new data and enqueues any received events.
Definition App.cpp:95
Args args
Definition App.hpp:40
bool _rendererActive
Definition App.hpp:42
void run()
Runs the application.
Definition App.cpp:28
int _stuMissedResponses
Definition App.hpp:61
Thread-safe queue for storing events received from the server. Allows for potential multi-threaded be...
Represents the current state of the game. Knows the world state, some metadata, and how to apply even...
Definition GameState.hpp:15
Simple TCP socket wrapper.
Definition TcpSocket.hpp:22