send world to client
This commit is contained in:
@@ -6,7 +6,7 @@ namespace td {
|
||||
namespace client {
|
||||
|
||||
Client::Client(const std::shared_ptr<IClientSocket>& a_Socket, const std::string& a_PlayerName) : m_Socket(a_Socket), m_Players(a_Socket) {
|
||||
ChangeState<LoggingState>(a_PlayerName);
|
||||
// ChangeState<LoggingState>(a_PlayerName);
|
||||
}
|
||||
|
||||
void Client::SendPacket(const protocol::PacketBase& a_Packet) {
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace client {
|
||||
PlayerManager::PlayerManager(const std::shared_ptr<IClientSocket>& a_Socket) : m_Socket(a_Socket) {
|
||||
a_Socket->OnReceive.Connect(std::bind(&PlayerManager::HandleBase, this, std::placeholders::_1));
|
||||
OnPlayerJoin.Connect([this](const PlayerInfo& a_Player){
|
||||
std::cout << "[Client " << this << "] " << a_Player.m_PlayerName << "(" << +a_Player.m_PlayerId << ") joined !\n";
|
||||
std::cout << "[Client " << this << "] " << a_Player.m_PlayerName << " joined !\n";
|
||||
});
|
||||
OnPlayerLeave.Connect([this](const PlayerID a_Player){
|
||||
std::cout << "[Client " << this << "] " << GetPlayer(a_Player).m_PlayerName << "(" << +a_Player << ") left !\n";
|
||||
|
||||
24
src/client/state/LobbyState.cpp
Normal file
24
src/client/state/LobbyState.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <client/state/LobbyState.h>
|
||||
|
||||
#include <client/state/GameState.h>
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
LobbyState::LobbyState(Client& a_Client) : ClientState(a_Client), m_World(std::make_shared<game::World>()) {}
|
||||
|
||||
LobbyState::~LobbyState() {}
|
||||
|
||||
void LobbyState::Handle(const protocol::packets::WorldHeaderPacket& a_Packet) {
|
||||
m_World->LoadMap(*a_Packet);
|
||||
}
|
||||
|
||||
void LobbyState::Handle(const protocol::packets::WorldDataPacket& a_Packet) {
|
||||
m_World->LoadMap(*a_Packet);
|
||||
ChangeState<GameState>(m_World, STEP_TIME);
|
||||
}
|
||||
|
||||
void LobbyState::Update(float a_Delta) {}
|
||||
|
||||
} // namespace client
|
||||
} // namespace td
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <client/state/LoggingState.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <client/state/LobbyState.h>
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
@@ -9,6 +9,9 @@ LoggingState::LoggingState(Client& a_Client, const std::string& a_PlayerName) :
|
||||
SendPacket(td::protocol::packets::PlayerLoginPacket(a_PlayerName));
|
||||
}
|
||||
|
||||
void LoggingState::Update(float a_Delta) {
|
||||
}
|
||||
|
||||
LoggingState::~LoggingState() {}
|
||||
|
||||
void LoggingState::Handle(const protocol::packets::PlayerJoinPacket& a_Packet) {
|
||||
@@ -16,7 +19,7 @@ void LoggingState::Handle(const protocol::packets::PlayerJoinPacket& a_Packet) {
|
||||
}
|
||||
|
||||
void LoggingState::Handle(const protocol::packets::LoggingSuccessPacket& a_Packet) {
|
||||
// TODO: switch state
|
||||
ChangeState<LobbyState>();
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
|
||||
Reference in New Issue
Block a user