27 std::srand(std::time(
nullptr));
42 auto runGame = [&]() {
55 std::cerr <<
"Fatal error " << e.
what() << std::endl;
79 if (event.type == SDL_QUIT) {
86 while (SDL_PollEvent(&event)) {
virtual void onEvent(const SDL_Event &event)
This function is called when a new window event is received.
ResourceHandler m_resourceHandler
Container for all game resources.
static void setWindow(Window *window)
ApplicationState & top() const
Get the top ApplicationState in the stack.
Window m_window
The main window.
CoreApplication(int argc, char **argv)
Constructor.
GameClock m_clock
Simulated time system.
static void setMuteState(bool muteState)
virtual const char * what() const noexcept
void createWindow(u16 screenWidth, u16 screenHeight, const char *windowTitle)
Open window.
virtual void update()=0
Execute actions every game tick.
RenderStates m_renderStates
The default render states.
void clearDeletedStates()
Clear the removed states of the stack.
std::size_t size() const
Get the amount of ApplicationState in the stack.
virtual void init()
Initialization function.
int run(bool isProtected=true)
Run the application.
virtual void onEvent(const SDL_Event &)
Do an action in response to an SDL event.
void draw(const IDrawable &drawable, const RenderStates &states=RenderStates::Default)
bool empty() const
Check if the container is empty.
void open(const std::string &caption, u16 width, u16 height)
void drawGame(std::function< void(void)> drawFunc)
const Argument & getArgument(const std::string &name)
static void setInstance(ApplicationStateStack &instance)
Set the current singleton instance.
bool m_loadSDL
If this flag is set to false, SDL won't be loaded.
ApplicationStateStack m_stateStack
Stack containing application states.
virtual void handleEvents()
Poll window events and send them to onEvent() and ApplicationStateStack.
void updateGame(std::function< void(void)> updateFunc)
void addArgument(const std::string &name, const Argument &argument)
static void setInstance(ResourceHandler &handler)
virtual void mainLoop()
Game main loop, automatically called by run()
SDLLoader m_sdlLoader
Init and free SDL.
ArgumentParser m_argumentParser
Helper for argument management.