summaryrefslogtreecommitdiffstats
path: root/src/Map.cpp
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-02-21 14:26:33 +0100
committerandrew <xdotftw@gmail.com>2014-02-21 14:26:33 +0100
commit8bf5d116fe4c7b2addeba2dac9a8b1fc93486444 (patch)
tree18257de4b83cc27990d042c1fa6eca5b8df667ef /src/Map.cpp
parentThread safe cMap manager (diff)
downloadcuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.tar
cuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.tar.gz
cuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.tar.bz2
cuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.tar.lz
cuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.tar.xz
cuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.tar.zst
cuberite-8bf5d116fe4c7b2addeba2dac9a8b1fc93486444.zip
Diffstat (limited to 'src/Map.cpp')
-rw-r--r--src/Map.cpp126
1 files changed, 76 insertions, 50 deletions
diff --git a/src/Map.cpp b/src/Map.cpp
index cb5472a22..0028a1e94 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -278,28 +278,35 @@ void cMap::UpdateDecorators(void)
-void cMap::UpdateClient(cPlayer * a_Player)
+void cMap::AddPlayer(cPlayer * a_Player, cClientHandle * a_Handle, Int64 a_WorldAge)
{
- ASSERT(a_Player != NULL);
- cClientHandle * Handle = a_Player->GetClientHandle();
+ cMapClient MapClient;
+
+ MapClient.m_LastUpdate = a_WorldAge;
+ MapClient.m_SendInfo = true;
+ MapClient.m_Handle = a_Handle;
+
+ m_Clients.push_back(MapClient);
+
+ cMapDecorator PlayerDecorator(this, a_Player);
+
+ m_Decorators.push_back(PlayerDecorator);
+}
+
+
- if (Handle == NULL)
- {
- return;
- }
- Int64 WorldAge = a_Player->GetWorld()->GetWorldAge();
- // Remove invalid clients
+void cMap::RemoveInactiveClients(Int64 a_WorldAge)
+{
for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end();)
{
- // Check if client is active
- if (it->m_LastUpdate < WorldAge - 5)
+ if (it->m_LastUpdate < a_WorldAge)
{
// Remove associated decorators
for (cMapDecoratorList::iterator it2 = m_Decorators.begin(); it2 != m_Decorators.end();)
{
- if (it2->GetPlayer()->GetClientHandle() == Handle)
+ if (it2->GetPlayer()->GetClientHandle() == it->m_Handle)
{
// Erase decorator
cMapDecoratorList::iterator temp = it2;
@@ -322,63 +329,82 @@ void cMap::UpdateClient(cPlayer * a_Player)
++it;
}
}
+}
- // Linear search for client state
- for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end(); ++it)
+
+
+
+
+void cMap::StreamNext(cMapClient & a_Client)
+{
+ cClientHandle * Handle = a_Client.m_Handle;
+
+ if (a_Client.m_SendInfo)
{
- if (it->m_Handle == Handle)
- {
- it->m_LastUpdate = WorldAge;
+ Handle->SendMapInfo(m_ID, m_Scale);
- if (it->m_SendInfo)
- {
- Handle->SendMapInfo(m_ID, m_Scale);
+ a_Client.m_SendInfo = false;
- it->m_SendInfo = false;
+ return;
+ }
- return;
- }
+ ++a_Client.m_NextDecoratorUpdate;
- ++it->m_NextDecoratorUpdate;
+ if (a_Client.m_NextDecoratorUpdate >= 4)
+ {
+ // TODO 2014-02-19 xdot
+ // This is dangerous as the player object may have been destroyed before the decorator is erased from the list
+ UpdateDecorators();
- if (it->m_NextDecoratorUpdate >= 4)
- {
- // TODO 2014-02-19 xdot
- // This is dangerous as the player object may have been destroyed before the decorator is erased from the list
- UpdateDecorators();
+ Handle->SendMapDecorators(m_ID, m_Decorators);
- Handle->SendMapDecorators(m_ID, m_Decorators);
+ a_Client.m_NextDecoratorUpdate = 0;
+ }
+ else
+ {
+ ++a_Client.m_DataUpdate;
- it->m_NextDecoratorUpdate = 0;
- }
- else
- {
- ++it->m_DataUpdate;
+ unsigned int Y = (a_Client.m_DataUpdate * 11) % m_Width;
- unsigned int Y = (it->m_DataUpdate * 11) % m_Width;
+ const Byte * Colors = &m_Data[Y * m_Height];
- const Byte * Colors = &m_Data[Y * m_Height];
+ Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height);
+ }
+}
- Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height);
- }
- return;
- }
+
+
+
+void cMap::UpdateClient(cPlayer * a_Player)
+{
+ ASSERT(a_Player != NULL);
+ cClientHandle * Handle = a_Player->GetClientHandle();
+
+ if (Handle == NULL)
+ {
+ return;
}
- // New player, construct a new client state
- cMapClient MapClient;
+ Int64 WorldAge = a_Player->GetWorld()->GetWorldAge();
- MapClient.m_LastUpdate = WorldAge;
- MapClient.m_SendInfo = true;
- MapClient.m_Handle = a_Player->GetClientHandle();
+ RemoveInactiveClients(WorldAge - 5);
- m_Clients.push_back(MapClient);
+ // Linear search for client state
+ for (cMapClientList::iterator it = m_Clients.begin(); it != m_Clients.end(); ++it)
+ {
+ if (it->m_Handle == Handle)
+ {
+ it->m_LastUpdate = WorldAge;
- // Insert new decorator
- cMapDecorator PlayerDecorator(this, a_Player);
+ StreamNext(*it);
- m_Decorators.push_back(PlayerDecorator);
+ return;
+ }
+ }
+
+ // New player, construct a new client state
+ AddPlayer(a_Player, Handle, WorldAge);
}