moved some stuff around, ready for dynamic chunk loading and that
This commit is contained in:
@@ -46,6 +46,7 @@ file(GLOB SourceFiles
|
||||
${SrcDIR}/util/*
|
||||
${SrcDIR}/game/*
|
||||
${SrcDIR}/world/*
|
||||
${SrcDIR}/world/chunk/*
|
||||
${SrcDIR}/renderer/*
|
||||
)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ uniform sampler2DArray tex;
|
||||
void main() {
|
||||
|
||||
outColour = texture(tex, TexCoord);
|
||||
//outColour = vec4(.9, .9, .9, 1);
|
||||
|
||||
if (outColour.w == .0)
|
||||
discard;
|
||||
|
||||
16
src/game.cpp
16
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<Chunk>(x, y));
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "renderer.hpp"
|
||||
|
||||
#include "../world/chunk/chunk.hpp"
|
||||
#include "../world/world.hpp"
|
||||
#include "shader.hpp"
|
||||
#include "chunk.hpp"
|
||||
|
||||
Renderer::Renderer() {
|
||||
|
||||
|
||||
@@ -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 <random>
|
||||
|
||||
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<float> 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);
|
||||
@@ -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
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef MINECRAFT_RENDERER_FACE_H_
|
||||
#define MINECRAFT_RENDERER_FACE_H_
|
||||
|
||||
#include "../common.hpp"
|
||||
#include "../../common.hpp"
|
||||
|
||||
namespace EFaceType {
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#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<glm::vec3>& verts, std::vector<glm::vec3>& uvs)
|
||||
|
||||
}
|
||||
|
||||
void Voxel::Clear() {
|
||||
|
||||
m_vertices.clear();
|
||||
m_uvs.clear();
|
||||
|
||||
}
|
||||
|
||||
std::vector<glm::vec3> Voxel::m_translateIntoChunk(std::vector<glm::vec3> verts, glm::vec3 trans) {
|
||||
|
||||
for (int i = 0; i < verts.size(); i++) {
|
||||
@@ -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<glm::vec3>& verts, std::vector<glm::vec3>& uvs);
|
||||
|
||||
void Clear();
|
||||
|
||||
uint8_t Block;
|
||||
|
||||
private:
|
||||
3
src/world/entity.cpp
Normal file
3
src/world/entity.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "entity.hpp"
|
||||
|
||||
|
||||
4
src/world/entity.hpp
Normal file
4
src/world/entity.hpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef MINECRAFT_WORLD_ENTITY_H_
|
||||
#define MINECRAFT_WORLD_ENTITY_H_
|
||||
|
||||
|
||||
@@ -3,16 +3,28 @@
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <thread>
|
||||
|
||||
class Shader;
|
||||
class Chunk;
|
||||
|
||||
class World {
|
||||
public:
|
||||
|
||||
std::map<std::string, std::shared_ptr<Shader>> Shaders;
|
||||
std::vector<std::shared_ptr<Chunk>> Chunks;
|
||||
|
||||
GLuint TextureID;
|
||||
private:
|
||||
|
||||
GLuint m_textureMapID;
|
||||
|
||||
|
||||
std::map<std::string, std::shared_ptr<Shader>> m_shaders;
|
||||
|
||||
|
||||
std::vector<std::thread> m_generatorThreads;
|
||||
|
||||
std::unordered_map<glm::vec2, std::shared_ptr<Chunk>> m_chunks;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user