twn_util.h: separate internal things away, remove indirect includes in places
This commit is contained in:
parent
e70366f82f
commit
1a7322dccf
@ -4,6 +4,7 @@ for that certain steps are taken:
|
||||
* number of public api calls is kept at the minimum
|
||||
* procedure signatures can only use basic types, no aggregates, with exception of Vec/Matrix types and alike,
|
||||
with no expectation on new additions (see /include/twn_types.h)
|
||||
* optionals can be expressed via pointer passage of value primitives, with NULL expressive default
|
||||
* /include/twn_game_api.json file is hand-kept with a schema to aid automatic generation and other tooling
|
||||
|
||||
one of main inspirations for that is opengl model
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef TWN_CAMERA_H
|
||||
#define TWN_CAMERA_H
|
||||
|
||||
#include "twn_util.h"
|
||||
#include "twn_types.h"
|
||||
#include "twn_engine_api.h"
|
||||
|
||||
/* TODO: make it cached? */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef TWN_CONTEXT_H
|
||||
#define TWN_CONTEXT_H
|
||||
|
||||
#include "twn_input.h"
|
||||
#include "twn_types.h"
|
||||
#include "twn_engine_api.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef TWN_DRAW_H
|
||||
#define TWN_DRAW_H
|
||||
|
||||
#include "twn_util.h"
|
||||
#include "twn_types.h"
|
||||
#include "twn_option.h"
|
||||
#include "twn_camera.h"
|
||||
#include "twn_engine_api.h"
|
||||
|
@ -2,14 +2,14 @@
|
||||
#ifndef TWN_GAME_API_H
|
||||
#define TWN_GAME_API_H
|
||||
|
||||
|
||||
#include "twn_input.h"
|
||||
#include "twn_context.h"
|
||||
#include "twn_draw.h"
|
||||
#include "twn_audio.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_input.h"
|
||||
#include "twn_engine_api.h"
|
||||
#include "twn_util.h"
|
||||
|
||||
#ifndef TWN_NOT_C
|
||||
|
||||
/* sole game logic and display function.
|
||||
all state must be used from and saved to supplied state pointer. */
|
||||
@ -18,5 +18,6 @@ TWN_API extern void game_tick(void);
|
||||
/* called when application is closing. */
|
||||
TWN_API extern void game_end(void);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "twn_game_object_c.h"
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_util_c.h"
|
||||
|
||||
#include <x-watcher.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "twn_game_object_c.h"
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_util_c.h"
|
||||
|
||||
#include <errhandlingapi.h>
|
||||
#include <libloaderapi.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "twn_gpu_texture_c.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_util_c.h"
|
||||
|
||||
|
||||
GPUTexture create_gpu_texture(TextureFilter filter, bool generate_mipmaps) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "twn_draw_c.h"
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_util_c.h"
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <GLES2/gl2.h>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "twn_draw_c.h"
|
||||
#include "twn_draw.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_util_c.h"
|
||||
#include "twn_engine_context_c.h"
|
||||
|
||||
#include <stb_truetype.h>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "twn_audio_c.h"
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_util_c.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stb_ds.h>
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_input_c.h"
|
||||
#include "twn_util.h"
|
||||
#include "twn_util_c.h"
|
||||
#include "twn_game_object_c.h"
|
||||
#include "twn_audio_c.h"
|
||||
#include "twn_textures_c.h"
|
||||
|
@ -3,6 +3,23 @@
|
||||
|
||||
#include "twn_types.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#define MAX SDL_max
|
||||
#define MIN SDL_min
|
||||
|
||||
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()))
|
||||
|
||||
/* for when there's absolutely no way to continue */
|
||||
_Noreturn void die_abruptly(void);
|
||||
|
||||
/* note: you must free the returned string */
|
||||
char *expand_asterisk(const char *mask, const char *to);
|
||||
|
||||
@ -22,7 +39,7 @@ static inline float fast_sqrt(float x)
|
||||
|
||||
|
||||
static inline Vec2 fast_cossine(float a) {
|
||||
const float s = sinf(a);
|
||||
const float s = SDL_sinf(a);
|
||||
return (Vec2){
|
||||
.x = fast_sqrt(1.0f - s * s) * (a >= (float)M_PI_2 && a < (float)(M_PI + M_PI_2) ? -1 : 1),
|
||||
.y = s
|
||||
|
Loading…
Reference in New Issue
Block a user