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>
107 lines
3.3 KiB
C++
107 lines
3.3 KiB
C++
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();
|
|
}
|
|
} |