Send map when selected
This commit is contained in:
parent
32b465b8e1
commit
5b92b877bc
@ -47,6 +47,7 @@ $cfile "../ItemGrid.h"
|
|||||||
$cfile "../BlockEntities/BlockEntity.h"
|
$cfile "../BlockEntities/BlockEntity.h"
|
||||||
$cfile "../BlockEntities/BlockEntityWithItems.h"
|
$cfile "../BlockEntities/BlockEntityWithItems.h"
|
||||||
$cfile "../BlockEntities/ChestEntity.h"
|
$cfile "../BlockEntities/ChestEntity.h"
|
||||||
|
$cfile "../BlockEntities/CommandBlockEntity.h"
|
||||||
$cfile "../BlockEntities/DropSpenserEntity.h"
|
$cfile "../BlockEntities/DropSpenserEntity.h"
|
||||||
$cfile "../BlockEntities/DispenserEntity.h"
|
$cfile "../BlockEntities/DispenserEntity.h"
|
||||||
$cfile "../BlockEntities/DropperEntity.h"
|
$cfile "../BlockEntities/DropperEntity.h"
|
||||||
|
@ -1190,6 +1190,19 @@ void cClientHandle::HandleSlotSelected(short a_SlotNum)
|
|||||||
{
|
{
|
||||||
m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum);
|
m_Player->GetInventory().SetEquippedSlotNum(a_SlotNum);
|
||||||
m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
53
src/Map.cpp
53
src/Map.cpp
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "ClientHandle.h"
|
#include "ClientHandle.h"
|
||||||
#include "World.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_World(a_World)
|
||||||
{
|
{
|
||||||
m_Data.assign(m_Width * m_Height, 0);
|
m_Data.assign(m_Width * m_Height, 0);
|
||||||
|
|
||||||
// Do not update map
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -41,19 +40,6 @@ cMap::cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, un
|
|||||||
{
|
{
|
||||||
m_Data.assign(m_Width * m_Height, 0);
|
m_Data.assign(m_Width * m_Height, 0);
|
||||||
|
|
||||||
UpdateMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMap::UpdateMap(void)
|
|
||||||
{
|
|
||||||
// ASSERT(m_World != NULL);
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
for (unsigned int X = 0; X < m_Width; ++X)
|
for (unsigned int X = 0; X < m_Width; ++X)
|
||||||
{
|
{
|
||||||
for (unsigned int Y = 0; Y < m_Height; ++Y)
|
for (unsigned int Y = 0; Y < m_Height; ++Y)
|
||||||
@ -68,6 +54,37 @@ void cMap::UpdateMap(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Y)
|
||||||
|
{
|
||||||
|
ASSERT(m_World != NULL);
|
||||||
|
|
||||||
|
cChunk * Chunk = NULL;
|
||||||
|
|
||||||
|
if (Chunk == NULL)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
eDimension cMap::GetDimension(void) const
|
eDimension cMap::GetDimension(void) const
|
||||||
{
|
{
|
||||||
ASSERT(m_World != NULL);
|
ASSERT(m_World != NULL);
|
||||||
@ -90,8 +107,6 @@ void cMap::Resize(unsigned int a_Width, unsigned int a_Height)
|
|||||||
m_Height = a_Height;
|
m_Height = a_Height;
|
||||||
|
|
||||||
m_Data.assign(m_Width * m_Height, 0);
|
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_CenterX = a_CenterX;
|
||||||
m_CenterZ = a_CenterZ;
|
m_CenterZ = a_CenterZ;
|
||||||
|
|
||||||
UpdateMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -123,8 +136,6 @@ void cMap::SetScale(unsigned int a_Scale)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Scale = a_Scale;
|
m_Scale = a_Scale;
|
||||||
|
|
||||||
UpdateMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
20
src/Map.h
20
src/Map.h
@ -26,28 +26,33 @@ class cWorld;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// tolua_begin
|
||||||
class cMap
|
class cMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef Byte ColorID;
|
typedef Byte ColorID;
|
||||||
|
|
||||||
|
// tolua_end
|
||||||
|
|
||||||
typedef std::vector<ColorID> cColorList;
|
typedef std::vector<ColorID> cColorList;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Construct an empty map
|
/** Construct an empty map. */
|
||||||
cMap(unsigned int a_ID, cWorld * a_World);
|
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);
|
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. */
|
/** Send this map to the specified client. */
|
||||||
void SendTo(cClientHandle & a_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 Resize(unsigned int a_Width, unsigned int a_Height);
|
||||||
|
|
||||||
void SetPosition(int a_CenterX, int a_CenterZ);
|
void SetPosition(int a_CenterX, int a_CenterZ);
|
||||||
@ -74,9 +79,16 @@ public:
|
|||||||
|
|
||||||
unsigned int GetNumBlocksPerPixel(void) const;
|
unsigned int GetNumBlocksPerPixel(void) const;
|
||||||
|
|
||||||
|
// tolua_end
|
||||||
|
|
||||||
|
|
||||||
private:
|
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_ID;
|
||||||
|
|
||||||
unsigned int m_Width;
|
unsigned int m_Width;
|
||||||
|
@ -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)
|
void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated)
|
||||||
{
|
{
|
||||||
MTRand r1;
|
MTRand r1;
|
||||||
@ -2958,7 +2994,7 @@ void cWorld::LoadMapData(void)
|
|||||||
|
|
||||||
IDSerializer.Load();
|
IDSerializer.Load();
|
||||||
|
|
||||||
unsigned int MapCount = IDSerializer.GetMapCount();
|
unsigned int MapCount = IDSerializer.GetMapCount() + 1;
|
||||||
|
|
||||||
m_MapData.clear();
|
m_MapData.clear();
|
||||||
|
|
||||||
@ -2980,9 +3016,14 @@ void cWorld::LoadMapData(void)
|
|||||||
|
|
||||||
void cWorld::SaveMapData(void)
|
void cWorld::SaveMapData(void)
|
||||||
{
|
{
|
||||||
|
if (m_MapData.empty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cIDCountSerializer IDSerializer(GetName());
|
cIDCountSerializer IDSerializer(GetName());
|
||||||
|
|
||||||
IDSerializer.SetMapCount(m_MapData.size());
|
IDSerializer.SetMapCount(m_MapData.size() - 1);
|
||||||
|
|
||||||
IDSerializer.Save();
|
IDSerializer.Save();
|
||||||
|
|
||||||
|
@ -553,6 +553,12 @@ public:
|
|||||||
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
|
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
|
||||||
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
|
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
|
// tolua_end
|
||||||
|
|
||||||
inline static void BlockToChunk( int a_X, int a_Y, int a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
|
inline static void BlockToChunk( int a_X, int a_Y, int a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
|
||||||
|
@ -111,7 +111,6 @@ void cMapSerializer::SaveMapToNBT(cFastNBTWriter & a_Writer)
|
|||||||
a_Writer.AddInt("xCenter", m_Map->GetCenterX());
|
a_Writer.AddInt("xCenter", m_Map->GetCenterX());
|
||||||
a_Writer.AddInt("zCenter", m_Map->GetCenterZ());
|
a_Writer.AddInt("zCenter", m_Map->GetCenterZ());
|
||||||
|
|
||||||
// Potential bug - The internal representation may change
|
|
||||||
const cMap::cColorList & Data = m_Map->GetData();
|
const cMap::cColorList & Data = m_Map->GetData();
|
||||||
a_Writer.AddByteArray("colors", (char *) Data.data(), Data.size());
|
a_Writer.AddByteArray("colors", (char *) Data.data(), Data.size());
|
||||||
|
|
||||||
@ -134,7 +133,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
|
|||||||
if (CurrLine >= 0)
|
if (CurrLine >= 0)
|
||||||
{
|
{
|
||||||
unsigned int Scale = a_NBT.GetByte(CurrLine);
|
unsigned int Scale = a_NBT.GetByte(CurrLine);
|
||||||
m_Map->m_Scale = Scale;
|
m_Map->SetScale(Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrLine = a_NBT.FindChildByName(Data, "dimension");
|
CurrLine = a_NBT.FindChildByName(Data, "dimension");
|
||||||
@ -176,7 +175,11 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
|
|||||||
unsigned int NumPixels = m_Map->GetNumPixels();
|
unsigned int NumPixels = m_Map->GetNumPixels();
|
||||||
m_Map->m_Data.resize(NumPixels);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user