From 9f80a278a6f188c8e9131df0684bad14a07491ee Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 21 Mar 2025 18:16:40 +0500 Subject: Toggles system rework, added flight pmove mode - Reworked toggles to use a constant-styled enumerations - Added TOGGLE_PM_FLIGHT and an according movement mode. Now server-side just doesn't simulate gravity altogether for players, instead relying on whatever the client provides which works fine for now. Closes #12 --- game/shared/collision.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'game/shared/collision.cc') diff --git a/game/shared/collision.cc b/game/shared/collision.cc index 126d3bb..0593fbb 100644 --- a/game/shared/collision.cc +++ b/game/shared/collision.cc @@ -6,6 +6,7 @@ #include "shared/coord.hh" #include "shared/dimension.hh" #include "shared/globals.hh" +#include "shared/gravity.hh" #include "shared/grounded.hh" #include "shared/transform.hh" #include "shared/velocity.hh" @@ -146,11 +147,15 @@ void CollisionComponent::fixed_update(Dimension *dimension) auto surface = voxel_surface::UNKNOWN; auto vertical_move = vgrid_collide(dimension, 1, collision, transform, velocity, surface); - if(vertical_move == cxpr::sign(dimension->get_gravity())) { - auto &component = dimension->entities.get_or_emplace(entity); - component.surface = surface; + if(dimension->entities.any_of(entity)) { + if(vertical_move == cxpr::sign(dimension->get_gravity())) + dimension->entities.emplace_or_replace(entity, GroundedComponent{surface}); + else dimension->entities.remove(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); } -- cgit