R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Rendering Class Reference

Graphical rendering system using Raylib. More...

#include <Rendering.hpp>

Collaboration diagram for Rendering:
Collaboration graph

Public Member Functions

 Rendering (EventBus &eventBus)
 Constructor with EventBus reference.
 
 ~Rendering ()
 Destructor.
 
bool Initialize (uint32_t width, uint32_t height, const std::string &title)
 Initialize the rendering system and create window.
 
void Shutdown ()
 Stop the rendering system and destroy window.
 
void ClearWindow ()
 Clears the window before rendering its content.
 
void Render ()
 Perform rendering of current frame.
 
bool IsWindowOpen () const
 Check if window is open.
 
void StartGame ()
 Switch immediately to the game scene.
 
bool LoadTexture (const std::string &textureName, const std::string &path)
 Load a texture from file.
 
void DrawSprite (const std::string &textureId, float xPosition, float yPosition, float rotation=0.0, float scale=1.0)
 Draw a sprite on screen.
 
void DrawText (const std::string &text, float xPosition, float yPosition, uint32_t size=24)
 Draw text on screen.
 
uint32_t GetWidth () const
 Get window width.
 
uint32_t GetHeight () const
 Get window height.
 
bool WindowShouldClose () const
 
void UpdateEntity (uint32_t id, RType::Messages::Shared::EntityType type, float x, float y, int health, const std::string &currentAnimation, int srcX, int srcY, int srcW, int srcH)
 Update or create an entity for rendering with animation.
 
void RemoveEntity (uint32_t id)
 Remove an entity from rendering.
 
void SetMyEntityId (uint32_t id)
 Set the local player's entity ID.
 
void ClearAllEntities ()
 Clear all entities from the rendering cache.
 
void SetBackground (const std::string &mainBackground, const std::string &parallaxBackground, float scrollSpeed, float parallaxSpeedFactor)
 Set up background layers for parallax scrolling.
 
void ClearBackground ()
 Clear background configuration.
 
void UpdateBackground (float deltaTime)
 Update background scroll positions.
 
void ShowGameOver (const std::string &reason)
 Display the game over screen.
 
bool IsKeyDown (int key) const
 Check if a key is currently being held down.
 
bool IsGamepadAvailable (int gamepad) const
 Check if a gamepad is available/connected.
 
bool IsGamepadButtonDown (int gamepad, int button) const
 Check if a gamepad button is currently held down.
 
void UpdateInterpolation (float deltaTime)
 Update interpolation for all entities.
 
void UpdatePingTimer (float deltaTime)
 Update ping display timer (called every frame)
 
void MoveEntityLocally (uint32_t entityId, float deltaX, float deltaY)
 Move an entity locally (client-side prediction)
 
void UpdateRoomList (const std::vector< RoomData > &rooms)
 Update room list from server data.
 
void UpdateWaitingRoom (const std::vector< Game::PlayerInfo > &players, const std::string &roomName, bool isHost, bool isSpectator=false)
 Update waiting room with player list.
 
void AddChatMessage (uint32_t playerId, const std::string &playerName, const std::string &message, uint64_t timestamp)
 Add a chat message to the chat widget.
 
void SetOnChatMessageSent (std::function< void(const std::string &)> callback)
 Set callback for when a chat message is sent.
 
void UpdateChatVisibility ()
 Update chat widget visibility based on current scene.
 
void SetClientSidePredictionEnabled (bool enabled)
 Enable or disable client-side prediction for local player.
 
void SetReconciliationThreshold (float threshold)
 Set the reconciliation threshold for client-side prediction.
 
float GetReconciliationThreshold () const
 Get the current reconciliation threshold.
 
void SetLocalPlayerMoving (bool moving)
 Set whether the local player is currently moving.
 
void SetPing (uint32_t pingMs)
 Set the current ping value for display.
 
void SetShowPing (bool enabled)
 Enable/disable ping display.
 
bool GetShowPing () const
 Get ping display state.
 
void SetShowFps (bool enabled)
 Enable/disable FPS display.
 
bool GetShowFps () const
 Get FPS display state.
 
void SetPlayerName (const std::string &name)
 Update the displayed player name (e.g., after authentication)
 

Private Types

enum class  Scene { MENU , IN_GAME , GAME_OVER }
 

Private Member Functions

void InitializeMenus ()
 Initialize UI factory, menus and all related callbacks.
 
void ApplyInitialMenuSettings ()
 Apply runtime settings affecting rendering (target FPS, HUD visibility...).
 
void InitializeConfirmQuitMenu ()
 
void InitializeSettingsMenu ()
 
void InitializeAccessibilityMenu ()
 
void InitializeKeyBindingsMenu ()
 
void InitializeMainMenu ()
 
void InitializeLoginMenu ()
 
void InitializeServerListMenu ()
 
void InitializeAddServerMenu ()
 
