From 2c6dccfb539065601a6339527c456a32be2da4b5 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Thu, 25 Jun 2026 17:13:50 +0800 Subject: [PATCH] refactor(server): replace Chunk with ServerChunk --- include/Cubed/gameplay/tree.hpp | 4 ++-- src/gameplay/builders/biome_builder.cpp | 18 +++++++++--------- src/gameplay/builders/desert_builder.cpp | 6 +++--- src/gameplay/builders/forest_builder.cpp | 8 ++++---- src/gameplay/builders/mountain_builder.cpp | 4 ++-- src/gameplay/builders/ocean_builder.cpp | 4 ++-- src/gameplay/builders/plain_builder.cpp | 8 ++++---- src/gameplay/builders/snowy_plain_builder.cpp | 8 ++++---- src/gameplay/tree.cpp | 10 +++++----- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/include/Cubed/gameplay/tree.hpp b/include/Cubed/gameplay/tree.hpp index da1f564..1613fc7 100644 --- a/include/Cubed/gameplay/tree.hpp +++ b/include/Cubed/gameplay/tree.hpp @@ -4,13 +4,13 @@ namespace Cubed { -class Chunk; +class ServerChunk; struct TreeStructNode { glm::ivec3 offset{0, 0, 0}; unsigned id = 0; }; -bool build_tree(Chunk& chunk, const glm::ivec3& pos); +bool build_tree(ServerChunk& chunk, const glm::ivec3& pos); } // namespace Cubed diff --git a/src/gameplay/builders/biome_builder.cpp b/src/gameplay/builders/biome_builder.cpp index 9c7b901..788b514 100644 --- a/src/gameplay/builders/biome_builder.cpp +++ b/src/gameplay/builders/biome_builder.cpp @@ -1,39 +1,39 @@ #include "Cubed/gameplay/builders/biome_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" namespace Cubed { void BiomeBuilder::build_bottom() { ChunkGenerator& chunk_generator = get_chunk_generator(); - Chunk& chunk = chunk_generator.chunk(); + ServerChunk& chunk = chunk_generator.chunk(); auto& m_blocks = chunk.blocks(); for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < 5; y++) { for (int z = 0; z < CHUNK_SIZE; z++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } } } } void BiomeBuilder::place_grass() { ChunkGenerator& chunk_generator = get_chunk_generator(); - Chunk& chunk = chunk_generator.chunk(); + ServerChunk& chunk = chunk_generator.chunk(); auto& blocks = chunk.blocks(); const auto& heightmap = chunk.get_heightmap(); auto& random = chunk_generator.random(); for (int x = 0; x < SIZE_X; ++x) { for (int z = 0; z < SIZE_Z; ++z) { int y = heightmap[x][z]; - BlockType top_id = blocks[Chunk::index(x, y, z)]; + BlockType top_id = blocks[ServerChunk::index(x, y, z)]; if (top_id != 1) { continue; } - if (blocks[Chunk::index(x, y + 1, z)] != 0) { + if (blocks[ServerChunk::index(x, y + 1, z)] != 0) { continue; } if (random.random_bool(0.2)) { if (y + 1 < SIZE_Y) { - blocks[Chunk::index(x, y + 1, z)] = 9; + blocks[ServerChunk::index(x, y + 1, z)] = 9; } } } @@ -42,7 +42,7 @@ void BiomeBuilder::place_grass() { void BiomeBuilder::ocean_water_build() { ChunkGenerator& chunk_generator = get_chunk_generator(); - Chunk& chunk = chunk_generator.chunk(); + ServerChunk& chunk = chunk_generator.chunk(); auto& blocks = chunk.blocks(); const auto& heightmap = chunk.get_heightmap(); @@ -51,7 +51,7 @@ void BiomeBuilder::ocean_water_build() { int height = heightmap[x][z]; if (height <= SEA_LEVEL) { for (int y = height; y <= SEA_LEVEL; y++) { - blocks[Chunk::index(x, y, z)] = 7; + blocks[ServerChunk::index(x, y, z)] = 7; } } } diff --git a/src/gameplay/builders/desert_builder.cpp b/src/gameplay/builders/desert_builder.cpp index 2b60cfa..fe90ee6 100644 --- a/src/gameplay/builders/desert_builder.cpp +++ b/src/gameplay/builders/desert_builder.cpp @@ -1,7 +1,7 @@ #include "Cubed/gameplay/builders/desert_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" namespace Cubed { DesertBuilder::DesertBuilder(ChunkGenerator& chunk_generator) : m_chunk_generator(chunk_generator) {} @@ -19,11 +19,11 @@ void DesertBuilder::build_blocks() { for (int z = 0; z < CHUNK_SIZE; z++) { int height = static_cast(m_heightmap[x][z]); for (int y = 5; y < height - 5; y++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } for (int y = height - 5; y <= height; y++) { - m_blocks[Chunk::index(x, y, z)] = 4; + m_blocks[ServerChunk::index(x, y, z)] = 4; } } } diff --git a/src/gameplay/builders/forest_builder.cpp b/src/gameplay/builders/forest_builder.cpp index 8607b02..deb1a5d 100644 --- a/src/gameplay/builders/forest_builder.cpp +++ b/src/gameplay/builders/forest_builder.cpp @@ -1,7 +1,7 @@ #include "Cubed/gameplay/builders/forest_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" #include "Cubed/gameplay/tree.hpp" #include @@ -24,12 +24,12 @@ void ForestBuilder::build_blocks() { for (int z = 0; z < CHUNK_SIZE; z++) { int height = static_cast(m_heightmap[x][z]); for (int y = 5; y < height - 5; y++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } for (int y = height - 5; y < height; y++) { - m_blocks[Chunk::index(x, y, z)] = 2; + m_blocks[ServerChunk::index(x, y, z)] = 2; } - m_blocks[Chunk::index(x, height, z)] = 1; + m_blocks[ServerChunk::index(x, height, z)] = 1; } } } diff --git a/src/gameplay/builders/mountain_builder.cpp b/src/gameplay/builders/mountain_builder.cpp index 0c8c379..2640626 100644 --- a/src/gameplay/builders/mountain_builder.cpp +++ b/src/gameplay/builders/mountain_builder.cpp @@ -1,7 +1,7 @@ #include "Cubed/gameplay/builders/mountain_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" namespace Cubed { MountainBuilder::MountainBuilder(ChunkGenerator& chunk_generator) : m_chunk_generator(chunk_generator) {} @@ -19,7 +19,7 @@ void MountainBuilder::build_blocks() { for (int z = 0; z < CHUNK_SIZE; z++) { int height = static_cast(m_heightmap[x][z]); for (int y = 5; y <= height; y++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } } } diff --git a/src/gameplay/builders/ocean_builder.cpp b/src/gameplay/builders/ocean_builder.cpp index 123461e..8eae6e6 100644 --- a/src/gameplay/builders/ocean_builder.cpp +++ b/src/gameplay/builders/ocean_builder.cpp @@ -1,7 +1,7 @@ #include "Cubed/gameplay/builders/ocean_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" namespace Cubed { OceanBuilder::OceanBuilder(ChunkGenerator& chunk_generator) : m_chunk_generator(chunk_generator) {} @@ -19,7 +19,7 @@ void OceanBuilder::build_blocks() { for (int z = 0; z < CHUNK_SIZE; z++) { int height = static_cast(m_heightmap[x][z]); for (int y = 5; y <= height; y++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } } } diff --git a/src/gameplay/builders/plain_builder.cpp b/src/gameplay/builders/plain_builder.cpp index a900905..cb50760 100644 --- a/src/gameplay/builders/plain_builder.cpp +++ b/src/gameplay/builders/plain_builder.cpp @@ -1,7 +1,7 @@ #include "Cubed/gameplay/builders/plain_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" namespace Cubed { PlainBuilder::PlainBuilder(ChunkGenerator& chunk_generator) : m_chunk_generator(chunk_generator) {} @@ -19,12 +19,12 @@ void PlainBuilder::build_blocks() { for (int z = 0; z < CHUNK_SIZE; z++) { int height = static_cast(m_heightmap[x][z]); for (int y = 5; y < height - 5; y++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } for (int y = height - 5; y < height; y++) { - m_blocks[Chunk::index(x, y, z)] = 2; + m_blocks[ServerChunk::index(x, y, z)] = 2; } - m_blocks[Chunk::index(x, height, z)] = 1; + m_blocks[ServerChunk::index(x, height, z)] = 1; } } } diff --git a/src/gameplay/builders/snowy_plain_builder.cpp b/src/gameplay/builders/snowy_plain_builder.cpp index 189ce46..3f9d455 100644 --- a/src/gameplay/builders/snowy_plain_builder.cpp +++ b/src/gameplay/builders/snowy_plain_builder.cpp @@ -1,7 +1,7 @@ #include "Cubed/gameplay/builders/snowy_plain_builder.hpp" -#include "Cubed/gameplay/chunk.hpp" #include "Cubed/gameplay/chunk_generator.hpp" +#include "Cubed/gameplay/server_chunk.hpp" namespace Cubed { SnowyPlainBuilder::SnowyPlainBuilder(ChunkGenerator& chunk_generator) : m_chunk_generator(chunk_generator) {} @@ -19,12 +19,12 @@ void SnowyPlainBuilder::build_blocks() { for (int z = 0; z < CHUNK_SIZE; z++) { int height = static_cast(m_heightmap[x][z]); for (int y = 5; y < height - 5; y++) { - m_blocks[Chunk::index(x, y, z)] = 3; + m_blocks[ServerChunk::index(x, y, z)] = 3; } for (int y = height - 5; y < height; y++) { - m_blocks[Chunk::index(x, y, z)] = 2; + m_blocks[ServerChunk::index(x, y, z)] = 2; } - m_blocks[Chunk::index(x, height, z)] = 8; + m_blocks[ServerChunk::index(x, height, z)] = 8; } } } diff --git a/src/gameplay/tree.cpp b/src/gameplay/tree.cpp index e717ac7..4589bfb 100644 --- a/src/gameplay/tree.cpp +++ b/src/gameplay/tree.cpp @@ -1,6 +1,6 @@ #include "Cubed/gameplay/tree.hpp" -#include "Cubed/gameplay/chunk.hpp" +#include "Cubed/gameplay/server_chunk.hpp" #include @@ -27,10 +27,10 @@ static constexpr std::array TREE{{ {{-1, 3, -2}, 6}, {{-2, 3, -1}, 6}, }}; -bool build_tree(Chunk& chunk, const glm::ivec3& pos) { +bool build_tree(ServerChunk& chunk, const glm::ivec3& pos) { auto& block = chunk.get_chunk_blocks(); - if (block[Chunk::index(pos)] != 1) { + if (block[ServerChunk::index(pos)] != 1) { return false; } for (const auto& d : TREE) { @@ -42,13 +42,13 @@ bool build_tree(Chunk& chunk, const glm::ivec3& pos) { z >= CHUNK_SIZE) { return false; } - if (block[Chunk::index(tree_node)] != 0) { + if (block[ServerChunk::index(tree_node)] != 0) { return false; } } for (const auto& d : TREE) { auto tree_node = pos + d.offset; - chunk.set_chunk_block(Chunk::index(tree_node), d.id); + chunk.set_chunk_block(ServerChunk::index(tree_node), d.id); } return true; }