36 lines
3.0 KiB
C++
36 lines
3.0 KiB
C++
#pragma once
|
|
#define SDL_MAIN_USE_CALLBACKS 1
|
|
#include <SDL3/SDL_main.h>
|
|
#include <hdk/sdl/Application.hpp>
|
|
|
|
/// @macro HDK_SDL_MAIN_CLASS(klass)
|
|
/// @brief Define the SDL main entry point using a class implementing hdk::sdl::ApplicationInterface.
|
|
/// @param klass Class name of the application implementation. Must implement hdk::sdl::ApplicationInterface with Init,
|
|
/// Event, Iterate, and Quit methods.
|
|
/// @details This macro generates the SDL main entry point functions (SDL_AppInit, SDL_AppEvent, SDL_AppIterate,
|
|
/// SDL_AppQuit) that create an instance of the specified class and delegate to its methods. This allows users to write
|
|
/// their application logic in a clean class structure while still integrating with SDL's application lifecycle. The
|
|
/// generated main functions handle the boilerplate of managing the application instance and connecting it to SDL's
|
|
/// event loop and lifecycle callbacks.
|
|
|
|
#define HDK_SDL_MAIN_CLASS(klass) \
|
|
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { \
|
|
klass* app = new klass(); \
|
|
*appstate = app; \
|
|
return app->Init(argc, argv); \
|
|
} \
|
|
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) { \
|
|
klass* app = static_cast<klass*>(appstate); \
|
|
return app->Event(event); \
|
|
} \
|
|
SDL_AppResult SDL_AppIterate(void* appstate) { \
|
|
klass* app = static_cast<klass*>(appstate); \
|
|
return app->Iterate(); \
|
|
} \
|
|
void SDL_AppQuit(void* appstate, SDL_AppResult result) { \
|
|
klass* app = static_cast<klass*>(appstate); \
|
|
app->Quit(result); \
|
|
delete app; \
|
|
}
|
|
|
|
// end of file
|