void InitializeRoomListMenu ()
 
void InitializeCreateRoomMenu ()
 
void InitializeWaitingRoomMenu ()
 
void InitializeDefeatMenu ()
 
void InitializeVictoryMenu ()
 
void InitializeConnectionMenu ()
 
void InitializeChatWidget ()
 
void SubscribeToConnectionEvents ()
 
void LoadAccessibilitySettings ()
 
void SaveAccessibilitySettings ()
 
void UpdateFpsCounter ()
 Update FPS counter based on delta time.
 
void HandleEscapeKeyInput ()
 Handle ESC key input to toggle settings overlay in-game.
 
void UpdateUI ()
 Update all UI elements based on current scene.
 
void RenderGameScene ()
 Render the game scene (entities).
 
void RenderUI ()
 Render all UI menus based on current scene and overlay state.
 
void RenderHUD ()
 Render HUD elements (ping, FPS).
 

Private Attributes

Scene _scene = Scene::MENU
 
std::string _gameOverReason
 
EventBus_eventBus
 
bool _initialized = false
 
bool _quitRequested = false
 
uint32_t _width = 0
 
uint32_t _height = 0
 
Graphics::RaylibGraphics _graphics
 
std::unique_ptr< Audio::SoundEffectManager_soundEffectManager
 
std::unique_ptr< UI::RaylibUIFactory_uiFactory
 
std::unique_ptr< Game::MainMenu_mainMenu
 
std::unique_ptr< Game::ServerListMenu_serverListMenu
 
std::unique_ptr< Game::AddServerMenu_addServerMenu
 
std::unique_ptr< Game::RoomListMenu_roomListMenu
 
std::unique_ptr< Game::CreateRoomMenu_createRoomMenu
 
std::unique_ptr< Game::WaitingRoomMenu_waitingRoomMenu
 
std::unique_ptr< Game::ConnectionMenu_connectionMenu
 
std::unique_ptr< Game::SettingsMenu_settingsMenu
 
std::unique_ptr< Game::AccessibilityMenu_accessibilityMenu
 
std::unique_ptr< Game::KeyBindingsMenu_keyBindingsMenu
 
std::unique_ptr< Game::ConfirmQuitMenu_confirmQuitMenu
 
std::unique_ptr< Game::LoginMenu_loginMenu
 
std::unique_ptr< Game::DefeatMenu_defeatMenu
 
std::unique_ptr< Game::VictoryMenu_victoryMenu
 
bool _settingsOverlay = false
 
bool _confirmQuitOverlay = false
 
bool _loginOverlay = false
 
bool _keyBindingsOverlay = false
 
std::string _selectedServerIp = "127.0.0.1"
 
uint16_t _selectedServerPort = 4242
 
bool _isConnecting = false
 
std::string _connectingServerName
 
std::string _selectedRoomId
 
std::unique_ptr< EntityRenderer_entityRenderer
 
std::unique_ptr< Game::ChatWidget_chatWidget
 
uint32_t _currentPing = 0
 
uint32_t _displayedPing = 0
 
float _pingUpdateTimer = 0.0f
 
bool _showPing = true
 
bool _showFps = true
 
uint32_t _fps = 0
 
float _fpsAccumulator = 0.0f
 
uint32_t _fpsFrameCount = 0
 

Static Private Attributes

static constexpr float PING_UPDATE_INTERVAL = 1.0f
 

Detailed Description

Graphical rendering system using Raylib.

Rendering handles the display of all visual game elements:

  • Game window
  • Sprites (ships, enemies, projectiles)
  • Text (UI, score, FPS)
  • Visual effects

Architecture:

  • Uses Raylib for 2D rendering
  • Caches textures for optimization
  • Handles double-buffering automatically
  • Integrates with EventBus for visual events

Definition at line 62 of file Rendering.hpp.

Member Enumeration Documentation

◆ Scene

enum class Rendering::Scene
strongprivate
Enumerator
MENU 
IN_GAME 
GAME_OVER 

Definition at line 469 of file Rendering.hpp.

Constructor & Destructor Documentation

◆ Rendering()

Rendering::Rendering ( EventBus eventBus)
explicit

Constructor with EventBus reference.

Parameters
eventBusEvent bus for inter-component communication
Note
Does not create the window, call initialize() after

Definition at line 15 of file Rendering.cpp.

References _entityRenderer, and _graphics.

◆ ~Rendering()

Rendering::~Rendering ( )

Destructor.

Frees Raylib wrapper resources (textures, window, etc.)

Definition at line 21 of file Rendering.cpp.

References Shutdown().

Here is the call graph for this function:

Member Function Documentation

◆ AddChatMessage()

void Rendering::AddChatMessage ( uint32_t  playerId,
const std::string &  playerName,
const std::string &  message,
uint64_t  timestamp 
)

Add a chat message to the chat widget.

