summaryrefslogtreecommitdiffstats
path: root/game/shared
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-06-25 00:44:36 +0500
committeruntodesu <kirill@untode.su>2025-06-25 00:44:36 +0500
commit88c01588aa0830e219eaa62588839e4d1e2883ce (patch)
tree602bb27dd3399aab4aae8c19630e3b7a8dac824b /game/shared
parent99cf6cca8dbbc1e563c10cf0167432d3d8af9783 (diff)
downloadvoxelius-88c01588aa0830e219eaa62588839e4d1e2883ce.tar.bz2
voxelius-88c01588aa0830e219eaa62588839e4d1e2883ce.zip
Clang-format the entire source code
Diffstat (limited to 'game/shared')
-rw-r--r--game/shared/chunk.cc25
-rw-r--r--game/shared/chunk.hh14
-rw-r--r--game/shared/chunk_aabb.cc39
-rw-r--r--game/shared/chunk_aabb.hh18
-rw-r--r--game/shared/collision.cc115
-rw-r--r--game/shared/collision.hh2
-rw-r--r--game/shared/coord.hh44
-rw-r--r--game/shared/dimension.cc58
-rw-r--r--game/shared/dimension.hh46
-rw-r--r--game/shared/factory.cc11
-rw-r--r--game/shared/factory.hh2
-rw-r--r--game/shared/feature.cc5
-rw-r--r--game/shared/feature.hh4
-rw-r--r--game/shared/game.cc13
-rw-r--r--game/shared/game.hh2
-rw-r--r--game/shared/game_items.cc52
-rw-r--r--game/shared/game_voxels.cc115
-rw-r--r--game/shared/globals.cc1
-rw-r--r--game/shared/gravity.cc3
-rw-r--r--game/shared/gravity.hh2
-rw-r--r--game/shared/item_registry.cc35
-rw-r--r--game/shared/item_registry.hh12
-rw-r--r--game/shared/protocol.cc77
-rw-r--r--game/shared/protocol.hh66
-rw-r--r--game/shared/ray_dda.cc28
-rw-r--r--game/shared/ray_dda.hh10
-rw-r--r--game/shared/splash.cc18
-rw-r--r--game/shared/stasis.cc9
-rw-r--r--game/shared/stasis.hh2
-rw-r--r--game/shared/threading.cc20
-rw-r--r--game/shared/threading.hh14
-rw-r--r--game/shared/transform.cc5
-rw-r--r--game/shared/transform.hh2
-rw-r--r--game/shared/types.hh4
-rw-r--r--game/shared/velocity.cc3
-rw-r--r--game/shared/velocity.hh2
-rw-r--r--game/shared/voxel_registry.cc42
-rw-r--r--game/shared/voxel_registry.hh102
-rw-r--r--game/shared/voxel_storage.cc11
-rw-r--r--game/shared/voxel_storage.hh4
40 files changed, 521 insertions, 516 deletions
diff --git a/game/shared/chunk.cc b/game/shared/chunk.cc
index 17fdcc1..da798fa 100644
--- a/game/shared/chunk.cc
+++ b/game/shared/chunk.cc
@@ -1,9 +1,10 @@
#include "shared/pch.hh"
+
#include "shared/chunk.hh"
#include "shared/coord.hh"
-Chunk::Chunk(entt::entity entity, Dimension *dimension)
+Chunk::Chunk(entt::entity entity, Dimension* dimension)
{
m_entity = entity;
m_dimension = dimension;
@@ -11,36 +12,38 @@ Chunk::Chunk(entt::entity entity, Dimension *dimension)
m_biome = BIOME_VOID;
}
-voxel_id Chunk::get_voxel(const local_pos &lpos) const
+voxel_id Chunk::get_voxel(const local_pos& lpos) const
{
return get_voxel(coord::to_index(lpos));
}
voxel_id Chunk::get_voxel(const std::size_t index) const
{
- if(index >= CHUNK_VOLUME)
+ if(index >= CHUNK_VOLUME) {
return NULL_VOXEL_ID;
- return m_voxels[index];
+ } else {
+ return m_voxels[index];
+ }
}
-void Chunk::set_voxel(voxel_id voxel, const local_pos &lpos)
+void Chunk::set_voxel(voxel_id voxel, const local_pos& lpos)
{
set_voxel(voxel, coord::to_index(lpos));
}
void Chunk::set_voxel(voxel_id voxel, const std::size_t index)
{
- if(index >= CHUNK_VOLUME)
- return;
- m_voxels[index] = voxel;
+ if(index < CHUNK_VOLUME) {
+ m_voxels[index] = voxel;
+ }
}
-const VoxelStorage &Chunk::get_voxels(void) const
+const VoxelStorage& Chunk::get_voxels(void) const
{
return m_voxels;
}
-void Chunk::set_voxels(const VoxelStorage &voxels)
+void Chunk::set_voxels(const VoxelStorage& voxels)
{
m_voxels = voxels;
}
@@ -60,7 +63,7 @@ entt::entity Chunk::get_entity(void) const
return m_entity;
}
-Dimension *Chunk::get_dimension(void) const
+Dimension* Chunk::get_dimension(void) const
{
return m_dimension;
}
diff --git a/game/shared/chunk.hh b/game/shared/chunk.hh
index 560d3a7..67bedae 100644
--- a/game/shared/chunk.hh
+++ b/game/shared/chunk.hh
@@ -11,27 +11,27 @@ class Dimension;
class Chunk final {
public:
- explicit Chunk(entt::entity entity, Dimension *dimension);
+ explicit Chunk(entt::entity entity, Dimension* dimension);
virtual ~Chunk(void) = default;
- voxel_id get_voxel(const local_pos &lpos) const;
+ voxel_id get_voxel(const local_pos& lpos) const;
voxel_id get_voxel(const std::size_t index) const;
- void set_voxel(voxel_id voxel, const local_pos &lpos);
+ void set_voxel(voxel_id voxel, const local_pos& lpos);
void set_voxel(voxel_id voxel, const std::size_t index);
- const VoxelStorage &get_voxels(void) const;
- void set_voxels(const VoxelStorage &voxels);
+ const VoxelStorage& get_voxels(void) const;
+ void set_voxels(const VoxelStorage& voxels);
unsigned int get_biome(void) const;
void set_biome(unsigned int biome);
entt::entity get_entity(void) const;
- Dimension *get_dimension(void) const;
+ Dimension* get_dimension(void) const;
private:
entt::entity m_entity;
- Dimension *m_dimension;
+ Dimension* m_dimension;
VoxelStorage m_voxels;
unsigned int m_biome;
};
diff --git a/game/shared/chunk_aabb.cc b/game/shared/chunk_aabb.cc
index b4e5b82..5f23ea9 100644
--- a/game/shared/chunk_aabb.cc
+++ b/game/shared/chunk_aabb.cc
@@ -1,55 +1,52 @@
#include "shared/pch.hh"
+
#include "shared/chunk_aabb.hh"
-void ChunkAABB::set_bounds(const chunk_pos &min, const chunk_pos &max)
+void ChunkAABB::set_bounds(const chunk_pos& min, const chunk_pos& max)
{
this->min = min;
this->max = max;
}
-void ChunkAABB::set_offset(const chunk_pos &base, const chunk_pos &size)
+void ChunkAABB::set_offset(const chunk_pos& base, const chunk_pos& size)
{
this->min = base;
this->max = base + size;
}
-bool ChunkAABB::contains(const chunk_pos &point) const
+bool ChunkAABB::contains(const chunk_pos& point) const
{
- if((point.x < min.x) || (point.x > max.x))
- return false;
- if((point.y < min.y) || (point.y > max.y))
- return false;
- if((point.z < min.z) || (point.z > max.z))
- return false;
- return true;
+ auto result = true;
+ result = result && (point.x >= min.x) && (point.x <= max.x);
+ result = result && (point.y >= min.y) && (point.y <= max.y);
+ result = result && (point.z >= min.z) && (point.z <= max.z);
+ return result;
}
-bool ChunkAABB::intersect(const ChunkAABB &other_box) const
+bool ChunkAABB::intersect(const ChunkAABB& other_box) const
{
- if((min.x >= other_box.max.x) || (max.x <= other_box.min.x))
- return false;
- if((min.y >= other_box.max.y) || (max.y <= other_box.min.y))
- return false;
- if((min.z >= other_box.max.z) || (max.z <= other_box.min.z))
- return false;
- return true;
+ auto result = true;
+ result = result && (min.x < other_box.max.x) && (max.x > other_box.min.x);
+ result = result && (min.y < other_box.max.y) && (max.y > other_box.min.y);
+ result = result && (min.z < other_box.max.z) && (max.z > other_box.min.z);
+ return result;
}
-ChunkAABB ChunkAABB::combine_with(const ChunkAABB &other_box) const
+ChunkAABB ChunkAABB::combine_with(const ChunkAABB& other_box) const
{
ChunkAABB result;
result.set_bounds(min, other_box.max);
return result;
}
-ChunkAABB ChunkAABB::multiply_with(const ChunkAABB &other_box) const
+ChunkAABB ChunkAABB::multiply_with(const ChunkAABB& other_box) const
{
ChunkAABB result;
result.set_bounds(other_box.min, max);
return result;
}
-ChunkAABB ChunkAABB::push(const chunk_pos &vector) const
+ChunkAABB ChunkAABB::push(const chunk_pos& vector) const
{
ChunkAABB result;
result.set_bounds(min + vector, max + vector);
diff --git a/game/shared/chunk_aabb.hh b/game/shared/chunk_aabb.hh
index 68b8701..e215f9a 100644
--- a/game/shared/chunk_aabb.hh
+++ b/game/shared/chunk_aabb.hh
@@ -9,18 +9,18 @@ public:
explicit ChunkAABB(void) = default;
virtual ~ChunkAABB(void) = default;
- void set_bounds(const chunk_pos &min, const chunk_pos &max);
- void set_offset(const chunk_pos &base, const chunk_pos &size);
+ void set_bounds(const chunk_pos& min, const chunk_pos& max);
+ void set_offset(const chunk_pos& base, const chunk_pos& size);
- const chunk_pos &get_min(void) const;
- const chunk_pos &get_max(void) const;
+ const chunk_pos& get_min(void) const;
+ const chunk_pos& get_max(void) const;
- bool contains(const chunk_pos &point) const;
- bool intersect(const ChunkAABB &other_box) const;
+ bool contains(const chunk_pos& point) const;
+ bool intersect(const ChunkAABB& other_box) const;
- ChunkAABB combine_with(const ChunkAABB &other_box) const;
- ChunkAABB multiply_with(const ChunkAABB &other_box) const;
- ChunkAABB push(const chunk_pos &vector) const;
+ ChunkAABB combine_with(const ChunkAABB& other_box) const;
+ ChunkAABB multiply_with(const ChunkAABB& other_box) const;
+ ChunkAABB push(const chunk_pos& vector) const;
public:
chunk_pos min;
diff --git a/game/shared/collision.cc b/game/shared/collision.cc
index 0593fbb..af880ab 100644
--- a/game/shared/collision.cc
+++ b/game/shared/collision.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/collision.hh"
#include "core/constexpr.hh"
@@ -12,12 +13,12 @@
#include "shared/velocity.hh"
#include "shared/voxel_registry.hh"
-static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent &collision, TransformComponent &transform, VelocityComponent &velocity, voxel_surface &touch_surface)
+static int vgrid_collide(const Dimension* dimension, int d, CollisionComponent& collision, TransformComponent& transform, VelocityComponent& velocity, voxel_surface& touch_surface)
{
const auto move = globals::fixed_frametime * velocity.value[d];
const auto move_sign = cxpr::sign<int>(move);
- const auto &ref_aabb = collision.aabb;
+ const auto& ref_aabb = collision.aabb;
const auto current_aabb = ref_aabb.push(transform.local);
auto next_aabb = AABB(current_aabb);
@@ -46,8 +47,7 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent &
ddir = local_pos::value_type(+1);
dmin = lpos_min[d];
dmax = lpos_max[d];
- }
- else {
+ } else {
ddir = local_pos::value_type(-1);
dmin = lpos_max[d];
dmax = lpos_min[d];
@@ -60,50 +60,50 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent &
for(auto i = dmin; i != dmax; i += ddir) {
for(auto j = lpos_min[u]; j < lpos_max[u]; ++j)
- for(auto k = lpos_min[v]; k < lpos_max[v]; ++k) {
- local_pos lpos;
- lpos[d] = i;
- lpos[u] = j;
- lpos[v] = k;
-
- const auto vpos = coord::to_voxel(transform.chunk, lpos);
- const auto info = voxel_registry::find(dimension->get_voxel(vpos));
-
- if(info == nullptr) {
- // Don't collide with something
- // that we assume to be nothing
- continue;
- }
-
- AABB vbox;
- vbox.min = glm::fvec3(lpos);
- vbox.max = glm::fvec3(lpos) + 1.0f;
-
- if(!next_aabb.intersect(vbox)) {
- // No intersection between the voxel
- // and the entity's collision hull
- continue;
- }
-
- if(info->touch_type == voxel_touch::SOLID) {
- // Solid touch type makes a collision
- // response whenever it is encountered
- velocity.value[d] = 0.0f;
- touch_surface = info->surface;
- return move_sign;
+ for(auto k = lpos_min[v]; k < lpos_max[v]; ++k) {
+ local_pos lpos;
+ lpos[d] = i;
+ lpos[u] = j;
+ lpos[v] = k;
+
+ const auto vpos = coord::to_voxel(transform.chunk, lpos);
+ const auto info = voxel_registry::find(dimension->get_voxel(vpos));
+
+ if(info == nullptr) {
+ // Don't collide with something
+ // that we assume to be nothing
+ continue;
+ }
+
+ AABB vbox;
+ vbox.min = glm::fvec3(lpos);
+ vbox.max = glm::fvec3(lpos) + 1.0f;
+
+ if(!next_aabb.intersect(vbox)) {
+ // No intersection between the voxel
+ // and the entity's collision hull
+ continue;
+ }
+
+ if(info->touch_type == voxel_touch::SOLID) {
+ // Solid touch type makes a collision
+ // response whenever it is encountered
+ velocity.value[d] = 0.0f;
+ touch_surface = info->surface;
+ return move_sign;
+ }
+
+ // In case of other touch types, they
+ // are latched and the last ever touch
+ // type is then responded to
+ if(info->touch_type != voxel_touch::NOTHING) {
+ latch_touch = info->touch_type;
+ latch_values = info->touch_values;
+ latch_surface = info->surface;
+ latch_vbox = vbox;
+ continue;
+ }
}
-
- // In case of other touch types, they
- // are latched and the last ever touch
- // type is then responded to
- if(info->touch_type != voxel_touch::NOTHING) {
- latch_touch = info->touch_type;
- latch_values = info->touch_values;
- latch_surface = info->surface;
- latch_vbox = vbox;
- continue;
- }
- }
}
if(latch_touch != voxel_touch::NOTHING) {
@@ -111,10 +111,12 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent &
const auto move_distance = cxpr::abs(current_aabb.min[d] - next_aabb.min[d]);
const auto threshold = 2.0f * globals::fixed_frametime;
- if(move_distance > threshold)
+ if(move_distance > threshold) {
velocity.value[d] *= -latch_values[d];
- else velocity.value[d] = 0.0f;
-
+ } else {
+ velocity.value[d] = 0.0f;
+ }
+
touch_surface = latch_surface;
return move_sign;
@@ -130,7 +132,7 @@ static int vgrid_collide(const Dimension *dimension, int d, CollisionComponent &
return 0;
}
-void CollisionComponent::fixed_update(Dimension *dimension)
+void CollisionComponent::fixed_update(Dimension* dimension)
{
// FIXME: this isn't particularly accurate considering
// some voxels might be passable and some other voxels
@@ -148,11 +150,12 @@ void CollisionComponent::fixed_update(Dimension *dimension)
auto vertical_move = vgrid_collide(dimension, 1, collision, transform, velocity, surface);
if(dimension->entities.any_of<GravityComponent>(entity)) {
- if(vertical_move == cxpr::sign<int>(dimension->get_gravity()))
- dimension->entities.emplace_or_replace<GroundedComponent>(entity, GroundedComponent{surface});
- else dimension->entities.remove<GroundedComponent>(entity);
- }
- else {
+ if(vertical_move == cxpr::sign<int>(dimension->get_gravity())) {
+ dimension->entities.emplace_or_replace<GroundedComponent>(entity, GroundedComponent { surface });
+ } else {
+ dimension->entities.remove<GroundedComponent>(entity);
+ }
+ } else {
// The entity cannot be grounded because the component
// setup of said entity should not let it comprehend the
// concept of resting on the ground (it flies around)
diff --git a/game/shared/collision.hh b/game/shared/collision.hh
index 3e3643f..641a803 100644
--- a/game/shared/collision.hh
+++ b/game/shared/collision.hh
@@ -13,7 +13,7 @@ public:
// NOTE: CollisionComponent::fixed_update must be called
// before TransformComponent::fixed_update and VelocityComponent::fixed_update
// because both transform and velocity may be updated internally
- static void fixed_update(Dimension *dimension);
+ static void fixed_update(Dimension* dimension);
};
#endif /* SHARED_COLLISION_HH */
diff --git a/game/shared/coord.hh b/game/shared/coord.hh
index e51624f..4a11e60 100644
--- a/game/shared/coord.hh
+++ b/game/shared/coord.hh
@@ -7,41 +7,41 @@
namespace coord
{
-constexpr chunk_pos to_chunk(const voxel_pos &vpos);
+constexpr chunk_pos to_chunk(const voxel_pos& vpos);
} // namespace coord
namespace coord
{
-constexpr local_pos to_local(const voxel_pos &vpos);
-constexpr local_pos to_local(const glm::fvec3 &fvec);
+constexpr local_pos to_local(const voxel_pos& vpos);
+constexpr local_pos to_local(const glm::fvec3& fvec);
constexpr local_pos to_local(std::size_t index);
} // namespace coord
namespace coord
{
-constexpr voxel_pos to_voxel(const chunk_pos &cpos, const local_pos &lpos);
-constexpr voxel_pos to_voxel(const chunk_pos &cpos, const glm::fvec3 &fvec);
+constexpr voxel_pos to_voxel(const chunk_pos& cpos, const local_pos& lpos);
+constexpr voxel_pos to_voxel(const chunk_pos& cpos, const glm::fvec3& fvec);
} // namespace coord
namespace coord
{
-constexpr std::size_t to_index(const local_pos &lpos);
+constexpr std::size_t to_index(const local_pos& lpos);
} // namespace coord
namespace coord
{
-constexpr glm::fvec3 to_relative(const chunk_pos &pivot_cpos, const chunk_pos &cpos, const glm::fvec3 &fvec);
-constexpr glm::fvec3 to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos);
-constexpr glm::fvec3 to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos, const glm::fvec3 &fvec);
+constexpr glm::fvec3 to_relative(const chunk_pos& pivot_cpos, const chunk_pos& cpos, const glm::fvec3& fvec);
+constexpr glm::fvec3 to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos);
+constexpr glm::fvec3 to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos, const glm::fvec3& fvec);
} // namespace coord
namespace coord
{
-constexpr glm::fvec3 to_fvec3(const chunk_pos &cpos);
-constexpr glm::fvec3 to_fvec3(const chunk_pos &cpos, const glm::fvec3 &fpos);
+constexpr glm::fvec3 to_fvec3(const chunk_pos& cpos);
+constexpr glm::fvec3 to_fvec3(const chunk_pos& cpos, const glm::fvec3& fpos);
} // namespace coord
-inline constexpr chunk_pos coord::to_chunk(const voxel_pos &vpos)
+inline constexpr chunk_pos coord::to_chunk(const voxel_pos& vpos)
{
return chunk_pos {
static_cast<chunk_pos::value_type>(vpos.x >> CHUNK_BITSHIFT),
@@ -50,7 +50,7 @@ inline constexpr chunk_pos coord::to_chunk(const voxel_pos &vpos)
};
}
-inline constexpr local_pos coord::to_local(const voxel_pos &vpos)
+inline constexpr local_pos coord::to_local(const voxel_pos& vpos)
{
return local_pos {
static_cast<local_pos::value_type>(cxpr::mod_signed<voxel_pos::value_type>(vpos.x, CHUNK_SIZE)),
@@ -59,7 +59,7 @@ inline constexpr local_pos coord::to_local(const voxel_pos &vpos)
};
}
-inline constexpr local_pos coord::to_local(const glm::fvec3 &fvec)
+inline constexpr local_pos coord::to_local(const glm::fvec3& fvec)
{
return local_pos {
static_cast<local_pos::value_type>(fvec.x),
@@ -77,7 +77,7 @@ inline constexpr local_pos coord::to_local(std::size_t index)
};
}
-inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const local_pos &lpos)
+inline constexpr voxel_pos coord::to_voxel(const chunk_pos& cpos, const local_pos& lpos)
{
return voxel_pos {
lpos.x + (static_cast<voxel_pos::value_type>(cpos.x) << CHUNK_BITSHIFT),
@@ -86,7 +86,7 @@ inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const local_po
};
}
-inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const glm::fvec3 &fvec)
+inline constexpr voxel_pos coord::to_voxel(const chunk_pos& cpos, const glm::fvec3& fvec)
{
return voxel_pos {
static_cast<voxel_pos::value_type>(fvec.x) + (static_cast<voxel_pos::value_type>(cpos.x) << CHUNK_BITSHIFT),
@@ -95,12 +95,12 @@ inline constexpr voxel_pos coord::to_voxel(const chunk_pos &cpos, const glm::fve
};
}
-inline constexpr std::size_t coord::to_index(const local_pos &lpos)
+inline constexpr std::size_t coord::to_index(const local_pos& lpos)
{
return static_cast<std::size_t>((lpos.y * CHUNK_SIZE + lpos.z) * CHUNK_SIZE + lpos.x);
}
-inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, const chunk_pos &cpos, const glm::fvec3 &fvec)
+inline constexpr glm::fvec3 coord::to_relative(const chunk_pos& pivot_cpos, const chunk_pos& cpos, const glm::fvec3& fvec)
{
return glm::fvec3 {
static_cast<float>((cpos.x - pivot_cpos.x) << CHUNK_BITSHIFT) + fvec.x,
@@ -109,7 +109,7 @@ inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, cons
};
}
-inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos)
+inline constexpr glm::fvec3 coord::to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos)
{
return glm::fvec3 {
static_cast<float>((cpos.x - pivot_cpos.x) << CHUNK_BITSHIFT) - pivot_fvec.x,
@@ -118,7 +118,7 @@ inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, cons
};
}
-inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, const glm::fvec3 &pivot_fvec, const chunk_pos &cpos, const glm::fvec3 &fvec)
+inline constexpr glm::fvec3 coord::to_relative(const chunk_pos& pivot_cpos, const glm::fvec3& pivot_fvec, const chunk_pos& cpos, const glm::fvec3& fvec)
{
return glm::fvec3 {
static_cast<float>((cpos.x - pivot_cpos.x) << CHUNK_BITSHIFT) + (fvec.x - pivot_fvec.x),
@@ -127,7 +127,7 @@ inline constexpr glm::fvec3 coord::to_relative(const chunk_pos &pivot_cpos, cons
};
}
-inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos &cpos)
+inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos& cpos)
{
return glm::fvec3 {
static_cast<float>(cpos.x << CHUNK_BITSHIFT),
@@ -136,7 +136,7 @@ inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos &cpos)
};
}
-inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos &cpos, const glm::fvec3 &fpos)
+inline constexpr glm::fvec3 coord::to_fvec3(const chunk_pos& cpos, const glm::fvec3& fpos)
{
return glm::fvec3 {
fpos.x + static_cast<float>(cpos.x << CHUNK_BITSHIFT),
diff --git a/game/shared/dimension.cc b/game/shared/dimension.cc
index 2377214..a919dc4 100644
--- a/game/shared/dimension.cc
+++ b/game/shared/dimension.cc
@@ -1,11 +1,12 @@
#include "shared/pch.hh"
+
#include "shared/dimension.hh"
+#include "shared/chunk.hh"
#include "shared/coord.hh"
#include "shared/globals.hh"
-#include "shared/chunk.hh"
-Dimension::Dimension(const char *name, float gravity)
+Dimension::Dimension(const char* name, float gravity)
{
m_name = name;
m_gravity = gravity;
@@ -19,7 +20,7 @@ Dimension::~Dimension(void)
chunks.clear();
}
-const char *Dimension::get_name(void) const
+const char* Dimension::get_name(void) const
{
return m_name.c_str();
}
@@ -29,7 +30,7 @@ float Dimension::get_gravity(void) const
return m_gravity;
}
-Chunk *Dimension::create_chunk(const chunk_pos &cpos)
+Chunk* Dimension::create_chunk(const chunk_pos& cpos)
{
auto it = m_chunkmap.find(cpos);
@@ -41,7 +42,7 @@ Chunk *Dimension::create_chunk(const chunk_pos &cpos)
auto entity = chunks.create();
auto chunk = new Chunk(entity, this);
- auto &component = chunks.emplace<ChunkComponent>(entity);
+ auto& component = chunks.emplace<ChunkComponent>(entity);
component.chunk = chunk;
component.cpos = cpos;
@@ -55,31 +56,36 @@ Chunk *Dimension::create_chunk(const chunk_pos &cpos)
return m_chunkmap.insert_or_assign(cpos, std::move(chunk)).first->second;
}
-Chunk *Dimension::find_chunk(entt::entity entity) const
+Chunk* Dimension::find_chunk(entt::entity entity) const
{
- if(chunks.valid(entity))
+ if(chunks.valid(entity)) {
return chunks.get<ChunkComponent>(entity).chunk;
- return nullptr;
+ } else {
+ return nullptr;
+ }
}
-Chunk *Dimension::find_chunk(const chunk_pos &cpos) const
+Chunk* Dimension::find_chunk(const chunk_pos& cpos) const
{
auto it = m_chunkmap.find(cpos);
- if(it != m_chunkmap.cend())
+
+ if(it != m_chunkmap.cend()) {
return it->second;
- return nullptr;
+ } else {
+ return nullptr;
+ }
}
void Dimension::remove_chunk(entt::entity entity)
{
if(chunks.valid(entity)) {
- auto &component = chunks.get<ChunkComponent>(entity);
+ auto& component = chunks.get<ChunkComponent>(entity);
m_chunkmap.erase(component.cpos);
chunks.destroy(entity);
}
}
-void Dimension::remove_chunk(const chunk_pos &cpos)
+void Dimension::remove_chunk(const chunk_pos& cpos)
{
auto it = m_chunkmap.find(cpos);
@@ -89,26 +95,28 @@ void Dimension::remove_chunk(const chunk_pos &cpos)
}
}
-void Dimension::remove_chunk(Chunk *chunk)
+void Dimension::remove_chunk(Chunk* chunk)
{
if(chunk) {
- const auto &component = chunks.get<ChunkComponent>(chunk->get_entity());
+ const auto& component = chunks.get<ChunkComponent>(chunk->get_entity());
m_chunkmap.erase(component.cpos);
chunks.destroy(chunk->get_entity());
}
}
-voxel_id Dimension::get_voxel(const voxel_pos &vpos) const
+voxel_id Dimension::get_voxel(const voxel_pos& vpos) const
{
auto cpos = coord::to_chunk(vpos);
auto lpos = coord::to_local(vpos);
-
- if(auto chunk = find_chunk(cpos))
+
+ if(auto chunk = find_chunk(cpos)) {
return chunk->get_voxel(lpos);
- return NULL_VOXEL_ID;
+ } else {
+ return NULL_VOXEL_ID;
+ }
}
-voxel_id Dimension::get_voxel(const chunk_pos &cpos, const local_pos &lpos) const
+voxel_id 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
@@ -116,7 +124,7 @@ voxel_id Dimension::get_voxel(const chunk_pos &cpos, const local_pos &lpos) cons
return get_voxel(coord::to_voxel(cpos, lpos));
}
-bool Dimension::set_voxel(voxel_id voxel, const voxel_pos &vpos)
+bool Dimension::set_voxel(voxel_id voxel, const voxel_pos& vpos)
{
auto cpos = coord::to_chunk(vpos);
auto lpos = coord::to_local(vpos);
@@ -139,7 +147,7 @@ bool Dimension::set_voxel(voxel_id voxel, const voxel_pos &vpos)
return false;
}
-bool Dimension::set_voxel(voxel_id voxel, const chunk_pos &cpos, const local_pos &lpos)
+bool Dimension::set_voxel(voxel_id voxel, const chunk_pos& cpos, const local_pos& lpos)
{
// This allows accessing set_voxel with negative
// local coordinates that usually would result in an
@@ -147,17 +155,15 @@ bool Dimension::set_voxel(voxel_id voxel, const chunk_pos &cpos, const local_pos
return set_voxel(voxel, coord::to_voxel(cpos, lpos));
}
-void Dimension::init(Config &config)
+void Dimension::init(Config& config)
{
-
}
void Dimension::init_late(std::uint64_t global_seed)
{
-
}
-bool Dimension::generate(const chunk_pos &cpos, VoxelStorage &voxels)
+bool Dimension::generate(const chunk_pos& cpos, VoxelStorage& voxels)
{
return false;
}
diff --git a/game/shared/dimension.hh b/game/shared/dimension.hh
index 8806115..c609a14 100644
--- a/game/shared/dimension.hh
+++ b/game/shared/dimension.hh
@@ -14,32 +14,32 @@ using dimension_height_map = std::array<voxel_pos::value_type, CHUNK_AREA>;
class Dimension {
public:
- explicit Dimension(const char *name, float gravity);
+ explicit Dimension(const char* name, float gravity);
virtual ~Dimension(void);
- const char *get_name(void) const;
+ const char* get_name(void) const;
float get_gravity(void) const;
public:
- Chunk *create_chunk(const chunk_pos &cpos);
- Chunk *find_chunk(entt::entity entity) const;
- Chunk *find_chunk(const chunk_pos &cpos) const;
+ Chunk* create_chunk(const chunk_pos& cpos);
+ Chunk* find_chunk(entt::entity entity) const;
+ Chunk* find_chunk(const chunk_pos& cpos) const;
void remove_chunk(entt::entity entity);
- void remove_chunk(const chunk_pos &cpos);
- void remove_chunk(Chunk *chunk);
+ void remove_chunk(const chunk_pos& cpos);
+ void remove_chunk(Chunk* chunk);
public:
- voxel_id get_voxel(const voxel_pos &vpos) const;
- voxel_id get_voxel(const chunk_pos &cpos, const local_pos &lpos) const;
+ voxel_id get_voxel(const voxel_pos& vpos) const;
+ voxel_id get_voxel(const chunk_pos& cpos, const local_pos& lpos) const;
- bool set_voxel(voxel_id voxel, const voxel_pos &vpos);
- bool set_voxel(voxel_id voxel, const chunk_pos &cpos, const local_pos &lpos);
+ bool set_voxel(voxel_id voxel, const voxel_pos& vpos);
+ bool set_voxel(voxel_id voxel, const chunk_pos& cpos, const local_pos& lpos);
public:
- virtual void init(Config &config);
+ virtual void init(Config& config);
virtual void init_late(std::uint64_t global_seed);
- virtual bool generate(const chunk_pos &cpos, VoxelStorage &voxels);
+ virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels);
public:
entt::registry chunks;
@@ -47,39 +47,39 @@ public:
private:
std::string m_name;
- emhash8::HashMap<chunk_pos, Chunk *> m_chunkmap;
+ emhash8::HashMap<chunk_pos, Chunk*> m_chunkmap;
float m_gravity;
};
struct ChunkComponent final {
chunk_pos cpos;
- Chunk *chunk;
+ Chunk* chunk;
};
struct ChunkCreateEvent final {
- Dimension *dimension;
+ Dimension* dimension;
chunk_pos cpos;
- Chunk *chunk;
+ Chunk* chunk;
};
struct ChunkDestroyEvent final {
- Dimension *dimension;
+ Dimension* dimension;
chunk_pos cpos;
- Chunk *chunk;
+ Chunk* chunk;
};
struct ChunkUpdateEvent final {
- Dimension *dimension;
+ Dimension* dimension;
chunk_pos cpos;
- Chunk *chunk;
+ Chunk* chunk;
};
struct VoxelSetEvent final {
- Dimension *dimension;
+ Dimension* dimension;
chunk_pos cpos;
local_pos lpos;
voxel_id voxel;
- Chunk *chunk;
+ Chunk* chunk;
};
#endif /* SHARED_DIMENSION_HH */
diff --git a/game/shared/factory.cc b/game/shared/factory.cc
index 34cc55c..ad65928 100644
--- a/game/shared/factory.cc
+++ b/game/shared/factory.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/factory.hh"
#include "shared/collision.hh"
@@ -10,25 +11,25 @@
#include "shared/transform.hh"
#include "shared/velocity.hh"
-void shared_factory::create_player(Dimension *dimension, entt::entity entity)
+void shared_factory::create_player(Dimension* dimension, entt::entity entity)
{
spdlog::debug("factory[{}]: assigning player components to {}", dimension->get_name(), static_cast<std::uint64_t>(entity));
- auto &collision = dimension->entities.emplace_or_replace<CollisionComponent>(entity);
+ auto& collision = dimension->entities.emplace_or_replace<CollisionComponent>(entity);
collision.aabb.min = glm::fvec3(-0.4f, -1.6f, -0.4f);
collision.aabb.max = glm::fvec3(+0.4f, +0.2f, +0.4f);
- auto &head = dimension->entities.emplace_or_replace<HeadComponent>(entity);
+ auto& head = dimension->entities.emplace_or_replace<HeadComponent>(entity);
head.angles = glm::fvec3(0.0f, 0.0f, 0.0f);
head.offset = glm::fvec3(0.0f, 0.0f, 0.0f);
dimension->entities.emplace_or_replace<PlayerComponent>(entity);
- auto &transform = dimension->entities.emplace_or_replace<TransformComponent>(entity);
+ auto& transform = dimension->entities.emplace_or_replace<TransformComponent>(entity);
transform.chunk = chunk_pos(0, 2, 0);
transform.local = glm::fvec3(0.0f, 0.0f, 0.0f);
transform.angles = glm::fvec3(0.0f, 0.0f, 0.0f);
- auto &velocity = dimension->entities.emplace_or_replace<VelocityComponent>(entity);
+ auto& velocity = dimension->entities.emplace_or_replace<VelocityComponent>(entity);
velocity.value = glm::fvec3(0.0f, 0.0f, 0.0f);
}
diff --git a/game/shared/factory.hh b/game/shared/factory.hh
index 79df276..c3449dd 100644
--- a/game/shared/factory.hh
+++ b/game/shared/factory.hh
@@ -6,7 +6,7 @@ class Dimension;
namespace shared_factory
{
-void create_player(Dimension *dimension, entt::entity entity);
+void create_player(Dimension* dimension, entt::entity entity);
} // namespace shared_factory
#endif /* SHARED_FACTORY */
diff --git a/game/shared/feature.cc b/game/shared/feature.cc
index 845bb40..eb6cceb 100644
--- a/game/shared/feature.cc
+++ b/game/shared/feature.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/feature.hh"
#include "shared/chunk.hh"
@@ -6,7 +7,7 @@
#include "shared/dimension.hh"
#include "shared/voxel_storage.hh"
-void 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;
@@ -28,7 +29,7 @@ void Feature::place(const voxel_pos &vpos, Dimension *dimension) const
}
}
-void 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/game/shared/feature.hh b/game/shared/feature.hh
index b5cb262..306841e 100644
--- a/game/shared/feature.hh
+++ b/game/shared/feature.hh
@@ -13,8 +13,8 @@ public:
virtual ~Feature(void) = default;
public:
- void place(const voxel_pos &vpos, Dimension *dimension) const;
- void place(const voxel_pos &vpos, const chunk_pos &cpos, VoxelStorage &voxels) const;
+ void place(const voxel_pos& vpos, Dimension* dimension) const;
+ void place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const;
};
#endif /* SHARED_FEATURE_HH */
diff --git a/game/shared/game.cc b/game/shared/game.cc
index 22693eb..73de8b5 100644
--- a/game/shared/game.cc
+++ b/game/shared/game.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/game.hh"
#include "core/cmdline.hh"
@@ -47,10 +48,10 @@ static std::filesystem::path get_userpath(void)
return std::filesystem::current_path();
}
-void shared_game::init(int argc, char **argv)
+void shared_game::init(int argc, char** argv)
{
auto logger = spdlog::default_logger();
- auto &logger_sinks = logger->sinks();
+ auto& logger_sinks = logger->sinks();
logger_sinks.clear();
logger_sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>());
@@ -62,11 +63,13 @@ void shared_game::init(int argc, char **argv)
constexpr auto default_loglevel = spdlog::level::trace;
#endif
- if(cmdline::contains("quiet"))
+ if(cmdline::contains("quiet")) {
logger->set_level(spdlog::level::warn);
- else if(cmdline::contains("verbose"))
+ } else if(cmdline::contains("verbose")) {
logger->set_level(spdlog::level::trace);
- else logger->set_level(default_loglevel);
+ } else {
+ logger->set_level(default_loglevel);
+ }
logger->set_pattern("%H:%M:%S.%e %^[%L]%$ %v");
logger->flush();
diff --git a/game/shared/game.hh b/game/shared/game.hh
index f274d25..59c5327 100644
--- a/game/shared/game.hh
+++ b/game/shared/game.hh
@@ -4,7 +4,7 @@
namespace shared_game
{
-void init(int argc, char **argv);
+void init(int argc, char** argv);
void deinit(void);
} // namespace shared_game
diff --git a/game/shared/game_items.cc b/game/shared/game_items.cc
index dae286f..f2f1c0c 100644
--- a/game/shared/game_items.cc
+++ b/game/shared/game_items.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/game_items.hh"
#include "shared/game_voxels.hh"
@@ -18,61 +19,32 @@ item_id game_items::mud = NULL_ITEM_ID;
void game_items::populate(void)
{
// Stone; a hardened slate rock
- game_items::stone = item_registry::construct("stone")
- .set_texture("textures/item/stone.png")
- .set_place_voxel(game_voxels::stone)
- .build();
+ game_items::stone = item_registry::construct("stone").set_texture("textures/item/stone.png").set_place_voxel(game_voxels::stone).build();
// Cobblestone; a bunch of small stones
- game_items::cobblestone = item_registry::construct("cobblestone")
- .set_texture("textures/item/cobblestone.png")
- .set_place_voxel(game_voxels::cobblestone)
- .build();
+ game_items::cobblestone = item_registry::construct("cobblestone").set_texture("textures/item/cobblestone.png").set_place_voxel(game_voxels::cobblestone).build();
// Dirt; it's very dirty
- game_items::dirt = item_registry::construct("dirt")
- .set_texture("textures/item/dirt.png")
- .set_place_voxel(game_voxels::dirt)
- .build();
-
+ game_items::dirt = item_registry::construct("dirt").set_texture("textures/item/dirt.png").set_place_voxel(game_voxels::dirt).build();
+
// Grass; literally just grassy dirt
- game_items::grass = item_registry::construct("grass")
- .set_texture("textures/item/grass.png")
- .set_place_voxel(game_voxels::grass)
- .build();
+ game_items::grass = item_registry::construct("grass").set_texture("textures/item/grass.png").set_place_voxel(game_voxels::grass).build();
// Oak leaves; they're bushy!
- game_items::oak_leaves = item_registry::construct("oak_leaves")
- .set_texture("textures/item/oak_leaves.png")
- .set_place_voxel(game_voxels::oak_leaves)
- .build();
+ game_items::oak_leaves = item_registry::construct("oak_leaves").set_texture("textures/item/oak_leaves.png").set_place_voxel(game_voxels::oak_leaves).build();
// Oak planks; watch for splinters!
- game_items::oak_planks = item_registry::construct("oak_planks")
- .set_texture("textures/item/oak_planks.png")
- .set_place_voxel(game_voxels::oak_planks)
- .build();
+ game_items::oak_planks = item_registry::construct("oak_planks").set_texture("textures/item/oak_planks.png").set_place_voxel(game_voxels::oak_planks).build();
// Oak log; a big wad of wood
- game_items::oak_log = item_registry::construct("oak_log")
- .set_texture("textures/item/oak_log.png")
- .set_place_voxel(game_voxels::oak_log)
- .build();
+ game_items::oak_log = item_registry::construct("oak_log").set_texture("textures/item/oak_log.png").set_place_voxel(game_voxels::oak_log).build();
// Glass; used for windowing
- game_items::glass = item_registry::construct("glass")
- .set_texture("textures/item/glass.png")
- .set_place_voxel(game_voxels::glass)
- .build();
+ game_items::glass = item_registry::construct("glass").set_texture("textures/item/glass.png").set_place_voxel(game_voxels::glass).build();
// Slime; it's bouncy!
- game_items::slime = item_registry::construct("slime")
- .set_texture("textures/item/slime.png")
- .set_place_voxel(game_voxels::slime)
- .build();
+ game_items::slime = item_registry::construct("slime").set_texture("textures/item/slime.png").set_place_voxel(game_voxels::slime).build();
// Mud; you sink in it!
- game_items::mud = item_registry::construct("mud")
- .set_texture("textures/item/mud.png")
- .build();
+ game_items::mud = item_registry::construct("mud").set_texture("textures/item/mud.png").build();
}
diff --git a/game/shared/game_voxels.cc b/game/shared/game_voxels.cc
index b72ded4..23c953b 100644
--- a/game/shared/game_voxels.cc
+++ b/game/shared/game_voxels.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/game_voxels.hh"
#include "shared/voxel_registry.hh"
@@ -20,94 +21,88 @@ void game_voxels::populate(void)
{
// Stone; the backbone of the generated world
game_voxels::stone = voxel_registry::construct("stone", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/stone_01.png")
- .add_texture_default("textures/voxel/stone_02.png")
- .add_texture_default("textures/voxel/stone_03.png")
- .add_texture_default("textures/voxel/stone_04.png")
- .set_surface(voxel_surface::STONE)
- .build();
+ .add_texture_default("textures/voxel/stone_01.png")
+ .add_texture_default("textures/voxel/stone_02.png")
+ .add_texture_default("textures/voxel/stone_03.png")
+ .add_texture_default("textures/voxel/stone_04.png")
+ .set_surface(voxel_surface::STONE)
+ .build();
// Cobblestone; should drop when a stone is broken, might also be present in surface features
game_voxels::cobblestone = voxel_registry::construct("cobblestone", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/cobblestone_01.png")
- .add_texture_default("textures/voxel/cobblestone_02.png")
- .set_surface(voxel_surface::STONE)
- .build();
+ .add_texture_default("textures/voxel/cobblestone_01.png")
+ .add_texture_default("textures/voxel/cobblestone_02.png")
+ .set_surface(voxel_surface::STONE)
+ .build();
// Dirt with a grass layer on top; the top layer of plains biome
game_voxels::grass = voxel_registry::construct("grass", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/grass_side_01.png")
- .add_texture_default("textures/voxel/grass_side_02.png")
- .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_01.png")
- .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_02.png")
- .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_03.png")
- .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_04.png")
- .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_01.png")
- .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_02.png")
- .set_surface(voxel_surface::GRASS)
- .build();
+ .add_texture_default("textures/voxel/grass_side_01.png")
+ .add_texture_default("textures/voxel/grass_side_02.png")
+ .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_01.png")
+ .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_02.png")
+ .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_03.png")
+ .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/dirt_04.png")
+ .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_01.png")
+ .add_texture(voxel_face::CUBE_TOP, "textures/voxel/grass_02.png")
+ .set_surface(voxel_surface::GRASS)
+ .build();
// Dirt; the under-surface layer of some biomes
game_voxels::dirt = voxel_registry::construct("dirt", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/dirt_01.png")
- .add_texture_default("textures/voxel/dirt_02.png")
- .add_texture_default("textures/voxel/dirt_03.png")
- .add_texture_default("textures/voxel/dirt_04.png")
- .set_surface(voxel_surface::DIRT)
- .build();
+ .add_texture_default("textures/voxel/dirt_01.png")
+ .add_texture_default("textures/voxel/dirt_02.png")
+ .add_texture_default("textures/voxel/dirt_03.png")
+ .add_texture_default("textures/voxel/dirt_04.png")
+ .set_surface(voxel_surface::DIRT)
+ .build();
// VTest; a test voxel to ensure animations work
game_voxels::vtest = voxel_registry::construct("vtest", voxel_type::CUBE, true, false)
- .add_texture_default("textures/voxel/vtest_F1.png")
- .add_texture_default("textures/voxel/vtest_F2.png")
- .add_texture_default("textures/voxel/vtest_F3.png")
- .add_texture_default("textures/voxel/vtest_F4.png")
- .build();
+ .add_texture_default("textures/voxel/vtest_F1.png")
+ .add_texture_default("textures/voxel/vtest_F2.png")
+ .add_texture_default("textures/voxel/vtest_F3.png")
+ .add_texture_default("textures/voxel/vtest_F4.png")
+ .build();
// VTest-CK; a pure blue chromakey I used to make the game's logo
- game_voxels::vtest_ck = voxel_registry::construct("vtest_ck", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/chromakey.png")
- .build();
+ game_voxels::vtest_ck = voxel_registry::construct("vtest_ck", voxel_type::CUBE, false, false).add_texture_default("textures/voxel/chromakey.png").build();
// Oak leaves; greenery. TODO: add trees as surface features
- game_voxels::oak_leaves = voxel_registry::construct("oak_leaves", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/oak_leaves.png")
- .set_surface(voxel_surface::GRASS)
- .build();
+ game_voxels::oak_leaves =
+ voxel_registry::construct("oak_leaves", voxel_type::CUBE, false, false).add_texture_default("textures/voxel/oak_leaves.png").set_surface(voxel_surface::GRASS).build();
// Oak planks; the thing that comes out of oak logs
game_voxels::oak_planks = voxel_registry::construct("oak_planks", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/oak_planks_01.png")
- .add_texture_default("textures/voxel/oak_planks_02.png")
- .set_surface(voxel_surface::WOOD)
- .build();
+ .add_texture_default("textures/voxel/oak_planks_01.png")
+ .add_texture_default("textures/voxel/oak_planks_02.png")
+ .set_surface(voxel_surface::WOOD)
+ .build();
// Oak logs; greenery. TODO: add trees as surface features
game_voxels::oak_log = voxel_registry::construct("oak_log", voxel_type::CUBE, false, false)
- .add_texture_default("textures/voxel/oak_wood_01.png")
- .add_texture_default("textures/voxel/oak_wood_02.png")
- .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/oak_wood_top.png")
- .add_texture(voxel_face::CUBE_TOP, "textures/voxel/oak_wood_top.png")
- .set_surface(voxel_surface::WOOD)
- .build();
+ .add_texture_default("textures/voxel/oak_wood_01.png")
+ .add_texture_default("textures/voxel/oak_wood_02.png")
+ .add_texture(voxel_face::CUBE_BOTTOM, "textures/voxel/oak_wood_top.png")
+ .add_texture(voxel_face::CUBE_TOP, "textures/voxel/oak_wood_top.png")
+ .set_surface(voxel_surface::WOOD)
+ .build();
// Glass; blend rendering test
- game_voxels::glass = voxel_registry::construct("glass", voxel_type::CUBE, false, true)
- .add_texture_default("textures/voxel/glass_01.png")
- .set_surface(voxel_surface::GLASS)
- .build();
+ game_voxels::glass =
+ voxel_registry::construct("glass", voxel_type::CUBE, false, true).add_texture_default("textures/voxel/glass_01.png").set_surface(voxel_surface::GLASS).build();
// Slime; it's bouncy!
game_voxels::slime = voxel_registry::construct("slime", voxel_type::CUBE, false, true)
- .set_touch(voxel_touch::BOUNCE, glm::fvec3(0.00f, 0.60f, 0.00f))
- .add_texture_default("textures/voxel/slime_01.png")
- .build();
+ .set_touch(voxel_touch::BOUNCE, glm::fvec3(0.00f, 0.60f, 0.00f))
+ .add_texture_default("textures/voxel/slime_01.png")
+ .build();
// Mud; you sink in it
game_voxels::mud = voxel_registry::construct("mud", voxel_type::CUBE, false, false)
- .set_touch(voxel_touch::SINK, glm::fvec3(0.50f, 0.75f, 0.50f))
- .add_texture_default("textures/voxel/mud_01.png")
- .add_texture_default("textures/voxel/mud_02.png")
- .set_surface(voxel_surface::DIRT)
- .build();
+ .set_touch(voxel_touch::SINK, glm::fvec3(0.50f, 0.75f, 0.50f))
+ .add_texture_default("textures/voxel/mud_01.png")
+ .add_texture_default("textures/voxel/mud_02.png")
+ .set_surface(voxel_surface::DIRT)
+ .build();
}
diff --git a/game/shared/globals.cc b/game/shared/globals.cc
index 466398f..8552214 100644
--- a/game/shared/globals.cc
+++ b/game/shared/globals.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/globals.hh"
entt::dispatcher globals::dispatcher;
diff --git a/game/shared/gravity.cc b/game/shared/gravity.cc
index 66b6589..068f658 100644
--- a/game/shared/gravity.cc
+++ b/game/shared/gravity.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/gravity.hh"
#include "shared/dimension.hh"
@@ -6,7 +7,7 @@
#include "shared/stasis.hh"
#include "shared/velocity.hh"
-void GravityComponent::fixed_update(Dimension *dimension)
+void GravityComponent::fixed_update(Dimension* dimension)
{
auto fixed_acceleration = globals::fixed_frametime * dimension->get_gravity();
auto group = dimension->entities.group<GravityComponent>(entt::get<VelocityComponent>, entt::exclude<StasisComponent>);
diff --git a/game/shared/gravity.hh b/game/shared/gravity.hh
index 06eeae7..53f51b7 100644
--- a/game/shared/gravity.hh
+++ b/game/shared/gravity.hh
@@ -6,7 +6,7 @@ class Dimension;
struct GravityComponent final {
public:
- static void fixed_update(Dimension *dimension);
+ static void fixed_update(Dimension* dimension);
};
#endif /* SHARED_GRAVITY_HH */
diff --git a/game/shared/item_registry.cc b/game/shared/item_registry.cc
index 23dffdc..1263201 100644
--- a/game/shared/item_registry.cc
+++ b/game/shared/item_registry.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/item_registry.hh"
#include "core/crc64.hh"
@@ -9,7 +10,7 @@ std::unordered_map<std::string, ItemInfoBuilder> item_registry::builders = {};
std::unordered_map<std::string, item_id> item_registry::names = {};
std::vector<std::shared_ptr<ItemInfo>> item_registry::items = {};
-ItemInfoBuilder::ItemInfoBuilder(const char *name)
+ItemInfoBuilder::ItemInfoBuilder(const char* name)
{
prototype.name = name;
prototype.texture = std::string();
@@ -17,14 +18,14 @@ ItemInfoBuilder::ItemInfoBuilder(const char *name)
prototype.cached_texture = nullptr;
}
-ItemInfoBuilder &ItemInfoBuilder::set_texture(const char *texture)
+ItemInfoBuilder& ItemInfoBuilder::set_texture(const char* texture)
{
prototype.texture = texture;
prototype.cached_texture = nullptr;
return *this;
}
-ItemInfoBuilder &ItemInfoBuilder::set_place_voxel(voxel_id place_voxel)
+ItemInfoBuilder& ItemInfoBuilder::set_place_voxel(voxel_id place_voxel)
{
prototype.place_voxel = place_voxel;
return *this;
@@ -51,27 +52,35 @@ item_id ItemInfoBuilder::build(void) const
return static_cast<item_id>(item_registry::items.size());
}
-ItemInfoBuilder &item_registry::construct(const char *name)
+ItemInfoBuilder& item_registry::construct(const char* name)
{
const auto it = item_registry::builders.find(name);
- if(it != item_registry::builders.cend())
+
+ if(it != item_registry::builders.cend()) {
return it->second;
- return item_registry::builders.emplace(name, ItemInfoBuilder(name)).first->second;
+ } else {
+ return item_registry::builders.emplace(name, ItemInfoBuilder(name)).first->second;
+ }
}
-ItemInfo *item_registry::find(const char *name)
+ItemInfo* item_registry::find(const char* name)
{
const auto it = item_registry::names.find(name);
- if(it != item_registry::names.cend())
+
+ if(it != item_registry::names.cend()) {
return item_registry::find(it->second);
- return nullptr;
+ } else {
+ return nullptr;
+ }
}
-ItemInfo *item_registry::find(const item_id item)
+ItemInfo* item_registry::find(const item_id item)
{
- if((item != NULL_ITEM_ID) && (item <= item_registry::items.size()))
+ if((item != NULL_ITEM_ID) && (item <= item_registry::items.size())) {
return item_registry::items[item - 1].get();
- return nullptr;
+ } else {
+ return nullptr;
+ }
}
void item_registry::purge(void)
@@ -85,7 +94,7 @@ std::uint64_t item_registry::calcualte_checksum(void)
{
std::uint64_t result = 0;
- for(const auto &info : item_registry::items) {
+ for(const auto& info : item_registry::items) {
result = crc64::get(info->name, result);
result += static_cast<std::uint64_t>(info->place_voxel);
}
diff --git a/game/shared/item_registry.hh b/game/shared/item_registry.hh
index 83b6053..17cff9f 100644
--- a/game/shared/item_registry.hh
+++ b/game/shared/item_registry.hh
@@ -21,12 +21,12 @@ struct ItemInfo final {
class ItemInfoBuilder final {
public:
- explicit ItemInfoBuilder(const char *name);
+ explicit ItemInfoBuilder(const char* name);
virtual ~ItemInfoBuilder(void) = default;
public:
- ItemInfoBuilder &set_texture(const char *texture);
- ItemInfoBuilder &set_place_voxel(voxel_id place_voxel);
+ ItemInfoBuilder& set_texture(const char* texture);
+ ItemInfoBuilder& set_place_voxel(voxel_id place_voxel);
public:
item_id build(void) const;
@@ -44,9 +44,9 @@ extern std::vector<std::shared_ptr<ItemInfo>> items;
namespace item_registry
{
-ItemInfoBuilder &construct(const char *name);
-ItemInfo *find(const char *name);
-ItemInfo *find(const item_id item);
+ItemInfoBuilder& construct(const char* name);
+ItemInfo* find(const char* name);
+ItemInfo* find(const item_id item);
} // namespace item_registry
namespace item_registry
diff --git a/game/shared/protocol.cc b/game/shared/protocol.cc
index 3b32701..0e57fe4 100644
--- a/game/shared/protocol.cc
+++ b/game/shared/protocol.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/protocol.hh"
#include "core/buffer.hh"
@@ -15,7 +16,7 @@
static ReadBuffer read_buffer;
static WriteBuffer write_buffer;
-ENetPacket *protocol::encode(const protocol::StatusRequest &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::StatusRequest& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::StatusRequest::ID);
@@ -23,7 +24,7 @@ ENetPacket *protocol::encode(const protocol::StatusRequest &packet, enet_uint32
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::StatusResponse &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::StatusResponse& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::StatusResponse::ID);
@@ -34,7 +35,7 @@ ENetPacket *protocol::encode(const protocol::StatusResponse &packet, enet_uint32
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::LoginRequest &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::LoginRequest& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::LoginRequest::ID);
@@ -46,7 +47,7 @@ ENetPacket *protocol::encode(const protocol::LoginRequest &packet, enet_uint32 f
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::LoginResponse &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::LoginResponse& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::LoginResponse::ID);
@@ -56,7 +57,7 @@ ENetPacket *protocol::encode(const protocol::LoginResponse &packet, enet_uint32
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::Disconnect &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::Disconnect& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::Disconnect::ID);
@@ -64,7 +65,7 @@ ENetPacket *protocol::encode(const protocol::Disconnect &packet, enet_uint32 fla
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::ChunkVoxels &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::ChunkVoxels& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::ChunkVoxels::ID);
@@ -75,7 +76,7 @@ ENetPacket *protocol::encode(const protocol::ChunkVoxels &packet, enet_uint32 fl
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::EntityTransform &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::EntityTransform& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::EntityTransform::ID);
@@ -92,7 +93,7 @@ ENetPacket *protocol::encode(const protocol::EntityTransform &packet, enet_uint3
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::EntityHead &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::EntityHead& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::EntityHead::ID);
@@ -103,7 +104,7 @@ ENetPacket *protocol::encode(const protocol::EntityHead &packet, enet_uint32 fla
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::EntityVelocity &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::EntityVelocity& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::EntityVelocity::ID);
@@ -114,15 +115,15 @@ ENetPacket *protocol::encode(const protocol::EntityVelocity &packet, enet_uint32
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::SpawnPlayer &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::SpawnPlayer& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::SpawnPlayer::ID);
- write_buffer.write_UI64(static_cast<std::uint64_t>(packet.entity));
+ write_buffer.write_UI64(static_cast<std::uint64_t>(packet.entity));
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::ChatMessage &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::ChatMessage& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::ChatMessage::ID);
@@ -132,7 +133,7 @@ ENetPacket *protocol::encode(const protocol::ChatMessage &packet, enet_uint32 fl
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::SetVoxel &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::SetVoxel& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::SetVoxel::ID);
@@ -144,7 +145,7 @@ ENetPacket *protocol::encode(const protocol::SetVoxel &packet, enet_uint32 flags
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::RemoveEntity &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::RemoveEntity& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::RemoveEntity::ID);
@@ -152,7 +153,7 @@ ENetPacket *protocol::encode(const protocol::RemoveEntity &packet, enet_uint32 f
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::EntityPlayer &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::EntityPlayer& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::EntityPlayer::ID);
@@ -160,17 +161,17 @@ ENetPacket *protocol::encode(const protocol::EntityPlayer &packet, enet_uint32 f
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::ScoreboardUpdate &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::ScoreboardUpdate& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::ScoreboardUpdate::ID);
write_buffer.write_UI16(static_cast<std::uint16_t>(packet.names.size()));
- for(const std::string &username : packet.names)
+ for(const std::string& username : packet.names)
write_buffer.write_string(username.substr(0, protocol::MAX_USERNAME));
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::RequestChunk &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::RequestChunk& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::RequestChunk::ID);
@@ -180,7 +181,7 @@ ENetPacket *protocol::encode(const protocol::RequestChunk &packet, enet_uint32 f
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::GenericSound &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::GenericSound& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::GenericSound::ID);
@@ -190,7 +191,7 @@ ENetPacket *protocol::encode(const protocol::GenericSound &packet, enet_uint32 f
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::EntitySound &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::EntitySound& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::EntitySound::ID);
@@ -201,7 +202,7 @@ ENetPacket *protocol::encode(const protocol::EntitySound &packet, enet_uint32 fl
return write_buffer.to_packet(flags);
}
-ENetPacket *protocol::encode(const protocol::DimensionInfo &packet, enet_uint32 flags)
+ENetPacket* protocol::encode(const protocol::DimensionInfo& packet, enet_uint32 flags)
{
write_buffer.reset();
write_buffer.write_UI16(protocol::DimensionInfo::ID);
@@ -210,34 +211,34 @@ ENetPacket *protocol::encode(const protocol::DimensionInfo &packet, enet_uint32
return write_buffer.to_packet(flags);
}
-void protocol::broadcast(ENetHost *host, ENetPacket *packet)
+void protocol::broadcast(ENetHost* host, ENetPacket* packet)
{
if(packet) {
enet_host_broadcast(host, protocol::CHANNEL, packet);
}
}
-void protocol::broadcast(ENetHost *host, ENetPacket *packet, ENetPeer *except)
+void protocol::broadcast(ENetHost* host, ENetPacket* packet, ENetPeer* except)
{
if(packet) {
for(unsigned int i = 0U; i < host->peerCount; ++i) {
if(host->peers[i].state == ENET_PEER_STATE_CONNECTED) {
- if(&host->peers[i] == except)
- continue;
- enet_peer_send(&host->peers[i], protocol::CHANNEL, packet);
+ if(&host->peers[i] != except) {
+ enet_peer_send(&host->peers[i], protocol::CHANNEL, packet);
+ }
}
}
}
}
-void protocol::send(ENetPeer *peer, ENetPacket *packet)
+void protocol::send(ENetPeer* peer, ENetPacket* packet)
{
if(packet) {
enet_peer_send(peer, protocol::CHANNEL, packet);
}
}
-void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, ENetPeer *peer)
+void protocol::decode(entt::dispatcher& dispatcher, const ENetPacket* packet, ENetPeer* peer)
{
read_buffer.reset(packet);
@@ -260,9 +261,9 @@ void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, EN
protocol::GenericSound generic_sound;
protocol::EntitySound entity_sound;
protocol::DimensionInfo dimension_info;
-
+
auto id = read_buffer.read_UI16();
-
+
switch(id) {
case protocol::StatusRequest::ID:
status_request.peer = peer;
@@ -405,14 +406,14 @@ void protocol::decode(entt::dispatcher &dispatcher, const ENetPacket *packet, EN
}
}
-ENetPacket *protocol::utils::make_disconnect(const char *reason, enet_uint32 flags)
+ENetPacket* protocol::utils::make_disconnect(const char* reason, enet_uint32 flags)
{
protocol::Disconnect packet;
packet.reason = std::string(reason);
return protocol::encode(packet, flags);
}
-ENetPacket *protocol::utils::make_chat_message(const char *message, enet_uint32 flags)
+ENetPacket* protocol::utils::make_chat_message(const char* message, enet_uint32 flags)
{
protocol::ChatMessage packet;
packet.type = protocol::ChatMessage::TEXT_MESSAGE;
@@ -420,7 +421,7 @@ ENetPacket *protocol::utils::make_chat_message(const char *message, enet_uint32
return protocol::encode(packet, flags);
}
-ENetPacket *protocol::utils::make_chunk_voxels(Dimension *dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_chunk_voxels(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
if(auto component = dimension->chunks.try_get<ChunkComponent>(entity)) {
protocol::ChunkVoxels packet;
@@ -432,7 +433,7 @@ ENetPacket *protocol::utils::make_chunk_voxels(Dimension *dimension, entt::entit
return nullptr;
}
-ENetPacket *protocol::utils::make_entity_head(Dimension *dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_head(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
if(auto component = dimension->entities.try_get<HeadComponent>(entity)) {
protocol::EntityHead packet;
@@ -444,7 +445,7 @@ ENetPacket *protocol::utils::make_entity_head(Dimension *dimension, entt::entity
return nullptr;
}
-ENetPacket *protocol::utils::make_entity_transform(Dimension *dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_transform(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
if(auto component = dimension->entities.try_get<TransformComponent>(entity)) {
protocol::EntityTransform packet;
@@ -458,7 +459,7 @@ ENetPacket *protocol::utils::make_entity_transform(Dimension *dimension, entt::e
return nullptr;
}
-ENetPacket *protocol::utils::make_entity_velocity(Dimension *dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_velocity(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
if(auto component = dimension->entities.try_get<VelocityComponent>(entity)) {
protocol::EntityVelocity packet;
@@ -470,7 +471,7 @@ ENetPacket *protocol::utils::make_entity_velocity(Dimension *dimension, entt::en
return nullptr;
}
-ENetPacket *protocol::utils::make_entity_player(Dimension *dimension, entt::entity entity, enet_uint32 flags)
+ENetPacket* protocol::utils::make_entity_player(Dimension* dimension, entt::entity entity, enet_uint32 flags)
{
if(dimension->entities.any_of<PlayerComponent>(entity)) {
protocol::EntityPlayer packet;
@@ -481,7 +482,7 @@ ENetPacket *protocol::utils::make_entity_player(Dimension *dimension, entt::enti
return nullptr;
}
-ENetPacket *protocol::utils::make_dimension_info(const Dimension *dimension)
+ENetPacket* protocol::utils::make_dimension_info(const Dimension* dimension)
{
protocol::DimensionInfo packet;
packet.name = dimension->get_name();
diff --git a/game/shared/protocol.hh b/game/shared/protocol.hh
index 727ab1f..5b25628 100644
--- a/game/shared/protocol.hh
+++ b/game/shared/protocol.hh
@@ -23,7 +23,7 @@ template<std::uint16_t packet_id>
struct Base {
constexpr static std::uint16_t ID = packet_id;
virtual ~Base(void) = default;
- ENetPeer *peer {nullptr};
+ ENetPeer* peer { nullptr };
};
} // namespace protocol
@@ -52,57 +52,57 @@ struct DimensionInfo;
namespace protocol
{
-ENetPacket *encode(const StatusRequest &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const StatusResponse &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const LoginRequest &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const LoginResponse &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const Disconnect &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const ChunkVoxels &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const EntityTransform &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const EntityHead &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const EntityVelocity &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const SpawnPlayer &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const ChatMessage &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const SetVoxel &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const RemoveEntity &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const EntityPlayer &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const ScoreboardUpdate &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const RequestChunk &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const GenericSound &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const EntitySound &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *encode(const DimensionInfo &packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const StatusRequest& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const StatusResponse& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const LoginRequest& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const LoginResponse& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const Disconnect& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const ChunkVoxels& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const EntityTransform& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const EntityHead& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const EntityVelocity& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const SpawnPlayer& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const ChatMessage& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const SetVoxel& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const RemoveEntity& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const EntityPlayer& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const ScoreboardUpdate& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const RequestChunk& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const GenericSound& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const EntitySound& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* encode(const DimensionInfo& packet, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
} // namespace protocol
namespace protocol
{
-void broadcast(ENetHost *host, ENetPacket *packet);
-void broadcast(ENetHost *host, ENetPacket *packet, ENetPeer *except);
-void send(ENetPeer *peer, ENetPacket *packet);
+void broadcast(ENetHost* host, ENetPacket* packet);
+void broadcast(ENetHost* host, ENetPacket* packet, ENetPeer* except);
+void send(ENetPeer* peer, ENetPacket* packet);
} // namespace protocol
namespace protocol
{
-void decode(entt::dispatcher &dispatcher, const ENetPacket *packet, ENetPeer *peer);
+void decode(entt::dispatcher& dispatcher, const ENetPacket* packet, ENetPeer* peer);
} // namespace protocol
namespace protocol::utils
{
-ENetPacket *make_disconnect(const char *reason, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *make_chat_message(const char *message, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_disconnect(const char* reason, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_chat_message(const char* message, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
} // namespace protocol::utils
namespace protocol::utils
{
-ENetPacket *make_chunk_voxels(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_chunk_voxels(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
} // namespace protocol::utils
namespace protocol::utils
{
-ENetPacket *make_entity_head(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *make_entity_transform(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *make_entity_velocity(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *make_entity_player(Dimension *dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
-ENetPacket *make_dimension_info(const Dimension *dimension);
+ENetPacket* make_entity_head(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_entity_transform(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_entity_velocity(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_entity_player(Dimension* dimension, entt::entity entity, enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE);
+ENetPacket* make_dimension_info(const Dimension* dimension);
} // namespace protocol::utils
struct protocol::StatusRequest final : public protocol::Base<0x0000> {
@@ -162,7 +162,7 @@ struct protocol::SpawnPlayer final : public protocol::Base<0x0009> {
struct protocol::ChatMessage final : public protocol::Base<0x000A> {
constexpr static std::uint16_t TEXT_MESSAGE = 0x0000;
- constexpr static std::uint16_t PLAYER_JOIN = 0x0001;
+ constexpr static std::uint16_t PLAYER_JOIN = 0x0001;
constexpr static std::uint16_t PLAYER_LEAVE = 0x0002;
std::uint16_t type;
diff --git a/game/shared/ray_dda.cc b/game/shared/ray_dda.cc
index 132d05a..3520817 100644
--- a/game/shared/ray_dda.cc
+++ b/game/shared/ray_dda.cc
@@ -1,20 +1,21 @@
#include "shared/pch.hh"
+
#include "shared/ray_dda.hh"
#include "shared/coord.hh"
#include "shared/dimension.hh"
-RayDDA::RayDDA(const 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);
}
-RayDDA::RayDDA(const 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 RayDDA::reset(const 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;
@@ -35,8 +36,7 @@ void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, con
if(direction.x < 0.0f) {
this->side_dist.x = this->delta_dist.x * (start_fpos.x - lpos.x);
this->vstep.x = voxel_pos::value_type(-1);
- }
- else {
+ } else {
this->side_dist.x = this->delta_dist.x * (lpos.x + 1.0f - start_fpos.x);
this->vstep.x = voxel_pos::value_type(+1);
}
@@ -44,8 +44,7 @@ void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, con
if(direction.y < 0.0f) {
this->side_dist.y = this->delta_dist.y * (start_fpos.y - lpos.y);
this->vstep.y = voxel_pos::value_type(-1);
- }
- else {
+ } else {
this->side_dist.y = this->delta_dist.y * (lpos.y + 1.0f - start_fpos.y);
this->vstep.y = voxel_pos::value_type(+1);
}
@@ -53,14 +52,13 @@ void RayDDA::reset(const Dimension *dimension, const chunk_pos &start_chunk, con
if(direction.z < 0.0f) {
this->side_dist.z = this->delta_dist.z * (start_fpos.z - lpos.z);
this->vstep.z = voxel_pos::value_type(-1);
- }
- else {
+ } else {
this->side_dist.z = this->delta_dist.z * (lpos.z + 1.0f - start_fpos.z);
this->vstep.z = voxel_pos::value_type(+1);
}
}
-void RayDDA::reset(const 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);
}
@@ -73,22 +71,19 @@ voxel_id RayDDA::step(void)
distance = side_dist.x;
side_dist.x += delta_dist.x;
vpos.x += vstep.x;
- }
- else {
+ } else {
vnormal = voxel_pos(0, -vstep.y, 0);
distance = side_dist.y;
side_dist.y += delta_dist.y;
vpos.y += vstep.y;
}
- }
- else {
+ } else {
if(side_dist.z < side_dist.y) {
vnormal = voxel_pos(0, 0, -vstep.z);
distance = side_dist.z;
side_dist.z += delta_dist.z;
vpos.z += vstep.z;
- }
- else {
+ } else {
vnormal = voxel_pos(0, -vstep.y, 0);
distance = side_dist.y;
side_dist.y += delta_dist.y;
@@ -99,4 +94,3 @@ voxel_id RayDDA::step(void)
// This is slower than I want it to be
return dimension->get_voxel(vpos);
}
-
diff --git a/game/shared/ray_dda.hh b/game/shared/ray_dda.hh
index 9b4374e..5378680 100644
--- a/game/shared/ray_dda.hh
+++ b/game/shared/ray_dda.hh
@@ -9,16 +9,16 @@ class Dimension;
class RayDDA final {
public:
explicit RayDDA(void) = default;
- explicit RayDDA(const Dimension *dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction);
- explicit RayDDA(const Dimension &dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction);
+ explicit RayDDA(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);
+ explicit RayDDA(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);
- void reset(const Dimension *dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction);
- void reset(const Dimension &dimension, const chunk_pos &start_chunk, const glm::fvec3 &start_fpos, const glm::fvec3 &direction);
+ void reset(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);
+ void reset(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);
voxel_id step(void);
public:
- const Dimension *dimension;
+ const Dimension* dimension;
chunk_pos start_chunk;
glm::fvec3 start_fpos;
glm::fvec3 direction;
diff --git a/game/shared/splash.cc b/game/shared/splash.cc
index 068c5c6..2381f7a 100644
--- a/game/shared/splash.cc
+++ b/game/shared/splash.cc
@@ -1,27 +1,28 @@
#include "shared/pch.hh"
+
#include "shared/splash.hh"
-constexpr static const char *SPLASHES_FILENAME_CLIENT = "misc/splashes_client.txt";
-constexpr static const char *SPLASHES_FILENAME_SERVER = "misc/splashes_server.txt";
+constexpr static const char* SPLASHES_FILENAME_CLIENT = "misc/splashes_client.txt";
+constexpr static const char* SPLASHES_FILENAME_SERVER = "misc/splashes_server.txt";
constexpr static std::size_t SPLASH_SERVER_MAX_LENGTH = 32;
static std::mt19937_64 splash_random;
static std::vector<std::string> splash_lines;
-static std::string sanitize_line(const std::string &line)
+static std::string sanitize_line(const std::string& line)
{
std::string result;
for(auto chr : line) {
- if((chr == '\r') || (chr == '\n'))
- continue;
- result.push_back(chr);
+ if(chr != '\r' && chr != '\n') {
+ result.push_back(chr);
+ }
}
return result;
}
-static void splash_init_filename(const char *filename)
+static void splash_init_filename(const char* filename)
{
if(auto file = PHYSFS_openRead(filename)) {
auto source = std::string(PHYSFS_fileLength(file), char(0x00));
@@ -34,8 +35,7 @@ static void splash_init_filename(const char *filename)
while(std::getline(stream, line))
splash_lines.push_back(sanitize_line(line));
splash_random.seed(std::random_device()());
- }
- else {
+ } else {
splash_lines.push_back(fmt::format("{}: {}", filename, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
splash_random.seed(std::random_device()());
}
diff --git a/game/shared/stasis.cc b/game/shared/stasis.cc
index 4e474af..462871d 100644
--- a/game/shared/stasis.cc
+++ b/game/shared/stasis.cc
@@ -1,16 +1,19 @@
#include "shared/pch.hh"
+
#include "shared/stasis.hh"
#include "shared/dimension.hh"
#include "shared/transform.hh"
-void StasisComponent::fixed_update(Dimension *dimension)
+void StasisComponent::fixed_update(Dimension* dimension)
{
auto view = dimension->entities.view<TransformComponent>();
for(auto [entity, transform] : view.each()) {
- if(dimension->find_chunk(transform.chunk))
+ if(dimension->find_chunk(transform.chunk)) {
dimension->entities.remove<StasisComponent>(entity);
- else dimension->entities.emplace_or_replace<StasisComponent>(entity);
+ } else {
+ dimension->entities.emplace_or_replace<StasisComponent>(entity);
+ }
}
}
diff --git a/game/shared/stasis.hh b/game/shared/stasis.hh
index 6a3e280..bd06d4e 100644
--- a/game/shared/stasis.hh
+++ b/game/shared/stasis.hh
@@ -8,7 +8,7 @@ class Dimension;
// out of bounds in a specific dimension
struct StasisComponent final {
public:
- static void fixed_update(Dimension *dimension);
+ static void fixed_update(Dimension* dimension);
};
#endif /* SHARED_STASIS_HH */
diff --git a/game/shared/threading.cc b/game/shared/threading.cc
index 71c30e1..ad496ee 100644
--- a/game/shared/threading.cc
+++ b/game/shared/threading.cc
@@ -1,15 +1,16 @@
#include "shared/pch.hh"
+
#include "shared/threading.hh"
#include "core/cmdline.hh"
#include "core/constexpr.hh"
-constexpr static const char *DEFAULT_POOL_SIZE_ARG = "4";
+constexpr static const char* DEFAULT_POOL_SIZE_ARG = "4";
-static BS::light_thread_pool *thread_pool;
-static std::deque<Task *> task_deque;
+static BS::light_thread_pool* thread_pool;
+static std::deque<Task*> task_deque;
-static void task_process(Task *task)
+static void task_process(Task* task)
{
task->set_status(task_status::PROCESSING);
task->process();
@@ -41,11 +42,12 @@ void threading::init(void)
// Use the maximum available number of concurrent
// hardware threads provided by the implementation
thread_pool_size = num_concurrent_threads;
- }
- else {
- if(num_concurrent_threads)
+ } else {
+ if(num_concurrent_threads) {
thread_pool_size = cxpr::clamp<unsigned int>(std::strtoul(argument, nullptr, 10), 1U, num_concurrent_threads);
- else thread_pool_size = cxpr::max<unsigned int>(std::strtoul(argument, nullptr, 10), 1U);
+ } else {
+ thread_pool_size = cxpr::max<unsigned int>(std::strtoul(argument, nullptr, 10), 1U);
+ }
}
spdlog::info("threading: using {} threads for pooling tasks", thread_pool_size);
@@ -99,7 +101,7 @@ void threading::update(void)
}
}
-void threading::detail::submit_new(Task *task)
+void threading::detail::submit_new(Task* task)
{
task->set_status(task_status::ENQUEUED);
diff --git a/game/shared/threading.hh b/game/shared/threading.hh
index 083ccbf..bce4811 100644
--- a/game/shared/threading.hh
+++ b/game/shared/threading.hh
@@ -3,10 +3,10 @@
#pragma once
enum class task_status : unsigned int {
- ENQUEUED = 0x0000U,
- PROCESSING = 0x0001U,
- COMPLETED = 0x0002U,
- CANCELLED = 0x0004U,
+ ENQUEUED = 0x0000U,
+ PROCESSING = 0x0001U,
+ COMPLETED = 0x0002U,
+ CANCELLED = 0x0004U,
};
class Task {
@@ -32,17 +32,17 @@ void update(void);
namespace threading::detail
{
-void submit_new(Task *task);
+void submit_new(Task* task);
} // namespace threading::detail
namespace threading
{
template<typename T, typename... AT>
-void submit(AT &&... args);
+void submit(AT&&... args);
} // namespace threading
template<typename T, typename... AT>
-inline void threading::submit(AT &&... args)
+inline void threading::submit(AT&&... args)
{
threading::detail::submit_new(new T(args...));
}
diff --git a/game/shared/transform.cc b/game/shared/transform.cc
index 6dc6126..f4b661c 100644
--- a/game/shared/transform.cc
+++ b/game/shared/transform.cc
@@ -1,10 +1,11 @@
#include "shared/pch.hh"
+
#include "shared/transform.hh"
#include "shared/const.hh"
#include "shared/dimension.hh"
-constexpr inline static void update_component(unsigned int dim, TransformComponent &component)
+constexpr inline static void update_component(unsigned int dim, TransformComponent& component)
{
if(component.local[dim] >= CHUNK_SIZE) {
component.local[dim] -= CHUNK_SIZE;
@@ -19,7 +20,7 @@ constexpr inline static void update_component(unsigned int dim, TransformCompone
}
}
-void TransformComponent::fixed_update(Dimension *dimension)
+void TransformComponent::fixed_update(Dimension* dimension)
{
auto view = dimension->entities.view<TransformComponent>();
diff --git a/game/shared/transform.hh b/game/shared/transform.hh
index 0c0cc51..f9c5f47 100644
--- a/game/shared/transform.hh
+++ b/game/shared/transform.hh
@@ -15,7 +15,7 @@ public:
// Updates TransformComponent values so that
// the local translation field is always within
// local coodrinates; [floating-point precision]
- static void fixed_update(Dimension *dimension);
+ static void fixed_update(Dimension* dimension);
};
// Client-side only - interpolated and previous transform
diff --git a/game/shared/types.hh b/game/shared/types.hh
index a107e54..85fbd19 100644
--- a/game/shared/types.hh
+++ b/game/shared/types.hh
@@ -20,7 +20,7 @@ using voxel_pos_xz = glm::vec<2, local_pos::value_type>;
template<>
struct std::hash<chunk_pos> final {
- constexpr inline std::size_t operator()(const chunk_pos &cpos) const
+ constexpr inline std::size_t operator()(const chunk_pos& cpos) const
{
std::size_t value = 0;
value ^= cpos.x * 73856093;
@@ -32,7 +32,7 @@ struct std::hash<chunk_pos> final {
template<>
struct std::hash<chunk_pos_xz> final {
- constexpr inline std::size_t operator()(const chunk_pos_xz &cwpos) const
+ constexpr inline std::size_t operator()(const chunk_pos_xz& cwpos) const
{
std::size_t value = 0;
value ^= cwpos.x * 73856093;
diff --git a/game/shared/velocity.cc b/game/shared/velocity.cc
index 6305363..329dc91 100644
--- a/game/shared/velocity.cc
+++ b/game/shared/velocity.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/velocity.hh"
#include "shared/dimension.hh"
@@ -6,7 +7,7 @@
#include "shared/stasis.hh"
#include "shared/transform.hh"
-void VelocityComponent::fixed_update(Dimension *dimension)
+void VelocityComponent::fixed_update(Dimension* dimension)
{
auto group = dimension->entities.group<VelocityComponent>(entt::get<TransformComponent>, entt::exclude<StasisComponent>);
diff --git a/game/shared/velocity.hh b/game/shared/velocity.hh
index 9aafed1..45a2858 100644
--- a/game/shared/velocity.hh
+++ b/game/shared/velocity.hh
@@ -11,7 +11,7 @@ public:
// Updates entities TransformComponent values
// according to velocities multiplied by fixed_frametime.
// NOTE: This system was previously called inertial
- static void fixed_update(Dimension *dimension);
+ static void fixed_update(Dimension* dimension);
};
#endif /* SHARED_VELOCITY_HH */
diff --git a/game/shared/voxel_registry.cc b/game/shared/voxel_registry.cc
index ce6ee7f..cb3c724 100644
--- a/game/shared/voxel_registry.cc
+++ b/game/shared/voxel_registry.cc
@@ -1,4 +1,5 @@
#include "shared/pch.hh"
+
#include "shared/voxel_registry.hh"
#include "core/crc64.hh"
@@ -7,7 +8,7 @@ std::unordered_map<std::string, VoxelInfoBuilder> voxel_registry::builders = {};
std::unordered_map<std::string, voxel_id> voxel_registry::names = {};
std::vector<std::shared_ptr<VoxelInfo>> voxel_registry::voxels = {};
-VoxelInfoBuilder::VoxelInfoBuilder(const char *name, voxel_type type, bool animated, bool blending)
+VoxelInfoBuilder::VoxelInfoBuilder(const char* name, voxel_type type, bool animated, bool blending)
{
prototype.name = name;
prototype.type = type;
@@ -44,27 +45,27 @@ VoxelInfoBuilder::VoxelInfoBuilder(const char *name, voxel_type type, bool anima
prototype.item_pick = NULL_ITEM_ID;
}
-VoxelInfoBuilder &VoxelInfoBuilder::add_texture_default(const char *texture)
+VoxelInfoBuilder& VoxelInfoBuilder::add_texture_default(const char* texture)
{
default_texture.paths.push_back(texture);
return *this;
}
-VoxelInfoBuilder &VoxelInfoBuilder::add_texture(voxel_face face, const char *texture)
+VoxelInfoBuilder& VoxelInfoBuilder::add_texture(voxel_face face, const char* texture)
{
const auto index = static_cast<std::size_t>(face);
prototype.textures[index].paths.push_back(texture);
return *this;
}
-VoxelInfoBuilder &VoxelInfoBuilder::set_touch(voxel_touch type, const glm::fvec3 &values)
+VoxelInfoBuilder& VoxelInfoBuilder::set_touch(voxel_touch type, const glm::fvec3& values)
{
prototype.touch_type = type;
prototype.touch_values = values;
return *this;
}
-VoxelInfoBuilder &VoxelInfoBuilder::set_surface(voxel_surface surface)
+VoxelInfoBuilder& VoxelInfoBuilder::set_surface(voxel_surface surface)
{
prototype.surface = surface;
return *this;
@@ -113,8 +114,7 @@ voxel_id VoxelInfoBuilder::build(void) const
new_info->textures[i].paths = default_texture.paths;
new_info->textures[i].cached_offset = SIZE_MAX;
new_info->textures[i].cached_plane = SIZE_MAX;
- }
- else {
+ } else {
new_info->textures[i].paths = prototype.textures[i].paths;
new_info->textures[i].cached_offset = SIZE_MAX;
new_info->textures[i].cached_plane = SIZE_MAX;
@@ -139,27 +139,35 @@ voxel_id VoxelInfoBuilder::build(void) const
return new_info->base_voxel;
}
-VoxelInfoBuilder &voxel_registry::construct(const char *name, voxel_type type, bool animated, bool blending)
+VoxelInfoBuilder& voxel_registry::construct(const char* name, voxel_type type, bool animated, bool blending)
{
const auto it = voxel_registry::builders.find(name);
- if(it != voxel_registry::builders.cend())
+
+ if(it != voxel_registry::builders.cend()) {
return it->second;
- return voxel_registry::builders.emplace(name, VoxelInfoBuilder(name, type, animated, blending)).first->second;
+ } else {
+ return voxel_registry::builders.emplace(name, VoxelInfoBuilder(name, type, animated, blending)).first->second;
+ }
}
-VoxelInfo *voxel_registry::find(const char *name)
+VoxelInfo* voxel_registry::find(const char* name)
{
const auto it = voxel_registry::names.find(name);
- if(it != voxel_registry::names.cend())
+
+ if(it != voxel_registry::names.cend()) {
return voxel_registry::find(it->second);
- return nullptr;
+ } else {
+ return nullptr;
+ }
}
-VoxelInfo *voxel_registry::find(const voxel_id voxel)
+VoxelInfo* voxel_registry::find(const voxel_id voxel)
{
- if((voxel != NULL_VOXEL_ID) && (voxel <= voxel_registry::voxels.size()))
+ if((voxel != NULL_VOXEL_ID) && (voxel <= voxel_registry::voxels.size())) {
return voxel_registry::voxels[voxel - 1].get();
- return nullptr;
+ } else {
+ return nullptr;
+ }
}
void voxel_registry::purge(void)
@@ -173,7 +181,7 @@ std::uint64_t voxel_registry::calcualte_checksum(void)
{
std::uint64_t result = 0;
- for(const std::shared_ptr<VoxelInfo> &info : voxel_registry::voxels) {
+ for(const std::shared_ptr<VoxelInfo>& info : voxel_registry::voxels) {
result = crc64::get(info->name, result);
result += static_cast<std::uint64_t>(info->type);
result += static_cast<std::uint64_t>(info->base_voxel);
diff --git a/game/shared/voxel_registry.hh b/game/shared/voxel_registry.hh
index b12bc68..5f7963f 100644
--- a/game/shared/voxel_registry.hh
+++ b/game/shared/voxel_registry.hh
@@ -5,70 +5,70 @@
#include "shared/types.hh"
enum class voxel_face : unsigned short {
- CUBE_NORTH = 0x0000,
- CUBE_SOUTH = 0x0001,
- CUBE_EAST = 0x0002,
- CUBE_WEST = 0x0003,
- CUBE_TOP = 0x0004,
+ CUBE_NORTH = 0x0000,
+ CUBE_SOUTH = 0x0001,
+ CUBE_EAST = 0x0002,
+ CUBE_WEST = 0x0003,
+ CUBE_TOP = 0x0004,
CUBE_BOTTOM = 0x0005,
- CUBE__NR = 0x0006,
+ CUBE__NR = 0x0006,
- CROSS_NESW = 0x0000,
- CROSS_NWSE = 0x0001,
- CROSS__NR = 0x0002,
+ CROSS_NESW = 0x0000,
+ CROSS_NWSE = 0x0001,
+ CROSS__NR = 0x0002,
};
enum class voxel_type : unsigned short {
- CUBE = 0x0000,
- CROSS = 0x0001, // TODO
- MODEL = 0x0002, // TODO
+ CUBE = 0x0000,
+ CROSS = 0x0001, // TODO
+ MODEL = 0x0002, // TODO
};
enum class voxel_facing : unsigned short {
- NORTH = 0x0000,
- SOUTH = 0x0001,
- EAST = 0x0002,
- WEST = 0x0003,
- UP = 0x0004,
- DOWN = 0x0005,
- NESW = 0x0006,
- NWSE = 0x0007,
+ NORTH = 0x0000,
+ SOUTH = 0x0001,
+ EAST = 0x0002,
+ WEST = 0x0003,
+ UP = 0x0004,
+ DOWN = 0x0005,
+ NESW = 0x0006,
+ NWSE = 0x0007,
};
enum class voxel_touch : unsigned short {
- SOLID = 0x0000, // The entity is stopped in its tracks
- BOUNCE = 0x0001, // The entity bounces back with some energy loss
- SINK = 0x0002, // The entity phases/sinks through the voxel
- NOTHING = 0xFFFF,
+ SOLID = 0x0000, // The entity is stopped in its tracks
+ BOUNCE = 0x0001, // The entity bounces back with some energy loss
+ SINK = 0x0002, // The entity phases/sinks through the voxel
+ NOTHING = 0xFFFF,
};
enum class voxel_surface : unsigned short {
- DEFAULT = 0x0000,
- STONE = 0x0001,
- DIRT = 0x0002,
- GLASS = 0x0003,
- GRASS = 0x0004,
- GRAVEL = 0x0005,
- METAL = 0x0006,
- SAND = 0x0007,
- WOOD = 0x0008,
- SLOSH = 0x0009,
- COUNT = 0x000A,
- UNKNOWN = 0xFFFF,
+ DEFAULT = 0x0000,
+ STONE = 0x0001,
+ DIRT = 0x0002,
+ GLASS = 0x0003,
+ GRASS = 0x0004,
+ GRAVEL = 0x0005,
+ METAL = 0x0006,
+ SAND = 0x0007,
+ WOOD = 0x0008,
+ SLOSH = 0x0009,
+ COUNT = 0x000A,
+ UNKNOWN = 0xFFFF,
};
using voxel_vis = unsigned short;
-constexpr static voxel_vis VIS_NORTH = 1 << static_cast<unsigned int>(voxel_facing::NORTH);
-constexpr static voxel_vis VIS_SOUTH = 1 << static_cast<unsigned int>(voxel_facing::SOUTH);
-constexpr static voxel_vis VIS_EAST = 1 << static_cast<unsigned int>(voxel_facing::EAST);
-constexpr static voxel_vis VIS_WEST = 1 << static_cast<unsigned int>(voxel_facing::WEST);
-constexpr static voxel_vis VIS_UP = 1 << static_cast<unsigned int>(voxel_facing::UP);
-constexpr static voxel_vis VIS_DOWN = 1 << static_cast<unsigned int>(voxel_facing::DOWN);
+constexpr static voxel_vis VIS_NORTH = 1 << static_cast<unsigned int>(voxel_facing::NORTH);
+constexpr static voxel_vis VIS_SOUTH = 1 << static_cast<unsigned int>(voxel_facing::SOUTH);
+constexpr static voxel_vis VIS_EAST = 1 << static_cast<unsigned int>(voxel_facing::EAST);
+constexpr static voxel_vis VIS_WEST = 1 << static_cast<unsigned int>(voxel_facing::WEST);
+constexpr static voxel_vis VIS_UP = 1 << static_cast<unsigned int>(voxel_facing::UP);
+constexpr static voxel_vis VIS_DOWN = 1 << static_cast<unsigned int>(voxel_facing::DOWN);
struct VoxelTexture final {
std::vector<std::string> paths;
std::size_t cached_offset; // client-side only
- std::size_t cached_plane; // client-side only
+ std::size_t cached_plane; // client-side only
};
struct VoxelInfo final {
@@ -100,14 +100,14 @@ struct VoxelInfo final {
class VoxelInfoBuilder final {
public:
- explicit VoxelInfoBuilder(const char *name, voxel_type type, bool animated, bool blending);
+ explicit VoxelInfoBuilder(const char* name, voxel_type type, bool animated, bool blending);
virtual ~VoxelInfoBuilder(void) = default;
public:
- VoxelInfoBuilder &add_texture_default(const char *texture);
- VoxelInfoBuilder &add_texture(voxel_face face, const char *texture);
- VoxelInfoBuilder &set_touch(voxel_touch type, const glm::fvec3 &values);
- VoxelInfoBuilder &set_surface(voxel_surface surface);
+ VoxelInfoBuilder& add_texture_default(const char* texture);
+ VoxelInfoBuilder& add_texture(voxel_face face, const char* texture);
+ VoxelInfoBuilder& set_touch(voxel_touch type, const glm::fvec3& values);
+ VoxelInfoBuilder& set_surface(voxel_surface surface);
public:
voxel_id build(void) const;
@@ -126,9 +126,9 @@ extern std::vector<std::shared_ptr<VoxelInfo>> voxels;
namespace voxel_registry
{
-VoxelInfoBuilder &construct(const char *name, voxel_type type, bool animated, bool blending);
-VoxelInfo *find(const char *name);
-VoxelInfo *find(const voxel_id voxel);
+VoxelInfoBuilder& construct(const char* name, voxel_type type, bool animated, bool blending);
+VoxelInfo* find(const char* name);
+VoxelInfo* find(const voxel_id voxel);
} // namespace voxel_registry
namespace voxel_registry
diff --git a/game/shared/voxel_storage.cc b/game/shared/voxel_storage.cc
index eb51347..f2c4d42 100644
--- a/game/shared/voxel_storage.cc
+++ b/game/shared/voxel_storage.cc
@@ -1,9 +1,10 @@
#include "shared/pch.hh"
+
#include "shared/voxel_storage.hh"
#include "core/buffer.hh"
-void VoxelStorage::serialize(WriteBuffer &buffer) const
+void VoxelStorage::serialize(WriteBuffer& buffer) const
{
auto bound = mz_compressBound(sizeof(VoxelStorage));
auto zdata = std::vector<unsigned char>(bound);
@@ -22,17 +23,19 @@ void VoxelStorage::serialize(WriteBuffer &buffer) const
buffer.write_UI64(bound);
// Write all the compressed data into the buffer
- for(std::size_t i = 0; i < bound; buffer.write_UI8(zdata[i++]));
+ for(std::size_t i = 0; i < bound; buffer.write_UI8(zdata[i++]))
+ ;
}
-void VoxelStorage::deserialize(ReadBuffer &buffer)
+void VoxelStorage::deserialize(ReadBuffer& buffer)
{
auto size = static_cast<mz_ulong>(sizeof(VoxelStorage));
auto bound = static_cast<mz_ulong>(buffer.read_UI64());
auto zdata = std::vector<unsigned char>(bound);
// Read all the compressed data from the buffer
- for(std::size_t i = 0; i < bound; zdata[i++] = buffer.read_UI8());
+ for(std::size_t i = 0; i < bound; zdata[i++] = buffer.read_UI8())
+ ;
mz_uncompress(reinterpret_cast<unsigned char*>(data()), &size, zdata.data(), bound);
diff --git a/game/shared/voxel_storage.hh b/game/shared/voxel_storage.hh
index 08d234d..a31cf3e 100644
--- a/game/shared/voxel_storage.hh
+++ b/game/shared/voxel_storage.hh
@@ -11,8 +11,8 @@ class WriteBuffer;
class VoxelStorage final : public std::array<voxel_id, CHUNK_VOLUME> {
public:
using std::array<voxel_id, CHUNK_VOLUME>::array;
- void serialize(WriteBuffer &buffer) const;
- void deserialize(ReadBuffer &buffer);
+ void serialize(WriteBuffer& buffer) const;
+ void deserialize(ReadBuffer& buffer);
};
#endif /* SHARED_VOXEL_STORAGE_HH */