diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-07-29 16:55:16 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-07-29 16:55:16 +0200 |
commit | f942405184c2d6067fb5303b58a225edf7e452b1 (patch) | |
tree | 83e70c7e3019e5b195c9caf41194b2113fa76d7f /src/Utility.cpp | |
parent | 2017-07-26 (diff) | |
download | AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.gz AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.bz2 AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.lz AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.xz AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.tar.zst AltCraft-f942405184c2d6067fb5303b58a225edf7e452b1.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Utility.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Utility.cpp b/src/Utility.cpp new file mode 100644 index 0000000..9fecc08 --- /dev/null +++ b/src/Utility.cpp @@ -0,0 +1,73 @@ +#include <thread> +#include "Utility.hpp" + +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; +} + +LoopExecutionTimeController::LoopExecutionTimeController(duration delayLength) : delayLength(delayLength) { + previousUpdate = clock::now(); +} + +LoopExecutionTimeController::~LoopExecutionTimeController() { + +} + +void LoopExecutionTimeController::SetDelayLength(duration length) { + delayLength = length; +} + +unsigned long long LoopExecutionTimeController::GetIterations() { + return iterations; +} + +void LoopExecutionTimeController::Update() { + iterations++; + auto timeToSleep = delayLength - GetDelta(); + if (timeToSleep.count()>0) + std::this_thread::sleep_for(timeToSleep); + previousUpdate = clock::now(); +} + +double LoopExecutionTimeController::GetDeltaMs() { + auto now = clock::now(); + return duration(now-previousUpdate).count(); +} + +LoopExecutionTimeController::duration LoopExecutionTimeController::GetDelta() { + auto now = clock::now(); + //std::cerr<<duration(now-previousUpdate).count()<<std::endl; + return duration(now-previousUpdate); +} |