Parameters
playerIdID of the player who sent the message
playerNameName of the player
messageThe message text
timestampMessage timestamp

Definition at line 1344 of file Rendering.cpp.

References _chatWidget.

◆ ApplyInitialMenuSettings()

void Rendering::ApplyInitialMenuSettings ( )
private

Apply runtime settings affecting rendering (target FPS, HUD visibility...).

Definition at line 89 of file Rendering.cpp.

References _graphics, _settingsMenu, _showFps, _showPing, and Graphics::RaylibGraphics::SetTargetFPS().

Referenced by Initialize().

Here is the call graph for this function:

◆ ClearAllEntities()

void Rendering::ClearAllEntities ( )

Clear all entities from the rendering cache.

Useful for scene transitions or disconnection.

Definition at line 1207 of file Rendering.cpp.

References _entityRenderer.

◆ ClearBackground()

void Rendering::ClearBackground ( )

Clear background configuration.

Called when leaving the game scene to stop background rendering.

Definition at line 1220 of file Rendering.cpp.

References _entityRenderer.

◆ ClearWindow()

void Rendering::ClearWindow ( )

Clears the window before rendering its content.

Note
Must be called at the beginning of each frame before drawing.

Definition at line 715 of file Rendering.cpp.

References _graphics, _initialized, and Graphics::RaylibGraphics::ClearWindow().

Here is the call graph for this function:

◆ DrawSprite()

void Rendering::DrawSprite ( const std::string &  textureId,
float  xPosition,
float  yPosition,
float  rotation = 0.0,
float  scale = 1.0 
)

Draw a sprite on screen.

Adds a sprite to the render queue for current frame.

Parameters
textureIdTexture identifier (loaded with loadTexture)
xX position on screen (0 = left)
yY position on screen (0 = top)
rotationRotation in degrees (0-360)
scaleScale (1.0 = original size, 2.0 = double)
Note
Sprite is centered on (x, y)
Call order determines render order (Z-order)
Uses Raylib wrapper's sprite rendering (pending implementation)

Definition at line 1158 of file Rendering.cpp.

References _graphics, and Graphics::RaylibGraphics::DrawTextureEx().

Here is the call graph for this function:

◆ DrawText()

void Rendering::DrawText ( const std::string &  text,
float  xPosition,
float  yPosition,
uint32_t  size = 24 
)

Draw text on screen.

Displays text with default font.

Parameters
textText to display (UTF-8 supported)
xX position (origin at top-left of text)
yY position (origin at top-left of text)
sizeFont size in pixels (default: 24)
Note
Uses default font loaded at initialization
Rendered on top of sprites (UI)
Font rendering via Raylib wrapper (not yet implemented)

Definition at line 1163 of file Rendering.cpp.

References _graphics, and Graphics::RaylibGraphics::DrawText().

Here is the call graph for this function:

◆ GetHeight()

uint32_t Rendering::GetHeight ( ) const

Get window height.

Returns
Height in pixels

Definition at line 1172 of file Rendering.cpp.

References _height.

◆ GetReconciliationThreshold()

float Rendering::GetReconciliationThreshold ( ) const

Get the current reconciliation threshold.

Returns
Current threshold in pixels

Delegates to EntityRenderer.

Definition at line 1278 of file Rendering.cpp.

References _entityRenderer.

◆ GetShowFps()

bool Rendering::GetShowFps ( ) const

Get FPS display state.

Definition at line 736 of file Rendering.cpp.

References _showFps.

◆ GetShowPing()

bool Rendering::GetShowPing ( ) const

Get ping display state.

Definition at line 728 of file Rendering.cpp.

References _showPing.

◆ GetWidth()

uint32_t Rendering::GetWidth ( ) const

Get window width.

Returns
Width in pixels

Definition at line 1168 of file Rendering.cpp.

References _width.

◆ HandleEscapeKeyInput()

void Rendering::HandleEscapeKeyInput ( )
private

Handle ESC key input to toggle settings overlay in-game.

Definition at line 856 of file Rendering.cpp.

References _graphics, _scene, _settingsMenu, _settingsOverlay, Input::KeyBindings::getInstance(), IN_GAME, Graphics::RaylibGraphics::IsKeyPressed(), Game::SettingsMenu::OVERLAY, and Input::PAUSE_MENU.

Referenced by Render().

Here is the call graph for this function:

◆ Initialize()

bool Rendering::Initialize ( uint32_t  width,
uint32_t  height,
const std::string &  title 
)

Initialize the rendering system and create window.

Creates a window through Raylib wrapper with specified parameters. Loads basic resources (fonts, shaders).

Parameters
widthWindow width in pixels
heightWindow height in pixels
titleWindow title
Returns
true if initialization succeeds, false otherwise
Note
Must be called before any other rendering call
Recommended: 1920x1080 for R-Type
Depends on Raylib wrapper implementation (not yet available)

