summaryrefslogtreecommitdiffstats
path: root/src/Utility.hpp
diff options
context:
space:
mode:
authorElisey Puzko <puzko.e02@gmail.com>2018-02-25 12:49:36 +0100
committerElisey Puzko <puzko.e02@gmail.com>2018-02-25 12:50:23 +0100
commit78221efae3c038e2c21cb553891d9de8c37cf809 (patch)
treef5d7dea2c6dc5a3d2feb8f4c0413f83beef61793 /src/Utility.hpp
parentSome nice hack to avoid conflict of std::min and min macro (diff)
downloadAltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar
AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.gz
AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.bz2
AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.lz
AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.xz
AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.zst
AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.zip
Diffstat (limited to 'src/Utility.hpp')
-rw-r--r--src/Utility.hpp56
1 files changed, 38 insertions, 18 deletions
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<unsigned char>;
template<class T>
void endswap(T *objp) {
- unsigned char *memp = reinterpret_cast<unsigned char *>(objp);
- std::reverse(memp, memp + sizeof(T));
+ unsigned char *memp = reinterpret_cast<unsigned char *>(objp);
+ std::reverse(memp, memp + sizeof(T));
}
template<class T>
void endswap(T &obj) {
- unsigned char *raw = reinterpret_cast<unsigned char *>(&obj);
- std::reverse(raw, raw + sizeof(T));
+ unsigned char *raw = reinterpret_cast<unsigned char *>(&obj);
+ std::reverse(raw, raw + sizeof(T));
+}
+
+template<typename T>
+T _min(T a, T b) {
+ return (a > b) ? b : a;
+}
+
+template<typename T, typename... Args>
+T _min(T a, T b, Args... args) {
+ return _min(a > b ? b : a, args...);
+}
+
+template<typename T>
+T _max(T a, T b) {
+ return (a > b) ? a : b;
+}
+
+template<typename T, typename... Args>
+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<clock>;
- using duration = std::chrono::duration<double,std::milli>;
- timePoint previousUpdate;
+ using clock = std::chrono::steady_clock ;
+ using timePoint = std::chrono::time_point<clock>;
+ using duration = std::chrono::duration<double,std::milli>;
+ 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();