Compare commits
4 Commits
3aa203bac9
...
04ad3afe7d
Author | SHA1 | Date | |
---|---|---|---|
04ad3afe7d | |||
5471f17bad | |||
37676b72be | |||
a0bec8bfc5 |
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
|
||||
1667158149 source:c:\development\xtreemminer\main.cpp
|
||||
1667164816 source:c:\development\xtreemminer\main.cpp
|
||||
<stdlib.h>
|
||||
<GL/glut.h>
|
||||
"Utilities.h"
|
||||
@ -11,13 +11,14 @@
|
||||
<cstdio>
|
||||
"FastNoiseLite.h"
|
||||
<random>
|
||||
<SFML/Window.hpp>
|
||||
|
||||
1667158420 c:\development\xtreemminer\include\noderenderer.h
|
||||
1667164197 c:\development\xtreemminer\include\noderenderer.h
|
||||
"Base.h"
|
||||
"MapBlock.h"
|
||||
<GL/glut.h>
|
||||
|
||||
1667156676 c:\development\xtreemminer\include\mapblock.h
|
||||
1667167677 c:\development\xtreemminer\include\mapblock.h
|
||||
"Base.h"
|
||||
<math.h>
|
||||
<cstdio>
|
||||
@ -54,3 +55,6 @@
|
||||
1667079584 c:\development\xtreemminer\include\fastnoiselite.h
|
||||
<cmath>
|
||||
|
||||
1667167831 source:c:\development\xtreemminer\mapblock.cpp
|
||||
"MapBlock.h"
|
||||
|
||||
|
@ -1,91 +1,33 @@
|
||||
#ifndef MAPBLOCK_H
|
||||
#define MAPBLOCK_H
|
||||
#ifndef MAPBLOCK
|
||||
#define MAPBLOCK
|
||||
#include "Base.h"
|
||||
#include <math.h>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MapBlock
|
||||
{
|
||||
public:
|
||||
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
|
||||
{
|
||||
public:
|
||||
MapBlock mapBlocks[16][16]; // 16 x 16 blocks
|
||||
|
||||
BlockManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int getNodeAt(int x, int y, int z)
|
||||
{
|
||||
//if(x < 16 && x >= 0 && z < 16 && z >= 0)
|
||||
//{
|
||||
if(x < 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, y, z);
|
||||
}
|
||||
|
||||
bool isAir(int x, int y, int z)
|
||||
{
|
||||
return getNodeAt(x, y, z) == 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MapBlock mapBlocks[16][16];
|
||||
BlockManager();
|
||||
int getNodeAt(int x, int y, int z);
|
||||
bool isAir(int x, int y, int z);
|
||||
};
|
||||
|
||||
|
||||
class BlockUtilities
|
||||
{
|
||||
public:
|
||||
BlockUtilities();
|
||||
static Position2D getBlockFromNodeCoordinates(int x, int z);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -25,7 +25,7 @@ class NodeRenderer
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
// Front
|
||||
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16 - 1) == 0)
|
||||
if(blockManager.isAir(x, y, z - 1))
|
||||
{
|
||||
glTexCoord2f(.0F, .0F);
|
||||
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||
@ -43,7 +43,7 @@ class NodeRenderer
|
||||
}
|
||||
|
||||
// Back
|
||||
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16 + 1) == 0)
|
||||
if(blockManager.isAir(x, y, z + 1))
|
||||
{
|
||||
|
||||
glTexCoord2f(.0F, .0F);
|
||||
@ -62,7 +62,7 @@ class NodeRenderer
|
||||
}
|
||||
|
||||
// Right
|
||||
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16 + 1, y, z - block.z * 16) == 0);
|
||||
if(blockManager.isAir(x + 1, y, z))
|
||||
{
|
||||
glTexCoord2f(1.0F, .0F);
|
||||
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||
@ -80,7 +80,7 @@ class NodeRenderer
|
||||
}
|
||||
|
||||
// Left
|
||||
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16 - 1, y, z - block.z * 16) == 0);
|
||||
if(blockManager.isAir(x - 1, y, z))
|
||||
{
|
||||
glTexCoord2f(1.0F, .0F);
|
||||
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
||||
@ -98,8 +98,10 @@ class NodeRenderer
|
||||
}
|
||||
|
||||
// Bottom
|
||||
if(blockManager.getNodeAt(x, y - 1, z) == 0);
|
||||
//printf("\n\nx: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
||||
if(blockManager.isAir(x, y - 1, z))
|
||||
{
|
||||
//printf("\nWUT? x: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
||||
glTexCoord2f(.0F, .0F);
|
||||
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||
|
||||
@ -114,7 +116,7 @@ class NodeRenderer
|
||||
}
|
||||
|
||||
// Top
|
||||
/*if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y + 1, z - block.z * 16) == 0);
|
||||
if(blockManager.isAir(x, y + 1, z))
|
||||
{
|
||||
glTexCoord2f(.0F, .0F);
|
||||
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
||||
@ -127,7 +129,7 @@ class NodeRenderer
|
||||
|
||||
glTexCoord2f(.0F, 1.0F);
|
||||
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
||||
}*/
|
||||
}
|
||||
|
||||
glEnd();
|
||||
return 1;
|
||||
|
79
main.cpp
79
main.cpp
@ -9,8 +9,7 @@
|
||||
#include <cstdio>
|
||||
#include "FastNoiseLite.h"
|
||||
#include <random>
|
||||
//#include <SFML/System.hpp>
|
||||
//#include <SFML/Window.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
|
||||
NodeRenderer renderer;
|
||||
//BlockManager blockManager;
|
||||
@ -43,18 +42,12 @@ void display()
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
|
||||
for(int x = 0; x < 16; x++)
|
||||
for(int x = 0; x < 64; x++)
|
||||
{
|
||||
for(int y = 0; y < 64; y++)
|
||||
{
|
||||
for(int z = 0; z < 16; z++)
|
||||
for(int z = 0; z < 64; z++)
|
||||
{
|
||||
|
||||
|
||||
// Math explanation for future reference:
|
||||
// The if statement below checks if the node at the coordinate is greater than 0 (0 = air), 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(blockManager.getNodeAt(x, y, z) > 0)
|
||||
{
|
||||
textureHandler.getTextureForNode(x, y, z);
|
||||
@ -92,79 +85,57 @@ void reshape(int width, int height)
|
||||
|
||||
void updateTimer(int time)
|
||||
{
|
||||
glutPostRedisplay();
|
||||
glutTimerFunc(30, &updateTimer, 0);
|
||||
}
|
||||
|
||||
void KeyboardFunc(unsigned char key, int x, int y)
|
||||
{
|
||||
if(key == 'a')
|
||||
{
|
||||
playerX += .8F;
|
||||
}
|
||||
|
||||
if(key == 'd')
|
||||
{
|
||||
playerX -= .8F;
|
||||
}
|
||||
|
||||
if(key == 'w')
|
||||
// Movement
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
|
||||
{
|
||||
playerZ += .8;
|
||||
}
|
||||
|
||||
if(key == 's')
|
||||
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
|
||||
{
|
||||
playerZ -= .8;
|
||||
}
|
||||
|
||||
if(key == 'q')
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
|
||||
{
|
||||
playerY += .8F;
|
||||
playerX += .8;
|
||||
}
|
||||
|
||||
if(key == 'e')
|
||||
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
|
||||
{
|
||||
playerY -= .8F;
|
||||
playerX -= .8;
|
||||
}
|
||||
|
||||
if(key == 't')
|
||||
// Rotation
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||
{
|
||||
playerRotX -= .8F;
|
||||
playerRotY -= .8;
|
||||
}
|
||||
|
||||
if(key == 'g')
|
||||
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||
{
|
||||
playerRotX += .8F;
|
||||
playerRotY += .8;
|
||||
}
|
||||
|
||||
if(key == 'f')
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||
{
|
||||
playerRotY -= .8F;
|
||||
playerRotX -= .8;
|
||||
}
|
||||
|
||||
if(key == 'h')
|
||||
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||
{
|
||||
playerRotY += .8F;
|
||||
playerRotX += .8;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(key == 27)
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
glutPostRedisplay();
|
||||
glutTimerFunc(30, &updateTimer, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
@ -197,9 +168,9 @@ int main(int argc, char **argv)
|
||||
cellular.SetNoiseType(FastNoiseLite::NoiseType_Cellular);
|
||||
cellular.SetFrequency(.1F);
|
||||
|
||||
for(int bx = 0; bx < 16; bx++)
|
||||
for(int bx = 0; bx < 4; bx++)
|
||||
{
|
||||
for(int bz = 0; bz < 16; bz++)
|
||||
for(int bz = 0; bz < 4; bz++)
|
||||
{
|
||||
for(int x = 0; x < 16; x++)
|
||||
{
|
||||
@ -218,7 +189,6 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
for(int y = 0; y < 16; y++)
|
||||
{
|
||||
@ -241,7 +211,6 @@ int main(int argc, char **argv)
|
||||
updateTimer(0);
|
||||
glutDisplayFunc(&display);
|
||||
glutReshapeFunc(&reshape);
|
||||
glutKeyboardFunc(&KeyboardFunc);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user