18 : AScene(assignedId), m_renderer(renderer)
20 auto ®istry = AScene::getRegistry();
22 registry.onComponentAdded(
23 [&renderer, ®istry](
const ecs::Entity e,
const std::type_info &type)
25 const auto *audioComp = registry.getComponent<
ecs::Audio>(e);
26 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
27 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
28 const auto *textComp = registry.getComponent<
ecs::Text>(e);
33 if (textComp && transform && fontComp)
35 renderer->createFont(fontComp->
id, fontComp->path);
37 {.font_name = fontComp->
id,
38 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
39 .content = textComp->content,
40 .size = textComp->font_size,
43 .name = textComp->
id});
48 registry.createEntity()
50 .with<ecs::Transform>(
"transform_title", 100.F, 40.F, 0.F)
52 .with<ecs::Text>(
"title", std::string(
"WAITING ROOM"), 64U)
57 .with<ecs::Transform>(
"transform_lobby_id", 100.F, 120.F, 0.F)
60 .with<ecs::Text>(
"lobby_id_text", std::string(
"Lobby ID"), 32U)
65 .with<ecs::Transform>(
"transform_player_count", 100.F, 160.F, 0.F)
68 .with<ecs::Text>(
"player_count_text", std::string(
"Players 0 of 4"), 32U)
73 .with<ecs::Transform>(
"transform_status", 100.F, 200.F, 0.F)
76 .with<ecs::Text>(
"status_text", std::string(
"Waiting for players"), 28U)
81 .with<ecs::Transform>(
"transform_leave", 100.F, 500.F, 0.F)
84 .with<ecs::Text>(
"leave_text", std::string(
" Leave Lobby"), 32U)
89 .with<ecs::Transform>(
"transform_ready", 100.F, 460.F, 0.F)
92 .with<ecs::Text>(
"ready_text", std::string(
" Ready"), 32U)
97 .with<ecs::Transform>(
"transform_start", 100.F, 420.F, 0.F)
100 .with<ecs::Text>(
"start_text", std::string(
" Start Game"), 32U)
131 catch (
const std::exception &e)
133 utl::Logger::log(
"WaitingRoomScene: Error handling lobby update: " + std::string(e.what()),
153 catch (
const std::exception &e)
155 utl::Logger::log(
"WaitingRoomScene: Error handling game start: " + std::string(e.what()),
165 auto ®istry = AScene::getRegistry();
175 if (leaveColor && readyColor && leaveText && readyText)
181 leaveText->content =
" Leave Lobby";
188 if (
m_isHost && startColor && startText)
193 startText->
content =
" Start Game";
202 leaveText->content =
" Leave Lobby";
216 startText->
content =
" Start Game";
227 statusColor->
a =
static_cast<std::uint8_t
>(150U + pulse * 105.0F);
307 auto ®istry = AScene::getRegistry();
311 lobbyIdText->
content =
"Lobby ID " + std::to_string(lobbyId);
334 auto ®istry = AScene::getRegistry();
357 statusText->
content =
"Lobby is full Waiting for host to start";
361 statusText->content =
371 float startY = 250.0F;
372 float spacing = 35.0F;
376 std::string playerText;
381 playerText =
"Player " + std::to_string(i + 1) +
" Connected";
386 playerText =
"Player " + std::to_string(i + 1) +
" Waiting";
391 registry.createEntity()
393 .with<ecs::Transform>(
"transform_player_" + std::to_string(i), 120.F, startY + i * spacing, 0.F)
394 .with<ecs::Color>(
"color_player_" + std::to_string(i), playerColor.
r, playerColor.
g, playerColor.
b,
396 .with<ecs::Text>(
"player_" + std::to_string(i), playerText, 26U)
410 auto ®istry = AScene::getRegistry();
413 if (
auto *text = registry.getComponent<
ecs::Text>(entity))
414 registry.removeComponent<
ecs::Text>(entity);
415 if (
auto *color = registry.getComponent<
ecs::Color>(entity))
417 if (
auto *transform = registry.getComponent<
ecs::Transform>(entity))
419 if (
auto *font = registry.getComponent<
ecs::Font>(entity))
420 registry.removeComponent<
ecs::Font>(entity);
450 std::vector<std::uint8_t> packetData;
451 packetData.resize(
sizeof(std::uint32_t));
452 std::memcpy(packetData.data(), &
m_lobbyId,
sizeof(std::uint32_t));
460 for (
const auto &
event : events)
This file contains the component definitions.
This file contains the Logger class.
Network packet serializer for RNP protocol.
Waiting room scene for R-Type multiplayer lobby system.
utl::EventBus & m_eventBus
std::uint32_t m_eventComponentId
void event(const eng::Event &event) override
Handle input events.
bool m_hasLobbyInfo
Whether lobby info has been received.
void processEventBus()
Process events from event bus.
void startGame()
Initiate game start sequence.
int m_selectedButton
Currently selected button index.
static constexpr int BUTTON_START
Start game button index (host only)
std::uint32_t m_lobbyId
Current lobby ID.
void handleLobbyUpdate(const utl::Event &event)
Handle lobby update event from server.
void leaveLobby() const
Send leave lobby request to server.
void setupEventSubscriptions() const
Subscribe to event bus events.
bool m_isHost
Whether local player is lobby host.
static constexpr int BUTTON_LEAVE
Leave lobby button index.
void setLobbyInfo(const rnp::LobbyInfo &lobbyInfo)
Update lobby information.
void update(float dt, const eng::WindowSize &size) override
Update the waiting room scene (called each frame)
std::function< void()> onGameStart
Callback invoked when game starts.
ecs::Entity m_readyButtonEntity
Ready button entity.
void handleGameStart(const utl::Event &event) const
Handle game start event from server.
ecs::Entity m_leaveButtonEntity
Leave button entity.
ecs::Entity m_playerCountEntity
Entity displaying player count.
void updatePlayerDisplay()
Update the player list display.
void setLobbyId(std::uint32_t lobbyId)
Set the lobby ID.
WaitingRoomScene(eng::id assignedId, const std::shared_ptr< eng::IRenderer > &renderer)
Constructor.
std::vector< ecs::Entity > m_playerEntities
Entities for player name displays.
ecs::Entity m_lobbyIdEntity
Entity displaying lobby ID.
std::function< void()> onLeaveLobby
Callback invoked when player leaves lobby.
float m_animationTime
Timer for UI animations.
ecs::Entity m_startButtonEntity
Start game button entity (host only)
static constexpr int BUTTON_READY
Ready button index.
void clearPlayerEntities()
Clear all player display entities.
rnp::LobbyInfo m_currentLobbyInfo
Current lobby state.
ecs::Entity m_statusEntity
Entity displaying lobby status.
Binary serializer for RNP protocol packets.
PacketLobbyUpdate deserializeLobbyUpdate()
Deserialize LOBBY_UPDATE packet.
PacketGameStart deserializeGameStart()
Deserialize GAME_START packet.
bool publish(const Event &event)
Publish an event to the bus.
std::vector< Event > consumeForTarget(std::uint32_t targetId, std::uint32_t maxEvents=100)
Consume events targeted to specific component.
void registerComponent(std::uint32_t componentId, const std::string &name)
Register component name for better debugging.
void subscribe(std::uint32_t componentId, EventType type)
Subscribe component to specific event types.
Event structure for inter-component communication.
static void log(const std::string &message, const LogLevel &logLevel)
This file contains common definitions and constants.
constexpr auto FONTS_RTYPE
static constexpr std::uint32_t NETWORK_CLIENT
Lobby information structure.
std::uint8_t currentPlayers
GAME_START packet payload.
LOBBY_UPDATE packet payload.
static constexpr eng::Color INFO_TEXT_COLOR
static constexpr eng::Color CYAN_ELECTRIC
static constexpr eng::Color GREEN_READY
static constexpr eng::Color TEXT_VALUE_COLOR
static constexpr eng::Color GRAY_BLUE_SUBTLE