migrat a SDL3 Callback API (SDL_AppInit/Iterate/Event/Quit) (milestone 3)

- main.cpp reescrit amb SDL_MAIN_USE_CALLBACKS
- Director convertit a màquina d'estats amb iterate() i handleEvent()
- Seccions (Logo, Intro, Title, Game) amb iterate() i handleEvent()
- Events SDL enrutats via SDL_AppEvent → Director → secció activa
- Eliminat SDL_PollEvent de iterate(), events via handleEvent()
- Transicions entre seccions gestionades per handleSectionTransition()
- Instructions i Game (demo) delegats frame a frame des de Title

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 19:32:31 +02:00
parent 18c4d6032d
commit 06d4712493
11 changed files with 306 additions and 132 deletions

View File

@@ -886,67 +886,94 @@ void Title::applyOptions() {
createTiledBackground();
}
// Bucle para el titulo del juego
// Ejecuta un frame
void Title::iterate() {
// Si las instrucciones están activas, delega el frame
if (instructionsActive) {
instructions->update();
instructions->render();
if (instructions->hasFinished()) {
bool wasQuit = instructions->isQuitRequested();
delete instructions;
instructions = nullptr;
instructionsActive = false;
if (wasQuit) {
section->name = SECTION_PROG_QUIT;
} else if (instructionsMode == m_auto) {
section->name = SECTION_PROG_TITLE;
init();
demo = true;
} else {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_3;
}
}
return;
}
// Si el juego demo está activo, delega el frame
if (demoGameActive) {
demoGame->iterate();
if (demoGame->hasFinished()) {
bool wasQuit = (section->name == SECTION_PROG_QUIT);
delete demoGame;
demoGame = nullptr;
demoGameActive = false;
if (wasQuit) {
section->name = SECTION_PROG_QUIT;
} else if (demoThenInstructions) {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_3;
demoThenInstructions = false;
runInstructions(m_auto);
} else {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
}
return;
}
// Ejecución normal del título
update();
render();
}
// Procesa un evento individual
void Title::handleEvent(SDL_Event *event) {
// Si hay un sub-estado activo, delega el evento
if (instructionsActive && instructions) {
// SDL_EVENT_QUIT ya lo maneja Director
return;
}
if (demoGameActive && demoGame) {
demoGame->handleEvent(event);
return;
}
// SDL_EVENT_QUIT ya lo maneja Director
if (event->type == SDL_EVENT_RENDER_DEVICE_RESET || event->type == SDL_EVENT_RENDER_TARGETS_RESET) {
reLoadTextures();
}
if (section->subsection == SUBSECTION_TITLE_3) {
if ((event->type == SDL_EVENT_KEY_UP) || (event->type == SDL_EVENT_JOYSTICK_BUTTON_UP)) {
menuVisible = true;
counter = TITLE_COUNTER;
}
}
}
// Bucle para el titulo del juego (compatibilidad)
void Title::run() {
while (section->name == SECTION_PROG_TITLE || instructionsActive || demoGameActive) {
// Si las instrucciones están activas, delega el frame
if (instructionsActive) {
instructions->update();
instructions->checkEvents();
instructions->render();
if (instructions->hasFinished()) {
bool wasQuit = instructions->isQuitRequested();
delete instructions;
instructions = nullptr;
instructionsActive = false;
if (wasQuit) {
section->name = SECTION_PROG_QUIT;
} else if (instructionsMode == m_auto) {
// Tras instrucciones automáticas (post-demo o subsection), reinicia título
section->name = SECTION_PROG_TITLE;
init();
demo = true;
} else {
// Tras instrucciones manuales (HOW TO PLAY), vuelve al menú
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_3;
}
}
continue;
}
// Si el juego demo está activo, delega el frame
if (demoGameActive) {
demoGame->iterate();
if (demoGame->hasFinished()) {
bool wasQuit = (section->name == SECTION_PROG_QUIT);
delete demoGame;
demoGame = nullptr;
demoGameActive = false;
if (wasQuit) {
section->name = SECTION_PROG_QUIT;
} else if (demoThenInstructions) {
// Restaura el section para Title y lanza instrucciones
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_3;
demoThenInstructions = false;
runInstructions(m_auto);
} else {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
}
continue;
}
// Ejecución normal del título
update();
checkEvents();
render();
iterate();
}
}