Add app::time
This commit is contained in:
parent
3ab93d21a7
commit
a6316d27f4
2 changed files with 13 additions and 0 deletions
|
|
@ -40,6 +40,8 @@ namespace psemek::app
|
|||
|
||||
void show_cursor(bool show);
|
||||
|
||||
float time() const;
|
||||
|
||||
private:
|
||||
struct impl;
|
||||
std::unique_ptr<impl> pimpl_;
|
||||
|
|
|
|||
|
|
@ -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<struct impl>()}
|
||||
{
|
||||
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<std::chrono::duration<float>>(clock::now() - impl().start_time).count();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue