refactor: migració a l'arquitectura SDL3 Callback API
Substitueix el bucle blocant main() → Director::run() → escena::run() per SDL_AppInit/Iterate/Event/Quit. Cada escena implementa ara iterate() (un frame) i handleEvent() (un event) sota una interfície base Scene. - Director gestiona l'escena activa i les transicions via switchToActiveScene() - Setup/cleanup que estava al voltant del while de run() mogut a ctor/dtor (música de Game/Ending/Ending2, volum de LoadingScreen) - GlobalEvents ja no processa SDL_EVENT_QUIT (ho fa Director::handleEvent) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,19 +41,23 @@ LoadingScreen::LoadingScreen()
|
||||
// Cambia el color del borde
|
||||
Screen::get()->setBorderColor(stringToColor("white"));
|
||||
transitionToState(State::SILENT1);
|
||||
|
||||
// Ajusta el volumen i neteja la pantalla (abans a run())
|
||||
Audio::get()->setMusicVolume(50);
|
||||
Screen::get()->start();
|
||||
Screen::get()->clearRenderer();
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LoadingScreen::~LoadingScreen() {
|
||||
Audio::get()->stopMusic();
|
||||
Audio::get()->setMusicVolume(100);
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void LoadingScreen::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void LoadingScreen::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
@@ -347,8 +351,7 @@ void LoadingScreen::renderColoredBorder(PaletteColor color) {
|
||||
void LoadingScreen::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
|
||||
@@ -400,22 +403,10 @@ void LoadingScreen::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
void LoadingScreen::run() {
|
||||
// Ajusta el volumen
|
||||
Audio::get()->setMusicVolume(50);
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->start();
|
||||
Screen::get()->clearRenderer();
|
||||
Screen::get()->render();
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::LOADING_SCREEN) {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
Audio::get()->setMusicVolume(100);
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void LoadingScreen::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
// Pinta el borde
|
||||
|
||||
Reference in New Issue
Block a user