summaryrefslogtreecommitdiffstats
path: root/src/game/shared/entity
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/shared/entity')
-rw-r--r--src/game/shared/entity/collision.cc32
-rw-r--r--src/game/shared/entity/collision.hh12
-rw-r--r--src/game/shared/entity/factory.cc12
-rw-r--r--src/game/shared/entity/factory.hh9
-rw-r--r--src/game/shared/entity/gravity.cc4
-rw-r--r--src/game/shared/entity/gravity.hh8
-rw-r--r--src/game/shared/entity/grounded.hh5
-rw-r--r--src/game/shared/entity/head.hh7
-rw-r--r--src/game/shared/entity/player.hh3
-rw-r--r--src/game/shared/entity/stasis.cc8
-rw-r--r--src/game/shared/entity/stasis.hh8
-rw-r--r--src/game/shared/entity/transform.cc6
-rw-r--r--src/game/shared/entity/transform.hh14
-rw-r--r--src/game/shared/entity/velocity.cc4
-rw-r--r--src/game/shared/entity/velocity.hh10
15 files changed, 50 insertions, 92 deletions
diff --git a/src/game/shared/entity/collision.cc b/src/game/shared/entity/collision.cc
index bc9209b..af23047 100644
--- a/src/game/shared/entity/collision.cc
+++ b/src/game/shared/entity/collision.cc
@@ -15,8 +15,8 @@
#include "shared/coord.hh"
#include "shared/globals.hh"
-static int vgrid_collide(const world::Dimension* dimension, int d, entity::Collision& collision, entity::Transform& transform,
- entity::Velocity& velocity, world::VoxelMaterial& touch_surface)
+static int vgrid_collide(const Dimension* dimension, int d, Collision& collision, Transform& transform, Velocity& velocity,
+ VoxelMaterial& touch_surface)
{
const auto move = globals::fixed_frametime * velocity.value[d];
const auto move_sign = math::sign<int>(move);
@@ -57,9 +57,9 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
dmax = lpos_min[d];
}
- world::VoxelTouch latch_touch = world::VTOUCH_NONE;
+ VoxelTouch latch_touch = VTOUCH_NONE;
glm::fvec3 latch_values = glm::fvec3(0.0f, 0.0f, 0.0f);
- world::VoxelMaterial latch_surface = world::VMAT_UNKNOWN;
+ VoxelMaterial latch_surface = VMAT_UNKNOWN;
math::AABBf latch_vbox;
for(auto i = dmin; i != dmax; i += ddir) {
@@ -87,7 +87,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
continue;
}
- if(voxel->is_touch_type<world::VTOUCH_SOLID>()) {
+ if(voxel->is_touch_type<VTOUCH_SOLID>()) {
// Solid touch type makes a collision
// response whenever it is encountered
velocity.value[d] = 0.0f;
@@ -98,7 +98,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
// In case of other touch types, they
// are latched and the last ever touch
// type is then responded to
- if(voxel->get_touch_type() != world::VTOUCH_NONE) {
+ if(voxel->get_touch_type() != VTOUCH_NONE) {
latch_touch = voxel->get_touch_type();
latch_values = voxel->get_touch_values();
latch_surface = voxel->get_surface_material();
@@ -108,8 +108,8 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
}
}
- if(latch_touch != world::VTOUCH_NONE) {
- if(latch_touch == world::VTOUCH_BOUNCE) {
+ if(latch_touch != VTOUCH_NONE) {
+ if(latch_touch == VTOUCH_BOUNCE) {
const auto move_distance = glm::abs(current_aabb.min[d] - next_aabb.min[d]);
const auto threshold = 2.0f * globals::fixed_frametime;
@@ -125,7 +125,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
return move_sign;
}
- if(latch_touch == world::VTOUCH_SINK) {
+ if(latch_touch == VTOUCH_SINK) {
velocity.value[d] *= latch_values[d];
touch_surface = latch_surface;
return move_sign;
@@ -135,7 +135,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli
return 0;
}
-void entity::Collision::fixed_update(world::Dimension* dimension)
+void Collision::fixed_update(Dimension* dimension)
{
// FIXME: this isn't particularly accurate considering
// some voxels might be passable and some other voxels
@@ -146,25 +146,25 @@ void entity::Collision::fixed_update(world::Dimension* dimension)
// we shouldn't treat all voxels as full cubes if we want
// to support slabs, stairs and non-full liquid voxels in the future
- auto group = dimension->entities.group<entity::Collision>(entt::get<entity::Transform, entity::Velocity>);
+ auto group = dimension->entities.group<Collision>(entt::get<Transform, Velocity>);
for(auto [entity, collision, transform, velocity] : group.each()) {
- auto surface = world::VMAT_UNKNOWN;
+ auto surface = VMAT_UNKNOWN;
auto vertical_move = vgrid_collide(dimension, 1, collision, transform, velocity, surface);
- if(dimension->entities.any_of<entity::Gravity>(entity)) {
+ if(dimension->entities.any_of<Gravity>(entity)) {
if(vertical_move == math::sign<int>(dimension->get_gravity())) {
- dimension->entities.emplace_or_replace<entity::Grounded>(entity, entity::Grounded { surface });
+ dimension->entities.emplace_or_replace<Grounded>(entity, Grounded { surface });
}
else {
- dimension->entities.remove<entity::Grounded>(entity);
+ dimension->entities.remove<Grounded>(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)
- dimension->entities.remove<entity::Grounded>(entity);
+ dimension->entities.remove<Grounded>(entity);
}
vgrid_collide(dimension, 0, collision, transform, velocity, surface);
diff --git a/src/game/shared/entity/collision.hh b/src/game/shared/entity/collision.hh
index b37f409..34a648c 100644
--- a/src/game/shared/entity/collision.hh
+++ b/src/game/shared/entity/collision.hh
@@ -2,20 +2,14 @@
#include "core/math/aabb.hh"
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Collision final {
math::AABBf aabb;
public:
- // NOTE: entity::Collision::fixed_update must be called
- // before entity::Transform::fixed_update and entity::Velocity::fixed_update
+ // NOTE: Collision::fixed_update must be called
+ // before Transform::fixed_update and Velocity::fixed_update
// because both transform and velocity may be updated internally
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/entity/factory.cc b/src/game/shared/entity/factory.cc
index 619a418..f2031df 100644
--- a/src/game/shared/entity/factory.cc
+++ b/src/game/shared/entity/factory.cc
@@ -13,25 +13,25 @@
#include "shared/globals.hh"
-void entity::shared::create_player(world::Dimension* dimension, entt::entity entity)
+void shared::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<entity::Collision>(entity);
+ auto& collision = dimension->entities.emplace_or_replace<Collision>(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<entity::Head>(entity);
+ auto& head = dimension->entities.emplace_or_replace<Head>(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<entity::Player>(entity);
+ dimension->entities.emplace_or_replace<Player>(entity);
- auto& transform = dimension->entities.emplace_or_replace<entity::Transform>(entity);
+ auto& transform = dimension->entities.emplace_or_replace<Transform>(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<entity::Velocity>(entity);
+ auto& velocity = dimension->entities.emplace_or_replace<Velocity>(entity);
velocity.value = glm::fvec3(0.0f, 0.0f, 0.0f);
}
diff --git a/src/game/shared/entity/factory.hh b/src/game/shared/entity/factory.hh
index e709060..7c94136 100644
--- a/src/game/shared/entity/factory.hh
+++ b/src/game/shared/entity/factory.hh
@@ -1,11 +1,8 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity::shared
+namespace shared
{
-void create_player(world::Dimension* dimension, entt::entity entity);
-} // namespace entity::shared
+void create_player(Dimension* dimension, entt::entity entity);
+} // namespace shared
diff --git a/src/game/shared/entity/gravity.cc b/src/game/shared/entity/gravity.cc
index f1708aa..6a5145f 100644
--- a/src/game/shared/entity/gravity.cc
+++ b/src/game/shared/entity/gravity.cc
@@ -9,10 +9,10 @@
#include "shared/globals.hh"
-void entity::Gravity::fixed_update(world::Dimension* dimension)
+void Gravity::fixed_update(Dimension* dimension)
{
auto fixed_acceleration = globals::fixed_frametime * dimension->get_gravity();
- auto group = dimension->entities.group<entity::Gravity>(entt::get<entity::Velocity>, entt::exclude<entity::Stasis>);
+ auto group = dimension->entities.group<Gravity>(entt::get<Velocity>, entt::exclude<Stasis>);
for(auto [entity, velocity] : group.each()) {
velocity.value.y += fixed_acceleration;
diff --git a/src/game/shared/entity/gravity.hh b/src/game/shared/entity/gravity.hh
index 21f4582..38b3c9b 100644
--- a/src/game/shared/entity/gravity.hh
+++ b/src/game/shared/entity/gravity.hh
@@ -1,14 +1,8 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Gravity final {
public:
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/entity/grounded.hh b/src/game/shared/entity/grounded.hh
index 6c33d1d..7307e79 100644
--- a/src/game/shared/entity/grounded.hh
+++ b/src/game/shared/entity/grounded.hh
@@ -2,11 +2,8 @@
#include "shared/world/voxel.hh"
-namespace entity
-{
// Assigned to entities which are grounded
// according to the collision and gravity system
struct Grounded final {
- world::VoxelMaterial surface;
+ VoxelMaterial surface;
};
-} // namespace entity
diff --git a/src/game/shared/entity/head.hh b/src/game/shared/entity/head.hh
index 3f5d6d1..9fa71d9 100644
--- a/src/game/shared/entity/head.hh
+++ b/src/game/shared/entity/head.hh
@@ -1,16 +1,13 @@
#pragma once
-namespace entity
-{
struct Head {
glm::fvec3 angles;
glm::fvec3 offset;
};
-} // namespace entity
-namespace entity::client
+namespace client
{
// Client-side only - interpolated and previous head
struct HeadIntr final : public Head {};
struct HeadPrev final : public Head {};
-} // namespace entity::client
+} // namespace client
diff --git a/src/game/shared/entity/player.hh b/src/game/shared/entity/player.hh
index 4bd0217..d7cd020 100644
--- a/src/game/shared/entity/player.hh
+++ b/src/game/shared/entity/player.hh
@@ -1,6 +1,3 @@
#pragma once
-namespace entity
-{
struct Player final {};
-} // namespace entity
diff --git a/src/game/shared/entity/stasis.cc b/src/game/shared/entity/stasis.cc
index 3b86294..0b8a0c8 100644
--- a/src/game/shared/entity/stasis.cc
+++ b/src/game/shared/entity/stasis.cc
@@ -6,16 +6,16 @@
#include "shared/world/dimension.hh"
-void entity::Stasis::fixed_update(world::Dimension* dimension)
+void Stasis::fixed_update(Dimension* dimension)
{
- auto view = dimension->entities.view<entity::Transform>();
+ auto view = dimension->entities.view<Transform>();
for(auto [entity, transform] : view.each()) {
if(dimension->find_chunk(transform.chunk)) {
- dimension->entities.remove<entity::Stasis>(entity);
+ dimension->entities.remove<Stasis>(entity);
}
else {
- dimension->entities.emplace_or_replace<entity::Stasis>(entity);
+ dimension->entities.emplace_or_replace<Stasis>(entity);
}
}
}
diff --git a/src/game/shared/entity/stasis.hh b/src/game/shared/entity/stasis.hh
index e6cb9e4..5adc592 100644
--- a/src/game/shared/entity/stasis.hh
+++ b/src/game/shared/entity/stasis.hh
@@ -1,16 +1,10 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
// Attached to entities with transform values
// out of bounds in a specific dimension
struct Stasis final {
public:
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
diff --git a/src/game/shared/entity/transform.cc b/src/game/shared/entity/transform.cc
index 379ddd5..cf09e2f 100644
--- a/src/game/shared/entity/transform.cc
+++ b/src/game/shared/entity/transform.cc
@@ -6,7 +6,7 @@
#include "shared/const.hh"
-constexpr inline static void update_component(unsigned int dim, entity::Transform& component)
+constexpr inline static void update_component(unsigned int dim, Transform& component)
{
if(component.local[dim] >= CHUNK_SIZE) {
component.local[dim] -= CHUNK_SIZE;
@@ -21,9 +21,9 @@ constexpr inline static void update_component(unsigned int dim, entity::Transfor
}
}
-void entity::Transform::fixed_update(world::Dimension* dimension)
+void Transform::fixed_update(Dimension* dimension)
{
- auto view = dimension->entities.view<entity::Transform>();
+ auto view = dimension->entities.view<Transform>();
for(auto [entity, transform] : view.each()) {
update_component(0U, transform);
diff --git a/src/game/shared/entity/transform.hh b/src/game/shared/entity/transform.hh
index 2b357f8..afbe9fa 100644
--- a/src/game/shared/entity/transform.hh
+++ b/src/game/shared/entity/transform.hh
@@ -2,29 +2,23 @@
#include "shared/types.hh"
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Transform {
chunk_pos chunk;
glm::fvec3 local;
glm::fvec3 angles;
public:
- // Updates entity::Transform values so that
+ // Updates Transform values so that
// the local translation field is always within
// local coodrinates; [floating-point precision]
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity
-namespace entity::client
+namespace client
{
// Client-side only - interpolated and previous transform
struct TransformIntr final : public Transform {};
struct TransformPrev final : public Transform {};
-} // namespace entity::client
+} // namespace client
diff --git a/src/game/shared/entity/velocity.cc b/src/game/shared/entity/velocity.cc
index 86df445..6fb8c80 100644
--- a/src/game/shared/entity/velocity.cc
+++ b/src/game/shared/entity/velocity.cc
@@ -9,9 +9,9 @@
#include "shared/globals.hh"
-void entity::Velocity::fixed_update(world::Dimension* dimension)
+void Velocity::fixed_update(Dimension* dimension)
{
- auto group = dimension->entities.group<entity::Velocity>(entt::get<entity::Transform>, entt::exclude<entity::Stasis>);
+ auto group = dimension->entities.group<Velocity>(entt::get<Transform>, entt::exclude<Stasis>);
for(auto [entity, velocity, transform] : group.each()) {
transform.local += velocity.value * globals::fixed_frametime;
diff --git a/src/game/shared/entity/velocity.hh b/src/game/shared/entity/velocity.hh
index c8a1c91..69fce9e 100644
--- a/src/game/shared/entity/velocity.hh
+++ b/src/game/shared/entity/velocity.hh
@@ -1,19 +1,13 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
-namespace entity
-{
struct Velocity final {
glm::fvec3 value;
public:
- // Updates entities entity::Transform values
+ // Updates entities Transform values
// according to velocities multiplied by fixed_frametime.
// NOTE: This system was previously called inertial
- static void fixed_update(world::Dimension* dimension);
+ static void fixed_update(Dimension* dimension);
};
-} // namespace entity