mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
perf: optimize chunk generation
This commit is contained in:
@@ -17,9 +17,22 @@ struct Block : public BlockTexture{
|
||||
};
|
||||
|
||||
struct BlockRenderData {
|
||||
glm::vec3 pos;
|
||||
std::vector<bool> draw_face;
|
||||
unsigned block_id;
|
||||
BlockRenderData() = default;
|
||||
BlockRenderData(const BlockRenderData&) = default;
|
||||
BlockRenderData& operator=(const BlockRenderData&) = default;
|
||||
BlockRenderData(BlockRenderData&& data) :
|
||||
draw_face(std::move(data.draw_face)),
|
||||
block_id(data.block_id)
|
||||
{
|
||||
|
||||
}
|
||||
BlockRenderData& operator=(BlockRenderData&& data) {
|
||||
draw_face = std::move(data.draw_face);
|
||||
block_id = data.block_id;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct LookBlock {
|
||||
|
||||
@@ -10,6 +10,9 @@ class World;
|
||||
|
||||
class Chunk {
|
||||
private:
|
||||
|
||||
bool m_is_gened = false;
|
||||
bool m_dirty = false;
|
||||
ChunkPos m_chunk_pos;
|
||||
World& m_world;
|
||||
// the index is a array of block id
|
||||
@@ -31,7 +34,9 @@ public:
|
||||
GLuint get_vbo() const;
|
||||
const std::vector<Vertex>& get_vertex_data() const;
|
||||
void init_chunk();
|
||||
|
||||
bool is_dirty() const;
|
||||
void mark_dirty();
|
||||
void clear_dirty();
|
||||
void set_chunk_block(int index, unsigned id);
|
||||
|
||||
};
|
||||
@@ -11,6 +11,16 @@ struct ChunkPos {
|
||||
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
|
||||
}
|
||||
};
|
||||
|
||||
ChunkPos operator+(const ChunkPos& pos) const{
|
||||
return ChunkPos{x + pos.x, z + pos.z};
|
||||
}
|
||||
|
||||
ChunkPos& operator+=(const ChunkPos& pos) {
|
||||
x += pos.x;
|
||||
z += pos.z;
|
||||
return *this;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ private:
|
||||
std::unordered_map<std::size_t, Player> m_players;
|
||||
std::vector<glm::vec4> m_planes;
|
||||
|
||||
std::pair<int, int> chunk_pos(int world_x, int world_z);
|
||||
std::pair<int, int> chunk_pos(int world_x, int world_z) const;
|
||||
void gen_chunks();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user