Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
App Class Reference

The main application class that manages the game state, network communication, and rendering. It parses command-line arguments, connects to the game server, receives events, updates the game state, and renders the game using a renderer. More...

#include <App.hpp>

+ Collaboration diagram for App:

Public Member Functions

 App (int argc, char **argv)
 
bool shouldRun () const
 Checks if the application should run based on the parsed arguments.
 
int exitCode () const
 Gets the exit code to return if the application should not run.
 
void run ()
 Runs the application.
 

Protected Member Functions

void pollAndEnqueue (TcpSocket &socket, EventQueue &queue)
 Polls the socket for new data and enqueues any received events.
 
bool _connectWithRetry (TcpSocket &socket, const std::string &host, int port)
 Attempts to connect with exponential backoff. Returns true on success.
 
void _trySendStu (TcpSocket &socket)
 Sends stu once per real second and silences it after 3 consecutive non-responses.
 
void _resetStuState ()
 Resets stu polling state, called on reconnect.
 

Protected Attributes

Args args
 
GameState state
 
bool _rendererActive = false
 
std::chrono::steady_clock::time_point _lastStuSent {}
 
int _stuMissedResponses = 0
 
bool _stuSilenced = false
 
std::unique_ptr< IAudioManager_audioManager
 

Detailed Description

The main application class that manages the game state, network communication, and rendering. It parses command-line arguments, connects to the game server, receives events, updates the game state, and renders the game using a renderer.

Definition at line 17 of file App.hpp.

Constructor & Destructor Documentation

◆ App()

App::App ( int  argc,
char **  argv 
)

Definition at line 22 of file App.cpp.

Member Function Documentation

◆ _connectWithRetry()

bool App::_connectWithRetry ( TcpSocket socket,
const std::string &  host,
int  port 
)
protected

Attempts to connect with exponential backoff. Returns true on success.

Definition at line 134 of file App.cpp.

References TcpSocket::connect(), g_interrupted, MAX_RETRIES, TcpSocket::send(), and TcpException::what().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _resetStuState()

void App::_resetStuState ( )
protected

Resets stu polling state, called on reconnect.

Definition at line 127 of file App.cpp.

References _lastStuSent, _stuMissedResponses, and _stuSilenced.

Referenced by run().

+ Here is the caller graph for this function:

◆ _trySendStu()

void App::_trySendStu ( TcpSocket socket)
protected

Sends stu once per real second and silences it after 3 consecutive non-responses.

Definition at line 105 of file App.cpp.

References _lastStuSent, _stuMissedResponses, _stuSilenced, GameState::receivedStuResponse, TcpSocket::send(), and state.

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exitCode()

int App::exitCode ( ) const

Gets the exit code to return if the application should not run.

Returns
The exit code to return.

Definition at line 26 of file App.cpp.

References args, and Args::exitCode().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pollAndEnqueue()

void App::pollAndEnqueue ( TcpSocket socket,
EventQueue queue 
)
protected

Polls the socket for new data and enqueues any received events.

Parameters
socketThe TCP socket to poll.
queueThe event queue to enqueue events into.

Definition at line 95 of file App.cpp.

References ProtocolParser::parse(), TcpSocket::poll(), EventQueue::push(), and TcpSocket::recvLine().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void App::run ( )

Runs the application.

Note
Should only be called if shouldRun() returns true.

Definition at line 28 of file App.cpp.

References _audioManager, _connectWithRetry(), _rendererActive, _resetStuState(), _trySendStu(), GameState::applyEvent(), args, EventQueue::clear(), AppConfig::dev, g_interrupted, Args::getConfig(), IRenderer::getPendingSpeedChange(), IRenderer::handleInput(), AppConfig::headless, IRenderer::init(), AppConfig::language, AppConfig::machine, pollAndEnqueue(), EventQueue::pop(), AppConfig::port, IRenderer::render(), IRenderer::setDevMode(), I18n::setLanguage(), IRenderer::setState(), IRenderer::shouldClose(), IRenderer::shutdown(), state, and TcpException::what().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shouldRun()

bool App::shouldRun ( ) const

Checks if the application should run based on the parsed arguments.

Returns
true if the application should run, false otherwise.

Definition at line 24 of file App.cpp.

References args, and Args::isValid().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _audioManager

std::unique_ptr<IAudioManager> App::_audioManager
protected

Definition at line 64 of file App.hpp.

Referenced by run().

◆ _lastStuSent

std::chrono::steady_clock::time_point App::_lastStuSent {}
protected

Definition at line 60 of file App.hpp.

Referenced by _resetStuState(), and _trySendStu().

◆ _rendererActive

bool App::_rendererActive = false
protected

Definition at line 42 of file App.hpp.

Referenced by run().

◆ _stuMissedResponses

int App::_stuMissedResponses = 0
protected

Definition at line 61 of file App.hpp.

Referenced by _resetStuState(), and _trySendStu().

◆ _stuSilenced

bool App::_stuSilenced = false
protected

Definition at line 62 of file App.hpp.

Referenced by _resetStuState(), and _trySendStu().

◆ args

Args App::args
protected

Definition at line 40 of file App.hpp.

Referenced by exitCode(), run(), and shouldRun().

◆ state

GameState App::state
protected

Definition at line 41 of file App.hpp.

Referenced by _trySendStu(), and run().


The documentation for this class was generated from the following files: