summaryrefslogtreecommitdiffstats
path: root/src/Utility.hpp
blob: 5bce76e83c8414679ba832f9651ce40122d607ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

#include <algorithm>
#include <string>
#include <chrono>
#include <vector>

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));
}

template<class T>
void endswap(T &obj) {
    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);
}

#define glCheckError()

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;
    timePoint previousPreviousUpdate;
    duration delayLength;
    unsigned long long iterations=0;
public:
    LoopExecutionTimeController(duration delayLength);

    void SetDelayLength(duration length);

    unsigned long long GetIterations();

    void Update();

    double GetDeltaMs();

    duration GetDelta();

    double GetDeltaS();

    double GetRealDeltaS();

    double RemainTimeMs();
};