Definition at line 25 of file Rendering.cpp.

References _entityRenderer, _fps, _fpsAccumulator, _fpsFrameCount, _graphics, _height, _initialized, _quitRequested, _showFps, _showPing, _width, ApplyInitialMenuSettings(), InitializeMenus(), Graphics::RaylibGraphics::InitWindow(), LOG_INFO, and LOG_WARNING.

Here is the call graph for this function:

◆ InitializeAccessibilityMenu()

◆ InitializeAddServerMenu()

void Rendering::InitializeAddServerMenu ( )
private

◆ InitializeChatWidget()

void Rendering::InitializeChatWidget ( )
private

Definition at line 1326 of file Rendering.cpp.

References _chatWidget, _graphics, _height, _uiFactory, _width, LOG_ERROR, and LOG_INFO.

Referenced by InitializeMenus().

◆ InitializeConfirmQuitMenu()

void Rendering::InitializeConfirmQuitMenu ( )
private

◆ InitializeConnectionMenu()

void Rendering::InitializeConnectionMenu ( )
private

Definition at line 462 of file Rendering.cpp.

References _connectionMenu, _eventBus, _graphics, _mainMenu, _soundEffectManager, _uiFactory, JOIN_GAME, EventBus::publish(), and StartGame().

Referenced by InitializeMenus().

Here is the call graph for this function:

◆ InitializeCreateRoomMenu()

void Rendering::InitializeCreateRoomMenu ( )
private

Definition at line 567 of file Rendering.cpp.

References _createRoomMenu, _eventBus, _graphics, _roomListMenu, _soundEffectManager, _uiFactory, _waitingRoomMenu, CREATE_ROOM, LOG_INFO, and EventBus::publish().

Referenced by InitializeMenus().

Here is the call graph for this function:

◆ InitializeDefeatMenu()

void Rendering::InitializeDefeatMenu ( )
private

Definition at line 491 of file Rendering.cpp.

References _defeatMenu, _eventBus, _mainMenu, _scene, _soundEffectManager, _uiFactory, LEAVE_ROOM, MENU, and EventBus::publish().

Referenced by InitializeMenus().

Here is the call graph for this function:

◆ InitializeKeyBindingsMenu()

void Rendering::InitializeKeyBindingsMenu ( )
private

◆ InitializeLoginMenu()

void Rendering::InitializeLoginMenu ( )
private

Definition at line 362 of file Rendering.cpp.

References _graphics, _loginMenu, _loginOverlay, _mainMenu, _soundEffectManager, and _uiFactory.

Referenced by InitializeMenus().

◆ InitializeMainMenu()

◆ InitializeMenus()

◆ InitializeRoomListMenu()

void Rendering::InitializeRoomListMenu ( )
private

Definition at line 531 of file Rendering.cpp.

References _createRoomMenu, _eventBus, _graphics, _mainMenu, _roomListMenu, _selectedRoomId, _soundEffectManager, _uiFactory, _waitingRoomMenu, JOIN_GAME, LOG_INFO, and EventBus::publish().

Referenced by InitializeMenus().

Here is the call graph for this function:

◆ InitializeServerListMenu()

void Rendering::InitializeServerListMenu ( )
private

◆ InitializeSettingsMenu()

◆ InitializeVictoryMenu()

void Rendering::InitializeVictoryMenu ( )
private

Definition at line 511 of file Rendering.cpp.

References _eventBus, _mainMenu, _scene, _soundEffectManager, _uiFactory, _victoryMenu, LEAVE_ROOM, MENU, and EventBus::publish().

Referenced by InitializeMenus().

Here is the call graph for this function:

◆ InitializeWaitingRoomMenu()

void Rendering::InitializeWaitingRoomMenu ( )
private

Definition at line 600 of file Rendering.cpp.

References _eventBus, _graphics, _roomListMenu, _soundEffectManager, _uiFactory, _waitingRoomMenu, LEAVE_ROOM, LOG_INFO, EventBus::publish(), and START_GAME_REQUEST.

Referenced by InitializeMenus().

Here is the call graph for this function:

◆ IsGamepadAvailable()

bool Rendering::IsGamepadAvailable ( int  gamepad) const

Check if a gamepad is available/connected.

Parameters
gamepadGamepad index (0-3)
Returns
true if the gamepad is connected

Definition at line 1236 of file Rendering.cpp.

References _graphics, and Graphics::RaylibGraphics::IsGamepadAvailable().

Here is the call graph for this function:

◆ IsGamepadButtonDown()

bool Rendering::IsGamepadButtonDown ( int  gamepad,
int  button 
) const

Check if a gamepad button is currently held down.

Parameters
gamepadGamepad index (0-3)
buttonButton code (GAMEPAD_BUTTON_* constants)
Returns
true if the button is down

