feat: add world class

This commit is contained in:
2026-03-07 17:00:05 +08:00
parent eccd744f8b
commit 668fa9a57d
12 changed files with 303 additions and 120 deletions

View File

@@ -1,4 +1,7 @@
#pragma once
constexpr int WORLD_SIZE_X = 32;
constexpr int WORLD_SIZE_Z = 32;
constexpr int MAX_BLOCK_NUM = 1;
constexpr int WORLD_SIZE_Y = 16;
constexpr int MAX_BLOCK_NUM = 2;
constexpr int CHUCK_SIZE = 16;
constexpr int DISTANCE = 1;

View File

@@ -0,0 +1,23 @@
#pragma once
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <string>
#include <vector>
struct BlockTexture {
std::string name;
unsigned id;
std::vector<GLuint> texture;
};
struct Block : public BlockTexture{
};
struct BlockRenderData {
glm::vec3 pos;
std::vector<bool> draw_face;
unsigned block_id;
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include <cstdint>
#include <Cubed/config.hpp>
#include <Cubed/gameplay/chuck_status.hpp>
#include <Cubed/gameplay/block.hpp>
class Chuck {
private:
// the index is a array of block id
std::vector<uint8_t> m_blocks;
public:
Chuck();
~Chuck();
const std::vector<uint8_t>& get_chuck_blocks() const;
void init_chuck();
static int get_index(int x, int y, int z);
};

View File

@@ -0,0 +1,15 @@
#pragma once
#include <functional>
struct ChuckPos {
int x;
int y;
bool operator==(const ChuckPos&) const = default;
struct Hash {
std::size_t operator()(const ChuckPos& pos) const{
std::size_t h1 = std::hash<int>{}(pos.x);
std::size_t h2 = std::hash<int>{}(pos.y);
return h1 ^ (h2 << 1);
}
};
};

View File

@@ -0,0 +1,21 @@
#pragma once
#include <unordered_map>
#include <Cubed/gameplay/chuck.hpp>
class World {
private:
BlockRenderData m_block_render_data;
std::unordered_map<ChuckPos , Chuck, ChuckPos::Hash> m_chucks;
public:
World();
~World();
const BlockRenderData& get_block_render_data(int x, int y ,int z);
void init_world();
void render();
};