twn_util.h: separate internal things away, remove indirect includes in places

This commit is contained in:
2024-10-12 21:16:25 +03:00
parent e70366f82f
commit 1a7322dccf
14 changed files with 45 additions and 44 deletions

View File

@ -3,21 +3,13 @@
#include "twn_types.h"
#include "twn_engine_api.h"
#include "twn_types.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <math.h>
/* DON'T FORGET ABOUT DOUBLE EVALUATION */
/* YOU THINK YOU WON'T, AND THEN YOU DO */
/* C23's typeof could fix it, so i will */
/* leave them as macros to be replaced. */
/* use the macro in tgmath.h for floats */
#define MAX SDL_max
#define MIN SDL_min
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288 /**< pi */
#endif
@ -26,16 +18,13 @@
#define DEG2RAD (M_PI / 180)
#define RAD2DEG (180 / M_PI)
#ifndef TWN_NOT_C
/* */
/* GENERAL UTILITIES */
/* */
TWN_API void *cmalloc(size_t size);
TWN_API void *crealloc(void *ptr, size_t size);
TWN_API void *ccalloc(size_t num, size_t size);
TWN_API void cry_impl(const char *file, const int line, const char *title, const char *text);
#define CRY(title, text) cry_impl(__FILE__, __LINE__, title, text)
#define CRY_SDL(title) cry_impl(__FILE__, __LINE__, title, SDL_GetError())
#define CRY_PHYSFS(title) \
cry_impl(__FILE__, __LINE__, title, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()))
#endif /* TWN_NOT_C */
TWN_API void log_info(const char *restrict format, ...);
@ -43,18 +32,6 @@ TWN_API void log_critical(const char *restrict format, ...);
TWN_API void log_warn(const char *restrict format, ...);
/* for when there's absolutely no way to continue */
TWN_API _Noreturn void die_abruptly(void);
/* "critical" allocation functions which will log and abort() on failure. */
/* if it is reasonable to handle this gracefully, use the standard versions. */
/* the stb implementations will be configured to use these */
TWN_API void *cmalloc(size_t size);
TWN_API void *crealloc(void *ptr, size_t size);
TWN_API void *ccalloc(size_t num, size_t size);
/* TODO: this is why generics were invented. sorry, i'm tired today */
TWN_API double clamp(double d, double min, double max);
TWN_API float clampf(float f, float min, float max);