Commit 239e1a59 authored by Hubert Denkmair's avatar Hubert Denkmair

use a std::map for log messages

parent f55221a9
......@@ -38,20 +38,18 @@ int RelayServer::Run()
con->FrameComplete(frame_id, _tcpProtocol);
auto key = con->getViewerKey();
if (key!=0)
if (logMessages.find(key) == logMessages.end())
{
for (auto& item: logMessages)
{
if (item.viewer_key == key)
{
con->LogMessage(frame_id, item.message);
}
}
return;
}
for (auto& item: logMessages.at(key))
{
con->LogMessage(frame_id, item.message);
}
}
);
_tcpProtocol.ClearLogItems();
//std::cout << "frame " << frame_id << " complete." << std::endl;
}
);
epoll.AddFileDescriptor(_clientSocket, EPOLLIN|EPOLLPRI|EPOLLERR);
......
......@@ -46,6 +46,14 @@ bool TcpProtocol::Read(int socket)
return true;
}
void TcpProtocol::ClearLogItems()
{
for (auto &kvp: _pendingLogItems)
{
_pendingLogItems[kvp.first].clear();
}
}
void TcpProtocol::OnMessageReceived(const char* data, size_t count)
{
msgpack::object_handle obj;
......@@ -192,7 +200,6 @@ void TcpProtocol::OnBotLogReceived(std::unique_ptr<MsgPackProtocol::BotLogMessag
{
for (auto& item: msg->items)
{
_pendingLogItems.push_back(item);
_pendingLogItems[item.viewer_key].emplace_back(item);
}
}
......@@ -4,6 +4,7 @@
#include <functional>
#include <vector>
#include <memory>
#include <map>
#include "SpatialMap.h"
#include "MsgPackProtocol.h"
......@@ -25,8 +26,9 @@ class TcpProtocol
const MsgPackProtocol::WorldUpdateMessage& GetWorldUpdate() const { return _worldUpdate; }
const std::vector<std::unique_ptr<MsgPackProtocol::Message>>& GetPendingMessages() const { return _pendingMessages; }
const std::vector<MsgPackProtocol::BotLogItem>& GetPendingLogItems() const { return _pendingLogItems; }
void ClearLogItems() { _pendingLogItems.clear(); }
typedef std::map<uint64_t, std::vector<MsgPackProtocol::BotLogItem>> LogItemMap;
const LogItemMap& GetPendingLogItems() const { return _pendingLogItems; }
void ClearLogItems();
private:
static constexpr const size_t SPATIAL_MAP_TILES_X = 128;
......@@ -34,7 +36,6 @@ class TcpProtocol
static constexpr const size_t SPATIAL_MAP_RESERVE_COUNT = 10;
typedef SpatialMap<FoodItem, SPATIAL_MAP_TILES_X, SPATIAL_MAP_TILES_Y> FoodMap;
typedef SpatialMap<SnakeSegmentItem, SPATIAL_MAP_TILES_X, SPATIAL_MAP_TILES_Y> SnakeSegmentMap;
std::vector<char> _buf;
......@@ -47,7 +48,8 @@ class TcpProtocol
std::vector<FoodItem>& _food;
std::vector<BotItem>& _bots;
std::vector<std::unique_ptr<MsgPackProtocol::Message>> _pendingMessages;
std::vector<MsgPackProtocol::BotLogItem> _pendingLogItems;
LogItemMap _pendingLogItems;
void OnMessageReceived(const char *data, size_t count);
......
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