Commit ad97506f authored by Hubert Denkmair's avatar Hubert Denkmair

prepare update refactor

parent 5e33d723
......@@ -7,8 +7,6 @@
#include <iostream>
TcpProtocol::TcpProtocol()
: _food(_worldUpdate.food)
, _bots(_worldUpdate.bots)
{
_buf.resize(BUFFER_SIZE);
}
......@@ -46,6 +44,14 @@ bool TcpProtocol::Read(int socket)
return true;
}
std::unique_ptr<MsgPackProtocol::WorldUpdateMessage> TcpProtocol::MakeWorldUpdateMessage() const
{
auto result = std::make_unique<MsgPackProtocol::WorldUpdateMessage>();
result->food = _food;
result->bots = _bots;
return result;
}
void TcpProtocol::ClearLogItems()
{
for (auto &kvp: _pendingLogItems)
......@@ -121,16 +127,13 @@ void TcpProtocol::OnMessageReceived(const char* data, size_t count)
void TcpProtocol::OnGameInfoReceived(const MsgPackProtocol::GameInfoMessage& msg)
{
//_segments = std::make_unique<SnakeSegmentMap>(msg.world_size_x, msg.world_size_y, 1000);
//_foodMap = std::make_unique<FoodMap>(msg.world_size_x, msg.world_size_y, 1000);
_gameInfo = msg;
}
void TcpProtocol::OnWorldUpdateReceived(const MsgPackProtocol::WorldUpdateMessage &msg)
{
_worldUpdate = msg;
_bots = _worldUpdate.bots;
_food = _worldUpdate.food;
_bots = msg.bots;
_food = msg.food;
}
void TcpProtocol::OnTickReceived(const MsgPackProtocol::TickMessage &msg)
......
......@@ -22,7 +22,8 @@ class TcpProtocol
bool Read(int socket);
const MsgPackProtocol::GameInfoMessage& GetGameInfo() const { return _gameInfo; }
const MsgPackProtocol::WorldUpdateMessage& GetWorldUpdate() const { return _worldUpdate; }
std::unique_ptr<MsgPackProtocol::WorldUpdateMessage> MakeWorldUpdateMessage() const;
const std::vector<std::unique_ptr<MsgPackProtocol::Message>>& GetPendingMessages() const { return _pendingMessages; }
typedef std::map<uint64_t, std::vector<MsgPackProtocol::BotLogItem>> LogItemMap;
......@@ -36,9 +37,8 @@ class TcpProtocol
FrameCompleteCallback _frameCompleteCallback;
MsgPackProtocol::GameInfoMessage _gameInfo;
MsgPackProtocol::WorldUpdateMessage _worldUpdate;
std::vector<FoodItem>& _food;
std::vector<BotItem>& _bots;
std::vector<FoodItem> _food;
std::vector<BotItem> _bots;
std::vector<std::unique_ptr<MsgPackProtocol::Message>> _pendingMessages;
LogItemMap _pendingLogItems;
......
......@@ -27,7 +27,7 @@ void WebsocketConnection::LogMessage(uint64_t frame_id, const std::string &messa
void WebsocketConnection::sendInitialData(const TcpProtocol &proto)
{
sendString(json(proto.GetGameInfo()).dump());
sendString(json(proto.GetWorldUpdate()).dump());
sendString(json(*proto.MakeWorldUpdateMessage()).dump());
}
void WebsocketConnection::sendString(std::string data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment