Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
client:: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamYuan committed May 9, 2023
1 parent b4db3a6 commit 41b71c6
Show file tree
Hide file tree
Showing 45 changed files with 217 additions and 52 deletions.
8 changes: 6 additions & 2 deletions client/include/client/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include <client/GlobalTexture.hpp>
#include <client/WorldRenderer.hpp>

#include <client/pass/WorldRenderGraph.hpp>
#include <client/rg/WorldRenderGraph.hpp>

#include <common/WorkPool.hpp>

namespace client {

class Application {
private:
GLFWwindow *m_window{};
Expand All @@ -28,7 +30,7 @@ class Application {

// frame objects
std::shared_ptr<myvk::FrameManager> m_frame_manager;
myvk::Ptr<WorldRenderGraph> m_world_render_graphs[kFrameCount];
myvk::Ptr<rg::WorldRenderGraph> m_world_render_graphs[kFrameCount];

// game objects and resources
std::shared_ptr<GlobalTexture> m_global_texture;
Expand Down Expand Up @@ -59,4 +61,6 @@ class Application {
~Application();
};

} // namespace client

#endif
46 changes: 25 additions & 21 deletions client/include/client/BlockMeshAlgo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <vector>

namespace client {

class BlockMeshAlgo {
private:
struct AO4 { // compressed ambient occlusion data for 4 vertices (a face)
Expand Down Expand Up @@ -194,7 +196,6 @@ class BlockMeshAlgo {
}

public:

template <typename GetBlockFunc, typename GetLightFunc, typename Push>
std::vector<ChunkMesher::MeshGenInfo> ChunkMesher::generate_mesh() const {
std::vector<MeshGenInfo> ret;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
;

Expand All @@ -335,7 +337,7 @@ class BlockMeshAlgo {
goto end_height_loop;
}
}
end_height_loop:
end_height_loop:

// Add quad
x[u] = i;
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -448,4 +450,6 @@ class BlockMeshAlgo {
ret.push_back(std::move(transparent_mesh_info));
return ret;
}
};
};

} // namespace client
4 changes: 4 additions & 0 deletions client/include/client/BlockVertex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <block/Block.hpp>

namespace client {

struct BlockVertex { // Compressed mesh vertex for chunk
static constexpr uint32_t kUnitBitOffset = 4u;
static constexpr uint32_t kUnitOffset = 1u << kUnitBitOffset;
Expand All @@ -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
4 changes: 4 additions & 0 deletions client/include/client/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

struct GLFWwindow;

namespace client {

class Camera {
public:
glm::vec3 m_position{0.0f, 0.0f, 0.0f};
Expand All @@ -38,4 +40,6 @@ class Camera {
void Update(UniformData *p_data);
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/Chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <memory>
#include <vector>

namespace client {

class World;

class Chunk : public std::enable_shared_from_this<Chunk> {
Expand Down Expand Up @@ -189,4 +191,6 @@ class Chunk : public std::enable_shared_from_this<Chunk> {
Sync m_mesh_sync{}, m_light_sync{};
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/ChunkGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <client/ChunkWorkerBase.hpp>

namespace client {

class ChunkGenerator : public ChunkWorkerBase {
public:
static inline std::unique_ptr<ChunkGenerator> Create(const std::weak_ptr<Chunk> &chunk_weak_ptr) {
Expand All @@ -14,4 +16,6 @@ class ChunkGenerator : public ChunkWorkerBase {
void Run() override;
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/ChunkLighter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <client/ChunkWorkerBase.hpp>
#include <common/Light.hpp>

namespace client {

class ChunkLighter final : public ChunkWorkerS26Base {
private:
uint64_t m_version{};
Expand Down Expand Up @@ -49,4 +51,6 @@ class ChunkLighter final : public ChunkWorkerS26Base {
void Run() override;
};

} // namespace client

#endif
12 changes: 8 additions & 4 deletions client/include/client/ChunkMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
#include "mesh/MeshHandle.hpp"
#include "mesh/MeshPool.hpp"

namespace client {

struct ChunkMeshInfo {
fAABB aabb;
glm::i32vec3 base_position;
uint32_t transparent;
};
static_assert(sizeof(ChunkMeshInfo) == 40);

using ChunkMeshHandle = MeshHandle<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshCluster = MeshCluster<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshPoolBase = MeshPool<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshInfoBuffer = MeshInfoBuffer<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshHandle = mesh::MeshHandle<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshCluster = mesh::MeshCluster<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshPoolBase = mesh::MeshPool<BlockVertex, uint16_t, ChunkMeshInfo>;
using ChunkMeshInfoBuffer = mesh::MeshInfoBuffer<BlockVertex, uint16_t, ChunkMeshInfo>;

class ChunkMeshPool : public ChunkMeshPoolBase {
private:
Expand All @@ -36,4 +38,6 @@ class ChunkMeshPool : public ChunkMeshPoolBase {
}
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/ChunkMesher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <client/ChunkWorkerBase.hpp>
#include <queue>

namespace client {

class ChunkMesher final : public ChunkWorkerS26Base {
public:
static inline std::unique_ptr<ChunkMesher> TryCreate(const std::shared_ptr<Chunk> &chunk_ptr) {
Expand Down Expand Up @@ -102,4 +104,6 @@ class ChunkMesher final : public ChunkWorkerS26Base {
std::vector<MeshGenInfo> generate_mesh() const;
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/ChunkWorkerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <common/WorkerBase.hpp>

namespace client {

class ChunkWorkerBase : public WorkerBase {
private:
std::weak_ptr<Chunk> m_chunk_weak_ptr;
Expand Down Expand Up @@ -59,4 +61,6 @@ class ChunkWorkerS6Base : public ChunkWorkerBase {
~ChunkWorkerS6Base() override = default;
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/ClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <spdlog/spdlog.h>

namespace client {

class ClientBase {
protected:
std::shared_ptr<World> m_world_ptr;
Expand All @@ -18,4 +20,6 @@ class ClientBase {
virtual bool IsConnected() = 0;
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <cinttypes>

namespace client {

constexpr const char *kAppName = "HyperCraft";
constexpr uint32_t kDefaultWidth = 1280, kDefaultHeight = 720;
constexpr uint32_t kFrameCount = 3;
Expand All @@ -11,4 +13,6 @@ constexpr float kCameraNear = 0.01f, kCameraFar = 640.0f;

constexpr uint32_t kWorldMaxLoadRadius = 20;

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/DefaultTerrain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <spdlog/spdlog.h>

namespace client {

class DefaultTerrain : public TerrainBase {
private:
using Block = block::Block;
Expand Down Expand Up @@ -542,4 +544,6 @@ class DefaultTerrain : public TerrainBase {
void Generate(const std::shared_ptr<Chunk> &chunk_ptr, int32_t light_map[kChunkSize * kChunkSize]) override;
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/ENetClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <future>

namespace client {

class ENetClient : public ClientBase, public std::enable_shared_from_this<ENetClient> {
private:
ENetHost *m_host{};
Expand All @@ -29,4 +31,6 @@ class ENetClient : public ClientBase, public std::enable_shared_from_this<ENetCl
}
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/GlobalTexture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <myvk/ImageView.hpp>
#include <myvk/Sampler.hpp>

namespace client {

class GlobalTexture {
private:
std::shared_ptr<myvk::Image> m_block_texture;
Expand All @@ -25,4 +27,6 @@ class GlobalTexture {
inline const auto &GetLightMapView() const { return m_lightmap_view; }
};

} // namespace client

#endif
4 changes: 4 additions & 0 deletions client/include/client/LocalClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <client/ClientBase.hpp>
#include <common/WorldDatabase.hpp>

namespace client {

class LocalClient : public ClientBase, public std::enable_shared_from_this<LocalClient> {
private:
std::unique_ptr<WorldDatabase> m_world_database;
Expand All @@ -15,4 +17,6 @@ class LocalClient : public ClientBase, public std::enable_shared_from_this<Local
static std::shared_ptr<LocalClient> Create(const std::shared_ptr<World> &world_ptr, const char *database_filename);
};

} // namespace client

#endif
Loading

0 comments on commit 41b71c6

Please sign in to comment.