1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #ifndef CORE_UTILITY_H
- #define CORE_UTILITY_H
- #include "core/Check.h"
- #include "core/Types.h"
- size_t corePopCount(u64 u);
- #define coreInterpolate(a, b, factor) (a * (1.0f - factor) + b * factor)
- #define CORE_PI 3.14159265358979323846f
- #define coreRadianToDegree(radians) (radians * (180.0f / CORE_PI))
- #define coreDegreeToRadian(degrees) (degrees * (CORE_PI / 180.0f))
- inline size_t coreMaxSize(size_t a, size_t b) {
- return a > b ? a : b;
- }
- inline size_t coreMinSize(size_t a, size_t b) {
- return a < b ? a : b;
- }
- check_format(3, 4) size_t
- coreToString(char* buffer, size_t n, const char* format, ...);
- size_t coreToStringSize(const void* p, char* buffer, size_t n);
- size_t coreToStringInt(const void* p, char* buffer, size_t n);
- void coreStringAdd(size_t* w, char** buffer, size_t* n, size_t shift);
- typedef void (*CoreExitHandler)(int, void*);
- [[noreturn]] void coreExitWithHandler(const char* file, int line, int value);
- void coreSetExitHandler(CoreExitHandler h, void* data);
- #define CORE_EXIT(exitValue) coreExitWithHandler(__FILE__, __LINE__, exitValue)
- typedef void (*CoreOutOfMemoryHandler)(void*);
- void coreSetOutOfMemoryHandler(CoreOutOfMemoryHandler h, void* data);
- #ifdef CORE_CHECK_MEMORY
- void* coreDebugAllocate(const char* file, int line, size_t n);
- void* coreDebugReallocate(const char* file, int line, void* p, size_t n);
- void coreFreeDebug(const char* file, int line, void* p);
- void corePrintMemoryReport(void);
- #define coreAllocate(n) coreDebugAllocate(__FILE__, __LINE__, n)
- #define coreReallocate(p, n) coreDebugReallocate(__FILE__, __LINE__, p, n)
- #define coreFree(p) coreFreeDebug(__FILE__, __LINE__, p)
- #else
- void* coreAllocate(size_t n);
- void* coreReallocate(void* p, size_t n);
- void coreFree(void* p);
- #define corePrintMemoryReport()
- #endif
- bool coreSleep(i64 nanos);
- i64 coreNanos(void);
- #endif
|