Started rewrite for chunks to come. Left old face and voxel code
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#version 330
|
#version 450
|
||||||
|
|
||||||
in vec3 TexCoord;
|
in vec3 TexCoord;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#version 330
|
#version 450
|
||||||
|
|
||||||
layout (location = 0) in vec3 position;
|
layout (location = 0) in vec3 position;
|
||||||
layout (location = 1) in vec3 texcoord;
|
layout (location = 1) in vec3 texcoord;
|
||||||
|
|||||||
@@ -82,17 +82,20 @@ void Game::Setup(int w, int h) {
|
|||||||
m_cameras["Default"] = std::make_shared<Camera>(w, h);
|
m_cameras["Default"] = std::make_shared<Camera>(w, h);
|
||||||
m_activeCamera = m_cameras["Default"];
|
m_activeCamera = m_cameras["Default"];
|
||||||
|
|
||||||
|
BlockDictionary.Build();
|
||||||
|
|
||||||
m_world = std::make_unique<World>();
|
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"] = std::make_shared<Shader>();
|
||||||
m_world->Shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple");
|
m_world->Shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple");
|
||||||
m_world->Shaders["Basic"]->Link();
|
m_world->Shaders["Basic"]->Link();
|
||||||
|
|
||||||
Texture texture;
|
Texture texture;
|
||||||
m_world->TextureID = texture.LoadTextures(TextureIdsAndPaths);
|
m_world->TextureID = texture.LoadTextures(BlockDictionary.Textures);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public:
|
|||||||
void MouseMoved(glm::vec2 mouseDelta);
|
void MouseMoved(glm::vec2 mouseDelta);
|
||||||
|
|
||||||
float MouseSensitivity = 0.1f;
|
float MouseSensitivity = 0.1f;
|
||||||
float CameraSpeed = 0.1f;
|
float CameraSpeed = 0.2f;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float roll, pitch, yaw;
|
float roll, pitch, yaw;
|
||||||
|
|||||||
@@ -5,13 +5,15 @@
|
|||||||
|
|
||||||
#include "voxel.hpp"
|
#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 x = 0; x < CHUNK_WIDTH; x++)
|
||||||
for (int y = 0; y < CHUNK_HEIGHT; y++)
|
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));
|
Voxels.push_back(std::make_shared<Voxel>(x, y, z));
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include "../common.hpp"
|
#include "../common.hpp"
|
||||||
|
|
||||||
#define CHUNK_HEIGHT 10
|
#define CHUNK_HEIGHT 32
|
||||||
#define CHUNK_WIDTH 10
|
#define CHUNK_WIDTH 16
|
||||||
#define CHUNK_DEPTH 10
|
#define CHUNK_DEPTH 16
|
||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
class Shader;
|
class Shader;
|
||||||
@@ -15,15 +15,17 @@ class Voxel;
|
|||||||
class Chunk {
|
class Chunk {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Chunk();
|
Chunk(int x, int z);
|
||||||
Chunk(std::vector<std::shared_ptr<Voxel>> voxels);
|
Chunk(std::vector<std::shared_ptr<Voxel>> voxels);
|
||||||
|
|
||||||
void Render(std::shared_ptr<Camera> camera, std::shared_ptr<Shader> shader);
|
void Render(std::shared_ptr<Camera> camera, std::shared_ptr<Shader> shader);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
// Indexed sequentially [x + WIDTH * (y + HEIGHT * z)] = voxel
|
// Indexed sequentially [x + WIDTH * (y + HEIGHT * z)] = voxelID
|
||||||
std::vector<std::shared_ptr<Voxel>> Voxels;
|
// 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:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "../util/stb_image.hpp"
|
#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;
|
Logger logger;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ GLuint Texture::LoadTextures(std::vector<std::pair<int, std::string>> textures)
|
|||||||
|
|
||||||
for (int i = 0; i < layers; i++) {
|
for (int i = 0; i < layers; i++) {
|
||||||
|
|
||||||
std::string path = basePath + textures[i].second;
|
std::string path = basePath + textures[i];
|
||||||
|
|
||||||
int xR = 0;
|
int xR = 0;
|
||||||
int yR = 0;
|
int yR = 0;
|
||||||
@@ -36,7 +36,6 @@ GLuint Texture::LoadTextures(std::vector<std::pair<int, std::string>> textures)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GLuint textureArray = 0;
|
GLuint textureArray = 0;
|
||||||
|
|
||||||
glGenTextures(1, &textureArray);
|
glGenTextures(1, &textureArray);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class Texture {
|
class Texture {
|
||||||
public:
|
public:
|
||||||
GLuint LoadTextures(std::vector<std::pair<int, std::string>> locations);
|
GLuint Texture::LoadTextures(std::vector<std::string> textures);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,10 +3,41 @@
|
|||||||
|
|
||||||
#include "../common.hpp"
|
#include "../common.hpp"
|
||||||
|
|
||||||
static std::vector<std::pair<int, std::string>> TextureIdsAndPaths {
|
class CBlockEntry {
|
||||||
{0, "dirt.png"},
|
public:
|
||||||
{1, "grass_side.png"},
|
uint8_t ID;
|
||||||
{2, "grass_top.png"}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user