aboutsummaryrefslogtreecommitdiffstats
path: root/include/utils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/utils.hpp')
-rw-r--r--include/utils.hpp76
1 files changed, 51 insertions, 25 deletions
diff --git a/include/utils.hpp b/include/utils.hpp
index e49b218..19a5d9f 100644
--- a/include/utils.hpp
+++ b/include/utils.hpp
@@ -1,13 +1,56 @@
#pragma once
-#include <vector>
-#include <unordered_map>
+static constexpr size_t KB = 1024U;
+static constexpr size_t MB = 1024U * KB;
+static constexpr size_t GB = 1024U * MB;
+const char* DUMMY_NAME = "NO_NAME";
-std::vector<uint8_t> read_file(const char* path);
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef int8_t s8;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef int64_t s64;
+
+uint8_t* read_file(const char* path, size_t size);
+
+const uint32_t max_markers = 1024U;
+// hashmap ?
+uint32_t marker_count = 0U;
+const char* marker_names[max_markers] = { 0 };
+uint64_t marker_counter_start[max_markers] = { 0 };
+uint64_t marker_counter_end[max_markers] = { 0 };
+
+#define BEGIN_MARKER(name) \
+ static uint32_t marker_##name##_index = UINT32_MAX; \
+ do { \
+ if (marker_##name##_index == UINT32_MAX) { \
+ marker_##name##_index = marker_count++; \
+ marker_names[marker_##name##_index] = #name; \
+ } \
+ { \
+ LARGE_INTEGER start_qpc; \
+ QueryPerformanceCounter(&start_qpc); \
+ marker_counter_start[marker_##name##_index] = start_qpc.QuadPart; \
+ } \
+ } while(0);
+
+#define END_MARKER(name) \
+ do { \
+ LARGE_INTEGER end_qpc; \
+ QueryPerformanceCounter(&end_qpc); \
+ marker_counter_end[marker_##name##_index] = end_qpc.QuadPart; \
+ } while(0);
#define PI 3.14159265359
#define EPSILON 0.000001
+
+#define ALIGN(value, alignment) \
+ (((value) + ((alignment) - 1)) & ~((alignment) - 1))
+
inline float deg_to_rad(float deg) {
return static_cast<float>(deg * PI / 180.f);
}
@@ -31,31 +74,14 @@ inline float clamp(float x, float min, float max) {
}
-#if defined(WINDOWS)
-
-#include <windows.h>
+#if _WIN32
void log_last_error();
-class watcher {
-public:
- typedef void(*func)(void);
-
- static bool watch_file(const char* filepath, func callback);
-
- static bool watch_dir(const char* dir_path);
-
- static void pull_changes();
-
-private:
+typedef void(*func)(void);
+bool watch_file(const char* filepath, func callback);
- struct watch_data {
- HANDLE dir_handle;
- OVERLAPPED overlapped;
- DWORD buffer[512];
- };
+bool watch_dir(const char* dir_path);
- inline static std::unordered_map<const char*, func> callbacks;
- inline static std::unordered_map<const char*, watch_data> watched_dirs;
-};
+void pull_changes();
#endif