Definition at line 1240 of file Rendering.cpp.

References _graphics, and Graphics::RaylibGraphics::IsGamepadButtonDown().

Here is the call graph for this function:

◆ IsKeyDown()

bool Rendering::IsKeyDown ( int  key) const

Check if a key is currently being held down.

Parameters
keyRaylib key code
Returns
true if key is down

Definition at line 1232 of file Rendering.cpp.

References _graphics, and Graphics::RaylibGraphics::IsKeyDown().

Here is the call graph for this function:

◆ IsWindowOpen()

bool Rendering::IsWindowOpen ( ) const

Check if window is open.

Returns
true if window exists and hasn't been closed
Note
Returns false if user closes the window

Definition at line 1146 of file Rendering.cpp.

References _graphics, _initialized, and Graphics::RaylibGraphics::IsWindowOpen().

Here is the call graph for this function:

◆ LoadAccessibilitySettings()

◆ LoadTexture()

bool Rendering::LoadTexture ( const std::string &  textureName,
const std::string &  path 
)

Load a texture from file.

Loads a texture into memory and associates it with an identifier. Texture is cached for reuse.

Parameters
idUnique identifier for this texture (e.g., "player_ship")
pathPath to image file (PNG, JPG, BMP)
Returns
true if loading succeeds, false otherwise
Note
Textures are shared (same texture = same memory)
Supported formats depend on Raylib wrapper implementation
Wrapper implementation pending

Definition at line 1153 of file Rendering.cpp.

References _graphics, and Graphics::RaylibGraphics::LoadTexture().

Here is the call graph for this function:

◆ MoveEntityLocally()

void Rendering::MoveEntityLocally ( uint32_t  entityId,
float  deltaX,
float  deltaY 
)

Move an entity locally (client-side prediction)

Parameters
entityIdEntity ID to move
deltaXMovement in X direction (pixels)
deltaYMovement in Y direction (pixels)

Used for local player prediction: moves the entity immediately without waiting for server confirmation.

Provides instant (0ms) input response for the local player.

Definition at line 1260 of file Rendering.cpp.

References _entityRenderer.

◆ RemoveEntity()

void Rendering::RemoveEntity ( uint32_t  id)

Remove an entity from rendering.

Parameters
idEntity unique identifier

Delegates to EntityRenderer. Call when entity is destroyed.

Definition at line 1195 of file Rendering.cpp.

References _entityRenderer.

◆ Render()

void Rendering::Render ( )

Perform rendering of current frame.

Clears buffer, draws all queued elements, and displays. Must be called once per frame.

Note
Uses Raylib wrapper's rendering pipeline
Synchronized with VSync if enabled
Implementation pending Raylib wrapper availability

Definition at line 808 of file Rendering.cpp.

References _graphics, _initialized, _quitRequested, Graphics::RaylibGraphics::BeginColorblindCapture(), Graphics::RaylibGraphics::ClearWindow(), Graphics::RaylibGraphics::DisplayWindow(), Graphics::RaylibGraphics::EndColorblindCapture(), HandleEscapeKeyInput(), RenderGameScene(), RenderHUD(), RenderUI(), Graphics::RaylibGraphics::StartDrawing(), UpdateFpsCounter(), UpdateUI(), and Graphics::RaylibGraphics::WindowShouldClose().

Here is the call graph for this function:

◆ RenderGameScene()

void Rendering::RenderGameScene ( )
private

Render the game scene (entities).

Definition at line 1004 of file Rendering.cpp.

References _entityRenderer, _graphics, _scene, Graphics::RaylibGraphics::GetDeltaTime(), and IN_GAME.

Referenced by Render().

Here is the call graph for this function:

◆ RenderHUD()

void Rendering::RenderHUD ( )
private

Render HUD elements (ping, FPS).

Definition at line 1110 of file Rendering.cpp.

References _displayedPing, _fps, _graphics, _showFps, _showPing, Graphics::RaylibGraphics::DrawRectFilled(), Graphics::RaylibGraphics::DrawText(), UI::TextUtils::EstimateTextWidth(), and Graphics::RaylibGraphics::GetWindowWidth().

Referenced by Render().

Here is the call graph for this function:

◆ RenderUI()

◆ SaveAccessibilitySettings()

◆ SetBackground()

void Rendering::SetBackground ( const std::string &  mainBackground,
const std::string &  parallaxBackground,
float  scrollSpeed,
float  parallaxSpeedFactor 
)

Set up background layers for parallax scrolling.

Parameters
mainBackgroundPath to the main background texture
parallaxBackgroundPath to the parallax layer texture (rendered on top, scrolls slower)
scrollSpeedBase scroll speed in pixels/second
parallaxSpeedFactorSpeed factor for parallax layer (0.5 = half speed)

Called when starting a game with map configuration.

Definition at line 1213 of file Rendering.cpp.

