summaryrefslogtreecommitdiffstats
path: root/src/Map.cpp
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-02-17 15:27:12 +0100
committerandrew <xdotftw@gmail.com>2014-02-17 15:27:12 +0100
commit3b24bc870bb39a8b8812ed307250e1188b9ff788 (patch)
tree8b6cf830e06a0fe6bd1eb8769ba571f9316a4707 /src/Map.cpp
parentcMap::UpdateRadius (diff)
downloadcuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.tar
cuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.tar.gz
cuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.tar.bz2
cuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.tar.lz
cuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.tar.xz
cuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.tar.zst
cuberite-3b24bc870bb39a8b8812ed307250e1188b9ff788.zip
Diffstat (limited to 'src/Map.cpp')
-rw-r--r--src/Map.cpp63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/Map.cpp b/src/Map.cpp
index e0f991693..e85c23d3a 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -50,15 +50,25 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un
+template <typename T>
+T Clamp(T a_X, T a_Min, T a_Max)
+{
+ return std::min(std::max(a_X, a_Min), a_Max);
+}
+
+
+
+
+
void cMap::UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius)
{
int PixelRadius = a_Radius / GetPixelWidth();
- unsigned int StartX = std::max(a_PixelX - PixelRadius, 0);
- unsigned int StartZ = std::max(a_PixelZ - PixelRadius, 0);
+ unsigned int StartX = Clamp(a_PixelX - PixelRadius, 0, (int)m_Width);
+ unsigned int StartZ = Clamp(a_PixelZ - PixelRadius, 0, (int)m_Height);
- unsigned int EndX = std::min(a_PixelX + PixelRadius, (int)m_Width);
- unsigned int EndZ = std::min(a_PixelZ + PixelRadius, (int)m_Height);
+ unsigned int EndX = Clamp(a_PixelX + PixelRadius, 0, (int)m_Width);
+ unsigned int EndZ = Clamp(a_PixelZ + PixelRadius, 0, (int)m_Height);
for (unsigned int X = StartX; X < EndX; ++X)
{
@@ -93,11 +103,9 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius)
-bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y)
+bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z)
{
- ASSERT(m_World != NULL);
-
- unsigned int PixelWidth = GetPixelWidth();
+ /*unsigned int PixelWidth = GetPixelWidth();
int BlockX = m_CenterX + ((a_X - m_Width) * PixelWidth);
int BlockZ = m_CenterZ + ((a_Y - m_Height) * PixelWidth);
@@ -119,7 +127,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y)
public:
cCalculatePixelCb(cMap * a_Map, int a_RelX, int a_RelZ)
- : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(0) {}
+ : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(4) {}
virtual bool Item(cChunk * a_Chunk) override
{
@@ -155,9 +163,9 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y)
} CalculatePixelCb(this, RelX, RelZ);
ASSERT(m_World != NULL);
- m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb);
+ m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb);*/
- m_Data[a_Y + (a_X * m_Height)] = CalculatePixelCb.GetPixelData();
+ m_Data[a_Z + (a_X * m_Height)] = 4;
return true;
}
@@ -166,6 +174,39 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y)
+void cMap::UpdateTrackedPlayers(void)
+{
+ cTrackedPlayerList NewList;
+
+ for (cTrackedPlayerList::iterator it = m_TrackedPlayers.begin(); it != m_TrackedPlayers.end(); ++it)
+ {
+ cPlayer * Player = *it;
+
+ UpdateRadius(*Player, DEFAULT_RADIUS);
+
+ if (true)
+ {
+ NewList.insert(Player);
+ }
+ }
+
+ std::swap(m_TrackedPlayers, NewList);
+}
+
+
+
+
+
+void cMap::AddTrackedPlayer(cPlayer * a_Player)
+{
+ ASSERT(a_Player != NULL);
+ m_TrackedPlayers.insert(a_Player);
+}
+
+
+
+
+
void cMap::EraseData(void)
{
m_Data.assign(m_Width * m_Height, 0);