Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/src/game/world/ClientWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ namespace World

void ClientWorld::reset()
{
_registry = Ecs::Registry{};
_registry.clear();
_registry = Ecs::Registry();
Comment thread
romain1717 marked this conversation as resolved.
_entityMap.clear();
_entityLastSeen.clear();
_scoresByPlayerId.clear();
Expand Down
30 changes: 16 additions & 14 deletions client/src/thread/ClientRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ namespace Thread
_eventBus->on<Engine::JoinRoomRequested>([this](const Engine::JoinRoomRequested &e) {
const auto req = nextReqId();
_tcpClient->sendPacket(*_tcpPacketFactory.makeJoinRoom(req, e.roomId));
if (const auto pkt = _tcpPacketFactory.makeRoomInfo(11))
if (const auto pkt = _tcpPacketFactory.makeRoomInfo(nextReqId()))
_tcpClient->sendPacket(*pkt);
});

Expand Down Expand Up @@ -385,6 +385,9 @@ namespace Thread
});

_eventBus->on<Engine::StartGameRequested>([this](const Engine::StartGameRequested &) {
if (!_stateManager->is<Engine::LobbyState>())
return;
_world->reset();
if (const auto pkt = _tcpPacketFactory.makeStartGame(nextReqId()))
_tcpClient->sendPacket(*pkt);
});
Expand All @@ -393,18 +396,6 @@ namespace Thread
if (const auto pkt = _tcpPacketFactory.makeLeaveRoom(nextReqId()))
_tcpClient->sendPacket(*pkt);
_pendingHome.store(true, std::memory_order_release);
});

_eventBus->on<Engine::UpdateRoomRequested>([this](const Engine::UpdateRoomRequested &) {
const auto req = nextReqId();
if (const auto pkt = _tcpPacketFactory.makeRoomInfo(req))
_tcpClient->sendPacket(*pkt);
});

_eventBus->on<Engine::LeaveRoomRequested>([this](const Engine::LeaveRoomRequested &) {
const auto req = nextReqId();
if (const auto pkt = _tcpPacketFactory.makeLeaveRoom(req))
(void) _tcpClient->sendPacket(*pkt);
_world->reset();
{
std::scoped_lock lock(_frameMutex);
Expand All @@ -415,6 +406,15 @@ namespace Thread
}
});

_eventBus->on<Engine::UpdateRoomRequested>([this](const Engine::UpdateRoomRequested &) {
if (!_stateManager->is<Engine::LobbyState>() || _pendingHome)
return;

const auto req = nextReqId();
if (const auto pkt = _tcpPacketFactory.makeRoomInfo(req))
_tcpClient->sendPacket(*pkt);
});

_eventBus->on<Engine::SendingMessage>([this](const Engine::SendingMessage &e) {
const auto req = nextReqId();
if (const auto pkt = _tcpPacketFactory.makeRoomMessage(req, e.message))
Expand Down Expand Up @@ -489,6 +489,8 @@ namespace Thread
});

_tcpPacketRouter->sink()->onRoomUpdatedSubscribe([&](uint32_t, const RoomData &room) {
if (_stateManager->is<Engine::GameState>())
return;
_roomManager->setCurrentData(room);
if (!_stateManager->is<Engine::LobbyState>())
_pendingJoinRoom.store(true, std::memory_order_release);
Expand Down Expand Up @@ -573,4 +575,4 @@ namespace Thread
(void) _udpClient->sendPacket(*pingPkt);
}

} // namespace Thread
} // namespace Thread
4 changes: 2 additions & 2 deletions client/src/ui/lobby/Lobby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ namespace Engine

bool _needUpdate = false; ///> Indicates if the lobby needs to be updated.

std::chrono::steady_clock::time_point _lastRefresh{}; ///> Last refresh time point.
static constexpr auto refreshPeriod = std::chrono::milliseconds(500); ///> Refresh period.
std::chrono::steady_clock::time_point _lastRefresh{}; ///> Last refresh time point.
static constexpr auto refreshPeriod = std::chrono::milliseconds(1000); ///> Refresh period.

size_t _lobbyCapacity = 4; ///> Maximum capacity of the lobby.

Expand Down
1 change: 1 addition & 0 deletions client/src/ui/rooms/RoomMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ namespace Engine
if (_root.join->onClickReleased(mx, my, [&] {
_page = Page::List;
_listRooms = true;
_createRoom = false;
_list.scroll = 0.f;
_list.lastRefresh = {};
updateListRooms();
Expand Down
6 changes: 4 additions & 2 deletions server/src/game/gameServer/GameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ namespace
const sockaddr_in *addr = sessionsL->getUdpAddress(event.sessionId);
if (!addr)
return;
if (const auto pkt = factoryL->createAcceptPacket(*addr, event.netPlayerId))
(void) serverL->sendPacket(*pkt);
if (const auto pkt = factoryL->createAcceptPacket(*addr, event.netPlayerId)) {
for (int i = 0; i < 3; i++)
(void) serverL->sendPacket(*pkt);
Comment thread
romain1717 marked this conversation as resolved.
}
});
}

Expand Down
Loading