Started rewrite for chunks to come. Left old face and voxel code

This commit is contained in:
Ben Kyd
2019-10-17 16:43:50 +01:00
parent 5a1a226ef2
commit 9dffa6f24f
10 changed files with 59 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
#version 330
#version 450
in vec3 TexCoord;

View File

@@ -1,4 +1,4 @@
#version 330
#version 450
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 texcoord;

View File

@@ -82,17 +82,20 @@ void Game::Setup(int w, int h) {
m_cameras["Default"] = std::make_shared<Camera>(w, h);
m_activeCamera = m_cameras["Default"];
BlockDictionary.Build();
m_world = std::make_unique<World>();
m_world->Chunks.push_back(std::make_shared<Chunk>());
m_world->Chunks.push_back(std::make_shared<Chunk>(0, 0));
m_world->Chunks.push_back(std::make_shared<Chunk>(1, 1));
m_world->Chunks.push_back(std::make_shared<Chunk>(1, 3));
m_world->Shaders["Basic"] = std::make_shared<Shader>();
m_world->Shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple");
m_world->Shaders["Basic"]->Link();
Texture texture;
m_world->TextureID = texture.LoadTextures(TextureIdsAndPaths);
m_world->TextureID = texture.LoadTextures(BlockDictionary.Textures);
}

View File

@@ -12,7 +12,6 @@
#include <string>
#include <map>
#if _WIN32
#include <SDL.h>
#else

View File

@@ -17,7 +17,7 @@ public:
void MouseMoved(glm::vec2 mouseDelta);
float MouseSensitivity = 0.1f;
float CameraSpeed = 0.1f;
float CameraSpeed = 0.2f;
private:
float roll, pitch, yaw;

View File

@@ -5,13 +5,15 @@
#include "voxel.hpp"
Chunk::Chunk() {
Chunk::Chunk(int x, int z) {
m_model = glm::mat4(1.0f);
m_model = glm::translate(glm::mat4(1.0f), { x * CHUNK_WIDTH, 0, z * CHUNK_DEPTH });
for (int x = 0; x < CHUNK_WIDTH; x++)
for (int y = 0; y < CHUNK_HEIGHT; y++)
for (int z = 0; z < CHUNK_HEIGHT; z++) {
for (int z = 0; z < CHUNK_DEPTH; z++) {
Voxels.push_back(std::make_shared<Voxel>(x, y, z));

View File

@@ -3,9 +3,9 @@
#include "../common.hpp"
#define CHUNK_HEIGHT 10
#define CHUNK_WIDTH 10
#define CHUNK_DEPTH 10
#define CHUNK_HEIGHT 32
#define CHUNK_WIDTH 16
#define CHUNK_DEPTH 16
class Camera;
class Shader;
@@ -15,15 +15,17 @@ class Voxel;
class Chunk {
public:
Chunk();
Chunk(int x, int z);
Chunk(std::vector<std::shared_ptr<Voxel>> voxels);
void Render(std::shared_ptr<Camera> camera, std::shared_ptr<Shader> shader);
void Update();
// Indexed sequentially [x + WIDTH * (y + HEIGHT * z)] = voxel
std::vector<std::shared_ptr<Voxel>> Voxels;
// Indexed sequentially [x + WIDTH * (y + HEIGHT * z)] = voxelID
// the voxel id is used to index the block dictionary to get properties
// to generate a mesh and send it to the GPU
std::vector<uint8_t> Voxels;
private:

View File

@@ -7,7 +7,7 @@
#define STB_IMAGE_IMPLEMENTATION
#include "../util/stb_image.hpp"
GLuint Texture::LoadTextures(std::vector<std::pair<int, std::string>> textures) {
GLuint Texture::LoadTextures(std::vector<std::string> textures) {
Logger logger;
@@ -21,7 +21,7 @@ GLuint Texture::LoadTextures(std::vector<std::pair<int, std::string>> textures)
for (int i = 0; i < layers; i++) {
std::string path = basePath + textures[i].second;
std::string path = basePath + textures[i];
int xR = 0;
int yR = 0;
@@ -36,7 +36,6 @@ GLuint Texture::LoadTextures(std::vector<std::pair<int, std::string>> textures)
}
GLuint textureArray = 0;
glGenTextures(1, &textureArray);

View File

@@ -5,7 +5,7 @@
class Texture {
public:
GLuint LoadTextures(std::vector<std::pair<int, std::string>> locations);
GLuint Texture::LoadTextures(std::vector<std::string> textures);
};
#endif

View File

@@ -3,10 +3,41 @@
#include "../common.hpp"
static std::vector<std::pair<int, std::string>> TextureIdsAndPaths {
{0, "dirt.png"},
{1, "grass_side.png"},
{2, "grass_top.png"}
class CBlockEntry {
public:
uint8_t ID;
};
// TODO: Make design of the class data oriented
class CBlockDictionary {
public:
void Build();
// The index of the texutres path in this array is equal to
// that textures ID, to be referenced in the block entry
std::vector<std::string> Textures;
// Only supports up to 255 blocs, 0 being air
// word stores vectors of chunks which are 16x16x256
// vectors of uint8_t which reference the block dictionary
std::map<uint8_t, CBlockEntry> BlockEntries;
private:
void registerTexture();
void registerBlock();
};
static CBlockDictionary BlockDictionary;
// static std::vector<std::pair<int, std::string>> TextureIdsAndPaths {
// {0, "dirt.png"},
// {1, "grass_side.png"},
// {2, "grass_top.png"}
// };
#endif