cmdfx 0.2.1
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1
11#pragma once
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17// Global Declarations
18
28
38int CmdFX_setTickSpeed(int tickspeed);
39
40// Time
41
46unsigned long currentTimeMillis();
47
52unsigned long long currentTimeNanos();
53
58void sleepMillis(unsigned long millis);
59
64void sleepNanos(unsigned long long nanos);
65
66// Math
67
75double clamp_d(double value, double min, double max);
76
84float clamp_f(float value, float min, float max);
85
93int clamp_i(int value, int min, int max);
94
102double lerp_d(double a, double b, double t);
103
111float lerp_f(float a, float b, float t);
112
120int lerp_i(int a, int b, double t);
121
129void rgb_to_hsv(int rgb, double* h, double* s, double* v);
130
138int hsv_to_rgb(double h, double s, double v);
139
147int lerp_color(int rgb1, int rgb2, double t);
148
149// Multithreading
150
158#define MAX_INTERNAL_CMDFX_MUTEXES 128
159
171
181
193
204void* CmdFX_getInternalMutex(int index);
205
215int CmdFX_lockMutex(void* mutex);
216
226int CmdFX_unlockMutex(void* mutex);
227
239
249
250#ifdef _WIN32
251#include <stdint.h>
252#define ThreadID uintptr_t
253#else
254#include <pthread.h>
255#define ThreadID pthread_t
256#endif
257
272ThreadID CmdFX_launchThread(void (*func)(void*), void* arg);
273
286int CmdFX_joinThread(ThreadID thread);
287
301int CmdFX_detachThread(ThreadID thread);
302
303#ifdef __cplusplus
304}
305#endif
int CmdFX_detachThread(ThreadID thread)
Detaches a thread.
int CmdFX_unlockMutex(void *mutex)
Unlocks a mutex.
int CmdFX_joinThread(ThreadID thread)
Joins a thread.
ThreadID CmdFX_launchThread(void(*func)(void *), void *arg)
Launches a thread.
double lerp_d(double a, double b, double t)
Linearly interpolates between two values.
int CmdFX_isThreadSafeEnabled()
Checks if thread-safe functions are enabled.
void rgb_to_hsv(int rgb, double *h, double *s, double *v)
Converts an RGB color to HSV.
int lerp_i(int a, int b, double t)
Linearly interpolates between two values.
float lerp_f(float a, float b, float t)
Linearly interpolates between two values.
void CmdFX_tryUnlockMutex(int id)
Tries to unlock a mutex.
int CmdFX_initThreadSafe()
Initializes thread-safe functions.
int hsv_to_rgb(double h, double s, double v)
Converts an HSV color to RGB.
int CmdFX_setTickSpeed(int tickspeed)
Sets the tick speed of cmdfx.
int lerp_color(int rgb1, int rgb2, double t)
Linearly interpolates between two colors.
float clamp_f(float value, float min, float max)
Clamps a value between a minimum and maximum.
unsigned long currentTimeMillis()
Gets the current time in milliseconds.
int CmdFX_lockMutex(void *mutex)
Locks a mutex.
void sleepMillis(unsigned long millis)
Pauses the program for a specified number of milliseconds.
int clamp_i(int value, int min, int max)
Clamps a value between a minimum and maximum.
void sleepNanos(unsigned long long nanos)
Pauses the program for a specified number of nanoseconds.
double clamp_d(double value, double min, double max)
Clamps a value between a minimum and maximum.
void CmdFX_tryLockMutex(int id)
Tries to lock a mutex.
int CmdFX_getTickSpeed()
Gets the tick speed of cmdfx.
unsigned long long currentTimeNanos()
Gets the current time in nanoseconds.
int CmdFX_destroyThreadSafe()
Cleans up thread-safe functions.
void * CmdFX_getInternalMutex(int index)
Gets an internal mutex.