summaryrefslogtreecommitdiffstats
path: root/src/Utility.hpp
blob: 52d6016eee48acd89b21c9155ae55e464079c3f6 (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
#pragma once

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

#include <easylogging++.h>
#include <GL/glew.h>

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

inline void endswap(unsigned char *arr, size_t arrLen) {
	std::reverse(arr, arr + arrLen);
}

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<clock>;
	using duration = std::chrono::duration<double,std::milli>;
	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();

	duration GetDelta();
};