XtreemNodes/MapBlock.cpp

68 lines
1.2 KiB
C++

#include "MapBlock.h"
int mapBlock[65536];
MapBlock::MapBlock()
{
}
// TODO; Make this function work with global coordinates and move it to BlockManager
void MapBlock::addNode(int id, int meta, int x, int y, int z)
{
mapBlock[256 * y + z * 16 + x] = id;
}
MapBlock mapBlocks[16][16];
BlockManager::BlockManager()
{
}
int BlockManager::getNodeAt(int x, int y, int z)
{
// Math explanation for future reference:
// The x and z coordinates need to be have block.[AXIS] * 16 subtracted from them
// so that the coordinates passed to the function are local block coordinates instead
// of global node coordinates (e.g. 1, and not 17)
if(x < 0 || y < 0 || z < 0)
{
return 0;
}
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
int localX = x - block.x * 16;
int localZ = z - block.z * 16;
return mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX];
}
bool BlockManager::isAir(int x, int y, int z)
{
return getNodeAt(x, y, z) == 0;
}
BlockUtilities::BlockUtilities()
{
}
Position2D BlockUtilities::getBlockFromNodeCoordinates(int x, int z)
{
Position2D pos2d;
pos2d.x = floor(x / 16);
pos2d.z = floor(z / 16);
return pos2d;
}