diff --git a/libs/app/include/psemek/app/app.hpp b/libs/app/include/psemek/app/app.hpp index 51de8b43..63995dc4 100644 --- a/libs/app/include/psemek/app/app.hpp +++ b/libs/app/include/psemek/app/app.hpp @@ -40,6 +40,8 @@ namespace psemek::app void show_cursor(bool show); + float time() const; + private: struct impl; std::unique_ptr pimpl_; diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index 8cfccf47..337e3614 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -31,6 +31,8 @@ namespace psemek::app } + using clock = std::chrono::high_resolution_clock; + struct app::impl { sdl_initializer init; @@ -39,6 +41,8 @@ namespace psemek::app bool running = false; + clock::time_point start_time; + ~impl() { if (gl_context) SDL_GL_DeleteContext(gl_context); @@ -49,6 +53,8 @@ namespace psemek::app app::app(std::string const & name) : pimpl_{std::make_unique()} { + impl().start_time = clock::now(); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl::sys::GetLeastMajorVersion()); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gl::sys::GetLeastMinorVersion()); @@ -206,4 +212,9 @@ namespace psemek::app SDL_ShowCursor(show ? SDL_TRUE : SDL_FALSE); } + float app::time() const + { + return std::chrono::duration_cast>(clock::now() - impl().start_time).count(); + } + }