diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ad937a..9a85e8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ file(GLOB SourceFiles ${SrcDIR}/util/* ${SrcDIR}/game/* ${SrcDIR}/world/* + ${SrcDIR}/world/chunk/* ${SrcDIR}/renderer/* ) diff --git a/resources/shaders/simple.frag b/resources/shaders/simple.frag index 1b05fdf..ea822ac 100644 --- a/resources/shaders/simple.frag +++ b/resources/shaders/simple.frag @@ -12,6 +12,7 @@ uniform sampler2DArray tex; void main() { outColour = texture(tex, TexCoord); + //outColour = vec4(.9, .9, .9, 1); if (outColour.w == .0) discard; diff --git a/src/game.cpp b/src/game.cpp index ae19751..16a2447 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7,8 +7,8 @@ #include "renderer/texture.hpp" #include "renderer/shader.hpp" #include "renderer/camera.hpp" -#include "renderer/chunk.hpp" +#include "world/chunk/chunk.hpp" #include "world/world.hpp" #include "world/block.hpp" @@ -60,15 +60,7 @@ void Game::Setup(int w, int h) { *m_logger << LOGGER_INFO << "Creating OpenGL context" << LOGGER_ENDL; m_glContext = SDL_GL_CreateContext(m_window); - if (IsMouseActive) { - - SDL_SetRelativeMouseMode(SDL_TRUE); - - } else { - - SDL_SetRelativeMouseMode(SDL_FALSE); - - } + SDL_SetRelativeMouseMode(SDL_TRUE); // Set VSYNC swap interval SDL_GL_SetSwapInterval(1); @@ -99,8 +91,8 @@ void Game::Setup(int w, int h) { Texture texture; m_world->TextureID = texture.LoadTextures(BlockDictionary->Textures); - for (int x = 0; x < 1; x++) - for (int y = 0; y < 1; y++) { + for (int x = 0; x < 2; x++) + for (int y = 0; y < 2; y++) { m_world->Chunks.push_back(std::make_shared(x, y)); diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index b0e6679..890a505 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -1,8 +1,8 @@ #include "renderer.hpp" +#include "../world/chunk/chunk.hpp" #include "../world/world.hpp" #include "shader.hpp" -#include "chunk.hpp" Renderer::Renderer() { diff --git a/src/renderer/chunk.cpp b/src/world/chunk/chunk.cpp similarity index 90% rename from src/renderer/chunk.cpp rename to src/world/chunk/chunk.cpp index 318f1b2..fe97a11 100644 --- a/src/renderer/chunk.cpp +++ b/src/world/chunk/chunk.cpp @@ -1,14 +1,16 @@ #include "chunk.hpp" -#include "shader.hpp" -#include "camera.hpp" +#include "../../renderer/shader.hpp" +#include "../../renderer/camera.hpp" #include "voxel.hpp" -#include "../world/block.hpp" +#include "../block.hpp" #include +static std::default_random_engine generator; + Chunk::Chunk(int x, int z) { m_model = glm::translate(glm::mat4(1.0f), { x * CHUNK_WIDTH, 0, z * CHUNK_DEPTH }); @@ -24,27 +26,23 @@ Chunk::Chunk(int x, int z) { continue; } + std::uniform_real_distribution distribution(0, 1); + float r = distribution(generator); - if (y == 0) { - + if (r > 0.8f) { + Voxels.push_back((uint8_t)EBlockType::Air); + continue; + } + + + if (y == 0) Voxels.push_back((uint8_t)EBlockType::Bedrock); - - } - else if (y < 28) { - + else if (y < 28) Voxels.push_back((uint8_t)EBlockType::Stone); - - } - else if (y < 32) { - + else if (y < 32) Voxels.push_back((uint8_t)EBlockType::Dirt); - - } - else { - + else Voxels.push_back((uint8_t)EBlockType::Grass); - - } } @@ -140,6 +138,8 @@ void Chunk::m_mesh() { m_vertices.insert(m_vertices.end(), tempVerts.begin(), tempVerts.end()); m_uvs.insert(m_uvs.end(), tempUVs.begin(), tempUVs.end()); + tmp.Clear(); + } glGenVertexArrays(1, &m_vao); diff --git a/src/renderer/chunk.hpp b/src/world/chunk/chunk.hpp similarity index 92% rename from src/renderer/chunk.hpp rename to src/world/chunk/chunk.hpp index 3126f50..82d54c3 100644 --- a/src/renderer/chunk.hpp +++ b/src/world/chunk/chunk.hpp @@ -1,7 +1,7 @@ #ifndef MINECRAFT_RENDERER_CHUNK_H_ #define MINECRAFT_RENDERER_CHUNK_H_ -#include "../common.hpp" +#include "../../common.hpp" #define CHUNK_HEIGHT 128 #define CHUNK_WIDTH 16 @@ -22,6 +22,9 @@ public: void Update(); + //bool Loaded = false; + //bool Render = false; + uint8_t BlockAt(int x, int y, int z); // Indexed sequentially [x + WIDTH * (y + HEIGHT * z)] = voxelID diff --git a/src/renderer/face.hpp b/src/world/chunk/face.hpp similarity index 98% rename from src/renderer/face.hpp rename to src/world/chunk/face.hpp index c29b7e8..20dc525 100644 --- a/src/renderer/face.hpp +++ b/src/world/chunk/face.hpp @@ -1,7 +1,7 @@ #ifndef MINECRAFT_RENDERER_FACE_H_ #define MINECRAFT_RENDERER_FACE_H_ -#include "../common.hpp" +#include "../../common.hpp" namespace EFaceType { diff --git a/src/renderer/voxel.cpp b/src/world/chunk/voxel.cpp similarity index 92% rename from src/renderer/voxel.cpp rename to src/world/chunk/voxel.cpp index 8f85391..b0ff73f 100644 --- a/src/renderer/voxel.cpp +++ b/src/world/chunk/voxel.cpp @@ -3,12 +3,12 @@ #include #include -#include "shader.hpp" -#include "camera.hpp" +#include "../../renderer/shader.hpp" +#include "../../renderer/camera.hpp" #include "face.hpp" -#include "../world/block.hpp" +#include "../block.hpp" Voxel::Voxel(glm::vec3 coordsInChunk, uint8_t block) { @@ -110,6 +110,13 @@ void Voxel::GetMesh(std::vector& verts, std::vector& uvs) } +void Voxel::Clear() { + + m_vertices.clear(); + m_uvs.clear(); + +} + std::vector Voxel::m_translateIntoChunk(std::vector verts, glm::vec3 trans) { for (int i = 0; i < verts.size(); i++) { diff --git a/src/renderer/voxel.hpp b/src/world/chunk/voxel.hpp similarity index 92% rename from src/renderer/voxel.hpp rename to src/world/chunk/voxel.hpp index 04e2d89..1e1b7b9 100644 --- a/src/renderer/voxel.hpp +++ b/src/world/chunk/voxel.hpp @@ -1,7 +1,7 @@ #ifndef MINECRAFT_RENDERER_VOXEL_H_ #define MINECRAFT_RENDERER_VOXEL_H_ -#include "../common.hpp" +#include "../../common.hpp" #include "face.hpp" @@ -15,6 +15,8 @@ public: void AddFace(EFaceType::Face face); void GetMesh(std::vector& verts, std::vector& uvs); + void Clear(); + uint8_t Block; private: diff --git a/src/world/entity.cpp b/src/world/entity.cpp new file mode 100644 index 0000000..f05e3ff --- /dev/null +++ b/src/world/entity.cpp @@ -0,0 +1,3 @@ +#include "entity.hpp" + + diff --git a/src/world/entity.hpp b/src/world/entity.hpp new file mode 100644 index 0000000..f589403 --- /dev/null +++ b/src/world/entity.hpp @@ -0,0 +1,4 @@ +#ifndef MINECRAFT_WORLD_ENTITY_H_ +#define MINECRAFT_WORLD_ENTITY_H_ + + diff --git a/src/world/world.hpp b/src/world/world.hpp index ad774a5..2c2e134 100644 --- a/src/world/world.hpp +++ b/src/world/world.hpp @@ -3,16 +3,28 @@ #include "../common.hpp" +#include + +#include + class Shader; class Chunk; class World { public: - std::map> Shaders; - std::vector> Chunks; - GLuint TextureID; +private: + + GLuint m_textureMapID; + + + std::map> m_shaders; + + + std::vector m_generatorThreads; + + std::unordered_map> m_chunks; };