Commit 59a025b0 authored by Hubert Denkmair's avatar Hubert Denkmair

add frame complete callback

parent aa5ca0e3
......@@ -31,10 +31,10 @@ RelayServer::RelayServer()
}
);
msg.SetMessageReceivedCallback(
[](std::vector<char> data)
msg.SetFrameCompleteCallback(
[](uint64_t frame_id)
{
//std::cout << "received " << data.size() << " bytes." << std::endl;
std::cout << "frame " << frame_id << " complete." << std::endl;
}
);
......
......@@ -10,9 +10,9 @@ TcpProtocol::TcpProtocol()
_buf.resize(BUFFER_SIZE);
}
void TcpProtocol::SetMessageReceivedCallback(TcpProtocol::MessageReceivedCallback callback)
void TcpProtocol::SetFrameCompleteCallback(TcpProtocol::FrameCompleteCallback callback)
{
_messageReceivedCallback = callback;
_frameCompleteCallback = callback;
}
bool TcpProtocol::Read(int socket)
......@@ -119,7 +119,7 @@ void TcpProtocol::OnWorldUpdateReceived(const MsgPackProtocol::WorldUpdateMessag
void TcpProtocol::OnTickReceived(const MsgPackProtocol::TickMessage &msg)
{
(void)msg;
_frameCompleteCallback(msg.frame_id);
}
void TcpProtocol::OnFoodSpawnReceived(const MsgPackProtocol::FoodSpawnMessage& msg)
......
......@@ -14,11 +14,11 @@ using SnakeSegmentItem = MsgPackProtocol::SnakeSegmentItem;
class TcpProtocol
{
public:
typedef std::function<void(std::vector<char>&)> MessageReceivedCallback;
typedef std::function<void(uint64_t frame_id)> FrameCompleteCallback;
static constexpr const size_t BUFFER_SIZE = 1024*1024;
TcpProtocol();
void SetMessageReceivedCallback(MessageReceivedCallback callback);
void SetFrameCompleteCallback(FrameCompleteCallback callback);
bool Read(int socket);
private:
......@@ -34,7 +34,7 @@ class TcpProtocol
size_t _bufHead=0;
size_t _bufTail=0;
MessageReceivedCallback _messageReceivedCallback;
FrameCompleteCallback _frameCompleteCallback;
std::unique_ptr<FoodMap> _food;
MsgPackProtocol::GameInfoMessage _gameInfo;
......
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