summaryrefslogtreecommitdiffstats
path: root/game/shared/entity
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-12-11 15:14:26 +0500
committeruntodesu <kirill@untode.su>2025-12-11 15:14:26 +0500
commitf40d09cb8f712e87691af4912f3630d92d692779 (patch)
tree7ac3a4168ff722689372fd489c6f94d0a2546e8f /game/shared/entity
parent8bcbd2729388edc63c82d77d314b583af1447c49 (diff)
downloadvoxelius-f40d09cb8f712e87691af4912f3630d92d692779.tar.bz2
voxelius-f40d09cb8f712e87691af4912f3630d92d692779.zip
Shuffle stuff around
- Use the new and improved hierarchy I figured out when making Prospero chat - Re-add NSIS scripts, again from Prospero - Update most build and utility scripts with their most recent versions
Diffstat (limited to 'game/shared/entity')
-rw-r--r--game/shared/entity/CMakeLists.txt16
-rw-r--r--game/shared/entity/collision.cc173
-rw-r--r--game/shared/entity/collision.hh21
-rw-r--r--game/shared/entity/factory.cc37
-rw-r--r--game/shared/entity/factory.hh11
-rw-r--r--game/shared/entity/gravity.cc20
-rw-r--r--game/shared/entity/gravity.hh14
-rw-r--r--game/shared/entity/grounded.hh12
-rw-r--r--game/shared/entity/head.hh16
-rw-r--r--game/shared/entity/player.hh6
-rw-r--r--game/shared/entity/stasis.cc21
-rw-r--r--game/shared/entity/stasis.hh16
-rw-r--r--game/shared/entity/transform.cc33
-rw-r--r--game/shared/entity/transform.hh30
-rw-r--r--game/shared/entity/velocity.cc19
-rw-r--r--game/shared/entity/velocity.hh19
16 files changed, 0 insertions, 464 deletions
diff --git a/game/shared/entity/CMakeLists.txt b/game/shared/entity/CMakeLists.txt
deleted file mode 100644
index 36e45b6..0000000
--- a/game/shared/entity/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-target_sources(shared PRIVATE
- "${CMAKE_CURRENT_LIST_DIR}/collision.cc"
- "${CMAKE_CURRENT_LIST_DIR}/collision.hh"
- "${CMAKE_CURRENT_LIST_DIR}/factory.cc"
- "${CMAKE_CURRENT_LIST_DIR}/factory.hh"
- "${CMAKE_CURRENT_LIST_DIR}/gravity.cc"
- "${CMAKE_CURRENT_LIST_DIR}/gravity.hh"
- "${CMAKE_CURRENT_LIST_DIR}/grounded.hh"
- "${CMAKE_CURRENT_LIST_DIR}/head.hh"
- "${CMAKE_CURRENT_LIST_DIR}/player.hh"
- "${CMAKE_CURRENT_LIST_DIR}/stasis.cc"
- "${CMAKE_CURRENT_LIST_DIR}/stasis.hh"
- "${CMAKE_CURRENT_LIST_DIR}/transform.cc"
- "${CMAKE_CURRENT_LIST_DIR}/transform.hh"
- "${CMAKE_CURRENT_LIST_DIR}/velocity.cc"
- "${CMAKE_CURRENT_LIST_DIR}/velocity.hh")
diff --git a/game/shared/entity/collision.cc b/game/shared/entity/collision.cc
deleted file mode 100644
index d2bc0a9..0000000
--- a/game/shared/entity/collision.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-#include "shared/pch.hh"
-
-#include "shared/entity/collision.hh"
-
-#include "core/math/constexpr.hh"
-
-#include "shared/entity/gravity.hh"
-#include "shared/entity/grounded.hh"
-#include "shared/entity/transform.hh"
-#include "shared/entity/velocity.hh"
-
-#include "shared/world/dimension.hh"
-#include "shared/world/voxel_registry.hh"
-
-#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)
-{
- const auto move = globals::fixed_frametime * velocity.value[d];
- const auto move_sign = math::sign<int>(move);
-
- const auto& ref_aabb = collision.aabb;
- const auto current_aabb = ref_aabb.push(transform.local);
-
- auto next_aabb = math::AABBf(current_aabb);
- next_aabb.min[d] += move;
- next_aabb.max[d] += move;
-
- local_pos lpos_min;
- lpos_min.x = static_cast<local_pos::value_type>(glm::floor(next_aabb.min.x));
- lpos_min.y = static_cast<local_pos::value_type>(glm::floor(next_aabb.min.y));
- lpos_min.z = static_cast<local_pos::value_type>(glm::floor(next_aabb.min.z));
-
- local_pos lpos_max;
- lpos_max.x = static_cast<local_pos::value_type>(glm::ceil(next_aabb.max.x));
- lpos_max.y = static_cast<local_pos::value_type>(glm::ceil(next_aabb.max.y));
- lpos_max.z = static_cast<local_pos::value_type>(glm::ceil(next_aabb.max.z));
-
- // Other axes
- const int u = (d + 1) % 3;
- const int v = (d + 2) % 3;
-
- local_pos::value_type ddir;
- local_pos::value_type dmin;
- local_pos::value_type dmax;
-
- if(move < 0.0f) {
- ddir = local_pos::value_type(+1);
- dmin = lpos_min[d];
- dmax = lpos_max[d];
- }
- else {
- ddir = local_pos::value_type(-1);
- dmin = lpos_max[d];
- dmax = lpos_min[d];
- }
-
- world::VoxelTouch latch_touch = world::VTOUCH_NONE;
- glm::fvec3 latch_values = glm::fvec3(0.0f, 0.0f, 0.0f);
- world::VoxelMaterial latch_surface = world::VMAT_UNKNOWN;
- math::AABBf latch_vbox;
-
- 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;
-
- auto vpos = coord::to_voxel(transform.chunk, lpos);
- auto voxel = dimension->get_voxel(vpos);
-
- if(voxel == nullptr) {
- // Don't collide with something
- // that we assume to be nothing
- continue;
- }
-
- math::AABBf vbox(voxel->get_collision().push(lpos));
-
- if(!next_aabb.intersect(vbox)) {
- // No intersection between the voxel
- // and the entity's collision hull
- continue;
- }
-
- if(voxel->is_touch_type<world::VTOUCH_SOLID>()) {
- // Solid touch type makes a collision
- // response whenever it is encountered
- velocity.value[d] = 0.0f;
- touch_surface = voxel->get_surface_material();
- return move_sign;
- }
-
- // 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) {
- latch_touch = voxel->get_touch_type();
- latch_values = voxel->get_touch_values();
- latch_surface = voxel->get_surface_material();
- latch_vbox = vbox;
- continue;
- }
- }
- }
-
- if(latch_touch != world::VTOUCH_NONE) {
- if(latch_touch == world::VTOUCH_BOUNCE) {
- const auto move_distance = glm::abs(current_aabb.min[d] - next_aabb.min[d]);
- const auto threshold = 2.0f * globals::fixed_frametime;
-
- if(move_distance > threshold) {
- velocity.value[d] *= -latch_values[d];
- }
- else {
- velocity.value[d] = 0.0f;
- }
-
- touch_surface = latch_surface;
-
- return move_sign;
- }
-
- if(latch_touch == world::VTOUCH_SINK) {
- velocity.value[d] *= latch_values[d];
- touch_surface = latch_surface;
- return move_sign;
- }
- }
-
- return 0;
-}
-
-void entity::Collision::fixed_update(world::Dimension* dimension)
-{
- // FIXME: this isn't particularly accurate considering
- // some voxels might be passable and some other voxels
- // might apply some slowing factor; what I might do in the
- // future is to add a specific value to the voxel registry
- // entries that would specify the amount of force we apply
- // to prevent player movement inside a specific voxel, plus
- // 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>);
-
- for(auto [entity, collision, transform, velocity] : group.each()) {
- auto surface = world::VMAT_UNKNOWN;
- auto vertical_move = vgrid_collide(dimension, 1, collision, transform, velocity, surface);
-
- if(dimension->entities.any_of<entity::Gravity>(entity)) {
- if(vertical_move == math::sign<int>(dimension->get_gravity())) {
- dimension->entities.emplace_or_replace<entity::Grounded>(entity, entity::Grounded { surface });
- }
- else {
- dimension->entities.remove<entity::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);
- }
-
- vgrid_collide(dimension, 0, collision, transform, velocity, surface);
- vgrid_collide(dimension, 2, collision, transform, velocity, surface);
- }
-}
diff --git a/game/shared/entity/collision.hh b/game/shared/entity/collision.hh
deleted file mode 100644
index 95a9b86..0000000
--- a/game/shared/entity/collision.hh
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#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
- // because both transform and velocity may be updated internally
- static void fixed_update(world::Dimension* dimension);
-};
-} // namespace entity
diff --git a/game/shared/entity/factory.cc b/game/shared/entity/factory.cc
deleted file mode 100644
index ba95b73..0000000
--- a/game/shared/entity/factory.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "shared/pch.hh"
-
-#include "shared/entity/factory.hh"
-
-#include "shared/entity/collision.hh"
-#include "shared/entity/gravity.hh"
-#include "shared/entity/head.hh"
-#include "shared/entity/player.hh"
-#include "shared/entity/transform.hh"
-#include "shared/entity/velocity.hh"
-
-#include "shared/world/dimension.hh"
-
-#include "shared/globals.hh"
-
-void entity::shared::create_player(world::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);
- 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);
- 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);
-
- auto& transform = dimension->entities.emplace_or_replace<entity::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);
- velocity.value = glm::fvec3(0.0f, 0.0f, 0.0f);
-}
diff --git a/game/shared/entity/factory.hh b/game/shared/entity/factory.hh
deleted file mode 100644
index be33045..0000000
--- a/game/shared/entity/factory.hh
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-namespace world
-{
-class Dimension;
-} // namespace world
-
-namespace entity::shared
-{
-void create_player(world::Dimension* dimension, entt::entity entity);
-} // namespace entity::shared
diff --git a/game/shared/entity/gravity.cc b/game/shared/entity/gravity.cc
deleted file mode 100644
index 09bc379..0000000
--- a/game/shared/entity/gravity.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "shared/pch.hh"
-
-#include "shared/entity/gravity.hh"
-
-#include "shared/entity/stasis.hh"
-#include "shared/entity/velocity.hh"
-
-#include "shared/world/dimension.hh"
-
-#include "shared/globals.hh"
-
-void entity::Gravity::fixed_update(world::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>);
-
- for(auto [entity, velocity] : group.each()) {
- velocity.value.y += fixed_acceleration;
- }
-}
diff --git a/game/shared/entity/gravity.hh b/game/shared/entity/gravity.hh
deleted file mode 100644
index 2cbcbbc..0000000
--- a/game/shared/entity/gravity.hh
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-namespace world
-{
-class Dimension;
-} // namespace world
-
-namespace entity
-{
-struct Gravity final {
-public:
- static void fixed_update(world::Dimension* dimension);
-};
-} // namespace entity
diff --git a/game/shared/entity/grounded.hh b/game/shared/entity/grounded.hh
deleted file mode 100644
index 34a0f9e..0000000
--- a/game/shared/entity/grounded.hh
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-
-#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;
-};
-} // namespace entity
diff --git a/game/shared/entity/head.hh b/game/shared/entity/head.hh
deleted file mode 100644
index 15ce7e5..0000000
--- a/game/shared/entity/head.hh
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma once
-
-namespace entity
-{
-struct Head {
- glm::fvec3 angles;
- glm::fvec3 offset;
-};
-} // namespace entity
-
-namespace entity::client
-{
-// Client-side only - interpolated and previous head
-struct HeadIntr final : public Head {};
-struct HeadPrev final : public Head {};
-} // namespace entity::client
diff --git a/game/shared/entity/player.hh b/game/shared/entity/player.hh
deleted file mode 100644
index abffd85..0000000
--- a/game/shared/entity/player.hh
+++ /dev/null
@@ -1,6 +0,0 @@
-#pragma once
-
-namespace entity
-{
-struct Player final {};
-} // namespace entity
diff --git a/game/shared/entity/stasis.cc b/game/shared/entity/stasis.cc
deleted file mode 100644
index eab8744..0000000
--- a/game/shared/entity/stasis.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "shared/pch.hh"
-
-#include "shared/entity/stasis.hh"
-
-#include "shared/entity/transform.hh"
-
-#include "shared/world/dimension.hh"
-
-void entity::Stasis::fixed_update(world::Dimension* dimension)
-{
- auto view = dimension->entities.view<entity::Transform>();
-
- for(auto [entity, transform] : view.each()) {
- if(dimension->find_chunk(transform.chunk)) {
- dimension->entities.remove<entity::Stasis>(entity);
- }
- else {
- dimension->entities.emplace_or_replace<entity::Stasis>(entity);
- }
- }
-}
diff --git a/game/shared/entity/stasis.hh b/game/shared/entity/stasis.hh
deleted file mode 100644
index cb364ce..0000000
--- a/game/shared/entity/stasis.hh
+++ /dev/null
@@ -1,16 +0,0 @@
-#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);
-};
-} // namespace entity
diff --git a/game/shared/entity/transform.cc b/game/shared/entity/transform.cc
deleted file mode 100644
index 0339b9e..0000000
--- a/game/shared/entity/transform.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "shared/pch.hh"
-
-#include "shared/entity/transform.hh"
-
-#include "shared/world/dimension.hh"
-
-#include "shared/const.hh"
-
-constexpr inline static void update_component(unsigned int dim, entity::Transform& component)
-{
- if(component.local[dim] >= CHUNK_SIZE) {
- component.local[dim] -= CHUNK_SIZE;
- component.chunk[dim] += 1;
- return;
- }
-
- if(component.local[dim] < 0.0f) {
- component.local[dim] += CHUNK_SIZE;
- component.chunk[dim] -= 1;
- return;
- }
-}
-
-void entity::Transform::fixed_update(world::Dimension* dimension)
-{
- auto view = dimension->entities.view<entity::Transform>();
-
- for(auto [entity, transform] : view.each()) {
- update_component(0U, transform);
- update_component(1U, transform);
- update_component(2U, transform);
- }
-}
diff --git a/game/shared/entity/transform.hh b/game/shared/entity/transform.hh
deleted file mode 100644
index f7db095..0000000
--- a/game/shared/entity/transform.hh
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#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
- // the local translation field is always within
- // local coodrinates; [floating-point precision]
- static void fixed_update(world::Dimension* dimension);
-};
-} // namespace entity
-
-namespace entity::client
-{
-// Client-side only - interpolated and previous transform
-struct TransformIntr final : public Transform {};
-struct TransformPrev final : public Transform {};
-} // namespace entity::client
diff --git a/game/shared/entity/velocity.cc b/game/shared/entity/velocity.cc
deleted file mode 100644
index 85ad53b..0000000
--- a/game/shared/entity/velocity.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "shared/pch.hh"
-
-#include "shared/entity/velocity.hh"
-
-#include "shared/entity/stasis.hh"
-#include "shared/entity/transform.hh"
-
-#include "shared/world/dimension.hh"
-
-#include "shared/globals.hh"
-
-void entity::Velocity::fixed_update(world::Dimension* dimension)
-{
- auto group = dimension->entities.group<entity::Velocity>(entt::get<entity::Transform>, entt::exclude<entity::Stasis>);
-
- for(auto [entity, velocity, transform] : group.each()) {
- transform.local += velocity.value * globals::fixed_frametime;
- }
-}
diff --git a/game/shared/entity/velocity.hh b/game/shared/entity/velocity.hh
deleted file mode 100644
index e57e555..0000000
--- a/game/shared/entity/velocity.hh
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-namespace world
-{
-class Dimension;
-} // namespace world
-
-namespace entity
-{
-struct Velocity final {
- glm::fvec3 value;
-
-public:
- // Updates entities entity::Transform values
- // according to velocities multiplied by fixed_frametime.
- // NOTE: This system was previously called inertial
- static void fixed_update(world::Dimension* dimension);
-};
-} // namespace entity