From 78221efae3c038e2c21cb553891d9de8c37cf809 Mon Sep 17 00:00:00 2001 From: Elisey Puzko Date: Sun, 25 Feb 2018 14:49:36 +0300 Subject: min/max functions --- src/Utility.hpp | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'src/Utility.hpp') diff --git a/src/Utility.hpp b/src/Utility.hpp index e8c508d..9b90cb9 100644 --- a/src/Utility.hpp +++ b/src/Utility.hpp @@ -11,18 +11,38 @@ using Uuid = std::vector; template void endswap(T *objp) { - unsigned char *memp = reinterpret_cast(objp); - std::reverse(memp, memp + sizeof(T)); + unsigned char *memp = reinterpret_cast(objp); + std::reverse(memp, memp + sizeof(T)); } template void endswap(T &obj) { - unsigned char *raw = reinterpret_cast(&obj); - std::reverse(raw, raw + sizeof(T)); + unsigned char *raw = reinterpret_cast(&obj); + std::reverse(raw, raw + sizeof(T)); +} + +template +T _min(T a, T b) { + return (a > b) ? b : a; +} + +template +T _min(T a, T b, Args... args) { + return _min(a > b ? b : a, args...); +} + +template +T _max(T a, T b) { + return (a > b) ? a : b; +} + +template +T _max(T a, T b, Args... args) { + return _max(a > b ? a : b, args...); } inline void endswap(unsigned char *arr, size_t arrLen) { - std::reverse(arr, arr + arrLen); + std::reverse(arr, arr + arrLen); } GLenum glCheckError_(const char *file, int line); @@ -30,27 +50,27 @@ GLenum glCheckError_(const char *file, int line); class LoopExecutionTimeController { - using clock = std::chrono::steady_clock ; - using timePoint = std::chrono::time_point; - using duration = std::chrono::duration; - timePoint previousUpdate; + using clock = std::chrono::steady_clock ; + using timePoint = std::chrono::time_point; + using duration = std::chrono::duration; + timePoint previousUpdate; timePoint previousPreviousUpdate; - duration delayLength; - unsigned long long iterations=0; + duration delayLength; + unsigned long long iterations=0; public: - LoopExecutionTimeController(duration delayLength); + LoopExecutionTimeController(duration delayLength); - ~LoopExecutionTimeController(); + ~LoopExecutionTimeController(); - void SetDelayLength(duration length); + void SetDelayLength(duration length); - unsigned long long GetIterations(); + unsigned long long GetIterations(); - void Update(); + void Update(); - double GetDeltaMs(); + double GetDeltaMs(); - duration GetDelta(); + duration GetDelta(); double GetDeltaS(); -- cgit v1.2.3