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);
|
void show_cursor(bool show);
|
||||||
|
|
||||||
|
float time() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct impl;
|
struct impl;
|
||||||
std::unique_ptr<impl> pimpl_;
|
std::unique_ptr<impl> pimpl_;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ namespace psemek::app
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using clock = std::chrono::high_resolution_clock;
|
||||||
|
|
||||||
struct app::impl
|
struct app::impl
|
||||||
{
|
{
|
||||||
sdl_initializer init;
|
sdl_initializer init;
|
||||||
|
|
@ -39,6 +41,8 @@ namespace psemek::app
|
||||||
|
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
|
||||||
|
clock::time_point start_time;
|
||||||
|
|
||||||
~impl()
|
~impl()
|
||||||
{
|
{
|
||||||
if (gl_context) SDL_GL_DeleteContext(gl_context);
|
if (gl_context) SDL_GL_DeleteContext(gl_context);
|
||||||
|
|
@ -49,6 +53,8 @@ namespace psemek::app
|
||||||
app::app(std::string const & name)
|
app::app(std::string const & name)
|
||||||
: pimpl_{std::make_unique<struct impl>()}
|
: 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_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl::sys::GetLeastMajorVersion());
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl::sys::GetLeastMajorVersion());
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gl::sys::GetLeastMinorVersion());
|
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);
|
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