1
0

Added cBlockArea:Expand() API function (untested)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1203 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-02-09 11:03:22 +00:00
parent d593a98249
commit bda7c4ac13
5 changed files with 161 additions and 6 deletions

View File

@ -108,31 +108,44 @@ function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, C
end
-- Rclk with a diamond to read a block area, dump it, crop it, dump it again, crop it again...
-- Rclk with a diamond to test block area cropping and expanding
if (Player:GetEquippedItem().m_ItemType == E_ITEM_DIAMOND) then
local Area = cBlockArea();
Area:Read(Player:GetWorld(),
BlockX - 9, BlockX + 9,
BlockX - 19, BlockX + 19,
BlockY - 7, BlockY + 7,
BlockZ - 9, BlockZ + 9
BlockZ - 19, BlockZ + 19
);
LOG("Size before cropping: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("crop0.dat");
Area:Crop(2, 3, 0, 0, 0, 0);
LOG("Size after cropping 1: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("crop1.dat");
Area:Crop(2, 3, 0, 0, 0, 0);
LOG("Size after cropping 2: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("crop2.dat");
Area:Expand(2, 3, 0, 0, 0, 0);
LOG("Size after expanding 1: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("expand1.dat");
Area:Expand(3, 2, 1, 1, 0, 0);
LOG("Size after expanding 2: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("expand2.dat");
Area:Crop(0, 0, 0, 0, 3, 2);
LOG("Size after cropping 3: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("crop3.dat");
Area:Crop(0, 0, 3, 2, 0, 0);
LOG("Size after cropping 4: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
Area:DumpToRawFile("crop4.dat");
LOG("Crop test done");
Player:SendMessage("Crop / expand test done.");
return false;
end
@ -193,7 +206,8 @@ function OnChunkGenerated(World, ChunkX, ChunkZ, ChunkDesc)
-- Test ChunkDesc / BlockArea interaction
local BlockArea = cBlockArea();
ChunkDesc:ReadBlockArea(BlockArea, 0, 15, 50, 70, 0, 15);
BlockArea:SaveToSchematicFile("ChunkBlocks_" .. ChunkX .. "_" .. ChunkZ .. ".schematic");
-- BlockArea:SaveToSchematicFile("ChunkBlocks_" .. ChunkX .. "_" .. ChunkZ .. ".schematic");
ChunkDesc:WriteBlockArea(BlockArea, 5, 115, 5);
return false;

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 02/08/13 21:06:19.
** Generated automatically by tolua++-1.0.92 on 02/09/13 10:54:12.
*/
#ifndef __cplusplus
@ -18038,6 +18038,49 @@ static int tolua_AllToLua_cBlockArea_Crop00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: Expand of class cBlockArea */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_Expand00
static int tolua_AllToLua_cBlockArea_Expand00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnumber(tolua_S,5,0,&tolua_err) ||
!tolua_isnumber(tolua_S,6,0,&tolua_err) ||
!tolua_isnumber(tolua_S,7,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,8,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
int a_SubMinX = ((int) tolua_tonumber(tolua_S,2,0));
int a_AddMaxX = ((int) tolua_tonumber(tolua_S,3,0));
int a_SubMinY = ((int) tolua_tonumber(tolua_S,4,0));
int a_AddMaxY = ((int) tolua_tonumber(tolua_S,5,0));
int a_SubMinZ = ((int) tolua_tonumber(tolua_S,6,0));
int a_AddMaxZ = ((int) tolua_tonumber(tolua_S,7,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Expand'", NULL);
#endif
{
self->Expand(a_SubMinX,a_AddMaxX,a_SubMinY,a_AddMaxY,a_SubMinZ,a_AddMaxZ);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'Expand'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: SetRelBlockType of class cBlockArea */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_SetRelBlockType00
static int tolua_AllToLua_cBlockArea_SetRelBlockType00(lua_State* tolua_S)
@ -22168,6 +22211,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"LoadFromSchematicFile",tolua_AllToLua_cBlockArea_LoadFromSchematicFile00);
tolua_function(tolua_S,"SaveToSchematicFile",tolua_AllToLua_cBlockArea_SaveToSchematicFile00);
tolua_function(tolua_S,"Crop",tolua_AllToLua_cBlockArea_Crop00);
tolua_function(tolua_S,"Expand",tolua_AllToLua_cBlockArea_Expand00);
tolua_function(tolua_S,"SetRelBlockType",tolua_AllToLua_cBlockArea_SetRelBlockType00);
tolua_function(tolua_S,"SetBlockType",tolua_AllToLua_cBlockArea_SetBlockType00);
tolua_function(tolua_S,"SetRelBlockMeta",tolua_AllToLua_cBlockArea_SetRelBlockMeta00);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 02/08/13 21:06:20.
** Generated automatically by tolua++-1.0.92 on 02/09/13 10:54:12.
*/
/* Exported function */

View File

@ -357,6 +357,36 @@ void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY
void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{
if (HasBlockTypes())
{
ExpandBlockTypes(a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
}
if (HasBlockMetas())
{
ExpandNibbles(m_BlockMetas, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
}
if (HasBlockLights())
{
ExpandNibbles(m_BlockLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
}
if (HasBlockSkyLights())
{
ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
}
m_OriginX -= a_SubMinX;
m_OriginY -= a_SubMinY;
m_OriginZ -= a_SubMinZ;
m_SizeX += a_SubMinX + a_AddMaxX;
m_SizeY += a_SubMinY + a_AddMaxY;
m_SizeZ += a_SubMinZ + a_AddMaxZ;
}
void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
{
if (m_BlockTypes == NULL)
@ -973,6 +1003,66 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX
void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{
int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX;
int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY;
int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ;
int BlockCount = NewSizeX * NewSizeY * NewSizeZ;
BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount];
memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE));
int OldIndex = 0;
for (int y = 0; y < m_SizeY; y++)
{
int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ;
for (int z = 0; z < m_SizeZ; z++)
{
int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX;
int idx = IndexBaseZ + a_SubMinX;
for (int x = 0; x < m_SizeX; x++)
{
NewBlockTypes[idx++] = m_BlockTypes[OldIndex++];
} // for x
} // for z
} // for y
delete m_BlockTypes;
m_BlockTypes = NewBlockTypes;
}
void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{
int NewSizeX = m_SizeX + a_SubMinX + a_AddMaxX;
int NewSizeY = m_SizeY + a_SubMinY + a_AddMaxY;
int NewSizeZ = m_SizeZ + a_SubMinZ + a_AddMaxZ;
int BlockCount = NewSizeX * NewSizeY * NewSizeZ;
NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount];
memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE));
int OldIndex = 0;
for (int y = 0; y < m_SizeY; y++)
{
int IndexBaseY = (y + a_SubMinY) * m_SizeX * m_SizeZ;
for (int z = 0; z < m_SizeZ; z++)
{
int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_SizeX;
int idx = IndexBaseZ + a_SubMinX;
for (int x = 0; x < m_SizeX; x++)
{
NewNibbles[idx++] = a_Array[OldIndex++];
} // for x
} // for z
} // for y
delete a_Array;
a_Array = NewNibbles;
}
bool cBlockArea::LoadFromSchematicNBT(cParsedNBT & a_NBT)
{
int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");

View File

@ -77,6 +77,9 @@ public:
/// Crops the internal contents by the specified amount of blocks from each border.
void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
/// Expands the internal contents by the specified amount of blocks from each border
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
// Setters:
void SetRelBlockType (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType);
void SetBlockType (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType);
@ -186,6 +189,10 @@ protected:
void CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
void CropNibbles (NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
// Expand helpers:
void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
void ExpandNibbles (NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
/// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful.
bool LoadFromSchematicNBT(cParsedNBT & a_NBT);