begin client-server
This commit is contained in:
@@ -1,21 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <server/IServerState.h>
|
||||
#include <td/game/World.h>
|
||||
#include <td/simulation/ServerSimulation.h>
|
||||
|
||||
namespace td {
|
||||
namespace server {
|
||||
|
||||
class GameState : public IServerState{
|
||||
class GameStateHandler;
|
||||
|
||||
class GameState : public IServerState {
|
||||
private:
|
||||
/* data */
|
||||
std::shared_ptr<game::World> m_World;
|
||||
sim::ServerSimulation m_Simulation;
|
||||
float m_Time;
|
||||
|
||||
public:
|
||||
GameState(/* args */) {}
|
||||
GameState(const std::shared_ptr<game::World>& a_World);
|
||||
~GameState() {}
|
||||
|
||||
virtual void HandlePacket(PlayerID a_Id, const protocol::PacketBase& a_Packet) override;
|
||||
virtual void Update(float a_Delta) override;
|
||||
virtual void OnPlayerJoin(PlayerID a_Id) override;
|
||||
virtual void OnPlayerLeave(PlayerID a_Id) override;
|
||||
|
||||
protected:
|
||||
virtual void Init() override;
|
||||
|
||||
friend class GameStateHandler;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
||||
25
include/server/state/GameStateHandler.h
Normal file
25
include/server/state/GameStateHandler.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
|
||||
namespace td {
|
||||
namespace server {
|
||||
|
||||
class GameState;
|
||||
|
||||
class GameStateHandler : public protocol::PacketHandler {
|
||||
private:
|
||||
GameState& m_GameState;
|
||||
PlayerID m_PlayerId;
|
||||
|
||||
using protocol::PacketHandler::Handle;
|
||||
|
||||
public:
|
||||
GameStateHandler(GameState& a_GameState, PlayerID a_PlayerId);
|
||||
|
||||
virtual void Handle(const protocol::packets::SpawnTroopPacket& a_Packet) override;
|
||||
virtual void Handle(const protocol::packets::PlaceTowerPacket& a_Packet) override;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace td
|
||||
@@ -5,11 +5,12 @@
|
||||
namespace td {
|
||||
namespace server {
|
||||
|
||||
// this class is temporary useless
|
||||
class LobbyState : public IServerState {
|
||||
private:
|
||||
/* data */
|
||||
std::shared_ptr<game::World> m_World;
|
||||
public:
|
||||
LobbyState(/* args */) {}
|
||||
LobbyState(const std::shared_ptr<game::World>& a_World) : m_World(a_World) {}
|
||||
~LobbyState() {}
|
||||
|
||||
virtual void HandlePacket(PlayerID a_Id, const protocol::PacketBase& a_Packet) override;
|
||||
|
||||
Reference in New Issue
Block a user