refactor(gameplay): separate player logic into manager and ECS components

This commit is contained in:
2026-07-28 21:00:04 +08:00
parent 0ff5820e6e
commit d15037e7a3
26 changed files with 640 additions and 493 deletions

View File

@@ -1,56 +1,58 @@
#include "Cubed/gameplay/systems/speed_system.hpp"
namespace Cubed {
void SpeedSystem::update(float dt, Entity& e) {
auto& m_velocity = e.velocity();
auto& m_move_state = e.move_state();
auto& m_movement = e.movement();
auto& direction = e.direction();
auto& m_gravity = e.gravity();
void SpeedSystem::update(float dt, ServerEntity& e) {
update(dt, e.velocity, e.move_state, e.movement, e.direction, e.gravity);
}
void SpeedSystem::update(float dt, Velocity& v, MoveState& move_state,
Movement& movement, Direction& direction,
const Gravity& g) {
// calculate speed
if (m_move_state.forward || m_move_state.back || m_move_state.left ||
m_move_state.right) {
if (move_state.forward || move_state.back || move_state.left ||
move_state.right) {
direction.value = glm::vec3(0.0f, 0.0f, 0.0f);
m_velocity.value.x += m_movement.acceleration * dt;
m_velocity.value.z += m_movement.acceleration * dt;
if (m_velocity.value.x > m_velocity.max.x) {
m_velocity.value.x = m_velocity.max.x;
v.value.x += movement.acceleration * dt;
v.value.z += movement.acceleration * dt;
if (v.value.x > v.max.x) {
v.value.x = v.max.x;
}
if (m_velocity.value.z > m_velocity.max.z) {
m_velocity.value.z = m_velocity.max.z;
if (v.value.z > v.max.z) {
v.value.z = v.max.z;
}
} else {
m_velocity.value.x += -m_movement.deceleration * dt;
m_velocity.value.z += -m_movement.deceleration * dt;
if (m_velocity.value.z < 0.0f) {
m_velocity.value.z = 0.0f;
v.value.x += -movement.deceleration * dt;
v.value.z += -movement.deceleration * dt;
if (v.value.z < 0.0f) {
v.value.z = 0.0f;
}
if (m_velocity.value.x < 0.0f) {
m_velocity.value.x = 0.0f;
if (v.value.x < 0.0f) {
v.value.x = 0.0f;
}
if (m_velocity.value.z < 0.0f && m_velocity.value.x < 0.0f) {
if (v.value.z < 0.0f && v.value.x < 0.0f) {
direction.value = glm::vec3(0.0f, 0.0f, 0.0f);
}
}
if (m_move_state.is_fly) {
if (m_move_state.up) {
m_velocity.value.y = m_velocity.max.y;
if (move_state.is_fly) {
if (move_state.up) {
v.value.y = v.max.y;
}
if (m_move_state.down) {
m_velocity.value.y = -m_velocity.max.y;
if (move_state.down) {
v.value.y = -v.max.y;
}
if (!m_move_state.down && !m_move_state.up) {
m_velocity.value.y = 0.0f;
if (!move_state.down && !move_state.up) {
v.value.y = 0.0f;
}
} else {
if (m_move_state.up && m_move_state.can_up) {
m_velocity.value.y = m_movement.jump_power;
m_move_state.can_up = false;
if (move_state.up && move_state.can_up) {
v.value.y = movement.jump_power;
move_state.can_up = false;
}
m_velocity.value.y += -m_gravity.value * dt;
v.value.y += -g.value * dt;
}
}
} // namespace Cubed