Split MapBlock's header and implementation
This commit is contained in:
parent
37676b72be
commit
5471f17bad
67
MapBlock.cpp
Normal file
67
MapBlock.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#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;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1667164139 source:c:\development\xtreemminer\main.cpp
|
1667164816 source:c:\development\xtreemminer\main.cpp
|
||||||
<stdlib.h>
|
<stdlib.h>
|
||||||
<GL/glut.h>
|
<GL/glut.h>
|
||||||
"Utilities.h"
|
"Utilities.h"
|
||||||
@ -11,13 +11,14 @@
|
|||||||
<cstdio>
|
<cstdio>
|
||||||
"FastNoiseLite.h"
|
"FastNoiseLite.h"
|
||||||
<random>
|
<random>
|
||||||
|
<SFML/Window.hpp>
|
||||||
|
|
||||||
1667164197 c:\development\xtreemminer\include\noderenderer.h
|
1667164197 c:\development\xtreemminer\include\noderenderer.h
|
||||||
"Base.h"
|
"Base.h"
|
||||||
"MapBlock.h"
|
"MapBlock.h"
|
||||||
<GL/glut.h>
|
<GL/glut.h>
|
||||||
|
|
||||||
1667161818 c:\development\xtreemminer\include\mapblock.h
|
1667167677 c:\development\xtreemminer\include\mapblock.h
|
||||||
"Base.h"
|
"Base.h"
|
||||||
<math.h>
|
<math.h>
|
||||||
<cstdio>
|
<cstdio>
|
||||||
@ -54,3 +55,6 @@
|
|||||||
1667079584 c:\development\xtreemminer\include\fastnoiselite.h
|
1667079584 c:\development\xtreemminer\include\fastnoiselite.h
|
||||||
<cmath>
|
<cmath>
|
||||||
|
|
||||||
|
1667167831 source:c:\development\xtreemminer\mapblock.cpp
|
||||||
|
"MapBlock.h"
|
||||||
|
|
||||||
|
@ -1,91 +1,33 @@
|
|||||||
#ifndef MAPBLOCK_H
|
#ifndef MAPBLOCK
|
||||||
#define MAPBLOCK_H
|
#define MAPBLOCK
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MapBlock
|
class MapBlock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int mapBlock[65536];
|
int mapBlock[65536];
|
||||||
|
MapBlock();
|
||||||
|
// TODO; Make this function work with global coordinates and move it to BlockManager
|
||||||
|
void addNode(int id, int meta, int x, int y, int z);
|
||||||
|
|
||||||
MapBlock()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int getNodeAt(int x, int y, int z) // Deprecated; only used internally.
|
|
||||||
{
|
|
||||||
return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addNode(int id, int meta, int x, int y, int z)
|
|
||||||
{
|
|
||||||
mapBlock[256 * y + z * 16 + x] = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlockUtilities
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BlockUtilities()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static Position2D getBlockFromNodeCoordinates(int x, int z)
|
|
||||||
{
|
|
||||||
Position2D pos2d;
|
|
||||||
pos2d.x = floor(x / 16);
|
|
||||||
pos2d.z = floor(z / 16);
|
|
||||||
return pos2d;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BlockManager
|
class BlockManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MapBlock mapBlocks[16][16]; // 16 x 16 blocks
|
MapBlock mapBlocks[16][16];
|
||||||
|
BlockManager();
|
||||||
BlockManager()
|
int getNodeAt(int x, int y, int z);
|
||||||
{
|
bool isAir(int x, int y, int z);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int getNodeAt(int x, int y, int z)
|
|
||||||
{
|
|
||||||
//if(x < 16 && x >= 0 && z < 16 && z >= 0)
|
|
||||||
//{
|
|
||||||
if(x < 0 || y < 0 || z < 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
|
||||||
//printf("\n\nold x: %i, old z: %i", x, z);
|
|
||||||
int localX = x - block.x * 16;
|
|
||||||
int localZ = z - block.z * 16;
|
|
||||||
//printf("\nnew x: %i, new z: %i", x, z);
|
|
||||||
return mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX];
|
|
||||||
//return mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isAir(int x, int y, int z)
|
|
||||||
{
|
|
||||||
return getNodeAt(x, y, z) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BlockUtilities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BlockUtilities();
|
||||||
|
static Position2D getBlockFromNodeCoordinates(int x, int z);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user