Fase 1: Migración inicial a C++20 modules

Implementada la estructura base de módulos para vibe2_modules:

- Configurado CMakeLists.txt para soportar C++23 y módulos
- Creado módulo core.cppm con tipos básicos (Color, ColorTheme, constantes)
- Creado módulo sdl_wrapper.cppm para encapsular SDL3
- Migrado defines.h completamente al módulo core
- Actualizado ball.h y ball.cpp para usar el módulo core
- Actualizado main.cpp para importar y usar el módulo core
- Eliminado defines.h obsoleto

El proyecto ahora compila y funciona con módulos C++20.
Próximos pasos: crear módulos especializados (physics, rendering, etc.)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-17 21:17:40 +02:00
parent 34a0e0505b
commit ea6bb25d5d
7 changed files with 199 additions and 44 deletions
+12 -12
View File
@@ -4,22 +4,22 @@
#include <cmath> // for fabs
#include "defines.h" // for BALL_SIZE, Color, SCREEN_HEIGHT, GRAVITY_FORCE
// defines.h ya no es necesario, todo está en el módulo core via ball.h
class Texture;
// Constructor
Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture)
Ball::Ball(float x, float vx, float vy, vibe2::Color color, std::shared_ptr<Texture> texture)
: sprite_(std::make_unique<Sprite>(texture)),
pos_({x, 0.0f, BALL_SIZE, BALL_SIZE}) {
pos_({x, 0.0f, vibe2::BALL_SIZE, vibe2::BALL_SIZE}) {
// Convertir velocidades de píxeles/frame a píxeles/segundo (multiplicar por 60)
vx_ = vx * 60.0f;
vy_ = vy * 60.0f;
sprite_->setPos({pos_.x, pos_.y});
sprite_->setSize(BALL_SIZE, BALL_SIZE);
sprite_->setClip({0, 0, BALL_SIZE, BALL_SIZE});
sprite_->setSize(vibe2::BALL_SIZE, vibe2::BALL_SIZE);
sprite_->setClip({0, 0, vibe2::BALL_SIZE, vibe2::BALL_SIZE});
color_ = color;
// Convertir gravedad de píxeles/frame² a píxeles/segundo² (multiplicar por 60²)
gravity_force_ = GRAVITY_FORCE * 60.0f * 60.0f;
gravity_force_ = vibe2::GRAVITY_FORCE * 60.0f * 60.0f;
on_floor_ = false;
stopped_ = false;
loss_ = ((rand() % 30) * 0.01f) + 0.6f;
@@ -42,7 +42,7 @@ void Ball::update(float deltaTime) {
pos_.y += vy_ * deltaTime;
} else {
// Si está en el suelo, mantenerla ahí
pos_.y = SCREEN_HEIGHT - pos_.h;
pos_.y = vibe2::SCREEN_HEIGHT - pos_.h;
}
// Comprueba las colisiones con el lateral izquierdo
@@ -52,8 +52,8 @@ void Ball::update(float deltaTime) {
}
// Comprueba las colisiones con el lateral derecho
if (pos_.x + pos_.w > SCREEN_WIDTH) {
pos_.x = SCREEN_WIDTH - pos_.w;
if (pos_.x + pos_.w > vibe2::SCREEN_WIDTH) {
pos_.x = vibe2::SCREEN_WIDTH - pos_.w;
vx_ = -vx_;
}
@@ -64,8 +64,8 @@ void Ball::update(float deltaTime) {
}
// Comprueba las colisiones con la parte inferior
if (pos_.y + pos_.h > SCREEN_HEIGHT) {
pos_.y = SCREEN_HEIGHT - pos_.h;
if (pos_.y + pos_.h > vibe2::SCREEN_HEIGHT) {
pos_.y = vibe2::SCREEN_HEIGHT - pos_.h;
vy_ = -vy_ * loss_;
if (std::fabs(vy_) < 6.0f) // Convertir 0.1f frame-based a 6.0f time-based
{
@@ -111,5 +111,5 @@ void Ball::modVel(float vx, float vy) {
// Cambia la gravedad (usa la versión convertida)
void Ball::switchGravity() {
gravity_force_ = gravity_force_ == 0.0f ? (GRAVITY_FORCE * 60.0f * 60.0f) : 0.0f;
gravity_force_ = gravity_force_ == 0.0f ? (vibe2::GRAVITY_FORCE * 60.0f * 60.0f) : 0.0f;
}