readd diverged version

This commit is contained in:
2023-09-23 21:19:52 +00:00
parent 45d324a9ec
commit 7e7a73f9b6
24 changed files with 11587 additions and 0 deletions

19
include/Base.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef BASE
#define BASE
#include "MapBlock.h"
class NodeManager;
class BlockManager;
extern NodeManager nodeManager;
extern BlockManager blockManager;
extern float light;
/*struct Position2D
{
int x;
int z;
};*/
#endif

19
include/Camera.h Normal file
View File

@@ -0,0 +1,19 @@
#include <glm/glm.hpp>
#include <glm/ext/matrix_transform.hpp>
class Camera
{
public:
Camera() = default;
virtual ~Camera()
{
}
const glm::mat4& get_view();
const glm::mat4& get_projection();
protected:
const glm::mat4& matrix;
glm::mat4 m_view, m_projection;
};

2586
include/FastNoiseLite.h Normal file

File diff suppressed because it is too large Load Diff

26
include/GUI.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef GUI
#define GUI
#include "Base.h"
#include <SFML/Main.hpp>
#include <SFML/Graphics.hpp>
class Button
{
public:
Button(sf::Image* normal, sf::Image* clicked, std::string text, Position2D location);
void checkClick(Position2D);
void setState(bool state);
void setText(std::string);
bool getVar();
sf::Sprite* getSprite();
sf::String* getText();
private:
sf::Sprite normal;
sf::Sprite clicked;
sf::Sprite* currentSpr;
sf::String String;
bool current;
};
#endif

21
include/LevelGenerator.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef LEVELGENERATOR
#define LEVELGENERATOR
#include "FastNoiseLite.h"
class LevelGenerator
{
public:
LevelGenerator();
void setSeed();
void generateBlock();
void terraformBlock();
void populate();
protected:
private:
FastNoiseLite perlin, os, cellular;
int seed = 138; // 1338, 1337. 138 are good ones
};
#endif

11
include/Logger.h Normal file
View File

@@ -0,0 +1,11 @@
#include <cstdio>
class Logger
{
public:
void log(char* comp, char* message);
{
printf("Message: %c", message);
}
};

38
include/MapBlock.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef MAPBLOCK
#define MAPBLOCK
#include "Base.h"
#include <math.h>
#include <cstdio>
class MapBlock
{
public:
int mapBlock[65536];
MapBlock();
};
class BlockManager
{
public:
MapBlock mapBlocks[16][16];
BlockManager();
int getNodeAt(int x, int y, int z);
void addNode(int id, int meta, int x, int y, int z);
bool isAir(int x, int y, int z);
bool isNodeClear(int x, int y, int z);
};
struct Position2D
{
int x;
int z;
};
class BlockUtilities
{
public:
BlockUtilities();
static Position2D getBlockFromNodeCoordinates(int x, int z);
};
#endif

285
include/NodeRenderer.h Normal file
View File

@@ -0,0 +1,285 @@
#ifndef NODERENDERER_H
#define NODERENDERER_H
#include "Base.h"
#include "MapBlock.h"
#include <GL/glut.h>
class NodeRenderer
{
public:
NodeRenderer()
{
}
virtual ~NodeRenderer()
{
}
int renderNode(int x, int y, int z, int tex)
{
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
Position2D textureCoordinate;
textureCoordinate.x = tex - (16 * floor(tex / 16));
textureCoordinate.z = floor(tex / 16) + 1;
//glColor3f(light, light, light);
glBegin(GL_TRIANGLES);
// Front
if(blockManager.isAir(x, y, z - 1))
{
/*glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
//glColor3f(.6F, .6F, .6F); // Bottom vertices
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0F, .0625F * textureCoordinate);
glVertex3f(x + .0F, y + .0F, z + .0F);*/
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
//glColor3f(.6F, .6F, .6F); // Bottom vertices
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + .0F);
//glColor3f(.6F, .6F, .6F); // Bottom vertices
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
}
// Back
if(blockManager.isAir(x, y, z + 1))
{
/*glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * textureCoordinate, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
//glColor3f(.6F, .6F, .6F);
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0F, .0625F * textureCoordinate);
glVertex3f(x + .0F, y + .0F, z + 1.0F);*/
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
//glColor3f(.6F, .6F, .6F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
//glColor3f(.6F, .6F, .6F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Right
if(blockManager.isAir(x + 1, y, z))
{
/*glTexCoord2f(.0625F * textureCoordinate, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
//glColor3f(.6F, .6F, .6F);
glTexCoord2f(.0625F * textureCoordinate, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0F, .0625F * textureCoordinate);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);*/
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
//glColor3f(.6F, .6F, .6F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Left
if(blockManager.isAir(x - 1, y, z))
{
/*glTexCoord2f(.0625F * textureCoordinate, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
//glColor3f(.6F, .6F, .6F);
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0F, .0625F * textureCoordinate);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);*/
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + .0F);
//glColor3i(100, 100, 100);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + .0F);
//glColor3i(255, 255, 255);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + .0F);
//glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
}
// Bottom
//printf("\n\nx: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
if(y > 0 && 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);
glTexCoord2f(.0625F * textureCoordinate, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0625F * textureCoordinate);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);*/
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0625F * textureCoordinate.x);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
}
// Top
if(blockManager.isNodeClear(x, y + 1, z))
{
/*glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0F, .0625F * textureCoordinate);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);*/
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
}
glEnd();
return 1;
}
protected:
private:
};
#endif

17
include/Nodes.h Normal file
View File

@@ -0,0 +1,17 @@
class Node
{
public:
Node(int i, int j)
{
id = i;
textureIndex = j;
}
int getTextureIndexFromSide(int side)
{
return textureIndex;
}
private:
int id;
int textureIndex;
};

77
include/TextureHandler.h Normal file
View File

@@ -0,0 +1,77 @@
#define STBI_FAILURE_USERMSG
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "Base.h"
#ifndef TEXTURE_HANDLER
#define TEXTURE_HANDLER
class TextureHandler
{
private:
int width = -1;
int height = -1;
int comp = -1;
unsigned char* imageData;
unsigned char* imageData1;
public:
GLuint texture;
unsigned char* loadTexture(char* filename)
{
return stbi_load(filename, &width, &height, &comp, 0);
}
void loadAllTextures()
{
int textureIndex = 0;
imageData = loadTexture("data/img/texturemap.png");
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
}
int getTextureForNode(int x, int y, int z)
{
//Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
if(blockManager.getNodeAt(x, y, z) == 1)
{
return 1;
}
else if(blockManager.getNodeAt(x, y, z) == 2)
{
return 2;
}
else if(blockManager.getNodeAt(x, y, z) == 3)
{
return 4;
}
else if(blockManager.getNodeAt(x, y, z) == 12)
{
return 81;
}
else if(blockManager.getNodeAt(x, y, z) == 13)
{
return 113;
}
else if(blockManager.getNodeAt(x, y, z) == 20)
{
return 17;
}
}
};
#endif

15
include/TitleMenu.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef TITLEMENU
#define TITLEMENU
class TitleMenu
{
public:
TitleMenu()
{
}
void renderGUI();
};
#endif

24
include/Utilities.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef UTILITIES
#define UTILITIES
class Utilities
{
public:
Utilities()
{
}
static float degToRad(int degrees)
{
return 3.14 / 180 * degrees; // Only the first three digits of pi
}
protected:
private:
};
#endif

7898
include/stb_image.h Normal file

File diff suppressed because it is too large Load Diff