From f942405184c2d6067fb5303b58a225edf7e452b1 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sat, 29 Jul 2017 19:55:16 +0500 Subject: 2017-07-29 --- src/Utility.hpp | 65 +++++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) (limited to 'src/Utility.hpp') diff --git a/src/Utility.hpp b/src/Utility.hpp index 11b4ff7..52d6016 100644 --- a/src/Utility.hpp +++ b/src/Utility.hpp @@ -1,7 +1,10 @@ #pragma once #include +#include +#include +#include #include template @@ -20,40 +23,30 @@ inline void endswap(unsigned char *arr, size_t arrLen) { std::reverse(arr, arr + arrLen); } -inline GLenum glCheckError_(const char *file, int line) { - GLenum errorCode; - while ((errorCode = glGetError()) != GL_NO_ERROR) { - std::string error; - switch (errorCode) { - case GL_INVALID_ENUM: - error = "INVALID_ENUM"; - break; - case GL_INVALID_VALUE: - error = "INVALID_VALUE"; - break; - case GL_INVALID_OPERATION: - error = "INVALID_OPERATION"; - break; - case GL_STACK_OVERFLOW: - error = "STACK_OVERFLOW"; - break; - case GL_STACK_UNDERFLOW: - error = "STACK_UNDERFLOW"; - break; - case GL_OUT_OF_MEMORY: - error = "OUT_OF_MEMORY"; - break; - case GL_INVALID_FRAMEBUFFER_OPERATION: - error = "INVALID_FRAMEBUFFER_OPERATION"; - break; - } - static int t = 0; - t++; - if (t>10) - LOG(FATAL); - LOG(ERROR) << "OpenGL error: " << error << " at " << file << ":" << line; - } - return errorCode; -} +GLenum glCheckError_(const char *file, int line); +#define glCheckError() glCheckError_(__FILE__, __LINE__) + + + +class LoopExecutionTimeController { + using clock = std::chrono::steady_clock ; + using timePoint = std::chrono::time_point; + using duration = std::chrono::duration; + timePoint previousUpdate; + duration delayLength; + unsigned long long iterations=0; +public: + LoopExecutionTimeController(duration delayLength); + + ~LoopExecutionTimeController(); + + void SetDelayLength(duration length); + + unsigned long long GetIterations(); + + void Update(); + + double GetDeltaMs(); -#define glCheckError() glCheckError_(__FILE__, __LINE__) \ No newline at end of file + duration GetDelta(); +}; -- cgit v1.2.3