Fase 6a+b: Entity gana RigidBody body_, GameScene gana PhysicsWorld
Infraestructura mínima para la migración real de entidades a física vectorial (Fase 6c-e). Sin cambios de comportamiento: las entidades aún no usan body_ ni se registran al mundo. Entity (core/entities/entity.hpp): - Nuevo member protegido: Physics::RigidBody body_ (default-construido) - Nuevo método virtual: postUpdate(dt) — no-op por default, override opcional para sincronizar mirror center_/angle_ desde body_ tras la integración física. - Nuevos getters: getBody() (mutable y const) - Include de core/physics/rigid_body.hpp GameScene (game/scenes/game_scene.hpp/cpp): - Nuevo member: Physics::PhysicsWorld physics_world_ - En init(): physics_world_.clear() + setBounds(PLAYAREA). Las entidades migradas se registrarán cada una en su propio init(). El loop de GameScene::update() no se modifica todavía. La invocación de physics_world_.update(dt) + postUpdate() se añade en Fase 6c junto con la primera entidad migrada (Ship), para validar el flujo tri-fase con un caso real en lugar de cambios especulativos al control de flujo. Smoke test xvfb OK. Compila y arranca sin cambios visibles. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
// entity.hpp - Clase base abstracta para todas las entidades del juego
|
||||
// © 2025 Orni Attack - Arquitectura de entidades
|
||||
//
|
||||
// Cada Entity incluye un Physics::RigidBody como member. Las entidades que
|
||||
// se simulen físicamente lo configuran en init() y registran en el
|
||||
// PhysicsWorld del GameScene. Las que no, ignoran el body (queda con
|
||||
// defaults inocuos: mass=1, radius=0).
|
||||
//
|
||||
// Flujo por frame (gestionado por GameScene):
|
||||
// 1. entity.update(dt) — aplicar fuerzas, decidir lógica
|
||||
// 2. world.update(dt) — integrar bodies, resolver colisiones
|
||||
// 3. entity.postUpdate(dt) — sincronizar mirror (center_, angle_)
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -8,6 +18,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/physics/rigid_body.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Entities {
|
||||
@@ -16,31 +27,44 @@ class Entity {
|
||||
public:
|
||||
virtual ~Entity() = default;
|
||||
|
||||
// Interfície principal (virtual pur)
|
||||
// Interfaz principal (virtual pur)
|
||||
virtual void init() = 0;
|
||||
virtual void update(float delta_time) = 0;
|
||||
virtual void draw() const = 0;
|
||||
[[nodiscard]] virtual bool isActive() const = 0;
|
||||
|
||||
// Interfície de colisión (override opcional)
|
||||
// Sincronización post-física (override opcional).
|
||||
// Llamado por GameScene tras world.update(). Default: no-op.
|
||||
virtual void postUpdate(float /*delta_time*/) {}
|
||||
|
||||
// Interfaz de colisión (override opcional)
|
||||
[[nodiscard]] virtual float getCollisionRadius() const { return 0.0F; }
|
||||
[[nodiscard]] virtual bool isCollidable() const { return false; }
|
||||
|
||||
// Getters comuns (inline, sin overhead)
|
||||
// Getters comunes (inline, sin overhead)
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float getAngle() const { return angle_; }
|
||||
[[nodiscard]] float getBrightness() const { return brightness_; }
|
||||
[[nodiscard]] const std::shared_ptr<Graphics::Shape>& getShape() const { return shape_; }
|
||||
|
||||
// Acceso al cuerpo físico (Fase 6+). El PhysicsWorld lo registra
|
||||
// por puntero; la entidad lo configura en init().
|
||||
[[nodiscard]] auto getBody() -> Physics::RigidBody& { return body_; }
|
||||
[[nodiscard]] auto getBody() const -> const Physics::RigidBody& { return body_; }
|
||||
|
||||
protected:
|
||||
// Estat comú (accés directe, sin overhead)
|
||||
// Estado común (acceso directo, sin overhead)
|
||||
SDL_Renderer* renderer_;
|
||||
std::shared_ptr<Graphics::Shape> shape_;
|
||||
Vec2 center_;
|
||||
float angle_{0.0F};
|
||||
float brightness_{1.0F};
|
||||
|
||||
// Constructor protegit (clase abstracta)
|
||||
// Cuerpo físico (Fase 6). Las entidades que se mueven por
|
||||
// física actualizan center_/angle_ en postUpdate() desde body_.
|
||||
Physics::RigidBody body_;
|
||||
|
||||
// Constructor protegido (clase abstracta)
|
||||
Entity(SDL_Renderer* renderer = nullptr)
|
||||
: renderer_(renderer),
|
||||
center_({.x = 0.0F, .y = 0.0F}) {}
|
||||
|
||||
@@ -131,6 +131,11 @@ void GameScene::init() {
|
||||
// Basat en el codi Pascal original: line 376
|
||||
std::srand(static_cast<unsigned>(std::time(nullptr)));
|
||||
|
||||
// Configurar el mundo físico con los límites de la zona de juego.
|
||||
// Las entidades se registrarán cada una al inicializarse (Fase 6c-e).
|
||||
physics_world_.clear();
|
||||
physics_world_.setBounds(Defaults::Zones::PLAYAREA);
|
||||
|
||||
// [NEW] Load stage configuration (only once)
|
||||
if (!stage_config_) {
|
||||
stage_config_ = StageSystem::StageLoader::load("data/stages/stages.yaml");
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "core/graphics/vector_text.hpp"
|
||||
#include "core/physics/physics_world.hpp"
|
||||
#include "core/rendering/sdl_manager.hpp"
|
||||
#include "core/system/scene_context.hpp"
|
||||
#include "core/system/game_config.hpp"
|
||||
@@ -46,6 +47,9 @@ class GameScene {
|
||||
SceneManager::SceneContext& context_;
|
||||
GameConfig::MatchConfig match_config_; // Configuración de jugadors active
|
||||
|
||||
// Mundo físico (Fase 5) — integración cinemática + colisiones
|
||||
Physics::PhysicsWorld physics_world_;
|
||||
|
||||
// Efectes visuals
|
||||
Effects::DebrisManager debris_manager_;
|
||||
Effects::FloatingScoreManager floating_score_manager_;
|
||||
|
||||
Reference in New Issue
Block a user