Utility.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef CORE_UTILITY_H
  2. #define CORE_UTILITY_H
  3. #include "core/Check.h"
  4. #include "core/Types.h"
  5. size_t corePopCount(u64 u);
  6. #define coreInterpolate(a, b, factor) (a * (1.0f - factor) + b * factor)
  7. #define CORE_PI 3.14159265358979323846f
  8. #define coreRadianToDegree(radians) (radians * (180.0f / CORE_PI))
  9. #define coreDegreeToRadian(degrees) (degrees * (CORE_PI / 180.0f))
  10. typedef void (*CoreExitHandler)(int, void*);
  11. void coreExitWithHandler(const char* file, int line, int value);
  12. void coreSetExitHandler(CoreExitHandler h, void* data);
  13. #define CORE_EXIT(exitValue) coreExitWithHandler(__FILE__, __LINE__, exitValue)
  14. typedef void (*CoreOutOfMemoryHandler)(void*);
  15. void coreSetOutOfMemoryHandler(CoreOutOfMemoryHandler h, void* data);
  16. #ifdef CORE_CHECK_MEMORY
  17. void* coreDebugAllocate(const char* file, int line, size_t n);
  18. void* coreDebugReallocate(const char* file, int line, void* p, size_t n);
  19. void coreFreeDebug(const char* file, int line, void* p);
  20. void corePrintMemoryReport(void);
  21. #define coreAllocate(n) coreDebugAllocate(__FILE__, __LINE__, n)
  22. #define coreReallocate(p, n) coreDebugReallocate(__FILE__, __LINE__, p, n)
  23. #define coreFree(p) coreFreeDebug(__FILE__, __LINE__, p)
  24. #else
  25. void* coreAllocate(size_t n);
  26. void* coreReallocate(void* p, size_t n);
  27. void coreFree(void* p);
  28. #define corePrintMemoryReport()
  29. #endif
  30. bool coreSleep(i64 nanos);
  31. i64 coreNanos(void);
  32. #endif