48 lines
1.9 KiB
C++
48 lines
1.9 KiB
C++
#pragma once
|
|
#include <hdk/sdl.hpp>
|
|
/// @file Application.hpp
|
|
/// For complete documentation, see src/Application.cpp
|
|
namespace hdk::sdl {
|
|
/** SDL Requires this interface to be implemented by the application class. */
|
|
class AppInterface {
|
|
public:
|
|
virtual SDL_AppResult Event(SDL_Event* event) = 0;
|
|
virtual SDL_AppResult Init(int argc, char* argv[]) = 0;
|
|
virtual SDL_AppResult Iterate() = 0;
|
|
virtual void Quit(SDL_AppResult code) = 0;
|
|
};
|
|
/** I'm calling it a public application because the AppStatus member is publicly accessible and so can be
|
|
* modified directly by the rest of application logic that has access to this application instance via this subclass.
|
|
*/
|
|
class PublicApp : public AppInterface {
|
|
public:
|
|
SDL_AppResult AppStatus { SDL_APP_CONTINUE };
|
|
virtual SDL_AppResult Event(SDL_Event* event) override { return AppStatus; }
|
|
virtual SDL_AppResult Init(int argc, char* argv[]) override { return AppStatus; }
|
|
virtual SDL_AppResult Iterate() override { return AppStatus; }
|
|
virtual void Quit(SDL_AppResult code) override {
|
|
// Default quit behavior is to do nothing, allowing the app to control its own lifetime.
|
|
}
|
|
};
|
|
/** Defines basically everything except for Init */
|
|
class ProtectedApp : public AppInterface {
|
|
protected:
|
|
SDL_AppResult AppStatus { SDL_APP_CONTINUE };
|
|
const sdl::Log& AppLog { sdl::Log::Application };
|
|
public:
|
|
sdl::evt::AllTypes events;
|
|
virtual SDL_AppResult Event(SDL_Event* event) override {
|
|
events.Trigger(event);
|
|
return AppStatus;
|
|
}
|
|
grid::eps::Conduit<> OnIterate;
|
|
|
|
virtual SDL_AppResult Iterate() override {
|
|
OnIterate();
|
|
return AppStatus;
|
|
}
|
|
virtual void Quit(SDL_AppResult code) override {
|
|
AppLog.Debug("Quit called with code %d", code);
|
|
}
|
|
};
|
|
} // namespace hdk::sdl
|