rework timers, update overlap/intersect and other procedures, some other things i dont remember

This commit is contained in:
veclavtalica
2024-10-22 14:45:30 +03:00
parent a527036436
commit a22bcfd97e
6 changed files with 144 additions and 115 deletions

View File

@ -24,74 +24,67 @@
TWN_API void *crealloc(void *ptr, size_t size);
TWN_API void *ccalloc(size_t num, size_t size);
TWN_API void log_info(const char *restrict format, ...);
TWN_API void log_critical(const char *restrict format, ...);
TWN_API void log_warn(const char *restrict format, ...);
/* saves all texture atlases as BMP files in the write directory */
TWN_API void textures_dump_atlases(void);
/* returns true if str ends with suffix */
TWN_API bool strends(const char *str, const char *suffix);
/* 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);
TWN_API int clampi(int i, int min, int max);
/* sets buf_out to a pointer to a byte buffer which must be freed. */
/* returns the size of this buffer. */
TWN_API int64_t file_to_bytes(const char *path, unsigned char **buf_out);
/* returns a pointer to a string which must be freed */
TWN_API char *file_to_str(const char *path);
/* returns true if the file exists in the filesystem */
TWN_API bool file_exists(const char *path);
#endif /* TWN_NOT_C */
TWN_API void log_info(const char *restrict format, ...);
TWN_API void log_critical(const char *restrict format, ...);
TWN_API void log_warn(const char *restrict format, ...);
/* 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);
TWN_API int clampi(int i, int min, int max);
/* sets buf_out to a pointer to a byte buffer which must be freed. */
/* returns the size of this buffer. */
TWN_API int64_t file_to_bytes(const char *path, unsigned char **buf_out);
/* returns a pointer to a string which must be freed */
TWN_API char *file_to_str(const char *path);
/* returns true if the file exists in the filesystem */
TWN_API bool file_exists(const char *path);
/* saves all texture atlases as BMP files in the write directory */
TWN_API void textures_dump_atlases(void);
/* returns true if str ends with suffix */
TWN_API TWN_API bool strends(const char *str, const char *suffix);
/* */
/* GAME LOGIC UTILITIES */
/* */
/* calculates the overlap of two rectangles and places it in result. */
/* result may be NULL. if this is the case, it will simply be ignored. */
/* returns true if the rectangles are indeed intersecting. */
TWN_API bool overlap_rect(const Recti *a, const Recti *b, Recti *result);
TWN_API bool overlap_frect(const Rect *a, const Rect *b, Rect *result);
/* calculates the overlap of two rectangles */
TWN_API Recti overlap_recti(const Recti a, const Recti b);
TWN_API Rect overlap_rect(const Rect a, const Rect b);
/* returns true if two rectangles are intersecting */
TWN_API bool intersect_rect(const Recti *a, const Recti *b);
TWN_API bool intersect_frect(const Rect *a, const Rect *b);
TWN_API bool intersect_recti(const Recti a, const Recti b);
TWN_API bool intersect_rect(const Rect a, const Rect b);
/* TODO: generics and specials (see m_vec2_from() for an example)*/
TWN_API Rect to_frect(Recti rect);
TWN_API Recti to_recti(Rect rect);
TWN_API Rect to_rect(Recti rect);
TWN_API Vec2 frect_center(Rect rect);
TWN_API Vec2i center_recti(Recti rect);
TWN_API Vec2 center_rect(Rect rect);
/* decrements an lvalue (which should be an int), stopping at 0 */
/* decrements an integer value, stopping at 0 */
/* meant for tick-based timers in game logic */
/*
* example:
* tick_timer(&player->jump_air_timer);
*/
TWN_API void tick_timer(int *value);
TWN_API int32_t timer_tick_frames(int32_t frames_left);
/* decrements a floating point second-based timer, stopping at 0.0 */
/* decrements a floating point second-based timer, stopping at 0.0f */
/* meant for poll based real time logic in game logic */
/* note that it should be decremented only on the next tick after its creation */
TWN_API void tick_ftimer(float *value);
TWN_API float timer_tick_seconds(float seconds_left);
/* same as `tick_ftimer` but instead of clamping it repeats */
/* returns true if value was cycled */
TWN_API bool repeat_ftimer(float *value, float at);
TWN_API struct timer_elapse_frames_result {
bool elapsed; int32_t frames_left;
} timer_elapse_frames(int32_t frames_left, int32_t interval);
TWN_API struct timer_elapse_seconds_result {
bool elapsed; float seconds_left;
} timer_elapse_seconds(float seconds_left, float interval);
#endif