48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#define SDL_MAIN_USE_CALLBACKS 1
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_main.h>
|
|
|
|
#include <iostream>
|
|
#include <memory>
|
|
|
|
#include "core/system/director.hpp"
|
|
#include "core/system/event_buffer.hpp"
|
|
|
|
auto SDL_AppInit(void** appstate, int argc, char* argv[]) -> SDL_AppResult {
|
|
(void)argc;
|
|
(void)argv;
|
|
|
|
// Marcador d'inici: ha de ser la PRIMERA línia de log del programa.
|
|
std::cout << "Game start\n";
|
|
|
|
// Construïm el Director amb make_unique i l'entreguem en cru a SDL.
|
|
// El SDL_AppQuit reclamarà la propietat amb un altre unique_ptr (RAII).
|
|
auto director = std::make_unique<Director>();
|
|
*appstate = director.release();
|
|
return SDL_APP_CONTINUE;
|
|
}
|
|
|
|
auto SDL_AppEvent(void* appstate, SDL_Event* event) -> SDL_AppResult {
|
|
(void)appstate;
|
|
EventBuffer::events.push_back(*event);
|
|
return SDL_APP_CONTINUE;
|
|
}
|
|
|
|
auto SDL_AppIterate(void* appstate) -> SDL_AppResult {
|
|
auto* director = static_cast<Director*>(appstate);
|
|
return director->iterate();
|
|
}
|
|
|
|
void SDL_AppQuit(void* appstate, SDL_AppResult result) {
|
|
(void)result;
|
|
// Reabsorbim la propietat: el destructor neteja l'escena; els singletons
|
|
// (Screen, Cache) viuen fins a la destrucció estàtica i SDL_Quit dispara
|
|
// via atexit després d'ells.
|
|
{
|
|
std::unique_ptr<Director> director(static_cast<Director*>(appstate));
|
|
}
|
|
// Marcador de fi: ha de ser l'ÚLTIMA línia de log del programa.
|
|
std::cout << "Bye!\n";
|
|
}
|