References _entityRenderer.

◆ SetClientSidePredictionEnabled()

void Rendering::SetClientSidePredictionEnabled ( bool  enabled)

Enable or disable client-side prediction for local player.

Parameters
enabledtrue to enable prediction (instant movement), false for interpolation

Delegates to EntityRenderer. Should be called when toggling prediction mode.

Definition at line 1266 of file Rendering.cpp.

References _entityRenderer.

◆ SetLocalPlayerMoving()

void Rendering::SetLocalPlayerMoving ( bool  moving)

Set whether the local player is currently moving.

Parameters
movingtrue if player is actively moving, false if stopped

This affects reconciliation behavior to prevent rollback when stopping. Delegates to EntityRenderer.

Definition at line 1285 of file Rendering.cpp.

References _entityRenderer.

◆ SetMyEntityId()

void Rendering::SetMyEntityId ( uint32_t  id)

Set the local player's entity ID.

Parameters
idEntity ID representing the local player

Allows visual differentiation of the player's own entity.

Definition at line 1201 of file Rendering.cpp.

References _entityRenderer.

◆ SetOnChatMessageSent()

void Rendering::SetOnChatMessageSent ( std::function< void(const std::string &)>  callback)

Set callback for when a chat message is sent.

Parameters
callbackFunction to call when user sends a message

Definition at line 1351 of file Rendering.cpp.

References _chatWidget.

◆ SetPing()

void Rendering::SetPing ( uint32_t  pingMs)

Set the current ping value for display.

Parameters
pingMsPing in milliseconds

Updates the ping value displayed in the top-right corner. Color changes based on quality:

  • Green: 0-50ms (excellent)
  • Yellow: 51-100ms (good)
  • Orange: 101-150ms (fair)
  • Red: 151+ms (poor)

Definition at line 1291 of file Rendering.cpp.

References _currentPing.

◆ SetPlayerName()

void Rendering::SetPlayerName ( const std::string &  name)

Update the displayed player name (e.g., after authentication)

Parameters
nameThe player's username

Definition at line 740 of file Rendering.cpp.

References _mainMenu, and LOG_INFO.

Referenced by SubscribeToConnectionEvents().

◆ SetReconciliationThreshold()

void Rendering::SetReconciliationThreshold ( float  threshold)

Set the reconciliation threshold for client-side prediction.

Parameters
thresholdDistance in pixels before server correction is applied

Controls when the client prediction is corrected by the server's authoritative position. Smaller values = more frequent corrections (tighter sync, more visual jitter) Larger values = fewer corrections (looser sync, smoother visuals)

Recommended ranges based on network latency:

  • Low latency (<50ms): 3.0f - 5.0f pixels
  • Medium latency (50-150ms): 5.0f - 10.0f pixels (default)
  • High latency (>150ms): 10.0f - 20.0f pixels

Delegates to EntityRenderer.

Note
Default is 5.0f pixels

Definition at line 1272 of file Rendering.cpp.

References _entityRenderer.

◆ SetShowFps()

void Rendering::SetShowFps ( bool  enabled)

Enable/disable FPS display.

Definition at line 732 of file Rendering.cpp.

References _showFps.

Referenced by InitializeSettingsMenu().

◆ SetShowPing()

void Rendering::SetShowPing ( bool  enabled)

Enable/disable ping display.

Definition at line 724 of file Rendering.cpp.

References _showPing.

Referenced by InitializeSettingsMenu().

◆ ShowGameOver()

void Rendering::ShowGameOver ( const std::string &  reason)

Display the game over screen.

Parameters
reasonReason for game over (e.g., "Defeat", "Victory")

Shows the appropriate game over menu based on the reason:

  • "Victory" or similar -> Victory screen
  • "Defeat" or similar -> Defeat screen

Definition at line 780 of file Rendering.cpp.

References _defeatMenu, _gameOverReason, _scene, _settingsMenu, _settingsOverlay, _victoryMenu, and GAME_OVER.

◆ Shutdown()

void Rendering::Shutdown ( )

Stop the rendering system and destroy window.

Frees all allocated graphical resources. Closes the window properly.

Definition at line 707 of file Rendering.cpp.

References _graphics, _initialized, and Graphics::RaylibGraphics::CloseWindow().

Referenced by ~Rendering().

Here is the call graph for this function:

◆ StartGame()

void Rendering::StartGame ( )

Switch immediately to the game scene.

Forces the rendering system to enter the game mode:

  • Hides all menus
  • Enables entity rendering
  • Sets scene to IN_GAME

Useful when the game state is already active (e.g. after login flow).

Definition at line 747 of file Rendering.cpp.

References _addServerMenu, _connectionMenu, _createRoomMenu, _entityRenderer, _graphics, _initialized, _mainMenu, _roomListMenu, _scene, _serverListMenu, _settingsMenu, _settingsOverlay, _waitingRoomMenu, IN_GAME, and LOG_INFO.

