summaryrefslogtreecommitdiffstats
path: root/src/game/shared/world
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-12-26 14:50:33 +0500
committeruntodesu <kirill@untode.su>2025-12-26 14:50:33 +0500
commit6c2abde5c99a236453b795abaa6d7d70105e31f7 (patch)
treef085049b9615a7d03cca5de40adb6529d6c13e11 /src/game/shared/world
parentf40d09cb8f712e87691af4912f3630d92d692779 (diff)
downloadvoxelius-6c2abde5c99a236453b795abaa6d7d70105e31f7.tar.bz2
voxelius-6c2abde5c99a236453b795abaa6d7d70105e31f7.zip
Just a big Ctrl+H refactoring
Diffstat (limited to 'src/game/shared/world')
-rw-r--r--src/game/shared/world/chunk.cc22
-rw-r--r--src/game/shared/world/chunk.hh6
-rw-r--r--src/game/shared/world/chunk_aabb.hh3
-rw-r--r--src/game/shared/world/dimension.cc34
-rw-r--r--src/game/shared/world/dimension.hh20
-rw-r--r--src/game/shared/world/feature.cc6
-rw-r--r--src/game/shared/world/feature.hh6
-rw-r--r--src/game/shared/world/item.cc16
-rw-r--r--src/game/shared/world/item.hh19
-rw-r--r--src/game/shared/world/item_registry.cc16
-rw-r--r--src/game/shared/world/item_registry.hh16
-rw-r--r--src/game/shared/world/ray_dda.cc14
-rw-r--r--src/game/shared/world/ray_dda.hh6
-rw-r--r--src/game/shared/world/voxel.cc44
-rw-r--r--src/game/shared/world/voxel.hh57
-rw-r--r--src/game/shared/world/voxel_registry.cc16
-rw-r--r--src/game/shared/world/voxel_registry.hh16
-rw-r--r--src/game/shared/world/voxel_storage.cc4
-rw-r--r--src/game/shared/world/voxel_storage.hh10
19 files changed, 129 insertions, 202 deletions
diff --git a/src/game/shared/world/chunk.cc b/src/game/shared/world/chunk.cc
index e2d60cb..10da80e 100644
--- a/src/game/shared/world/chunk.cc
+++ b/src/game/shared/world/chunk.cc
@@ -6,7 +6,7 @@
#include "shared/coord.hh"
-world::Chunk::Chunk(entt::entity entity, Dimension* dimension)
+Chunk::Chunk(entt::entity entity, Dimension* dimension)
{
m_entity = entity;
m_dimension = dimension;
@@ -14,12 +14,12 @@ world::Chunk::Chunk(entt::entity entity, Dimension* dimension)
m_biome = BIOME_VOID;
}
-const world::Voxel* world::Chunk::get_voxel(const local_pos& lpos) const
+const Voxel* Chunk::get_voxel(const local_pos& lpos) const
{
return get_voxel(coord::to_index(lpos));
}
-const world::Voxel* world::Chunk::get_voxel(const std::size_t index) const
+const Voxel* Chunk::get_voxel(const std::size_t index) const
{
if(index >= CHUNK_VOLUME) {
return nullptr;
@@ -28,12 +28,12 @@ const world::Voxel* world::Chunk::get_voxel(const std::size_t index) const
return voxel_registry::find(m_voxels[index]);
}
-void world::Chunk::set_voxel(const Voxel* voxel, const local_pos& lpos)
+void Chunk::set_voxel(const Voxel* voxel, const local_pos& lpos)
{
set_voxel(voxel, coord::to_index(lpos));
}
-void world::Chunk::set_voxel(const Voxel* voxel, const std::size_t index)
+void Chunk::set_voxel(const Voxel* voxel, const std::size_t index)
{
if(index < CHUNK_VOLUME) {
m_voxels[index] = voxel ? voxel->get_id() : NULL_VOXEL_ID;
@@ -41,32 +41,32 @@ void world::Chunk::set_voxel(const Voxel* voxel, const std::size_t index)
}
}
-const world::VoxelStorage& world::Chunk::get_voxels(void) const
+const VoxelStorage& Chunk::get_voxels(void) const
{
return m_voxels;
}
-void world::Chunk::set_voxels(const VoxelStorage& voxels)
+void Chunk::set_voxels(const VoxelStorage& voxels)
{
m_voxels = voxels;
}
-unsigned int world::Chunk::get_biome(void) const
+unsigned int Chunk::get_biome(void) const
{
return m_biome;
}
-void world::Chunk::set_biome(unsigned int biome)
+void Chunk::set_biome(unsigned int biome)
{
m_biome = biome;
}
-entt::entity world::Chunk::get_entity(void) const
+entt::entity Chunk::get_entity(void) const
{
return m_entity;
}
-world::Dimension* world::Chunk::get_dimension(void) const
+Dimension* Chunk::get_dimension(void) const
{
return m_dimension;
}
diff --git a/src/game/shared/world/chunk.hh b/src/game/shared/world/chunk.hh
index 7518127..f8e38b4 100644
--- a/src/game/shared/world/chunk.hh
+++ b/src/game/shared/world/chunk.hh
@@ -6,14 +6,9 @@
constexpr static unsigned int BIOME_VOID = 0U;
-namespace world
-{
class Dimension;
class Voxel;
-} // namespace world
-namespace world
-{
class Chunk final {
public:
explicit Chunk(entt::entity entity, Dimension* dimension);
@@ -40,4 +35,3 @@ private:
VoxelStorage m_voxels;
unsigned int m_biome;
};
-} // namespace world
diff --git a/src/game/shared/world/chunk_aabb.hh b/src/game/shared/world/chunk_aabb.hh
index f07d3e1..0f8851c 100644
--- a/src/game/shared/world/chunk_aabb.hh
+++ b/src/game/shared/world/chunk_aabb.hh
@@ -4,7 +4,4 @@
#include "shared/types.hh"
-namespace world
-{
using ChunkAABB = math::AABB<chunk_pos::value_type>;
-} // namespace world
diff --git a/src/game/shared/world/dimension.cc b/src/game/shared/world/dimension.cc
index 0088753..84ca539 100644
--- a/src/game/shared/world/dimension.cc
+++ b/src/game/shared/world/dimension.cc
@@ -8,13 +8,13 @@
#include "shared/coord.hh"
#include "shared/globals.hh"
-world::Dimension::Dimension(std::string_view name, float gravity)
+Dimension::Dimension(std::string_view name, float gravity)
{
m_name = name;
m_gravity = gravity;
}
-world::Dimension::~Dimension(void)
+Dimension::~Dimension(void)
{
for(const auto it : m_chunkmap)
delete it.second;
@@ -22,17 +22,17 @@ world::Dimension::~Dimension(void)
chunks.clear();
}
-std::string_view world::Dimension::get_name(void) const
+std::string_view Dimension::get_name(void) const
{
return m_name;
}
-float world::Dimension::get_gravity(void) const
+float Dimension::get_gravity(void) const
{
return m_gravity;
}
-world::Chunk* world::Dimension::create_chunk(const chunk_pos& cpos)
+Chunk* Dimension::create_chunk(const chunk_pos& cpos)
{
auto it = m_chunkmap.find(cpos);
@@ -58,7 +58,7 @@ world::Chunk* world::Dimension::create_chunk(const chunk_pos& cpos)
return m_chunkmap.insert_or_assign(cpos, std::move(chunk)).first->second;
}
-world::Chunk* world::Dimension::find_chunk(entt::entity entity) const
+Chunk* Dimension::find_chunk(entt::entity entity) const
{
if(chunks.valid(entity)) {
return chunks.get<ChunkComponent>(entity).chunk;
@@ -68,7 +68,7 @@ world::Chunk* world::Dimension::find_chunk(entt::entity entity) const
}
}
-world::Chunk* world::Dimension::find_chunk(const chunk_pos& cpos) const
+Chunk* Dimension::find_chunk(const chunk_pos& cpos) const
{
auto it = m_chunkmap.find(cpos);
@@ -80,7 +80,7 @@ world::Chunk* world::Dimension::find_chunk(const chunk_pos& cpos) const
}
}
-void world::Dimension::remove_chunk(entt::entity entity)
+void Dimension::remove_chunk(entt::entity entity)
{
if(chunks.valid(entity)) {
auto& component = chunks.get<ChunkComponent>(entity);
@@ -89,7 +89,7 @@ void world::Dimension::remove_chunk(entt::entity entity)
}
}
-void world::Dimension::remove_chunk(const chunk_pos& cpos)
+void Dimension::remove_chunk(const chunk_pos& cpos)
{
auto it = m_chunkmap.find(cpos);
@@ -99,7 +99,7 @@ void world::Dimension::remove_chunk(const chunk_pos& cpos)
}
}
-void world::Dimension::remove_chunk(Chunk* chunk)
+void Dimension::remove_chunk(Chunk* chunk)
{
if(chunk) {
const auto& component = chunks.get<ChunkComponent>(chunk->get_entity());
@@ -108,7 +108,7 @@ void world::Dimension::remove_chunk(Chunk* chunk)
}
}
-const world::Voxel* world::Dimension::get_voxel(const voxel_pos& vpos) const
+const Voxel* Dimension::get_voxel(const voxel_pos& vpos) const
{
auto cpos = coord::to_chunk(vpos);
auto lpos = coord::to_local(vpos);
@@ -120,7 +120,7 @@ const world::Voxel* world::Dimension::get_voxel(const voxel_pos& vpos) const
return nullptr;
}
-const world::Voxel* world::Dimension::get_voxel(const chunk_pos& cpos, const local_pos& lpos) const
+const Voxel* Dimension::get_voxel(const chunk_pos& cpos, const local_pos& lpos) const
{
// This allows accessing get_voxel with negative
// local coordinates that usually would result in an
@@ -128,7 +128,7 @@ const world::Voxel* world::Dimension::get_voxel(const chunk_pos& cpos, const loc
return get_voxel(coord::to_voxel(cpos, lpos));
}
-bool world::Dimension::set_voxel(const Voxel* voxel, const voxel_pos& vpos)
+bool Dimension::set_voxel(const Voxel* voxel, const voxel_pos& vpos)
{
auto cpos = coord::to_chunk(vpos);
auto lpos = coord::to_local(vpos);
@@ -165,7 +165,7 @@ bool world::Dimension::set_voxel(const Voxel* voxel, const voxel_pos& vpos)
return false;
}
-bool world::Dimension::set_voxel(const Voxel* voxel, const chunk_pos& cpos, const local_pos& lpos)
+bool Dimension::set_voxel(const Voxel* voxel, const chunk_pos& cpos, const local_pos& lpos)
{
// This allows accessing set_voxel with negative
// local coordinates that usually would result in an
@@ -173,15 +173,15 @@ bool world::Dimension::set_voxel(const Voxel* voxel, const chunk_pos& cpos, cons
return set_voxel(voxel, coord::to_voxel(cpos, lpos));
}
-void world::Dimension::init(io::ConfigMap& config)
+void Dimension::init(ConfigMap& config)
{
}
-void world::Dimension::init_late(std::uint64_t global_seed)
+void Dimension::init_late(std::uint64_t global_seed)
{
}
-bool world::Dimension::generate(const chunk_pos& cpos, VoxelStorage& voxels)
+bool Dimension::generate(const chunk_pos& cpos, VoxelStorage& voxels)
{
return false;
}
diff --git a/src/game/shared/world/dimension.hh b/src/game/shared/world/dimension.hh
index 6549bf6..b57640a 100644
--- a/src/game/shared/world/dimension.hh
+++ b/src/game/shared/world/dimension.hh
@@ -3,26 +3,15 @@
#include "shared/const.hh"
#include "shared/types.hh"
-namespace io
-{
class ConfigMap;
-} // namespace io
-namespace world
-{
class Chunk;
class Voxel;
class VoxelStorage;
-} // namespace world
-namespace world
-{
using dimension_entropy_map = std::array<std::uint64_t, CHUNK_AREA>;
using dimension_height_map = std::array<voxel_pos::value_type, CHUNK_AREA>;
-} // namespace world
-namespace world
-{
class Dimension {
public:
explicit Dimension(std::string_view name, float gravity);
@@ -48,7 +37,7 @@ public:
bool set_voxel(const Voxel* voxel, const chunk_pos& cpos, const local_pos& lpos);
public:
- virtual void init(io::ConfigMap& config);
+ virtual void init(ConfigMap& config);
virtual void init_late(std::uint64_t global_seed);
virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels);
@@ -61,18 +50,12 @@ private:
emhash8::HashMap<chunk_pos, Chunk*> m_chunkmap;
float m_gravity;
};
-} // namespace world
-namespace world
-{
struct ChunkComponent final {
chunk_pos cpos;
Chunk* chunk;
};
-} // namespace world
-namespace world
-{
struct ChunkCreateEvent final {
Dimension* dimension;
chunk_pos cpos;
@@ -98,4 +81,3 @@ struct VoxelSetEvent final {
local_pos lpos;
Chunk* chunk;
};
-} // namespace world
diff --git a/src/game/shared/world/feature.cc b/src/game/shared/world/feature.cc
index 2468473..3974082 100644
--- a/src/game/shared/world/feature.cc
+++ b/src/game/shared/world/feature.cc
@@ -8,7 +8,7 @@
#include "shared/coord.hh"
-void world::Feature::place(const voxel_pos& vpos, Dimension* dimension) const
+void Feature::place(const voxel_pos& vpos, Dimension* dimension) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
@@ -30,7 +30,7 @@ void world::Feature::place(const voxel_pos& vpos, Dimension* dimension) const
}
}
-void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const
+void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
@@ -52,7 +52,7 @@ void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk&
}
}
-void world::Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const
+void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
diff --git a/src/game/shared/world/feature.hh b/src/game/shared/world/feature.hh
index 0d28b20..b80869d 100644
--- a/src/game/shared/world/feature.hh
+++ b/src/game/shared/world/feature.hh
@@ -2,16 +2,11 @@
#include "shared/types.hh"
-namespace world
-{
class Chunk;
class Dimension;
class Voxel;
class VoxelStorage;
-} // namespace world
-namespace world
-{
class Feature final : public std::vector<std::tuple<voxel_pos, const Voxel*, bool>> {
public:
Feature(void) = default;
@@ -22,4 +17,3 @@ public:
void place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const;
void place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const;
};
-} // namespace world
diff --git a/src/game/shared/world/item.cc b/src/game/shared/world/item.cc
index 5e60609..bc1546a 100644
--- a/src/game/shared/world/item.cc
+++ b/src/game/shared/world/item.cc
@@ -6,17 +6,17 @@
#include "shared/world/voxel.hh"
-world::Item::Item(const Item& source, item_id id) noexcept : Item(source)
+Item::Item(const Item& source, item_id id) noexcept : Item(source)
{
m_id = id;
}
-void world::Item::set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept
+void Item::set_cached_texture(resource_ptr<TextureGUI> texture) const noexcept
{
m_cached_texture = std::move(texture);
}
-std::uint64_t world::Item::get_checksum(std::uint64_t combine) const
+std::uint64_t Item::get_checksum(std::uint64_t combine) const
{
combine = math::crc64(m_name.data(), m_name.size(), combine);
combine = math::crc64(m_texture.data(), m_texture.size(), combine);
@@ -27,29 +27,29 @@ std::uint64_t world::Item::get_checksum(std::uint64_t combine) const
return combine;
}
-world::ItemBuilder::ItemBuilder(std::string_view name)
+ItemBuilder::ItemBuilder(std::string_view name)
{
set_name(name);
}
-void world::ItemBuilder::set_name(std::string_view name)
+void ItemBuilder::set_name(std::string_view name)
{
assert(name.size());
m_name = name;
}
-void world::ItemBuilder::set_texture(std::string_view texture)
+void ItemBuilder::set_texture(std::string_view texture)
{
m_texture = texture;
}
-void world::ItemBuilder::set_place_voxel(const Voxel* place_voxel)
+void ItemBuilder::set_place_voxel(const Voxel* place_voxel)
{
m_place_voxel = place_voxel;
}
-std::unique_ptr<world::Item> world::ItemBuilder::build(item_id id) const
+std::unique_ptr<Item> ItemBuilder::build(item_id id) const
{
return std::make_unique<Item>(*this, id);
}
diff --git a/src/game/shared/world/item.hh b/src/game/shared/world/item.hh
index ffa7f5c..bcec37a 100644
--- a/src/game/shared/world/item.hh
+++ b/src/game/shared/world/item.hh
@@ -9,13 +9,8 @@
// anywhere else in the shared and server code
struct TextureGUI;
-namespace world
-{
class Voxel;
-} // namespace world
-namespace world
-{
class Item {
public:
Item(void) = default;
@@ -41,10 +36,7 @@ protected:
mutable resource_ptr<TextureGUI> m_cached_texture; // Client-side only
};
-} // namespace world
-namespace world
-{
class ItemBuilder final : public Item {
public:
explicit ItemBuilder(std::string_view name);
@@ -56,29 +48,28 @@ public:
std::unique_ptr<Item> build(item_id id) const;
};
-} // namespace world
-constexpr std::string_view world::Item::get_name(void) const noexcept
+constexpr std::string_view Item::get_name(void) const noexcept
{
return m_name;
}
-constexpr item_id world::Item::get_id(void) const noexcept
+constexpr item_id Item::get_id(void) const noexcept
{
return m_id;
}
-constexpr std::string_view world::Item::get_texture(void) const noexcept
+constexpr std::string_view Item::get_texture(void) const noexcept
{
return m_texture;
}
-constexpr const world::Voxel* world::Item::get_place_voxel(void) const noexcept
+constexpr const Voxel* Item::get_place_voxel(void) const noexcept
{
return m_place_voxel;
}
-constexpr resource_ptr<TextureGUI>& world::Item::get_cached_texture(void) const noexcept
+constexpr resource_ptr<TextureGUI>& Item::get_cached_texture(void) const noexcept
{
return m_cached_texture;
}
diff --git a/src/game/shared/world/item_registry.cc b/src/game/shared/world/item_registry.cc
index d89abe9..c7d8d9b 100644
--- a/src/game/shared/world/item_registry.cc
+++ b/src/game/shared/world/item_registry.cc
@@ -7,19 +7,19 @@
#include "shared/world/voxel_registry.hh"
static std::uint64_t registry_checksum = 0U;
-std::unordered_map<std::string, item_id> world::item_registry::names = {};
-std::vector<std::unique_ptr<world::Item>> world::item_registry::items = {};
+std::unordered_map<std::string, item_id> item_registry::names = {};
+std::vector<std::unique_ptr<Item>> item_registry::items = {};
static void recalculate_checksum(void)
{
registry_checksum = 0U;
- for(const auto& item : world::item_registry::items) {
+ for(const auto& item : item_registry::items) {
registry_checksum = item->get_checksum(registry_checksum);
}
}
-world::Item* world::item_registry::register_item(const ItemBuilder& builder)
+Item* item_registry::register_item(const ItemBuilder& builder)
{
assert(builder.get_name().size());
assert(nullptr == find(builder.get_name()));
@@ -35,7 +35,7 @@ world::Item* world::item_registry::register_item(const ItemBuilder& builder)
return items.back().get();
}
-world::Item* world::item_registry::find(std::string_view name)
+Item* item_registry::find(std::string_view name)
{
const auto it = names.find(std::string(name));
@@ -46,7 +46,7 @@ world::Item* world::item_registry::find(std::string_view name)
return items[it->second - 1].get();
}
-world::Item* world::item_registry::find(const item_id item)
+Item* item_registry::find(const item_id item)
{
if(item == NULL_ITEM_ID || item > items.size()) {
return nullptr;
@@ -55,14 +55,14 @@ world::Item* world::item_registry::find(const item_id item)
return items[item - 1].get();
}
-void world::item_registry::purge(void)
+void item_registry::purge(void)
{
registry_checksum = 0U;
items.clear();
names.clear();
}
-std::uint64_t world::item_registry::get_checksum(void)
+std::uint64_t item_registry::get_checksum(void)
{
return registry_checksum;
}
diff --git a/src/game/shared/world/item_registry.hh b/src/game/shared/world/item_registry.hh
index a841a2d..f8fe641 100644
--- a/src/game/shared/world/item_registry.hh
+++ b/src/game/shared/world/item_registry.hh
@@ -2,25 +2,25 @@
#include "shared/world/item.hh"
-namespace world::item_registry
+namespace item_registry
{
extern std::unordered_map<std::string, item_id> names;
extern std::vector<std::unique_ptr<Item>> items;
-} // namespace world::item_registry
+} // namespace item_registry
-namespace world::item_registry
+namespace item_registry
{
Item* register_item(const ItemBuilder& builder);
Item* find(std::string_view name);
Item* find(const item_id item);
-} // namespace world::item_registry
+} // namespace item_registry
-namespace world::item_registry
+namespace item_registry
{
void purge(void);
-} // namespace world::item_registry
+} // namespace item_registry
-namespace world::item_registry
+namespace item_registry
{
std::uint64_t get_checksum(void);
-} // namespace world::item_registry
+} // namespace item_registry
diff --git a/src/game/shared/world/ray_dda.cc b/src/game/shared/world/ray_dda.cc
index d6383b9..5dbf82e 100644
--- a/src/game/shared/world/ray_dda.cc
+++ b/src/game/shared/world/ray_dda.cc
@@ -6,20 +6,17 @@
#include "shared/coord.hh"
-world::RayDDA::RayDDA(const world::Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+RayDDA::RayDDA(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
reset(dimension, start_chunk, start_fpos, direction);
}
-world::RayDDA::RayDDA(const world::Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+RayDDA::RayDDA(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
reset(dimension, start_chunk, start_fpos, direction);
}
-void world::RayDDA::reset(const world::Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+void RayDDA::reset(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
this->dimension = dimension;
this->start_chunk = start_chunk;
@@ -65,13 +62,12 @@ void world::RayDDA::reset(const world::Dimension* dimension, const chunk_pos& st
}
}
-void world::RayDDA::reset(const world::Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos,
- const glm::fvec3& direction)
+void RayDDA::reset(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction)
{
reset(&dimension, start_chunk, start_fpos, direction);
}
-const world::Voxel* world::RayDDA::step(void)
+const Voxel* RayDDA::step(void)
{
if(side_dist.x < side_dist.z) {
if(side_dist.x < side_dist.y) {
diff --git a/src/game/shared/world/ray_dda.hh b/src/game/shared/world/ray_dda.hh
index 0f548ba..72f746e 100644
--- a/src/game/shared/world/ray_dda.hh
+++ b/src/game/shared/world/ray_dda.hh
@@ -2,14 +2,9 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
class Voxel;
-} // namespace world
-namespace world
-{
class RayDDA final {
public:
RayDDA(void) = default;
@@ -35,4 +30,3 @@ public:
voxel_pos vnormal;
voxel_pos vpos;
};
-} // namespace world
diff --git a/src/game/shared/world/voxel.cc b/src/game/shared/world/voxel.cc
index 21fe62c..4f47c2d 100644
--- a/src/game/shared/world/voxel.cc
+++ b/src/game/shared/world/voxel.cc
@@ -6,33 +6,33 @@
#include "shared/world/dimension.hh"
-world::Voxel::Voxel(const Voxel& source, voxel_id id) noexcept : Voxel(source)
+Voxel::Voxel(const Voxel& source, voxel_id id) noexcept : Voxel(source)
{
m_id = id;
}
-void world::Voxel::on_place(Dimension* dimension, const voxel_pos& vpos) const
+void Voxel::on_place(Dimension* dimension, const voxel_pos& vpos) const
{
if(m_on_place) {
m_on_place(dimension, vpos);
}
}
-void world::Voxel::on_remove(Dimension* dimension, const voxel_pos& vpos) const
+void Voxel::on_remove(Dimension* dimension, const voxel_pos& vpos) const
{
if(m_on_remove) {
m_on_remove(dimension, vpos);
}
}
-void world::Voxel::on_tick(Dimension* dimension, const voxel_pos& vpos) const
+void Voxel::on_tick(Dimension* dimension, const voxel_pos& vpos) const
{
if(m_on_tick) {
m_on_tick(dimension, vpos);
}
}
-std::size_t world::Voxel::get_random_texture_index(VoxelFace face, const voxel_pos& vpos) const
+std::size_t Voxel::get_random_texture_index(VoxelFace face, const voxel_pos& vpos) const
{
const auto& textures = get_face_textures(face);
@@ -46,7 +46,7 @@ std::size_t world::Voxel::get_random_texture_index(VoxelFace face, const voxel_p
return static_cast<std::size_t>(hash % textures.size());
}
-void world::Voxel::set_face_cache(VoxelFace face, std::size_t offset, std::size_t plane)
+void Voxel::set_face_cache(VoxelFace face, std::size_t offset, std::size_t plane)
{
assert(face < m_cached_face_offsets.size());
assert(face < m_cached_face_planes.size());
@@ -55,7 +55,7 @@ void world::Voxel::set_face_cache(VoxelFace face, std::size_t offset, std::size_
m_cached_face_planes[face] = plane;
}
-std::uint64_t world::Voxel::get_checksum(std::uint64_t combine) const
+std::uint64_t Voxel::get_checksum(std::uint64_t combine) const
{
combine = math::crc64(m_name.data(), m_name.size(), combine);
combine += static_cast<std::uint64_t>(m_shape);
@@ -63,76 +63,76 @@ std::uint64_t world::Voxel::get_checksum(std::uint64_t combine) const
return combine;
}
-world::VoxelBuilder::VoxelBuilder(std::string_view name)
+VoxelBuilder::VoxelBuilder(std::string_view name)
{
set_name(name);
}
-void world::VoxelBuilder::set_on_place(VoxelOnPlaceFunc func) noexcept
+void VoxelBuilder::set_on_place(VoxelOnPlaceFunc func) noexcept
{
m_on_place = std::move(func);
}
-void world::VoxelBuilder::set_on_remove(VoxelOnRemoveFunc func) noexcept
+void VoxelBuilder::set_on_remove(VoxelOnRemoveFunc func) noexcept
{
m_on_remove = std::move(func);
}
-void world::VoxelBuilder::set_on_tick(VoxelOnTickFunc func) noexcept
+void VoxelBuilder::set_on_tick(VoxelOnTickFunc func) noexcept
{
m_on_tick = std::move(func);
}
-void world::VoxelBuilder::set_name(std::string_view name) noexcept
+void VoxelBuilder::set_name(std::string_view name) noexcept
{
assert(name.size());
m_name = name;
}
-void world::VoxelBuilder::set_render_mode(VoxelRender mode) noexcept
+void VoxelBuilder::set_render_mode(VoxelRender mode) noexcept
{
m_render_mode = mode;
}
-void world::VoxelBuilder::set_shape(VoxelShape shape) noexcept
+void VoxelBuilder::set_shape(VoxelShape shape) noexcept
{
m_shape = shape;
}
-void world::VoxelBuilder::set_animated(bool animated) noexcept
+void VoxelBuilder::set_animated(bool animated) noexcept
{
m_animated = animated;
}
-void world::VoxelBuilder::set_touch_type(VoxelTouch type) noexcept
+void VoxelBuilder::set_touch_type(VoxelTouch type) noexcept
{
m_touch_type = type;
}
-void world::VoxelBuilder::set_touch_values(const glm::fvec3& values) noexcept
+void VoxelBuilder::set_touch_values(const glm::fvec3& values) noexcept
{
m_touch_values = values;
}
-void world::VoxelBuilder::set_surface_material(VoxelMaterial material) noexcept
+void VoxelBuilder::set_surface_material(VoxelMaterial material) noexcept
{
m_surface_material = material;
}
-void world::VoxelBuilder::set_collision(const math::AABBf& box) noexcept
+void VoxelBuilder::set_collision(const math::AABBf& box) noexcept
{
m_collision = box;
}
-void world::VoxelBuilder::add_default_texture(std::string_view path)
+void VoxelBuilder::add_default_texture(std::string_view path)
{
assert(path.size());
m_default_textures.emplace_back(path);
}
-void world::VoxelBuilder::add_face_texture(VoxelFace face, std::string_view path)
+void VoxelBuilder::add_face_texture(VoxelFace face, std::string_view path)
{
assert(face < m_face_textures.size());
assert(path.size());
@@ -140,7 +140,7 @@ void world::VoxelBuilder::add_face_texture(VoxelFace face, std::string_view path
m_face_textures[face].emplace_back(path);
}
-std::unique_ptr<world::Voxel> world::VoxelBuilder::build(voxel_id id) const
+std::unique_ptr<Voxel> VoxelBuilder::build(voxel_id id) const
{
assert(m_name.size());
assert(id);
diff --git a/src/game/shared/world/voxel.hh b/src/game/shared/world/voxel.hh
index 6013962..0a8c4a3 100644
--- a/src/game/shared/world/voxel.hh
+++ b/src/game/shared/world/voxel.hh
@@ -4,13 +4,8 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
-} // namespace world
-namespace world
-{
enum VoxelRender : unsigned int {
VRENDER_NONE = 0U, ///< The voxel is not rendered at all
VRENDER_OPAQUE, ///< The voxel is fully opaque
@@ -65,17 +60,11 @@ enum VoxelVisBits : unsigned int {
VVIS_UP = 1U << VFACE_TOP, ///< Positive Y
VVIS_DOWN = 1U << VFACE_BOTTOM, ///< Negative Y
};
-} // namespace world
-namespace world
-{
using VoxelOnPlaceFunc = std::function<void(Dimension*, const voxel_pos&)>;
using VoxelOnRemoveFunc = std::function<void(Dimension*, const voxel_pos&)>;
using VoxelOnTickFunc = std::function<void(Dimension*, const voxel_pos&)>;
-} // namespace world
-namespace world
-{
class Voxel {
public:
Voxel(void) = default;
@@ -154,10 +143,7 @@ protected:
VoxelOnRemoveFunc m_on_remove;
VoxelOnTickFunc m_on_tick;
};
-} // namespace world
-namespace world
-{
class VoxelBuilder final : public Voxel {
public:
VoxelBuilder(void) = default;
@@ -184,59 +170,58 @@ public:
std::unique_ptr<Voxel> build(voxel_id id) const;
};
-} // namespace world
-constexpr std::string_view world::Voxel::get_name(void) const noexcept
+constexpr std::string_view Voxel::get_name(void) const noexcept
{
return m_name;
}
-constexpr voxel_id world::Voxel::get_id(void) const noexcept
+constexpr voxel_id Voxel::get_id(void) const noexcept
{
return m_id;
}
-constexpr world::VoxelRender world::Voxel::get_render_mode(void) const noexcept
+constexpr VoxelRender Voxel::get_render_mode(void) const noexcept
{
return m_render_mode;
}
-constexpr world::VoxelShape world::Voxel::get_shape(void) const noexcept
+constexpr VoxelShape Voxel::get_shape(void) const noexcept
{
return m_shape;
}
-constexpr bool world::Voxel::is_animated(void) const noexcept
+constexpr bool Voxel::is_animated(void) const noexcept
{
return m_animated;
}
-constexpr world::VoxelTouch world::Voxel::get_touch_type(void) const noexcept
+constexpr VoxelTouch Voxel::get_touch_type(void) const noexcept
{
return m_touch_type;
}
-constexpr const glm::fvec3& world::Voxel::get_touch_values(void) const noexcept
+constexpr const glm::fvec3& Voxel::get_touch_values(void) const noexcept
{
return m_touch_values;
}
-constexpr world::VoxelMaterial world::Voxel::get_surface_material(void) const noexcept
+constexpr VoxelMaterial Voxel::get_surface_material(void) const noexcept
{
return m_surface_material;
}
-constexpr const math::AABBf& world::Voxel::get_collision(void) const noexcept
+constexpr const math::AABBf& Voxel::get_collision(void) const noexcept
{
return m_collision;
}
-constexpr const std::vector<std::string>& world::Voxel::get_default_textures(void) const noexcept
+constexpr const std::vector<std::string>& Voxel::get_default_textures(void) const noexcept
{
return m_default_textures;
}
-constexpr const std::vector<std::string>& world::Voxel::get_face_textures(VoxelFace face) const noexcept
+constexpr const std::vector<std::string>& Voxel::get_face_textures(VoxelFace face) const noexcept
{
assert(face <= m_face_textures.size());
@@ -247,40 +232,40 @@ constexpr const std::vector<std::string>& world::Voxel::get_face_textures(VoxelF
return m_face_textures[face];
}
-constexpr std::size_t world::Voxel::get_cached_face_offset(VoxelFace face) const noexcept
+constexpr std::size_t Voxel::get_cached_face_offset(VoxelFace face) const noexcept
{
assert(face <= m_cached_face_offsets.size());
return m_cached_face_offsets[face];
}
-constexpr std::size_t world::Voxel::get_cached_face_plane(VoxelFace face) const noexcept
+constexpr std::size_t Voxel::get_cached_face_plane(VoxelFace face) const noexcept
{
assert(face <= m_cached_face_planes.size());
return m_cached_face_planes[face];
}
-template<world::VoxelRender RenderMode>
-constexpr bool world::Voxel::is_render_mode(void) const noexcept
+template<VoxelRender RenderMode>
+constexpr bool Voxel::is_render_mode(void) const noexcept
{
return m_render_mode == RenderMode;
}
-template<world::VoxelShape Shape>
-constexpr bool world::Voxel::is_shape(void) const noexcept
+template<VoxelShape Shape>
+constexpr bool Voxel::is_shape(void) const noexcept
{
return m_shape == Shape;
}
-template<world::VoxelTouch TouchType>
-constexpr bool world::Voxel::is_touch_type(void) const noexcept
+template<VoxelTouch TouchType>
+constexpr bool Voxel::is_touch_type(void) const noexcept
{
return m_touch_type == TouchType;
}
-template<world::VoxelMaterial Material>
-constexpr bool world::Voxel::is_surface_material(void) const noexcept
+template<VoxelMaterial Material>
+constexpr bool Voxel::is_surface_material(void) const noexcept
{
return m_surface_material == Material;
}
diff --git a/src/game/shared/world/voxel_registry.cc b/src/game/shared/world/voxel_registry.cc
index fae83fa..f950a4d 100644
--- a/src/game/shared/world/voxel_registry.cc
+++ b/src/game/shared/world/voxel_registry.cc
@@ -3,19 +3,19 @@
#include "shared/world/voxel_registry.hh"
static std::uint64_t registry_checksum = 0U;
-emhash8::HashMap<std::string, voxel_id> world::voxel_registry::names;
-std::vector<std::unique_ptr<world::Voxel>> world::voxel_registry::voxels;
+emhash8::HashMap<std::string, voxel_id> voxel_registry::names;
+std::vector<std::unique_ptr<Voxel>> voxel_registry::voxels;
static void recalculate_checksum(void)
{
registry_checksum = 0U;
- for(const auto& voxel : world::voxel_registry::voxels) {
+ for(const auto& voxel : voxel_registry::voxels) {
registry_checksum = voxel->get_checksum(registry_checksum);
}
}
-world::Voxel* world::voxel_registry::register_voxel(const VoxelBuilder& builder)
+Voxel* voxel_registry::register_voxel(const VoxelBuilder& builder)
{
assert(builder.get_name().size());
assert(nullptr == find(builder.get_name()));
@@ -31,7 +31,7 @@ world::Voxel* world::voxel_registry::register_voxel(const VoxelBuilder& builder)
return voxels.back().get();
}
-world::Voxel* world::voxel_registry::find(std::string_view name)
+Voxel* voxel_registry::find(std::string_view name)
{
const auto it = names.find(std::string(name));
@@ -42,7 +42,7 @@ world::Voxel* world::voxel_registry::find(std::string_view name)
return voxels[it->second - 1].get();
}
-world::Voxel* world::voxel_registry::find(voxel_id id)
+Voxel* voxel_registry::find(voxel_id id)
{
if(id == NULL_VOXEL_ID || id > voxels.size()) {
return nullptr;
@@ -51,14 +51,14 @@ world::Voxel* world::voxel_registry::find(voxel_id id)
return voxels[id - 1].get();
}
-void world::voxel_registry::purge(void)
+void voxel_registry::purge(void)
{
registry_checksum = 0U;
voxels.clear();
names.clear();
}
-std::uint64_t world::voxel_registry::get_checksum(void)
+std::uint64_t voxel_registry::get_checksum(void)
{
return registry_checksum;
}
diff --git a/src/game/shared/world/voxel_registry.hh b/src/game/shared/world/voxel_registry.hh
index a1e0eee..5dbaf50 100644
--- a/src/game/shared/world/voxel_registry.hh
+++ b/src/game/shared/world/voxel_registry.hh
@@ -2,25 +2,25 @@
#include "shared/world/voxel.hh"
-namespace world::voxel_registry
+namespace voxel_registry
{
extern emhash8::HashMap<std::string, voxel_id> names;
extern std::vector<std::unique_ptr<Voxel>> voxels;
-} // namespace world::voxel_registry
+} // namespace voxel_registry
-namespace world::voxel_registry
+namespace voxel_registry
{
Voxel* register_voxel(const VoxelBuilder& builder);
Voxel* find(std::string_view name);
Voxel* find(voxel_id id);
-} // namespace world::voxel_registry
+} // namespace voxel_registry
-namespace world::voxel_registry
+namespace voxel_registry
{
void purge(void);
-} // namespace world::voxel_registry
+} // namespace voxel_registry
-namespace world::voxel_registry
+namespace voxel_registry
{
std::uint64_t get_checksum(void);
-} // namespace world::voxel_registry
+} // namespace voxel_registry
diff --git a/src/game/shared/world/voxel_storage.cc b/src/game/shared/world/voxel_storage.cc
index 68e261c..43ca116 100644
--- a/src/game/shared/world/voxel_storage.cc
+++ b/src/game/shared/world/voxel_storage.cc
@@ -4,7 +4,7 @@
#include "core/io/buffer.hh"
-void world::VoxelStorage::serialize(io::WriteBuffer& buffer) const
+void VoxelStorage::serialize(WriteBuffer& buffer) const
{
auto bound = mz_compressBound(sizeof(VoxelStorage));
auto zdata = std::vector<unsigned char>(bound);
@@ -28,7 +28,7 @@ void world::VoxelStorage::serialize(io::WriteBuffer& buffer) const
}
}
-void world::VoxelStorage::deserialize(io::ReadBuffer& buffer)
+void VoxelStorage::deserialize(ReadBuffer& buffer)
{
auto size = static_cast<mz_ulong>(sizeof(VoxelStorage));
auto bound = static_cast<mz_ulong>(buffer.read<std::uint64_t>());
diff --git a/src/game/shared/world/voxel_storage.hh b/src/game/shared/world/voxel_storage.hh
index ac7f03d..ef427b3 100644
--- a/src/game/shared/world/voxel_storage.hh
+++ b/src/game/shared/world/voxel_storage.hh
@@ -3,18 +3,12 @@
#include "shared/const.hh"
#include "shared/types.hh"
-namespace io
-{
class ReadBuffer;
class WriteBuffer;
-} // namespace io
-namespace world
-{
class VoxelStorage final : public std::array<voxel_id, CHUNK_VOLUME> {
public:
using std::array<voxel_id, CHUNK_VOLUME>::array;
- void serialize(io::WriteBuffer& buffer) const;
- void deserialize(io::ReadBuffer& buffer);
+ void serialize(WriteBuffer& buffer) const;
+ void deserialize(ReadBuffer& buffer);
};
-} // namespace world