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

57
source/modules/core.cppm Normal file
View File

@@ -0,0 +1,57 @@
export module vibe2.core;
#include <cstdint>
export namespace vibe2 {
// Constantes de pantalla
constexpr char WINDOW_CAPTION[] = "vibe2_modules";
constexpr int SCREEN_WIDTH = 320;
constexpr int SCREEN_HEIGHT = 240;
constexpr int WINDOW_SIZE = 3;
constexpr int BALL_SIZE = 10;
constexpr float GRAVITY_FORCE = 0.2f;
constexpr std::uint64_t TEXT_DURATION = 2000;
// Tipos básicos
struct Color {
int r, g, b;
constexpr Color(int red = 0, int green = 0, int blue = 0)
: r(red), g(green), b(blue) {}
};
struct Position {
float x, y;
constexpr Position(float px = 0.0f, float py = 0.0f)
: x(px), y(py) {}
};
struct Velocity {
float vx, vy;
constexpr Velocity(float x_vel = 0.0f, float y_vel = 0.0f)
: vx(x_vel), vy(y_vel) {}
};
// Enums para el sistema de temas
enum class ColorTheme {
SUNSET = 0,
OCEAN = 1,
NEON = 2,
FOREST = 3
};
// Constantes útiles para la física
namespace physics {
constexpr float FRICTION_FACTOR = 0.97f;
constexpr float VELOCITY_THRESHOLD = 6.0f;
constexpr float CONVERSION_FACTOR = 60.0f; // Frame-based to time-based
}
// Constantes para debug
namespace debug {
constexpr int DEFAULT_TEXT_SIZE = 8; // Píxeles por carácter
constexpr int MARGIN = 8; // Margen por defecto
}
}

107
source/modules/external/sdl_wrapper.cppm vendored Normal file
View File

@@ -0,0 +1,107 @@
export module vibe2.external.sdl_wrapper;
// Incluir headers de SDL3
#include <cstdint>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_keycode.h>
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_rect.h>
export namespace vibe2::sdl {
// Re-exportar tipos de SDL que usamos frecuentemente
using Window = SDL_Window;
using Renderer = SDL_Renderer;
using Event = SDL_Event;
using FRect = SDL_FRect;
using Vertex = SDL_Vertex;
using Texture = SDL_Texture;
// Re-exportar constantes de SDL
constexpr auto INIT_VIDEO = SDL_INIT_VIDEO;
constexpr auto WINDOW_OPENGL = SDL_WINDOW_OPENGL;
constexpr auto EVENT_QUIT = SDL_EVENT_QUIT;
constexpr auto EVENT_KEY_DOWN = SDL_EVENT_KEY_DOWN;
constexpr auto LOGICAL_PRESENTATION_INTEGER_SCALE = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
// Re-exportar teclas que usamos
constexpr auto KEY_ESCAPE = SDLK_ESCAPE;
constexpr auto KEY_SPACE = SDLK_SPACE;
constexpr auto KEY_G = SDLK_G;
constexpr auto KEY_V = SDLK_V;
constexpr auto KEY_H = SDLK_H;
constexpr auto KEY_T = SDLK_T;
constexpr auto KEY_F1 = SDLK_F1;
constexpr auto KEY_F2 = SDLK_F2;
constexpr auto KEY_F3 = SDLK_F3;
constexpr auto KEY_F4 = SDLK_F4;
constexpr auto KEY_1 = SDLK_1;
constexpr auto KEY_2 = SDLK_2;
constexpr auto KEY_3 = SDLK_3;
constexpr auto KEY_4 = SDLK_4;
constexpr auto KEY_5 = SDLK_5;
constexpr auto KEY_6 = SDLK_6;
constexpr auto KEY_7 = SDLK_7;
constexpr auto KEY_8 = SDLK_8;
// Wrapper functions para funciones de SDL más usadas
inline bool init(Uint32 flags) {
return SDL_Init(flags);
}
inline void quit() {
SDL_Quit();
}
inline Window* createWindow(const char* title, int w, int h, Uint64 flags) {
return SDL_CreateWindow(title, w, h, flags);
}
inline void destroyWindow(Window* window) {
SDL_DestroyWindow(window);
}
inline Renderer* createRenderer(Window* window, const char* name) {
return SDL_CreateRenderer(window, name);
}
inline void destroyRenderer(Renderer* renderer) {
SDL_DestroyRenderer(renderer);
}
inline bool setRenderDrawColor(Renderer* renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
return SDL_SetRenderDrawColor(renderer, r, g, b, a);
}
inline bool setRenderLogicalPresentation(Renderer* renderer, int w, int h, SDL_RendererLogicalPresentation mode) {
return SDL_SetRenderLogicalPresentation(renderer, w, h, mode);
}
inline bool setRenderVSync(Renderer* renderer, int vsync) {
return SDL_SetRenderVSync(renderer, vsync);
}
inline bool renderGeometry(Renderer* renderer, Texture* texture, const Vertex* vertices, int num_vertices, const int* indices, int num_indices) {
return SDL_RenderGeometry(renderer, texture, vertices, num_vertices, indices, num_indices);
}
inline bool renderPresent(Renderer* renderer) {
return SDL_RenderPresent(renderer);
}
inline bool pollEvent(Event* event) {
return SDL_PollEvent(event);
}
inline Uint64 getTicks() {
return SDL_GetTicks();
}
inline const char* getError() {
return SDL_GetError();
}
}