2014-02-08 15:55:21 -05:00
|
|
|
|
|
|
|
// ChunkStay.cpp
|
|
|
|
|
|
|
|
// Implements the cChunkStay class representing a base for classes that keep chunks loaded
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "ChunkStay.h"
|
|
|
|
#include "ChunkMap.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cChunkStay::cChunkStay(void) :
|
2014-10-20 16:55:07 -04:00
|
|
|
m_ChunkMap(nullptr)
|
2014-02-08 15:55:21 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cChunkStay::~cChunkStay()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cChunkStay::Clear(void)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_ChunkMap == nullptr);
|
2014-02-08 15:55:21 -05:00
|
|
|
m_Chunks.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cChunkStay::Add(int a_ChunkX, int a_ChunkZ)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_ChunkMap == nullptr);
|
2014-02-08 15:55:21 -05:00
|
|
|
|
|
|
|
for (cChunkCoordsVector::const_iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr)
|
|
|
|
{
|
|
|
|
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ))
|
|
|
|
{
|
|
|
|
// Already present
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // for itr - Chunks[]
|
2014-08-28 05:36:35 -04:00
|
|
|
m_Chunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
|
2014-02-08 15:55:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cChunkStay::Remove(int a_ChunkX, int a_ChunkZ)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_ChunkMap == nullptr);
|
2014-02-08 15:55:21 -05:00
|
|
|
|
|
|
|
for (cChunkCoordsVector::iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr)
|
|
|
|
{
|
|
|
|
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ))
|
|
|
|
{
|
|
|
|
// Found, un-"stay"
|
|
|
|
m_Chunks.erase(itr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // for itr - m_Chunks[]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cChunkStay::Enable(cChunkMap & a_ChunkMap)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_ChunkMap == nullptr);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-08 16:23:38 -05:00
|
|
|
m_OutstandingChunks = m_Chunks;
|
2014-02-08 15:55:21 -05:00
|
|
|
m_ChunkMap = &a_ChunkMap;
|
|
|
|
a_ChunkMap.AddChunkStay(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cChunkStay::Disable(void)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(m_ChunkMap != nullptr);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-12 16:15:09 -04:00
|
|
|
cChunkMap * ChunkMap = m_ChunkMap;
|
2014-10-20 16:55:07 -04:00
|
|
|
m_ChunkMap = nullptr;
|
2014-04-12 16:15:09 -04:00
|
|
|
ChunkMap->DelChunkStay(*this);
|
2014-02-08 15:55:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-10 16:47:10 -05:00
|
|
|
bool cChunkStay::ChunkAvailable(int a_ChunkX, int a_ChunkZ)
|
2014-02-08 15:55:21 -05:00
|
|
|
{
|
|
|
|
// Check if this is a chunk that we want:
|
|
|
|
bool IsMine = false;
|
2014-02-08 16:01:04 -05:00
|
|
|
for (cChunkCoordsVector::iterator itr = m_OutstandingChunks.begin(), end = m_OutstandingChunks.end(); itr != end; ++itr)
|
2014-02-08 15:55:21 -05:00
|
|
|
{
|
|
|
|
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ))
|
|
|
|
{
|
|
|
|
m_OutstandingChunks.erase(itr);
|
|
|
|
IsMine = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // for itr - m_OutstandingChunks[]
|
|
|
|
if (!IsMine)
|
|
|
|
{
|
2014-02-10 16:47:10 -05:00
|
|
|
return false;
|
2014-02-08 15:55:21 -05:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-08 15:55:21 -05:00
|
|
|
// Call the appropriate callbacks:
|
|
|
|
OnChunkAvailable(a_ChunkX, a_ChunkZ);
|
|
|
|
if (m_OutstandingChunks.empty())
|
|
|
|
{
|
2014-02-10 16:47:10 -05:00
|
|
|
return OnAllChunksAvailable();
|
2014-02-08 15:55:21 -05:00
|
|
|
}
|
2014-02-10 16:47:10 -05:00
|
|
|
return false;
|
2014-02-08 15:55:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|