68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#include <psemek/app/application.hpp>
|
|
#include <psemek/gfx/init.hpp>
|
|
#include <psemek/sdl2/init.hpp>
|
|
#include <psemek/sdl2/window.hpp>
|
|
#include <psemek/sdl2/events.hpp>
|
|
#include <psemek/util/clock.hpp>
|
|
#include <psemek/util/pretty_print.hpp>
|
|
#include <psemek/log/log.hpp>
|
|
|
|
#undef main
|
|
|
|
int main() try
|
|
{
|
|
using namespace psemek;
|
|
|
|
util::clock<std::chrono::milliseconds, std::chrono::high_resolution_clock> clock;
|
|
|
|
#ifdef PSEMEK_PACKAGE_MODE
|
|
log::level const stdio_log_level = log::level::info;
|
|
#else
|
|
log::level const stdio_log_level = log::level::debug;
|
|
#endif
|
|
|
|
log::add_sink(log::default_sink(io::std_out(), stdio_log_level));
|
|
log::register_thread("main");
|
|
|
|
auto const factory = app::make_application_factory();
|
|
auto const options = factory->options();
|
|
|
|
sdl2::window window(options);
|
|
|
|
gfx::init();
|
|
|
|
app::application::context context;
|
|
context.show_cursor = [&](bool show){ window.show_cursor(show); };
|
|
context.vsync = [&](bool on){ window.vsync(on); };
|
|
|
|
auto application = factory->create(options, context);
|
|
application->on_event(app::resize_event{window.size()});
|
|
|
|
window.show();
|
|
|
|
log::info() << "Started in " << util::pretty(clock.duration(), std::chrono::milliseconds{1});
|
|
log::info() << "Running";
|
|
|
|
while (application->running())
|
|
{
|
|
if (sdl2::poll_events(*application))
|
|
application->stop();
|
|
if (!application->running()) break;
|
|
application->update();
|
|
application->present();
|
|
window.swap();
|
|
}
|
|
|
|
log::info() << "Quitting";
|
|
return EXIT_SUCCESS;
|
|
}
|
|
catch (std::exception const & e)
|
|
{
|
|
psemek::log::error() << e.what();
|
|
return EXIT_FAILURE;
|
|
}
|
|
catch (...)
|
|
{
|
|
psemek::log::error() << "Unknown exception";
|
|
return EXIT_FAILURE;
|
|
}
|