27 LOG_WARNING(
"Rendering already initialized, skipping");
52 LOG_INFO(
"Rendering initialized: ", width,
"x", height,
" (", title,
")");
64 LOG_WARNING(
"[Rendering] Sound effect manager initialization failed - sounds disabled");
143 _settingsMenu->SetOnAutoMatchmakingChanged([
this](
bool enabled) {
144 LOG_INFO(
"[Rendering] Auto-matchmaking preference ", enabled ?
"enabled" :
"disabled");
166 LOG_INFO(
"[Rendering] Back to main menu - leaving room");
213 LOG_INFO(
"[Rendering] Applying colorblind filter: ",
static_cast<int>(filter));
239 LOG_INFO(
"[Rendering] Game speed changed to: ",
static_cast<int>(speed * 100),
"%");
247 LOG_INFO(
"[Rendering] Opening key bindings configuration");
290 LOG_INFO(
"[Rendering] Key bindings changed, saving...");
309 if (autoMatchmaking) {
311 LOG_INFO(
"[Rendering] Auto-matchmaking enabled, sending auto-matchmaking request");
387 _serverListMenu->SetOnServerSelected([
this](
const std::string &ip, uint16_t port) {
400 LOG_INFO(
"[Rendering] Connecting to server: ", ip,
":", port,
"...");
410 std::string serverInfo = ip +
":" + std::to_string(port);
438 _addServerMenu->SetOnAdd([
this](
const std::string &name,
const std::string &ip,
const std::string &port) {
439 LOG_INFO(
"[Rendering] Adding server: ", name,
" - ", ip,
":", port);
444 uint16_t portNum =
static_cast<uint16_t
>(std::stoi(port));
447 LOG_ERROR(
"[Rendering] Failed to parse port: ", port);
474 [
this](
const std::string &nickname,
const std::string &ip,
const std::string &port) {
535 _roomListMenu->SetOnRoomSelected([
this](
const std::string &roomId) {
536 LOG_INFO(
"[Rendering] Room selected: ", roomId);
572 [
this](
const std::string &roomName, uint32_t maxPlayers,
bool isPrivate,
float gameSpeedMultiplier) {
573 LOG_INFO(
"[Rendering] Creating room: ", roomName,
" (Max: ", maxPlayers,
", Private: ", isPrivate,
574 ", Speed: ",
static_cast<int>(gameSpeedMultiplier * 100),
"%)");
577 std::string roomData = roomName +
"|" + std::to_string(maxPlayers) +
"|" +
578 (isPrivate ?
"1" :
"0") +
"|" + std::to_string(gameSpeedMultiplier);
605 LOG_INFO(
"[Rendering] Start Game button clicked");
611 LOG_INFO(
"[Rendering] Back to room list - leaving room");
630 const std::string &username =
event.getData();
641 LOG_INFO(
"[Rendering] Authentication successful, returning to main menu");
645 bool enabled = (
event.getData() ==
"1");
647 LOG_INFO(
"[Rendering] Applied auto-matchmaking preference from server: ",
648 enabled ?
"ON" :
"OFF");
649 LOG_INFO(
"[Rendering] Matchmaking will only trigger when player clicks PLAY button");
652 LOG_INFO(
"[Rendering] Connection successful!");
669 LOG_ERROR(
"[Rendering] Connection failed: ", event.getData());
678 _serverListMenu->SetConnectionError(
"Connection failed: Server unreachable");
684 LOG_INFO(
"[Rendering] Room list received");
687 LOG_INFO(
"[Rendering] Registration successful: ", event.getData());
689 _loginMenu->SetSuccessMessage(
"Registration successful! You can now login.");
692 LOG_ERROR(
"[Rendering] Registration failed: ", event.getData());
697 LOG_ERROR(
"[Rendering] Login failed: ", event.getData());
744 LOG_INFO(
"[Rendering] Player name updated to: ", name);
751 LOG_INFO(
"Rendering: Force switching to Game Scene");
785 bool isVictory = (reason.find(
"Victory") != std::string::npos) ||
786 (reason.find(
"victory") != std::string::npos) ||
787 (reason.find(
"Win") != std::string::npos) || (reason.find(
"win") != std::string::npos);
936 std::string username =
_loginMenu->GetUsername();
937 std::string password =
_loginMenu->GetPassword();
939 if (!username.empty() && !password.empty()) {
940 LOG_INFO(
"[Rendering] Sending register request for user: " + username);
942 std::string credentials = username +
":" + password;
948 _loginMenu->SetErrorMessage(
"Please enter username and password");
953 std::string username =
_loginMenu->GetUsername();
954 std::string password =
_loginMenu->GetPassword();
956 if (!username.empty() && !password.empty()) {
957 LOG_INFO(
"[Rendering] Sending login request for user: " + username);
959 std::string credentials = username +
":" + password;
965 _loginMenu->SetErrorMessage(
"Please enter username and password");
970 LOG_INFO(
"[Rendering] Guest login selected - sending guest credentials");
973 std::string credentials =
"guest:guest";
1085 int screenCenterX =
static_cast<int>(
_width) / 2;
1086 int screenCenterY =
static_cast<int>(
_height) / 2;
1091 int textWidth =
static_cast<int>(
_gameOverReason.length() * fontSize * 0.6);
1092 int textX = screenCenterX - textWidth / 2;
1097 int textWidth =
static_cast<int>(
_gameOverReason.length() * fontSize * 0.6);
1098 int textX = screenCenterX - textWidth / 2;
1111 const int fontSize = 20;
1112 const int margin = 10;
1121 const std::string pingText =
1122 hasMeasurement ? (
"PING: " + std::to_string(
_displayedPing) +
" ms") : std::string(
"PING: --");
1125 const int x = hudRightX - textWidth;
1131 hudY += fontSize + pad * 2 + 6;
1136 const std::string fpsText =
"FPS: " + std::to_string(
_fps);
1138 const int x = hudRightX - textWidth;
1155 return result != -1;
1160 _graphics.
DrawTextureEx(textureId.c_str(), 0, 0, 0, 0, xPosition, yPosition, rotation, scale, 0xFFFFFFFF);
1164 _graphics.
DrawText(-1, text.c_str(),
static_cast<int>(xPosition),
static_cast<int>(yPosition),
1165 static_cast<int>(size), 0xFFFFFFFF);
1188 int health,
const std::string ¤tAnimation,
int srcX,
int srcY,
int srcW,
1191 _entityRenderer->updateEntity(
id, type, x, y, health, currentAnimation, srcX, srcY, srcW, srcH);
1214 float scrollSpeed,
float parallaxSpeedFactor) {
1216 _entityRenderer->setBackground(mainBackground, parallaxBackground, scrollSpeed, parallaxSpeedFactor);
1300 std::vector<Game::RoomListMenu::RoomInfo> roomInfos;
1301 for (
const auto &room : rooms) {
1302 roomInfos.emplace_back(room.roomId, room.roomName, room.playerCount, room.maxPlayers, room.isPrivate,
1307 LOG_INFO(
"[Rendering] Room list updated with ", rooms.size(),
" rooms");
1311 bool isHost,
bool isSpectator) {
1317 _waitingRoomMenu->SetRoomInfo(roomName,
static_cast<uint32_t
>(players.size()),
1322 LOG_INFO(
"[Rendering] Waiting room updated with ", players.size(),
" players, isHost=", isHost,
1323 ", isSpectator=", isSpectator);
1328 LOG_ERROR(
"[Rendering] Cannot initialize chat widget: UIFactory not initialized");
1335 float x =
_width - 300.0f;
1341 LOG_INFO(
"[Rendering] Chat widget initialized");
1345 uint64_t timestamp) {
1347 _chatWidget->AddMessage(playerId, playerName, message, timestamp);
1367 shouldBeVisible =
false;
1379 LOG_INFO(
"[Rendering] No accessibility settings file found, using defaults");
1459 LOG_ERROR(
"[Rendering] Failed to save accessibility settings");
@ APPLY_AUTO_MATCHMAKING_PREF
@ UPDATE_AUTO_MATCHMAKING_PREF
Type-safe event publication/subscription system.
void publish(const T &event)
Publish an event to all subscribers.
size_t subscribe(EventCallback< T > callback)
Subscribe to a specific event type.
float GetDeltaTime() const override
Get the time elapsed for the last frame.
void DrawRectFilled(int x, int y, int width, int height, unsigned int color) override
Draw a filled rectangle.
void DisplayWindow() override
Display the current frame to the window (end drawing and swap buffers)
void DrawTextureEx(const char *textureName, int srcX, int srcY, int srcW, int srcH, float destX, float destY, float rotation, float scale, unsigned int tint) override
Draw a texture with advanced parameters (rotation, scale, source rectangle)
bool IsKeyPressed(int key) const override
Check if a key was pressed (triggered once when key goes down)
bool IsKeyDown(int key) const override
Check if a key is currently being held down.
void CloseWindow() override
Close the graphics window and cleanup resources.
bool WindowShouldClose() const override
Check if the window should close.
void SetTargetFPS(int fps) override
Set the target frames per second for rendering.
void BeginColorblindCapture() override
Begin capturing frame for colorblind filter processing.
void SetColorblindFilter(ColorblindFilterType filter) override
Set the colorblind filter type.
void StartDrawing() override
Begin drawing frame (setup canvas for drawing operations)
void ClearWindow() override
Clear the window with the current clear color.
bool IsGamepadAvailable(int gamepad) const override
Check if a gamepad is available/connected.
void DrawText(int fontHandle, const char *text, int x, int y, int fontSize, unsigned int color) override
Draw text using a loaded font.
bool IsWindowOpen() const override
Check if the window is still open.
int GetWindowWidth() const override
Get current window width in pixels.
void InitWindow(int width, int height, const char *title) override
Initialize the graphics window.
void EndColorblindCapture() override
End capturing and apply the colorblind filter.
bool IsGamepadButtonDown(int gamepad, int button) const override
Check if a gamepad button is currently held down.
int LoadTexture(const char *name, const char *filepath) override
Load a texture from an image file.
std::string _connectingServerName
std::unique_ptr< EntityRenderer > _entityRenderer
uint32_t GetHeight() const
Get window height.
void UpdateEntity(uint32_t id, RType::Messages::Shared::EntityType type, float x, float y, int health, const std::string ¤tAnimation, int srcX, int srcY, int srcW, int srcH)
Update or create an entity for rendering with animation.
Graphics::RaylibGraphics _graphics
std::string _selectedServerIp
void ClearBackground()
Clear background configuration.
Rendering(EventBus &eventBus)
Constructor with EventBus reference.
std::unique_ptr< Game::SettingsMenu > _settingsMenu
void RenderHUD()
Render HUD elements (ping, FPS).
void ClearAllEntities()
Clear all entities from the rendering cache.
void MoveEntityLocally(uint32_t entityId, float deltaX, float deltaY)
Move an entity locally (client-side prediction)
void SetMyEntityId(uint32_t id)
Set the local player's entity ID.
void InitializeAccessibilityMenu()
bool GetShowPing() const
Get ping display state.
std::unique_ptr< Game::AccessibilityMenu > _accessibilityMenu
bool IsKeyDown(int key) const
Check if a key is currently being held down.
bool WindowShouldClose() const
void InitializeLoginMenu()
static constexpr float PING_UPDATE_INTERVAL
void InitializeServerListMenu()
void InitializeMenus()
Initialize UI factory, menus and all related callbacks.
void InitializeVictoryMenu()
void SetOnChatMessageSent(std::function< void(const std::string &)> callback)
Set callback for when a chat message is sent.
void UpdateFpsCounter()
Update FPS counter based on delta time.
void UpdateRoomList(const std::vector< RoomData > &rooms)
Update room list from server data.
bool LoadTexture(const std::string &textureName, const std::string &path)
Load a texture from file.
void InitializeCreateRoomMenu()
void RemoveEntity(uint32_t id)
Remove an entity from rendering.
void SetBackground(const std::string &mainBackground, const std::string ¶llaxBackground, float scrollSpeed, float parallaxSpeedFactor)
Set up background layers for parallax scrolling.
std::unique_ptr< Game::RoomListMenu > _roomListMenu
std::string _gameOverReason
void SubscribeToConnectionEvents()
void SetShowPing(bool enabled)
Enable/disable ping display.
std::unique_ptr< UI::RaylibUIFactory > _uiFactory
void DrawText(const std::string &text, float xPosition, float yPosition, uint32_t size=24)
Draw text on screen.
void UpdateInterpolation(float deltaTime)
Update interpolation for all entities.
void InitializeMainMenu()
std::unique_ptr< Game::ConnectionMenu > _connectionMenu
std::unique_ptr< Game::KeyBindingsMenu > _keyBindingsMenu
bool GetShowFps() const
Get FPS display state.
bool IsWindowOpen() const
Check if window is open.
void UpdateChatVisibility()
Update chat widget visibility based on current scene.
void ApplyInitialMenuSettings()
Apply runtime settings affecting rendering (target FPS, HUD visibility...).
bool Initialize(uint32_t width, uint32_t height, const std::string &title)
Initialize the rendering system and create window.
void InitializeConfirmQuitMenu()
void InitializeRoomListMenu()
void RenderGameScene()
Render the game scene (entities).
std::unique_ptr< Game::CreateRoomMenu > _createRoomMenu
std::unique_ptr< Game::AddServerMenu > _addServerMenu
std::unique_ptr< Game::VictoryMenu > _victoryMenu
void SetLocalPlayerMoving(bool moving)
Set whether the local player is currently moving.
void InitializeConnectionMenu()
std::unique_ptr< Game::ConfirmQuitMenu > _confirmQuitMenu
std::unique_ptr< Game::LoginMenu > _loginMenu
std::unique_ptr< Game::DefeatMenu > _defeatMenu
void Render()
Perform rendering of current frame.
void SetReconciliationThreshold(float threshold)
Set the reconciliation threshold for client-side prediction.
void InitializeKeyBindingsMenu()
void Shutdown()
Stop the rendering system and destroy window.
void UpdateUI()
Update all UI elements based on current scene.
void InitializeDefeatMenu()
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 ShowGameOver(const std::string &reason)
Display the game over screen.
void LoadAccessibilitySettings()
void SetPlayerName(const std::string &name)
Update the displayed player name (e.g., after authentication)
void InitializeSettingsMenu()
void ClearWindow()
Clears the window before rendering its content.
std::unique_ptr< Game::MainMenu > _mainMenu
uint32_t GetWidth() const
Get window width.
std::unique_ptr< Game::WaitingRoomMenu > _waitingRoomMenu
void SetClientSidePredictionEnabled(bool enabled)
Enable or disable client-side prediction for local player.
void UpdatePingTimer(float deltaTime)
Update ping display timer (called every frame)
std::unique_ptr< Game::ChatWidget > _chatWidget
void InitializeChatWidget()
uint16_t _selectedServerPort
void StartGame()
Switch immediately to the game scene.
void HandleEscapeKeyInput()
Handle ESC key input to toggle settings overlay in-game.
void UpdateBackground(float deltaTime)
Update background scroll positions.
void SetPing(uint32_t pingMs)
Set the current ping value for display.
void SaveAccessibilitySettings()
void DrawSprite(const std::string &textureId, float xPosition, float yPosition, float rotation=0.0, float scale=1.0)
Draw a sprite on screen.
void InitializeAddServerMenu()
std::unique_ptr< Audio::SoundEffectManager > _soundEffectManager
void RenderUI()
Render all UI menus based on current scene and overlay state.
bool IsGamepadButtonDown(int gamepad, int button) const
Check if a gamepad button is currently held down.
void InitializeWaitingRoomMenu()
float GetReconciliationThreshold() const
Get the current reconciliation threshold.
std::string _selectedRoomId
bool IsGamepadAvailable(int gamepad) const
Check if a gamepad is available/connected.
std::unique_ptr< Game::ServerListMenu > _serverListMenu
void UpdateWaitingRoom(const std::vector< Game::PlayerInfo > &players, const std::string &roomName, bool isHost, bool isSpectator=false)
Update waiting room with player list.
void SetShowFps(bool enabled)
Enable/disable FPS display.
ColorblindFilterType
Colorblind filter types for accessibility.
@ DEUTERANOPIA
Green-blind (reduced green sensitivity)
@ PROTANOPIA
Red-blind (reduced red sensitivity)
@ MONOCHROMACY
Complete color blindness (grayscale)
@ TRITANOPIA
Blue-blind (reduced blue sensitivity)
EntityType
Entity type enum - matches Cap'n Proto enum.
constexpr const char * SETTINGS_FILE_PATH
Default settings file path.
bool SaveSettings(const AccessibilitySettings &settings, const char *filePath=SETTINGS_FILE_PATH)
Save accessibility settings to file (C-style binary write)
bool LoadSettings(AccessibilitySettings &settings, const char *filePath=SETTINGS_FILE_PATH)
Load accessibility settings from file (C-style binary read)
int EstimateTextWidth(const std::string &text, int fontSize)
Estimate the width of text in pixels.
Binary struct for storing accessibility settings.
ColorblindFilterType colorblindFilter
Colorblind filter type.
void SetDefaults()
Initialize with default values.