Support for more than one mapblock/chunk | WARNING: Shitty performance, even on RTX 3070

This commit is contained in:
2022-10-29 14:09:42 -04:00
parent 6b05eaf331
commit 8cde72f632
4 changed files with 59 additions and 45 deletions

View File

@@ -7,8 +7,8 @@
#include "TextureHandler.h"
#include <cstdio>
#include <random>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
//#include <SFML/System.hpp>
//#include <SFML/Window.hpp>
NodeRenderer renderer;
//BlockManager blockManager;
@@ -37,28 +37,21 @@ void display()
glBegin(GL_QUADS);
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
if(nodeManager.getNodeAt(x, y, z) > 0)
{
textureHandler.getTextureForNode(x, y, z);
renderer.renderNode(x, y, z);
}
}
}
}
for(int x = 0; x < 16; x++)
for(int x = 0; x < 128; x++)
{
for(int z = 0; z < 16; z++)
for(int z = 0; z < 128; z++)
{
for(int y = 0; y < 256; y++)
{
if(nodeManager1.getNodeAt(x, y, z) > 0)
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, 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.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) > 0)
{
textureHandler.getTextureForNode(x, y, z);
renderer.renderNode(x, y, z);
@@ -71,10 +64,11 @@ void display()
glFlush();
glutSwapBuffers();
/*
sf::Vector2i lastMousePos = sf::Vector2i(0, 0);
sf::Vector2i mouseDelta = sf::Mouse::getPosition() - lastMousePos;
lastMousePos = sf::Mouse::getPosition();
const sf::Window& window = nullptr;
sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos;
lastMousePos = sf::Mouse::getPosition(window);*/
glutPostRedisplay();
}
@@ -172,30 +166,45 @@ int main(int argc, char **argv)
for(int x = 0; x < 16; x++)
for(int bx = 0; bx < 8; bx++)
{
for(int z = 0; z < 16; z++)
for(int bz = 0; bz < 8; bz++)
{
for(int y = 0; y < 256; y++)
for(int x = 0; x < 16; x++)
{
blockManager.mapBlocks[0][0].addNode(rand() % 3, 0, x, y, z);
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 16; y++)
{
blockManager.mapBlocks[bx][bz].addNode(rand() % 3, 0, x, y, z);
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
}
}
}
}
}
for(int x = 0; x < 16; x++)
/*
for(int x = 0; x < 32; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
for(int y = 0; y < 16; y++)
{
blockManager.mapBlocks[1][0].addNode(rand() % 3, 0, x, y, z);
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
printf("x - (blockX * 16): %i | X: %i, Y: %i, Z: %i, blockX: %i, blockZ: %i nodeAt: %i\n", x - (block.x * 16), x, y, z, block.x, block.z, blockManager.mapBlocks[block.x][block.z].getNodeAt(x - (block.x * 16), y, z));
}
}
}
*/
updateTimer();
glutDisplayFunc(&display);