mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add world class
This commit is contained in:
@@ -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;
|
||||
23
include/Cubed/gameplay/block.hpp
Normal file
23
include/Cubed/gameplay/block.hpp
Normal 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;
|
||||
};
|
||||
23
include/Cubed/gameplay/chuck.hpp
Normal file
23
include/Cubed/gameplay/chuck.hpp
Normal 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);
|
||||
};
|
||||
15
include/Cubed/gameplay/chuck_status.hpp
Normal file
15
include/Cubed/gameplay/chuck_status.hpp
Normal 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);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
21
include/Cubed/gameplay/world.hpp
Normal file
21
include/Cubed/gameplay/world.hpp
Normal 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();
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user