From 37fdcb8a0f435c42f737252450626f2bd38bbd0f Mon Sep 17 00:00:00 2001 From: ladevieq Date: Tue, 5 May 2026 00:50:13 +0200 Subject: Clean up around included files --- include/utils.hpp | 78 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 26 deletions(-) (limited to 'include/utils.hpp') 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 -#include - -std::vector read_file(const char* path); +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"; + +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(deg * PI / 180.f); } @@ -31,31 +74,14 @@ inline float clamp(float x, float min, float max) { } -#if defined(WINDOWS) - -#include +#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 callbacks; - inline static std::unordered_map watched_dirs; -}; +void pull_changes(); #endif -- cgit v1.3