From 41b71c6dd0dccf109fb3dd4a6972441aa206544c Mon Sep 17 00:00:00 2001 From: AdamYuan Date: Tue, 9 May 2023 22:21:11 +0800 Subject: [PATCH] client:: namespace --- client/include/client/Application.hpp | 8 +++- client/include/client/BlockMeshAlgo.hpp | 46 ++++++++++--------- client/include/client/BlockVertex.hpp | 4 ++ client/include/client/Camera.hpp | 4 ++ client/include/client/Chunk.hpp | 4 ++ client/include/client/ChunkGenerator.hpp | 4 ++ client/include/client/ChunkLighter.hpp | 4 ++ client/include/client/ChunkMesh.hpp | 12 +++-- client/include/client/ChunkMesher.hpp | 4 ++ client/include/client/ChunkWorkerBase.hpp | 4 ++ client/include/client/ClientBase.hpp | 4 ++ client/include/client/Config.hpp | 4 ++ client/include/client/DefaultTerrain.hpp | 4 ++ client/include/client/ENetClient.hpp | 4 ++ client/include/client/GlobalTexture.hpp | 4 ++ client/include/client/LocalClient.hpp | 4 ++ client/include/client/TerrainBase.hpp | 4 ++ client/include/client/World.hpp | 4 ++ client/include/client/WorldRenderer.hpp | 4 ++ client/include/client/mesh/MeshCluster.hpp | 4 ++ client/include/client/mesh/MeshHandle.hpp | 4 ++ client/include/client/mesh/MeshInfo.hpp | 4 ++ client/include/client/mesh/MeshPool.hpp | 4 ++ .../client/{pass => rg}/ChunkCullPass.hpp | 30 ++++++------ .../client/{pass => rg}/ChunkOpaquePass.hpp | 4 ++ .../{pass => rg}/ChunkTransparentPass.hpp | 4 ++ .../{pass => rg}/DepthHierarchyPass.hpp | 4 ++ .../client/{pass => rg}/FixTJunctionPass.hpp | 4 ++ .../client/{pass => rg}/OITBlendPass.hpp | 4 ++ .../client/{pass => rg}/WorldRenderGraph.hpp | 4 ++ client/src/Application.cpp | 16 ++++--- client/src/Camera.cpp | 4 ++ client/src/Chunk.cpp | 2 + client/src/ChunkGenerator.cpp | 4 ++ client/src/ChunkLighter.cpp | 4 ++ client/src/ChunkMesher.cpp | 4 ++ client/src/ChunkWorkerBase.cpp | 4 ++ client/src/DefaultTerrain.cpp | 4 ++ client/src/ENetClient.cpp | 4 ++ client/src/GlobalTexture.cpp | 6 ++- client/src/LocalClient.cpp | 4 ++ client/src/World.cpp | 6 ++- client/src/WorldLoadingList.inl | 3 -- client/src/WorldRenderer.cpp | 2 + client/src/main.cpp | 2 +- 45 files changed, 217 insertions(+), 52 deletions(-) rename client/include/client/{pass => rg}/ChunkCullPass.hpp (84%) rename client/include/client/{pass => rg}/ChunkOpaquePass.hpp (99%) rename client/include/client/{pass => rg}/ChunkTransparentPass.hpp (99%) rename client/include/client/{pass => rg}/DepthHierarchyPass.hpp (98%) rename client/include/client/{pass => rg}/FixTJunctionPass.hpp (98%) rename client/include/client/{pass => rg}/OITBlendPass.hpp (98%) rename client/include/client/{pass => rg}/WorldRenderGraph.hpp (99%) diff --git a/client/include/client/Application.hpp b/client/include/client/Application.hpp index 38788aa..373bf1f 100644 --- a/client/include/client/Application.hpp +++ b/client/include/client/Application.hpp @@ -10,10 +10,12 @@ #include #include -#include +#include #include +namespace client { + class Application { private: GLFWwindow *m_window{}; @@ -28,7 +30,7 @@ class Application { // frame objects std::shared_ptr m_frame_manager; - myvk::Ptr m_world_render_graphs[kFrameCount]; + myvk::Ptr m_world_render_graphs[kFrameCount]; // game objects and resources std::shared_ptr m_global_texture; @@ -59,4 +61,6 @@ class Application { ~Application(); }; +} // namespace client + #endif diff --git a/client/include/client/BlockMeshAlgo.hpp b/client/include/client/BlockMeshAlgo.hpp index 2dc5596..f8171a9 100644 --- a/client/include/client/BlockMeshAlgo.hpp +++ b/client/include/client/BlockMeshAlgo.hpp @@ -6,6 +6,8 @@ #include +namespace client { + class BlockMeshAlgo { private: struct AO4 { // compressed ambient occlusion data for 4 vertices (a face) @@ -194,7 +196,6 @@ class BlockMeshAlgo { } public: - template std::vector ChunkMesher::generate_mesh() const { std::vector ret; @@ -228,7 +229,7 @@ class BlockMeshAlgo { std::swap(u_light_axis, v_light_axis); auto op_nei_pos = BlockFaceProceed(pos, BlockFaceOpposite(cur_light_face)), - nei_pos = BlockFaceProceed(pos, cur_light_face); + nei_pos = BlockFaceProceed(pos, cur_light_face); light4_init(&low_light4, cur_light_face, op_nei_pos.x, op_nei_pos.y, op_nei_pos.z); if (get_block(nei_pos.x, nei_pos.y, nei_pos.z).GetIndirectLightPass()) light4_init(&high_light4, cur_light_face, pos.x, pos.y, pos.z); @@ -249,14 +250,14 @@ class BlockMeshAlgo { for (const auto &vert : mesh_face->vertices) { info.aabb.Merge({base.x + vert.x, base.y + vert.y, base.z + vert.z}); uint8_t du = vert.pos[u_light_axis], dv = vert.pos[v_light_axis], - dw = std::min(vert.pos[cur_light_axis], (uint8_t)BlockVertex::kUnitOffset); + dw = std::min(vert.pos[cur_light_axis], (uint8_t)BlockVertex::kUnitOffset); if (cur_light_face & 1u) dw = BlockVertex::kUnitOffset - (int32_t)dw; uint8_t ao = vert.ao, sunlight, torchlight; light4_interpolate(low_light4, high_light4, du, dv, dw, &ao, &sunlight, &torchlight); info.vertices.emplace_back(base.x + vert.x, base.y + vert.y, base.z + vert.z, mesh_face->axis, - mesh_face->render_face, ao, sunlight, torchlight, mesh_face->texture.GetID(), - mesh_face->texture.GetTransformation()); + mesh_face->render_face, ao, sunlight, torchlight, + mesh_face->texture.GetID(), mesh_face->texture.GetTransformation()); } info.indices.push_back(cur_vertex); @@ -295,8 +296,8 @@ class BlockMeshAlgo { if (x[axis] != 0 && a.ShowFace((f = axis << 1), b)) { texture_mask[0][counter] = a.GetTexture(f); face_mask |= 1u; - light4_init(light_mask[0] + counter, f, (int_fast8_t)(x[0] + q[0]), (int_fast8_t)(x[1] + q[1]), - (int_fast8_t)(x[2] + q[2])); + light4_init(light_mask[0] + counter, f, (int_fast8_t)(x[0] + q[0]), + (int_fast8_t)(x[1] + q[1]), (int_fast8_t)(x[2] + q[2])); } if (Chunk::kSize != x[axis] && b.ShowFace((f = (axis << 1) | 1), a)) { texture_mask[1][counter] = b.GetTexture(f); @@ -321,8 +322,9 @@ class BlockMeshAlgo { const Light4 quad_light = local_light_mask[counter]; // Compute width uint_fast8_t width, height; - for (width = 1; quad_texture == local_texture_mask[counter + width] && - quad_light == local_light_mask[counter + width] && i + width < Chunk::kSize; + for (width = 1; + quad_texture == local_texture_mask[counter + width] && + quad_light == local_light_mask[counter + width] && i + width < Chunk::kSize; ++width) ; @@ -335,7 +337,7 @@ class BlockMeshAlgo { goto end_height_loop; } } - end_height_loop: + end_height_loop: // Add quad x[u] = i; @@ -355,7 +357,7 @@ class BlockMeshAlgo { // if (quad_texture.GetRotation() == ) MeshGenInfo &info = - quad_texture.UseTransparentPass() ? transparent_mesh_info : opaque_mesh_info; + quad_texture.UseTransparentPass() ? transparent_mesh_info : opaque_mesh_info; // if indices would exceed, restart uint16_t cur_vertex = info.vertices.size(); if (cur_vertex + 4 > UINT16_MAX) { @@ -365,11 +367,11 @@ class BlockMeshAlgo { info.transparent = trans; } info.aabb.Merge({{uint32_t(x[0]) << BlockVertex::kUnitBitOffset, - uint32_t(x[1]) << BlockVertex::kUnitBitOffset, - uint32_t(x[2]) << BlockVertex::kUnitBitOffset}, + uint32_t(x[1]) << BlockVertex::kUnitBitOffset, + uint32_t(x[2]) << BlockVertex::kUnitBitOffset}, {uint32_t(x[0] + du[0] + dv[0]) << BlockVertex::kUnitBitOffset, - uint32_t(x[1] + du[1] + dv[1]) << BlockVertex::kUnitBitOffset, - uint32_t(x[2] + du[2] + dv[2]) << BlockVertex::kUnitBitOffset}}); + uint32_t(x[1] + du[1] + dv[1]) << BlockVertex::kUnitBitOffset, + uint32_t(x[2] + du[2] + dv[2]) << BlockVertex::kUnitBitOffset}}); BlockFace quad_face = (axis << 1) | quad_face_inv; info.vertices.emplace_back(uint32_t(x[0]) << BlockVertex::kUnitBitOffset, @@ -385,11 +387,11 @@ class BlockMeshAlgo { quad_light.torchlight[1], quad_texture.GetID(), quad_texture.GetTransformation()); info.vertices.emplace_back( - uint32_t(x[0] + du[0] + dv[0]) << BlockVertex::kUnitBitOffset, - uint32_t(x[1] + du[1] + dv[1]) << BlockVertex::kUnitBitOffset, - uint32_t(x[2] + du[2] + dv[2]) << BlockVertex::kUnitBitOffset, axis, quad_face, - quad_light.ao[2], quad_light.sunlight[2], quad_light.torchlight[2], - quad_texture.GetID(), quad_texture.GetTransformation()); + uint32_t(x[0] + du[0] + dv[0]) << BlockVertex::kUnitBitOffset, + uint32_t(x[1] + du[1] + dv[1]) << BlockVertex::kUnitBitOffset, + uint32_t(x[2] + du[2] + dv[2]) << BlockVertex::kUnitBitOffset, axis, quad_face, + quad_light.ao[2], quad_light.sunlight[2], quad_light.torchlight[2], + quad_texture.GetID(), quad_texture.GetTransformation()); info.vertices.emplace_back(uint32_t(x[0] + dv[0]) << BlockVertex::kUnitBitOffset, uint32_t(x[1] + dv[1]) << BlockVertex::kUnitBitOffset, uint32_t(x[2] + dv[2]) << BlockVertex::kUnitBitOffset, axis, @@ -448,4 +450,6 @@ class BlockMeshAlgo { ret.push_back(std::move(transparent_mesh_info)); return ret; } -}; \ No newline at end of file +}; + +} // namespace client \ No newline at end of file diff --git a/client/include/client/BlockVertex.hpp b/client/include/client/BlockVertex.hpp index acb61ab..5f99844 100644 --- a/client/include/client/BlockVertex.hpp +++ b/client/include/client/BlockVertex.hpp @@ -2,6 +2,8 @@ #include +namespace client { + struct BlockVertex { // Compressed mesh vertex for chunk static constexpr uint32_t kUnitBitOffset = 4u; static constexpr uint32_t kUnitOffset = 1u << kUnitBitOffset; @@ -13,3 +15,5 @@ struct BlockVertex { // Compressed mesh vertex for chunk tex10_trans3_face3_ao2_sl6_tl6((tex - 1u) | (tex_trans << 10u) | (face << 13u) | (ao << 16u) | (sunlight << 18u) | (torchlight << 24u)) {} }; + +} // namespace client \ No newline at end of file diff --git a/client/include/client/Camera.hpp b/client/include/client/Camera.hpp index c9fd031..3ad069c 100644 --- a/client/include/client/Camera.hpp +++ b/client/include/client/Camera.hpp @@ -13,6 +13,8 @@ struct GLFWwindow; +namespace client { + class Camera { public: glm::vec3 m_position{0.0f, 0.0f, 0.0f}; @@ -38,4 +40,6 @@ class Camera { void Update(UniformData *p_data); }; +} // namespace client + #endif diff --git a/client/include/client/Chunk.hpp b/client/include/client/Chunk.hpp index e82176b..d76642b 100644 --- a/client/include/client/Chunk.hpp +++ b/client/include/client/Chunk.hpp @@ -14,6 +14,8 @@ #include #include +namespace client { + class World; class Chunk : public std::enable_shared_from_this { @@ -189,4 +191,6 @@ class Chunk : public std::enable_shared_from_this { Sync m_mesh_sync{}, m_light_sync{}; }; +} // namespace client + #endif diff --git a/client/include/client/ChunkGenerator.hpp b/client/include/client/ChunkGenerator.hpp index 3f49df2..5500417 100644 --- a/client/include/client/ChunkGenerator.hpp +++ b/client/include/client/ChunkGenerator.hpp @@ -3,6 +3,8 @@ #include +namespace client { + class ChunkGenerator : public ChunkWorkerBase { public: static inline std::unique_ptr Create(const std::weak_ptr &chunk_weak_ptr) { @@ -14,4 +16,6 @@ class ChunkGenerator : public ChunkWorkerBase { void Run() override; }; +} // namespace client + #endif diff --git a/client/include/client/ChunkLighter.hpp b/client/include/client/ChunkLighter.hpp index 3983a63..f3d9050 100644 --- a/client/include/client/ChunkLighter.hpp +++ b/client/include/client/ChunkLighter.hpp @@ -4,6 +4,8 @@ #include #include +namespace client { + class ChunkLighter final : public ChunkWorkerS26Base { private: uint64_t m_version{}; @@ -49,4 +51,6 @@ class ChunkLighter final : public ChunkWorkerS26Base { void Run() override; }; +} // namespace client + #endif diff --git a/client/include/client/ChunkMesh.hpp b/client/include/client/ChunkMesh.hpp index d147ced..d1e45d2 100644 --- a/client/include/client/ChunkMesh.hpp +++ b/client/include/client/ChunkMesh.hpp @@ -9,6 +9,8 @@ #include "mesh/MeshHandle.hpp" #include "mesh/MeshPool.hpp" +namespace client { + struct ChunkMeshInfo { fAABB aabb; glm::i32vec3 base_position; @@ -16,10 +18,10 @@ struct ChunkMeshInfo { }; static_assert(sizeof(ChunkMeshInfo) == 40); -using ChunkMeshHandle = MeshHandle; -using ChunkMeshCluster = MeshCluster; -using ChunkMeshPoolBase = MeshPool; -using ChunkMeshInfoBuffer = MeshInfoBuffer; +using ChunkMeshHandle = mesh::MeshHandle; +using ChunkMeshCluster = mesh::MeshCluster; +using ChunkMeshPoolBase = mesh::MeshPool; +using ChunkMeshInfoBuffer = mesh::MeshInfoBuffer; class ChunkMeshPool : public ChunkMeshPoolBase { private: @@ -36,4 +38,6 @@ class ChunkMeshPool : public ChunkMeshPoolBase { } }; +} // namespace client + #endif diff --git a/client/include/client/ChunkMesher.hpp b/client/include/client/ChunkMesher.hpp index 1ce3e80..5313e3c 100644 --- a/client/include/client/ChunkMesher.hpp +++ b/client/include/client/ChunkMesher.hpp @@ -6,6 +6,8 @@ #include #include +namespace client { + class ChunkMesher final : public ChunkWorkerS26Base { public: static inline std::unique_ptr TryCreate(const std::shared_ptr &chunk_ptr) { @@ -102,4 +104,6 @@ class ChunkMesher final : public ChunkWorkerS26Base { std::vector generate_mesh() const; }; +} // namespace client + #endif diff --git a/client/include/client/ChunkWorkerBase.hpp b/client/include/client/ChunkWorkerBase.hpp index c7cfbb4..7364ab3 100644 --- a/client/include/client/ChunkWorkerBase.hpp +++ b/client/include/client/ChunkWorkerBase.hpp @@ -5,6 +5,8 @@ #include +namespace client { + class ChunkWorkerBase : public WorkerBase { private: std::weak_ptr m_chunk_weak_ptr; @@ -59,4 +61,6 @@ class ChunkWorkerS6Base : public ChunkWorkerBase { ~ChunkWorkerS6Base() override = default; }; +} // namespace client + #endif diff --git a/client/include/client/ClientBase.hpp b/client/include/client/ClientBase.hpp index 2ecac88..a29b1dc 100644 --- a/client/include/client/ClientBase.hpp +++ b/client/include/client/ClientBase.hpp @@ -6,6 +6,8 @@ #include +namespace client { + class ClientBase { protected: std::shared_ptr m_world_ptr; @@ -18,4 +20,6 @@ class ClientBase { virtual bool IsConnected() = 0; }; +} // namespace client + #endif diff --git a/client/include/client/Config.hpp b/client/include/client/Config.hpp index 0bf5aac..8889ba9 100644 --- a/client/include/client/Config.hpp +++ b/client/include/client/Config.hpp @@ -3,6 +3,8 @@ #include +namespace client { + constexpr const char *kAppName = "HyperCraft"; constexpr uint32_t kDefaultWidth = 1280, kDefaultHeight = 720; constexpr uint32_t kFrameCount = 3; @@ -11,4 +13,6 @@ constexpr float kCameraNear = 0.01f, kCameraFar = 640.0f; constexpr uint32_t kWorldMaxLoadRadius = 20; +} // namespace client + #endif diff --git a/client/include/client/DefaultTerrain.hpp b/client/include/client/DefaultTerrain.hpp index 9678c6c..6de86ed 100644 --- a/client/include/client/DefaultTerrain.hpp +++ b/client/include/client/DefaultTerrain.hpp @@ -13,6 +13,8 @@ #include +namespace client { + class DefaultTerrain : public TerrainBase { private: using Block = block::Block; @@ -542,4 +544,6 @@ class DefaultTerrain : public TerrainBase { void Generate(const std::shared_ptr &chunk_ptr, int32_t light_map[kChunkSize * kChunkSize]) override; }; +} // namespace client + #endif diff --git a/client/include/client/ENetClient.hpp b/client/include/client/ENetClient.hpp index 6a8f9b4..15803bd 100644 --- a/client/include/client/ENetClient.hpp +++ b/client/include/client/ENetClient.hpp @@ -7,6 +7,8 @@ #include +namespace client { + class ENetClient : public ClientBase, public std::enable_shared_from_this { private: ENetHost *m_host{}; @@ -29,4 +31,6 @@ class ENetClient : public ClientBase, public std::enable_shared_from_this #include +namespace client { + class GlobalTexture { private: std::shared_ptr m_block_texture; @@ -25,4 +27,6 @@ class GlobalTexture { inline const auto &GetLightMapView() const { return m_lightmap_view; } }; +} // namespace client + #endif diff --git a/client/include/client/LocalClient.hpp b/client/include/client/LocalClient.hpp index 0cee7b2..3b6444e 100644 --- a/client/include/client/LocalClient.hpp +++ b/client/include/client/LocalClient.hpp @@ -4,6 +4,8 @@ #include #include +namespace client { + class LocalClient : public ClientBase, public std::enable_shared_from_this { private: std::unique_ptr m_world_database; @@ -15,4 +17,6 @@ class LocalClient : public ClientBase, public std::enable_shared_from_this Create(const std::shared_ptr &world_ptr, const char *database_filename); }; +} // namespace client + #endif diff --git a/client/include/client/TerrainBase.hpp b/client/include/client/TerrainBase.hpp index 03f4985..1f0a4a9 100644 --- a/client/include/client/TerrainBase.hpp +++ b/client/include/client/TerrainBase.hpp @@ -10,6 +10,8 @@ #include +namespace client { + class Chunk; class TerrainBase { private: @@ -69,4 +71,6 @@ template class TerrainCache { } }; +} // namespace client + #endif diff --git a/client/include/client/World.hpp b/client/include/client/World.hpp index f87cc68..567b7cc 100644 --- a/client/include/client/World.hpp +++ b/client/include/client/World.hpp @@ -15,6 +15,8 @@ #include +namespace client { + class WorldRenderer; class ClientBase; @@ -58,4 +60,6 @@ class World : public std::enable_shared_from_this { void Update(const glm::vec3 &position); }; +} // namespace client + #endif diff --git a/client/include/client/WorldRenderer.hpp b/client/include/client/WorldRenderer.hpp index 1f40499..3205d3e 100644 --- a/client/include/client/WorldRenderer.hpp +++ b/client/include/client/WorldRenderer.hpp @@ -16,6 +16,8 @@ #include #include +namespace client { + class WorldRenderer : public std::enable_shared_from_this { private: std::shared_ptr m_chunk_mesh_pool; @@ -37,4 +39,6 @@ class WorldRenderer : public std::enable_shared_from_this { inline const auto &GetChunkMeshPool() const { return m_chunk_mesh_pool; } }; +} // namespace client + #endif diff --git a/client/include/client/mesh/MeshCluster.hpp b/client/include/client/mesh/MeshCluster.hpp index f429ece..0353d91 100644 --- a/client/include/client/mesh/MeshCluster.hpp +++ b/client/include/client/mesh/MeshCluster.hpp @@ -14,6 +14,8 @@ #include +namespace client::mesh { + // Used for zero-overhead rendering (with GPU culling) template class MeshCluster { static_assert(sizeof(Index) == 4 || sizeof(Index) == 2 || sizeof(Index) == 1, "sizeof Index must be 1, 2 or 4"); @@ -173,4 +175,6 @@ template class MeshCluster { : (sizeof(Index) == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT8_EXT); }; +} // namespace client::mesh + #endif diff --git a/client/include/client/mesh/MeshHandle.hpp b/client/include/client/mesh/MeshHandle.hpp index 7c853d3..6f2cb8b 100644 --- a/client/include/client/mesh/MeshHandle.hpp +++ b/client/include/client/mesh/MeshHandle.hpp @@ -7,6 +7,8 @@ #include "MeshCluster.hpp" #include "MeshPool.hpp" +namespace client::mesh { + template class MeshHandle { private: std::shared_ptr> m_pool_ptr; @@ -106,4 +108,6 @@ template class MeshHandle { } }; +} // namespace client + #endif diff --git a/client/include/client/mesh/MeshInfo.hpp b/client/include/client/mesh/MeshInfo.hpp index 0fb3c63..a36f2d2 100644 --- a/client/include/client/mesh/MeshInfo.hpp +++ b/client/include/client/mesh/MeshInfo.hpp @@ -3,10 +3,14 @@ #include +namespace client::mesh { + // Mesh information template struct MeshInfo { uint32_t m_index_count, m_first_index, m_vertex_offset; Info m_info; }; +} + #endif diff --git a/client/include/client/mesh/MeshPool.hpp b/client/include/client/mesh/MeshPool.hpp index 73bdc50..a9c519b 100644 --- a/client/include/client/mesh/MeshPool.hpp +++ b/client/include/client/mesh/MeshPool.hpp @@ -12,6 +12,8 @@ #include +namespace client::mesh { + template class MeshPool : public myvk::DeviceObjectBase { public: struct LocalUpdate { @@ -256,4 +258,6 @@ template class MeshInfoBuffer f } }; +} // namespace client::mesh + #endif diff --git a/client/include/client/pass/ChunkCullPass.hpp b/client/include/client/rg/ChunkCullPass.hpp similarity index 84% rename from client/include/client/pass/ChunkCullPass.hpp rename to client/include/client/rg/ChunkCullPass.hpp index 6a3ae4a..012bfd9 100644 --- a/client/include/client/pass/ChunkCullPass.hpp +++ b/client/include/client/rg/ChunkCullPass.hpp @@ -5,6 +5,8 @@ #include +namespace client::rg { + class ChunkCullPass final : public myvk_rg::ComputePassBase { private: static inline constexpr uint32_t group_x_64(uint32_t x) { return (x >> 6u) + (((x & 0x3fu) > 0u) ? 1u : 0u); } @@ -38,15 +40,15 @@ class ChunkCullPass final : public myvk_rg::ComputePassBase { trans_draw_count_buffer->SetSize(chunk_mesh_pool_ptr->GetMaxClusters() * sizeof(uint32_t)); AddDescriptorInput<0, myvk_rg::Usage::kStorageBufferW, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>( - {"opaque_draw_cmd"}, opaque_draw_cmd_buffer); + {"opaque_draw_cmd"}, opaque_draw_cmd_buffer); AddDescriptorInput<1, myvk_rg::Usage::kStorageBufferRW, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>( - {"opaque_draw_count"}, opaque_draw_count_buffer); + {"opaque_draw_count"}, opaque_draw_count_buffer); AddDescriptorInput<2, myvk_rg::Usage::kStorageBufferW, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>( - {"trans_draw_cmd"}, trans_draw_cmd_buffer); + {"trans_draw_cmd"}, trans_draw_cmd_buffer); AddDescriptorInput<3, myvk_rg::Usage::kStorageBufferRW, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>( - {"trans_draw_count"}, trans_draw_count_buffer); + {"trans_draw_count"}, trans_draw_count_buffer); AddDescriptorInput<4, myvk_rg::Usage::kStorageBufferR, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>( - {"mesh_info"}, mesh_info_buffer); + {"mesh_info"}, mesh_info_buffer); AddDescriptorInput<5, myvk_rg::Usage::kUniformBuffer, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>({"camera"}, camera_buffer); @@ -63,8 +65,8 @@ class ChunkCullPass final : public myvk_rg::ComputePassBase { reduction_create_info.reductionMode = VK_SAMPLER_REDUCTION_MODE_MAX; create_info.pNext = &reduction_create_info; AddDescriptorInput<6, myvk_rg::Usage::kSampledImage, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT>( - {"depth_hierarchy"}, depth_hierarchy, - myvk::Sampler::Create(GetRenderGraphPtr()->GetDevicePtr(), create_info)); + {"depth_hierarchy"}, depth_hierarchy, + myvk::Sampler::Create(GetRenderGraphPtr()->GetDevicePtr(), create_info)); } inline void Update(const std::vector> &prepared_clusters) { m_p_prepared_clusters = &prepared_clusters; @@ -75,14 +77,14 @@ class ChunkCullPass final : public myvk_rg::ComputePassBase { inline auto GetTransparentDrawCountOutput() { return MakeBufferOutput({"trans_draw_count"}); } inline void CreatePipeline() final { auto pipeline_layout = - myvk::PipelineLayout::Create(GetRenderGraphPtr()->GetDevicePtr(), {GetVkDescriptorSetLayout()}, - {{VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(uint32_t) * 3}}); + myvk::PipelineLayout::Create(GetRenderGraphPtr()->GetDevicePtr(), {GetVkDescriptorSetLayout()}, + {{VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(uint32_t) * 3}}); static constexpr uint32_t kChunkCullingCompSpv[] = { #include }; m_pipeline = myvk::ComputePipeline::Create( - pipeline_layout, myvk::ShaderModule::Create(GetRenderGraphPtr()->GetDevicePtr(), kChunkCullingCompSpv, - sizeof(kChunkCullingCompSpv))); + pipeline_layout, myvk::ShaderModule::Create(GetRenderGraphPtr()->GetDevicePtr(), kChunkCullingCompSpv, + sizeof(kChunkCullingCompSpv))); } inline void CmdExecute(const myvk::Ptr &command_buffer) const final { command_buffer->CmdBindPipeline(m_pipeline); @@ -90,9 +92,9 @@ class ChunkCullPass final : public myvk_rg::ComputePassBase { // Clear counters auto *opaque_draw_count_mapped = - GetResource({"opaque_draw_count"})->GetMappedData(); + GetResource({"opaque_draw_count"})->GetMappedData(); auto *trans_draw_count_mapped = - GetResource({"trans_draw_count"})->GetMappedData(); + GetResource({"trans_draw_count"})->GetMappedData(); std::fill(opaque_draw_count_mapped, opaque_draw_count_mapped + m_chunk_mesh_pool_ptr->GetMaxClusters(), 0u); std::fill(trans_draw_count_mapped, trans_draw_count_mapped + m_chunk_mesh_pool_ptr->GetMaxClusters(), 0u); @@ -108,4 +110,6 @@ class ChunkCullPass final : public myvk_rg::ComputePassBase { } }; +} + #endif diff --git a/client/include/client/pass/ChunkOpaquePass.hpp b/client/include/client/rg/ChunkOpaquePass.hpp similarity index 99% rename from client/include/client/pass/ChunkOpaquePass.hpp rename to client/include/client/rg/ChunkOpaquePass.hpp index a9166b0..7ab7cc7 100644 --- a/client/include/client/pass/ChunkOpaquePass.hpp +++ b/client/include/client/rg/ChunkOpaquePass.hpp @@ -5,6 +5,8 @@ #include +namespace client::rg { + class ChunkOpaquePass final : public myvk_rg::GraphicsPassBase { private: const std::vector> *m_p_prepared_clusters; @@ -100,4 +102,6 @@ class ChunkOpaquePass final : public myvk_rg::GraphicsPassBase { } }; +} // namespace client::rg + #endif diff --git a/client/include/client/pass/ChunkTransparentPass.hpp b/client/include/client/rg/ChunkTransparentPass.hpp similarity index 99% rename from client/include/client/pass/ChunkTransparentPass.hpp rename to client/include/client/rg/ChunkTransparentPass.hpp index b433523..1584690 100644 --- a/client/include/client/pass/ChunkTransparentPass.hpp +++ b/client/include/client/rg/ChunkTransparentPass.hpp @@ -5,6 +5,8 @@ #include +namespace client::rg { + class ChunkTransparentPass final : public myvk_rg::GraphicsPassBase { private: const std::vector> *m_p_prepared_clusters; @@ -126,4 +128,6 @@ class ChunkTransparentPass final : public myvk_rg::GraphicsPassBase { inline auto GetRevealOutput() { return MakeImageOutput({"reveal"}); } }; +} // namespace client::rg + #endif diff --git a/client/include/client/pass/DepthHierarchyPass.hpp b/client/include/client/rg/DepthHierarchyPass.hpp similarity index 98% rename from client/include/client/pass/DepthHierarchyPass.hpp rename to client/include/client/rg/DepthHierarchyPass.hpp index 76d9bcb..fb2889f 100644 --- a/client/include/client/pass/DepthHierarchyPass.hpp +++ b/client/include/client/rg/DepthHierarchyPass.hpp @@ -3,6 +3,8 @@ #include +namespace client::rg { + class DepthHierarchyPass final : public myvk_rg::PassGroupBase { private: myvk_rg::ImageInput m_depth_image{}; @@ -113,4 +115,6 @@ class DepthHierarchyPass final : public myvk_rg::PassGroupBase { inline auto GetDepthHierarchyOutput() { return GetResource({"depth_hierarchy"}); } }; +} // namespace client::rg + #endif diff --git a/client/include/client/pass/FixTJunctionPass.hpp b/client/include/client/rg/FixTJunctionPass.hpp similarity index 98% rename from client/include/client/pass/FixTJunctionPass.hpp rename to client/include/client/rg/FixTJunctionPass.hpp index 9ac2920..871ecdc 100644 --- a/client/include/client/pass/FixTJunctionPass.hpp +++ b/client/include/client/rg/FixTJunctionPass.hpp @@ -3,6 +3,8 @@ #include +namespace client::rg { + class FixTJunctionPass final : public myvk_rg::GraphicsPassBase { private: myvk::Ptr m_pipeline; @@ -72,4 +74,6 @@ class FixTJunctionPass final : public myvk_rg::GraphicsPassBase { inline auto GetFixedDepthOutput() { return MakeImageOutput({"fixed_depth"}); } }; +} // namespace client::rg + #endif diff --git a/client/include/client/pass/OITBlendPass.hpp b/client/include/client/rg/OITBlendPass.hpp similarity index 98% rename from client/include/client/pass/OITBlendPass.hpp rename to client/include/client/rg/OITBlendPass.hpp index c5bead4..719849e 100644 --- a/client/include/client/pass/OITBlendPass.hpp +++ b/client/include/client/rg/OITBlendPass.hpp @@ -3,6 +3,8 @@ #include +namespace client::rg { + class OITBlendPass final : public myvk_rg::GraphicsPassBase { private: myvk::Ptr m_pipeline; @@ -70,4 +72,6 @@ class OITBlendPass final : public myvk_rg::GraphicsPassBase { inline auto GetColorOutput() { return MakeImageOutput({"color"}); } }; +} // namespace client::rg + #endif diff --git a/client/include/client/pass/WorldRenderGraph.hpp b/client/include/client/rg/WorldRenderGraph.hpp similarity index 99% rename from client/include/client/pass/WorldRenderGraph.hpp rename to client/include/client/rg/WorldRenderGraph.hpp index e8fb705..fa14a1f 100644 --- a/client/include/client/pass/WorldRenderGraph.hpp +++ b/client/include/client/rg/WorldRenderGraph.hpp @@ -15,6 +15,8 @@ #include #include +namespace client::rg { + class WorldRenderGraph final : public myvk_rg::RenderGraph { private: std::shared_ptr m_chunk_mesh_pool_ptr; @@ -147,4 +149,6 @@ class WorldRenderGraph final : public myvk_rg::RenderGraph { } }; +} // namespace client::rg + #endif diff --git a/client/src/Application.cpp b/client/src/Application.cpp index 0cb46d5..a527da5 100644 --- a/client/src/Application.cpp +++ b/client/src/Application.cpp @@ -9,8 +9,15 @@ #include +#include +#include +#include +#include + #include +namespace client { + void Application::create_glfw_window() { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); @@ -102,11 +109,6 @@ void Application::draw_frame(double delta) { m_frame_manager->Render(); } -#include -#include -#include -#include - Application::Application() { glfwInit(); @@ -129,7 +131,7 @@ Application::Application() { auto chunk_renderer = m_world_renderer->GetChunkMeshPool(); for (auto &world_rg : m_world_render_graphs) { - world_rg = WorldRenderGraph::Create(m_main_queue, m_frame_manager, chunk_renderer, m_global_texture); + world_rg = rg::WorldRenderGraph::Create(m_main_queue, m_frame_manager, chunk_renderer, m_global_texture); world_rg->SetCanvasSize(m_frame_manager->GetExtent()); } } @@ -190,3 +192,5 @@ void Application::glfw_framebuffer_resize_callback(GLFWwindow *window, int width auto *app = (Application *)glfwGetWindowUserPointer(window); app->m_frame_manager->Resize(); } + +} // namespace client diff --git a/client/src/Camera.cpp b/client/src/Camera.cpp index 53bde4f..adf37a1 100644 --- a/client/src/Camera.cpp +++ b/client/src/Camera.cpp @@ -5,6 +5,8 @@ #include #include +namespace client { + void Camera::move_forward(float dist, float dir) { m_position.x -= glm::sin(m_yaw + dir) * dist; m_position.z -= glm::cos(m_yaw + dir) * dist; @@ -58,3 +60,5 @@ void Camera::Update(Camera::UniformData *p_data) { glm::mat4 view_projection = fetch_matrix(); *p_data = {glm::vec4(m_position, 0.0), view_projection}; } + +} // namespace client diff --git a/client/src/Chunk.cpp b/client/src/Chunk.cpp index 33a45b4..40e15ee 100644 --- a/client/src/Chunk.cpp +++ b/client/src/Chunk.cpp @@ -1 +1,3 @@ #include + +namespace client {} diff --git a/client/src/ChunkGenerator.cpp b/client/src/ChunkGenerator.cpp index 13f239c..9909b4f 100644 --- a/client/src/ChunkGenerator.cpp +++ b/client/src/ChunkGenerator.cpp @@ -7,6 +7,8 @@ #include +namespace client { + void ChunkGenerator::Run() { if (!lock()) return; @@ -50,3 +52,5 @@ void ChunkGenerator::Run() { } m_chunk_ptr->SetMeshedFlag(); } + +} // namespace client \ No newline at end of file diff --git a/client/src/ChunkLighter.cpp b/client/src/ChunkLighter.cpp index 5cb3b0a..263e506 100644 --- a/client/src/ChunkLighter.cpp +++ b/client/src/ChunkLighter.cpp @@ -4,6 +4,8 @@ #include +namespace client { + template && std::is_signed_v>> static constexpr uint32_t chunk_xyz_extended14_to_index(T x, T y, T z) { bool x_inside = 0 <= x && x < kChunkSize, y_inside = 0 <= y && y < kChunkSize, z_inside = 0 <= z && z < kChunkSize; @@ -124,3 +126,5 @@ void ChunkLighter::Run() { return; } */ } + +} // namespace client diff --git a/client/src/ChunkMesher.cpp b/client/src/ChunkMesher.cpp index ac69283..7da67e9 100644 --- a/client/src/ChunkMesher.cpp +++ b/client/src/ChunkMesher.cpp @@ -10,6 +10,8 @@ #include +namespace client { + thread_local std::queue ChunkMesher::m_light_queue; template && std::is_signed_v>> @@ -545,3 +547,5 @@ void ChunkMesher::Run() { // Push mesh to chunk m_chunk_ptr->PushMesh(m_version, mesh_handles); } + +} // namespace client \ No newline at end of file diff --git a/client/src/ChunkWorkerBase.cpp b/client/src/ChunkWorkerBase.cpp index 4f3cfbc..f6ebb71 100644 --- a/client/src/ChunkWorkerBase.cpp +++ b/client/src/ChunkWorkerBase.cpp @@ -2,6 +2,8 @@ #include +namespace client { + void ChunkWorkerBase::try_push_worker(std::unique_ptr &&worker) const { if (!worker) return; @@ -9,3 +11,5 @@ void ChunkWorkerBase::try_push_worker(std::unique_ptr &&worker) if (world) world->GetWorkPoolPtr()->PushWorker(std::move(worker)); } + +} // namespace client \ No newline at end of file diff --git a/client/src/DefaultTerrain.cpp b/client/src/DefaultTerrain.cpp index bde5207..b56caf8 100644 --- a/client/src/DefaultTerrain.cpp +++ b/client/src/DefaultTerrain.cpp @@ -5,6 +5,8 @@ #include #include +namespace client { + void DefaultTerrain::Generate(const std::shared_ptr &chunk_ptr, int32_t light_map[kChunkSize * kChunkSize]) { #if 1 std::shared_ptr xz_info = m_xz_cache.Acquire( @@ -507,3 +509,5 @@ void DefaultTerrain::DecorationInfo::PopToChunk(const std::shared_ptr &ch chunk_ptr->SetBlock(idx, i.second); } } + +} // namespace client \ No newline at end of file diff --git a/client/src/ENetClient.cpp b/client/src/ENetClient.cpp index e10a33e..4b6c409 100644 --- a/client/src/ENetClient.cpp +++ b/client/src/ENetClient.cpp @@ -1,6 +1,8 @@ #include #include +namespace client { + std::shared_ptr ENetClient::Create(const std::shared_ptr &world_ptr, const char *host_str, uint16_t port, uint32_t timeout) { ENetHost *host; @@ -49,3 +51,5 @@ ENetPeer *ENetClient::connect(std::string &&host, uint16_t port, uint32_t timeou return nullptr; } } + +} // namespace client \ No newline at end of file diff --git a/client/src/GlobalTexture.cpp b/client/src/GlobalTexture.cpp index cb1c5cf..53369d3 100644 --- a/client/src/GlobalTexture.cpp +++ b/client/src/GlobalTexture.cpp @@ -8,6 +8,8 @@ #include +namespace client { + std::shared_ptr GlobalTexture::Create(const std::shared_ptr &command_pool) { std::shared_ptr ret = std::make_shared(); ret->create_block_texture(command_pool); @@ -107,4 +109,6 @@ void GlobalTexture::create_block_texture(const std::shared_ptr fence = myvk::Fence::Create(command_buffer->GetDevicePtr()); command_buffer->Submit(fence); fence->Wait(); -} \ No newline at end of file +} + +} // namespace client \ No newline at end of file diff --git a/client/src/LocalClient.cpp b/client/src/LocalClient.cpp index 934fbe7..817f619 100644 --- a/client/src/LocalClient.cpp +++ b/client/src/LocalClient.cpp @@ -2,6 +2,8 @@ #include +namespace client { + std::shared_ptr LocalClient::Create(const std::shared_ptr &world_ptr, const char *database_filename) { std::shared_ptr ret = std::make_shared(); @@ -16,3 +18,5 @@ std::shared_ptr LocalClient::Create(const std::shared_ptr &w // return nullptr; return ret; } + +} // namespace client \ No newline at end of file diff --git a/client/src/World.cpp b/client/src/World.cpp index 4896e1d..a7013ac 100644 --- a/client/src/World.cpp +++ b/client/src/World.cpp @@ -5,6 +5,9 @@ #include #include +#include + +namespace client { World::~World() { for (const auto &i : m_chunks) @@ -12,7 +15,6 @@ World::~World() { } #include "WorldLoadingList.inl" - void World::Update(const glm::vec3 &position) { constexpr int16_t kR = 11; @@ -79,3 +81,5 @@ std::shared_ptr World::FindChunk(const ChunkPos3 &position) const { auto it = m_chunks.find(position); return it == m_chunks.end() ? nullptr : it->second; } + +} // namespace client diff --git a/client/src/WorldLoadingList.inl b/client/src/WorldLoadingList.inl index 92519aa..65b89eb 100644 --- a/client/src/WorldLoadingList.inl +++ b/client/src/WorldLoadingList.inl @@ -1,6 +1,3 @@ -#include -#include - constexpr ChunkPos3 kWorldLoadingList[] = { {0, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, 1, 1}, {0, 1, -1}, {0, -1, 0}, {0, -1, 1}, {0, -1, -1}, {1, 0, 0}, diff --git a/client/src/WorldRenderer.cpp b/client/src/WorldRenderer.cpp index 08259b8..3e99ce2 100644 --- a/client/src/WorldRenderer.cpp +++ b/client/src/WorldRenderer.cpp @@ -2,3 +2,5 @@ #include #include + +namespace client {} diff --git a/client/src/main.cpp b/client/src/main.cpp index 46a1e39..928d645 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -3,7 +3,7 @@ int main() { spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%t] [%^%l%$] %v"); - Application app{}; + client::Application app{}; app.Run(); return 0; }