Referenced by InitializeConnectionMenu().

◆ SubscribeToConnectionEvents()

◆ UpdateBackground()

void Rendering::UpdateBackground ( float  deltaTime)

Update background scroll positions.

Parameters
deltaTimeTime elapsed since last frame (in seconds)

Should be called every frame during gameplay.

Definition at line 1226 of file Rendering.cpp.

References _entityRenderer.

◆ UpdateChatVisibility()

void Rendering::UpdateChatVisibility ( )

Update chat widget visibility based on current scene.

Definition at line 1357 of file Rendering.cpp.

References _chatWidget, _scene, _settingsMenu, _waitingRoomMenu, and IN_GAME.

Referenced by UpdateUI().

◆ UpdateEntity()

void Rendering::UpdateEntity ( uint32_t  id,
RType::Messages::Shared::EntityType  type,
float  x,
float  y,
int  health,
const std::string &  currentAnimation,
int  srcX,
int  srcY,
int  srcW,
int  srcH 
)

Update or create an entity for rendering with animation.

Parameters
idEntity unique identifier
typeEntity type (Player, Enemy, Bullet)
xWorld position X
yWorld position Y
healthCurrent health (-1 if not applicable)
currentAnimationCurrent animation clip name
srcXSprite source X on spritesheet
srcYSprite source Y on spritesheet
srcWSprite width
srcHSprite height

Delegates to EntityRenderer. Call when receiving GameState updates.

Definition at line 1187 of file Rendering.cpp.

References _entityRenderer.

◆ UpdateFpsCounter()

void Rendering::UpdateFpsCounter ( )
private

Update FPS counter based on delta time.

Definition at line 845 of file Rendering.cpp.

References _fps, _fpsAccumulator, _fpsFrameCount, _graphics, and Graphics::RaylibGraphics::GetDeltaTime().

Referenced by Render().

Here is the call graph for this function:

◆ UpdateInterpolation()

void Rendering::UpdateInterpolation ( float  deltaTime)

Update interpolation for all entities.

Parameters
deltaTimeTime elapsed since last frame (in seconds)

Should be called every frame before Render() to smoothly interpolate entity positions between network updates.

Delegates to EntityRenderer.

Definition at line 1244 of file Rendering.cpp.

References _entityRenderer.

◆ UpdatePingTimer()

void Rendering::UpdatePingTimer ( float  deltaTime)

Update ping display timer (called every frame)

Parameters
deltaTimeTime elapsed since last frame (in seconds)

Updates the displayed ping value once per second to avoid flickering and optimize performance. Should be called from GameLoop's update().

Definition at line 1250 of file Rendering.cpp.

References _currentPing, _displayedPing, _pingUpdateTimer, and PING_UPDATE_INTERVAL.

◆ UpdateRoomList()

void Rendering::UpdateRoomList ( const std::vector< RoomData > &  rooms)

Update room list from server data.

Parameters
roomsVector of room information

Definition at line 1295 of file Rendering.cpp.

References _roomListMenu, and LOG_INFO.

◆ UpdateUI()

void Rendering::UpdateUI ( )
private

◆ UpdateWaitingRoom()

void Rendering::UpdateWaitingRoom ( const std::vector< Game::PlayerInfo > &  players,
const std::string &  roomName,
bool  isHost,
bool  isSpectator = false 
)

Update waiting room with player list.

Parameters
playersVector of players in the room
roomNameName of the room
isHostWhether local player is the host
isSpectatorWhether local player is a spectator

Definition at line 1310 of file Rendering.cpp.

References _waitingRoomMenu, and LOG_INFO.

◆ WindowShouldClose()

bool Rendering::WindowShouldClose ( ) const

Definition at line 1176 of file Rendering.cpp.

References _graphics, _initialized, and Graphics::RaylibGraphics::WindowShouldClose().

Here is the call graph for this function:

Member Data Documentation

◆ _accessibilityMenu

◆ _addServerMenu

std::unique_ptr<Game::AddServerMenu> Rendering::_addServerMenu
private

◆ _chatWidget

std::unique_ptr<Game::ChatWidget> Rendering::_chatWidget
private

◆ _confirmQuitMenu

std::unique_ptr<Game::ConfirmQuitMenu> Rendering::_confirmQuitMenu
private

Definition at line 496 of file Rendering.hpp.

Referenced by InitializeConfirmQuitMenu(), RenderUI(), and UpdateUI().

◆ _confirmQuitOverlay

bool Rendering::_confirmQuitOverlay = false
private

Definition at line 502 of file Rendering.hpp.

Referenced by InitializeConfirmQuitMenu(), and RenderUI().

◆ _connectingServerName

std::string Rendering::_connectingServerName
private

Definition at line 510 of file Rendering.hpp.

