refactor(ecs): move entity physics to tick-based systems

Update PhysicalSystem and SpeedSystem to operate on entt::registry
instead of individual components. Add TickVelocity for server creatures
so movement is calculated per tick without frame delta time. LocalPlayer
now implements its own client-side physics with collision detection.
This commit is contained in:
2026-07-31 20:39:40 +08:00
parent 412f88565a
commit c5ce91e653
8 changed files with 276 additions and 121 deletions

View File

@@ -3,10 +3,17 @@
#include <glm/glm.hpp>
namespace Cubed {
struct TickVelocity {
glm::vec3 value{0.0f};
// blocks/tick!!! -1 for in
glm::vec3 max{1.0f, -1.0f, 1.0f};
};
struct Velocity {
glm::vec3 value{0.0f};
// blocks/second!!!
glm::vec3 max{4.5f, 7.5f, 7.5f};
};
@@ -23,4 +30,5 @@ struct Gravity {
float value = DEFAULT_G;
};
} // namespace Cubed

View File

@@ -8,7 +8,7 @@ namespace Cubed {
struct BaseServerCreature {
Transform transform{};
Velocity velocity{};
TickVelocity velocity{};
Movement movement{};

View File

@@ -149,12 +149,14 @@ private:
void update_direction();
void update_lookup_block();
void update_move(float delta_time);
void update_move(float dt);
void update_player_chunk();
void play_walk_sound(float dt);
Gait compute_gait() const;
void update_speed(float dt);
std::tuple<bool, bool, bool> update_physical(float dt);
glm::vec3 get_move_distance(float dt);
};
} // namespace Cubed

View File

@@ -1,18 +1,16 @@
#pragma once
#include "Cubed/gameplay/ecs/movement.hpp"
#include "Cubed/gameplay/ecs/state.hpp"
#include "Cubed/gameplay/ecs/transform.hpp"
#include "Cubed/gameplay/world.hpp"
namespace Cubed {
#include <entt/entt.hpp>
namespace Cubed {
class ServerWorld;
class PhysicalSystem {
public:
static glm::vec3 get_move_distance(float dt, const Direction& d,
const Velocity& v);
static glm::vec3 get_move_distance(const Direction& d,
const TickVelocity& v);
static std::tuple<bool, bool, bool>
update(float dt, World& world, glm::vec3& moved_pos, Velocity& v,
Direction& direction, MoveState& move_state, HitboxID hitbox);
static void update(ServerWorld& world, entt::registry& registry);
private:
};

View File

@@ -1,15 +1,10 @@
#pragma once
#include "Cubed/gameplay/ecs/movement.hpp"
#include "Cubed/gameplay/ecs/state.hpp"
#include "Cubed/gameplay/ecs/transform.hpp"
#include <entt/entt.hpp>
namespace Cubed {
class SpeedSystem {
public:
static void update(float dt, Velocity& v, MoveState& move_state,
Movement& movement, Direction& direction,
const Gravity& g);
static void update(float dt, entt::registry& registry);
private:
};