This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.hpp
61 lines (53 loc) · 1.54 KB
/
utils.hpp
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
#pragma once
#define NOMINMAX
#include <windows.h>
#include <filesystem>
namespace Win32GameEngine {
using namespace std;
using String = LPTSTR;
using ConstString = LPCTSTR;
template<template <typename...> typename Template, typename... Args>
void _derived_from_template(const Template<Args...> &);
template<typename T, template <typename...> typename Template>
concept derived_from_template = requires(const T & t) {
_derived_from_template<Template>(t);
};
struct Ticker {
ULONGLONG const start;
ULONGLONG last, rate;
Ticker(ULONGLONG rate) : start(GetTickCount64()), last(start), rate(rate) {}
Ticker() : Ticker(0) {}
static inline ULONGLONG get() { return GetTickCount64(); }
inline ULONGLONG since() const { return get() - start; }
inline ULONGLONG elapsed() const { return get() - last; }
inline void tick() { last = get(); }
void setrate(ULONGLONG rate) { this->rate = rate; }
inline bool isup() const { return rate && elapsed() >= rate; }
};
struct File {
unsigned char *data;
int size;
File(ConstString url) : data(nullptr), size(-1) {
auto path = filesystem::current_path();
path.append(url);
url = path.c_str();
FILE *file = nullptr;
_wfopen_s(&file, url, L"rb");
if(!file)
throw L"File not found.";
fseek(file, 0, SEEK_END);
size = ftell(file);
fseek(file, 0, SEEK_SET);
data = new unsigned char[size];
fread(data, 1, size, file);
fclose(file);
}
~File() {
delete[] data;
}
};
}
#include "linear.hpp"
#include "buffer.hpp"
#include "event.hpp"
#include "window.hpp"