Referenced by InitializeServerListMenu().

◆ _connectionMenu

std::unique_ptr<Game::ConnectionMenu> Rendering::_connectionMenu
private

Definition at line 492 of file Rendering.hpp.

Referenced by InitializeConnectionMenu(), RenderUI(), StartGame(), and UpdateUI().

◆ _createRoomMenu

std::unique_ptr<Game::CreateRoomMenu> Rendering::_createRoomMenu
private

◆ _currentPing

uint32_t Rendering::_currentPing = 0
private

Definition at line 522 of file Rendering.hpp.

Referenced by SetPing(), and UpdatePingTimer().

◆ _defeatMenu

std::unique_ptr<Game::DefeatMenu> Rendering::_defeatMenu
private

Definition at line 498 of file Rendering.hpp.

Referenced by InitializeDefeatMenu(), RenderUI(), ShowGameOver(), and UpdateUI().

◆ _displayedPing

uint32_t Rendering::_displayedPing = 0
private

Definition at line 523 of file Rendering.hpp.

Referenced by RenderHUD(), and UpdatePingTimer().

◆ _entityRenderer

◆ _eventBus

◆ _fps

uint32_t Rendering::_fps = 0
private

Definition at line 531 of file Rendering.hpp.

Referenced by Initialize(), RenderHUD(), and UpdateFpsCounter().

◆ _fpsAccumulator

float Rendering::_fpsAccumulator = 0.0f
private

Definition at line 532 of file Rendering.hpp.

Referenced by Initialize(), and UpdateFpsCounter().

◆ _fpsFrameCount

uint32_t Rendering::_fpsFrameCount = 0
private

Definition at line 533 of file Rendering.hpp.

Referenced by Initialize(), and UpdateFpsCounter().

◆ _gameOverReason

std::string Rendering::_gameOverReason
private

Definition at line 472 of file Rendering.hpp.

Referenced by RenderUI(), and ShowGameOver().

◆ _graphics

◆ _height

uint32_t Rendering::_height = 0
private

◆ _initialized

bool Rendering::_initialized = false
private

◆ _isConnecting

bool Rendering::_isConnecting = false
private

Definition at line 509 of file Rendering.hpp.

Referenced by InitializeServerListMenu(), and SubscribeToConnectionEvents().

◆ _keyBindingsMenu

std::unique_ptr<Game::KeyBindingsMenu> Rendering::_keyBindingsMenu
private

◆ _keyBindingsOverlay

bool Rendering::_keyBindingsOverlay = false
private

Definition at line 504 of file Rendering.hpp.

Referenced by InitializeAccessibilityMenu(), and InitializeKeyBindingsMenu().

◆ _loginMenu

std::unique_ptr<Game::LoginMenu> Rendering::_loginMenu
private

◆ _loginOverlay

bool Rendering::_loginOverlay = false
private

Definition at line 503 of file Rendering.hpp.

Referenced by InitializeLoginMenu(), and InitializeMainMenu().

◆ _mainMenu

◆ _pingUpdateTimer

float Rendering::_pingUpdateTimer = 0.0f
private

Definition at line 524 of file Rendering.hpp.

Referenced by UpdatePingTimer().

◆ _quitRequested

bool Rendering::_quitRequested = false
private

◆ _roomListMenu

◆ _scene

◆ _selectedRoomId

std::string Rendering::_selectedRoomId
private

Definition at line 513 of file Rendering.hpp.

Referenced by InitializeRoomListMenu().

◆ _selectedServerIp

std::string Rendering::_selectedServerIp = "127.0.0.1"
private

Definition at line 507 of file Rendering.hpp.

Referenced by InitializeServerListMenu().

◆ _selectedServerPort

uint16_t Rendering::_selectedServerPort = 4242
private

Definition at line 508 of file Rendering.hpp.

Referenced by InitializeServerListMenu().

◆ _serverListMenu

std::unique_ptr<Game::ServerListMenu> Rendering::_serverListMenu
private

◆ _settingsMenu

◆ _settingsOverlay

bool Rendering::_settingsOverlay = false
private

◆ _showFps

bool Rendering::_showFps = true
private

◆ _showPing

bool Rendering::_showPing = true
private

◆ _soundEffectManager

◆ _uiFactory

◆ _victoryMenu

std::unique_ptr<Game::VictoryMenu> Rendering::_victoryMenu
private

Definition at line 499 of file Rendering.hpp.

Referenced by InitializeVictoryMenu(), RenderUI(), ShowGameOver(), and UpdateUI().

◆ _waitingRoomMenu

◆ _width

uint32_t Rendering::_width = 0
private

◆ PING_UPDATE_INTERVAL

constexpr float Rendering::PING_UPDATE_INTERVAL = 1.0f
staticconstexprprivate

Definition at line 525 of file Rendering.hpp.

Referenced by UpdatePingTimer().


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