-
Notifications
You must be signed in to change notification settings - Fork 10
sys.h
If you find any errors, please open an issue or submit a pull request!
Sys is the system
utility within astera. Sys comprises 2 main parts, timing and configuration.
However if you don't want the configuration functions in your project you can define ASTERA_NO_CONF
before including the sys header to exclude it.
The timing system in astera is defined in milliseconds
.
There are defines to convert nanoseconds, microseconds, milliseconds, and seconds to and from each of the units. For example SEC_TO_MS
is just defined as 1e-6
which is just 1 / 1000.
sys.h also includes two typedefs for timing:
-
s_timer
- holds the last update, and the delta to this update. -
time_s
- defined as adouble
, or optionallyfloat
if the macroASTERA_SYS_LOWP_TIME
The timing functions within sys.h also include:
-
time_s s_get_time();
- Returns the current time in milliseconds -
time_s s_timer_update(s_timer* timer);
- Updates a timer & returns the calculated delta -
s_timer s_timer_create();
- Create a timer struct with current time -
time_s s_sleep(time_s duration);
- Sleep for time (milliseconds), return time slept
The configuration portion of sys is essentially a barebone (and unreliable) INI File loader. Keep in mind that this loader works off of new line, splits by equals, and doesn't support tables.
Reading
The loader essentially splits each line by the =
sign and reallocates the data into an s_table
for usage. It can prove useful, but isn't the most reliable of configuration methods.
In order to use this loader you'll want to call s_table s_table_get(unsigned char* data, uint32_t length);
. The data passed being the raw data of the file (you can use the asset system to load this data).
Once you're done with the table, you can call s_table_free(s_table table)
to free the arrays within it.
Writing
If you construct one of these tables and want to write it to file you can do so with
uint8_t s_table_write(s_table* table, char* filepath);
or
uint8_t s_table_write_mem(void* data, uint32_t dst_length, s_table* table, uint32_t* write_length);
This is reference section is meant to be a programmer's companion when using astera! NOTE: This is still under construction, feedback is welcome!
General
-
ASTERA_SYS_LOWP_TIME
- typedef'stime_s
to single precisionfloat
instead of the defaultdouble
. -
ASTERA_NO_CONF
- Prevents configuration utilities from being included & defined
Timing
-
SEC_TO_NS
- Convert seconds to nanoseconds -
SEC_TO_MCS
- Convert seconds to microseconds -
SEC_TO_MS
- Convert seconds to milliseconds -
SEC_TO_MIN
- Convert seconds to minutes -
SEC_TO_HOUR
- Convert seconds to hours -
MS_TO_NS
- Convert milliseconds to nanoseconds -
MS_TO_MCS
- Convert milliseconds to microseconds -
MS_TO_SEC
- Convert milliseconds to seconds -
MS_TO_MIN
- Convert milliseconds to minutes -
MS_TO_HOUR
- Convert milliseconds to hours -
MCS_TO_NS
- Convert microseconds to nanoseconds -
MCS_TO_MS
- Convert microseconds to milliseconds -
MCS_TO_SEC
- Convert microseconds to seconds -
MCS_TO_MIN
- Convert microseconds to minutes -
MCS_TO_HOUR
- Convert microseconds to hours -
NS_TO_MCS
- Convert nanoseconds to microseconds -
NS_TO_MS
- Convert nanoseconds to milliseconds -
NS_TO_SEC
- Convert nanoseconds to seconds -
NS_TO_MIN
- Convert nanoseconds to minutes -
NS_TO_HOUR
- Convert nanoseconds to hours
Configuration
-
s_table
- The struct representation of a configuration file
Timing
-
time_s
- The representation of time (double by default, float optional) -
s_timer
- A timer type for tracking time deltas
Configuration
-
s_table s_table_get(unsigned char* data, uint32_t length);
- Process a file's contents as a Psuedo-INI File -
void s_table_free(s_table table);
- Free the contents of ans_table
type. -
uint8_t s_table_write(s_table* table, char* filepath);
- Write ans_table
type to filepath in psuedo-ini format. -
uint8_t s_table_write_mem();
- Write ans_table
type to memory
Timing
-
time_s s_get_time();
- Get the current time -
time_s s_timer_update(s_timer* t);
- Update the mark & delta for timer -
s_timer s_timer_create();
- Create an updateds_timer
type -
time_s s_sleep(time_s duration);
- Sleep for time in milliseconds
Other
-
char* s_itoa(int32_t value, char* string, int8_t base);
- Convert an integer to string