summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-02-14 15:21:16 +0100
committerandrew <xdotftw@gmail.com>2014-02-14 15:21:16 +0100
commit5b92b877bcc0c5072dbea98b6c54106f954aa758 (patch)
treefa91320608d925cac74804fd44597198e2f3760e /src
parentIDCount Serialization (diff)
downloadcuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.tar
cuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.tar.gz
cuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.tar.bz2
cuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.tar.lz
cuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.tar.xz
cuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.tar.zst
cuberite-5b92b877bcc0c5072dbea98b6c54106f954aa758.zip
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/AllToLua.pkg1
-rw-r--r--src/ClientHandle.cpp13
-rw-r--r--src/Map.cpp47
-rw-r--r--src/Map.h20
-rw-r--r--src/World.cpp45
-rw-r--r--src/World.h6
-rw-r--r--src/WorldStorage/MapSerializer.cpp9
7 files changed, 114 insertions, 27 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index f65aed9bb..335acff95 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -47,6 +47,7 @@ $cfile "../ItemGrid.h"
$cfile "../BlockEntities/BlockEntity.h"
$cfile "../BlockEntities/BlockEntityWithItems.h"
$cfile "../BlockEntities/ChestEntity.h"
+$cfile "../BlockEntities/CommandBlockEntity.h"
$cfile "../BlockEntities/DropSpenserEntity.h"
$cfile "../BlockEntities/DispenserEntity.h"
$cfile "../BlockEntities/DropperEntity.h"
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 8e44a61fd..a2cbaefff 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1190,6 +1190,19 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum)
{
m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum);
m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this);
+
+ const cItem & Item = m_Player->GetInventory().GetEquippedItem();
+ if (Item.m_ItemType == E_ITEM_MAP)
+ {
+ // TODO 2014-02-14 xdot: Do not hardcode this.
+ cMap * Map = m_Player->GetWorld()->GetMapData(Item.m_ItemDamage);
+
+ if (Map != NULL)
+ {
+ // TODO 2014-02-14 xdot: Optimization - Do not send the whole map.
+ Map->SendTo(*this);
+ }
+ }
}
diff --git a/src/Map.cpp b/src/Map.cpp
index f99b01752..4acd9512c 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -7,6 +7,7 @@
#include "ClientHandle.h"
#include "World.h"
+#include "Chunk.h"
@@ -22,8 +23,6 @@ cMap::cMap(unsigned int a_ID, cWorld * a_World)
, m_World(a_World)
{
m_Data.assign(m_Width * m_Height, 0);
-
- // Do not update map
}
@@ -41,27 +40,45 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un
{
m_Data.assign(m_Width * m_Height, 0);
- UpdateMap();
+ for (unsigned int X = 0; X < m_Width; ++X)
+ {
+ for (unsigned int Y = 0; Y < m_Height; ++Y)
+ {
+ // Debug
+ m_Data[Y + X * m_Height] = rand() % 100;
+ }
+ }
}
-void cMap::UpdateMap(void)
+bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y)
{
- // ASSERT(m_World != NULL);
+ ASSERT(m_World != NULL);
- // TODO
+ cChunk * Chunk = NULL;
- for (unsigned int X = 0; X < m_Width; ++X)
+ if (Chunk == NULL)
{
- for (unsigned int Y = 0; Y < m_Height; ++Y)
- {
- // Debug
- m_Data[Y + X * m_Height] = rand() % 100;
- }
+ return false;
}
+
+ int Height = Chunk->GetHeight(a_X, a_Y);
+
+ // TODO
+
+ return true;
+}
+
+
+
+
+
+void cMap::EraseData(void)
+{
+ m_Data.assign(m_Width * m_Height, 0);
}
@@ -90,8 +107,6 @@ void cMap::Resize(unsigned int a_Width, unsigned int a_Height)
m_Height = a_Height;
m_Data.assign(m_Width * m_Height, 0);
-
- UpdateMap();
}
@@ -107,8 +122,6 @@ void cMap::SetPosition(int a_CenterX, int a_CenterZ)
m_CenterX = a_CenterX;
m_CenterZ = a_CenterZ;
-
- UpdateMap();
}
@@ -123,8 +136,6 @@ void cMap::SetScale(unsigned int a_Scale)
}
m_Scale = a_Scale;
-
- UpdateMap();
}
diff --git a/src/Map.h b/src/Map.h
index dbb15afdd..c443445de 100644
--- a/src/Map.h
+++ b/src/Map.h
@@ -26,28 +26,33 @@ class cWorld;
+// tolua_begin
class cMap
{
public:
typedef Byte ColorID;
+ // tolua_end
+
typedef std::vector<ColorID> cColorList;
public:
- /// Construct an empty map
+ /** Construct an empty map. */
cMap(unsigned int a_ID, cWorld * a_World);
cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3);
- /** Update the map (Query the world) */
- void UpdateMap(void);
-
/** Send this map to the specified client. */
void SendTo(cClientHandle & a_Client);
+ // tolua_begin
+
+ /** Erase pixel data */
+ void EraseData(void);
+
void Resize(unsigned int a_Width, unsigned int a_Height);
void SetPosition(int a_CenterX, int a_CenterZ);
@@ -74,9 +79,16 @@ public:
unsigned int GetNumBlocksPerPixel(void) const;
+ // tolua_end
+
private:
+ /** Update the specified pixel. */
+ bool UpdatePixel(unsigned int a_X, unsigned int a_Y);
+
+ void PixelToWorldCoords(unsigned int a_X, unsigned int a_Y, int & a_WorldX, int & a_WorldY);
+
unsigned int m_ID;
unsigned int m_Width;
diff --git a/src/World.cpp b/src/World.cpp
index a308778df..2a3e53332 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1554,6 +1554,42 @@ bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock
+cMap * cWorld::GetMapData(unsigned int a_ID)
+{
+ if (a_ID < m_MapData.size())
+ {
+ return &m_MapData[a_ID];
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+
+
+
+
+cMap * cWorld::CreateMap(int a_CenterX, int a_CenterY, int a_Scale)
+{
+ if (m_MapData.size() >= 65536)
+ {
+ LOGD("cWorld::CreateMap - Too many maps in use");
+
+ return NULL;
+ }
+
+ cMap Map(m_MapData.size(), a_CenterX, a_CenterY, this, a_Scale);
+
+ m_MapData.push_back(Map);
+
+ return &m_MapData[Map.GetID()];
+}
+
+
+
+
+
void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated)
{
MTRand r1;
@@ -2958,7 +2994,7 @@ void cWorld::LoadMapData(void)
IDSerializer.Load();
- unsigned int MapCount = IDSerializer.GetMapCount();
+ unsigned int MapCount = IDSerializer.GetMapCount() + 1;
m_MapData.clear();
@@ -2980,9 +3016,14 @@ void cWorld::LoadMapData(void)
void cWorld::SaveMapData(void)
{
+ if (m_MapData.empty())
+ {
+ return;
+ }
+
cIDCountSerializer IDSerializer(GetName());
- IDSerializer.SetMapCount(m_MapData.size());
+ IDSerializer.SetMapCount(m_MapData.size() - 1);
IDSerializer.Save();
diff --git a/src/World.h b/src/World.h
index 02e56a247..a9b1ca2cb 100644
--- a/src/World.h
+++ b/src/World.h
@@ -552,6 +552,12 @@ public:
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
+
+ /** Returns the map with the specified ID, NULL if out of range. */
+ cMap * GetMapData(unsigned int a_ID);
+
+ /** Creates a new map. Returns NULL on error */
+ cMap * CreateMap(int a_CenterX, int a_CenterY, int a_Scale = 3);
// tolua_end
diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp
index aab4c7816..6dab19d4f 100644
--- a/src/WorldStorage/MapSerializer.cpp
+++ b/src/WorldStorage/MapSerializer.cpp
@@ -111,7 +111,6 @@ void cMapSerializer::SaveMapToNBT(cFastNBTWriter & a_Writer)
a_Writer.AddInt("xCenter", m_Map->GetCenterX());
a_Writer.AddInt("zCenter", m_Map->GetCenterZ());
- // Potential bug - The internal representation may change
const cMap::cColorList & Data = m_Map->GetData();
a_Writer.AddByteArray("colors", (char *) Data.data(), Data.size());
@@ -134,7 +133,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
if (CurrLine >= 0)
{
unsigned int Scale = a_NBT.GetByte(CurrLine);
- m_Map->m_Scale = Scale;
+ m_Map->SetScale(Scale);
}
CurrLine = a_NBT.FindChildByName(Data, "dimension");
@@ -176,7 +175,11 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
unsigned int NumPixels = m_Map->GetNumPixels();
m_Map->m_Data.resize(NumPixels);
- // TODO xdot: Parse the byte array.
+ CurrLine = a_NBT.FindChildByName(Data, "colors");
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_ByteArray))
+ {
+ memcpy(m_Map->m_Data.data(), a_NBT.GetData(CurrLine), NumPixels);
+ }
return true;
}