123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #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 coreSleepNanos(i64 nanos);
- i64 coreGetNanos(void);
- #ifdef IMPORT_CORE
- #define popCount corePopCount
- #define interpolate coreInterpolate
- #define PI CORE_PI
- #define radianToDegree coreRadianToDegree
- #define degreeToRadian coreDegreeToRadian
- #define maxSize coreMaxSize
- #define minSize coreMinSize
- #define toString coreToString
- #define toStringSize coreToStringSize
- #define toStringInt coreToStringInt
- #define stringAdd coreStringAdd
- #define ExitHandler CoreExitHandler
- #define setExitHandler coreSetExitHandler
- #define EXIT CORE_EXIT
- #define OutOfMemoryHandler CoreOutOfMemoryHandler
- #define setOutOfMemoryHandler coreSetOutOfMemoryHandler
- #define printMemoryReport corePrintMemoryReport
- #define cAllocate coreAllocate
- #define cReallocate coreReallocate
- #define cFree coreFree
- #define sleepNanos coreSleepNanos
- #define getNanos coreGetNanos
- #endif
- #endif
|