cmdfx 1.0.1
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
util.hpp
Go to the documentation of this file.
1
11#pragma once
12
13extern "C" {
14#include "cmdfx/core/util.h"
15}
16
17namespace CmdFX
18{
19
20// Global Declarations
21
22int getTickSpeed() {
23 return CmdFX_getTickSpeed();
24}
25
26int setTickSpeed(int tickspeed) {
27 return CmdFX_setTickSpeed(tickspeed);
28}
29
30// Time
31
32unsigned long currentTimeMillis() {
33 return ::currentTimeMillis();
34}
35
36unsigned long long currentTimeNanos() {
37 return ::currentTimeNanos();
38}
39
40void sleepMillis(unsigned long millis) {
41 ::sleepMillis(millis);
42}
43
44void sleepNanos(unsigned long long nanos) {
45 ::sleepNanos(nanos);
46}
47
48// Math
49
50double clamp(double value, double min, double max) {
51 return clamp_d(value, min, max);
52}
53
54float clamp(float value, float min, float max) {
55 return clamp_f(value, min, max);
56}
57
58int clamp(int value, int min, int max) {
59 return clamp_i(value, min, max);
60}
61
62double lerp(double a, double b, double t) {
63 return lerp_d(a, b, t);
64}
65
66float lerp(float a, float b, float t) {
67 return lerp_f(a, b, t);
68}
69
70int lerp(int a, int b, double t) {
71 return lerp_i(a, b, t);
72}
73
74void rgbToHsv(int rgb, double* h, double* s, double* v) {
75 rgb_to_hsv(rgb, h, s, v);
76}
77
78int hsvToRgb(double h, double s, double v) {
79 return hsv_to_rgb(h, s, v);
80}
81
82int lerpColor(int rgb1, int rgb2, double t) {
83 return lerp_color(rgb1, rgb2, t);
84}
85
86// Multithreading
87
88ThreadID launchThread(void (*func)(void*), void* arg) {
89 return CmdFX_launchThread(func, arg);
90}
91
92int joinThread(ThreadID thread) {
93 return CmdFX_joinThread(thread);
94}
95
96int detachThread(ThreadID thread) {
97 return CmdFX_detachThread(thread);
98}
99
100void* getInternalMutex(int id) {
101 return CmdFX_getInternalMutex(id);
102}
103
104int lockMutex(void* mutex) {
105 return CmdFX_lockMutex(mutex);
106}
107
108int unlockMutex(void* mutex) {
109 return CmdFX_unlockMutex(mutex);
110}
111
112void tryLockMutex(int id) {
114}
115
116void tryUnlockMutex(int id) {
118}
119
120int isThreadSafeEnabled() {
122}
123
124int initThreadSafe() {
125 return CmdFX_initThreadSafe();
126}
127
128int destroyThreadSafe() {
130}
131
132} // namespace CmdFX
Cross-Platform Utilities for CmdFX.
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.
int clamp_i(int value, int min, int max)
Clamps a value between a minimum and maximum.
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.
Primary namespace for CmdFX.
Definition cmdfx.hpp:26