libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
|
#include <string.h>
#include <stdint.h>
#include "assert.h"
#include "core.h"
#include "crc64.h"
#include "time.h"
Go to the source code of this file.
Data Structures | |
struct | delay_line_t |
Macros | |
#define | DEF_DELAY_LINE_PULL(typename, abbrev_type) |
#define | DEF_DELAY_LINE_PEEK(typename, abbrev_type) |
#define | DEF_DELAY_LINE_PUSH(typename, abbrev_type) |
#define | DEF_DELAY_LINE_PUSH_IMM(typename, abbrev_type) |
#define | DELAY_LINE_PUSH(line, value) DELAY_LINE_PUSH_macro_requires_C11_or_greater |
#define | DELAY_LINE_PUSH_IMM(line, value) DELAY_LINE_PUSH_IMM_macro_requires_C11_or_greater |
Typedefs | |
typedef uint64_t(* | delay_line_time_func_t) (void *userinfo) |
Functions | |
static void | delay_line_init (delay_line_t *line, uint64_t delay_us) |
static void | delay_line_init_time_func (delay_line_t *line, uint64_t delay_us, delay_line_time_func_t time_func, void *time_func_userinfo) |
static void | delay_line_refresh_delay (delay_line_t *line) |
static void | delay_line_set_delay (delay_line_t *line, uint64_t delay_us) |
static uint64_t | delay_line_get_delay (const delay_line_t *line) |
static uint64_t | delay_line_get_delay_act (const delay_line_t *line) |
static void | delay_line_set_rand (delay_line_t *line, double rand_fract) |
static double | delay_line_get_rand (const delay_line_t *line) |
static int64_t | delay_line_pull_i64 (delay_line_t *line) |
static uint64_t | delay_line_pull_u64 (delay_line_t *line) |
static double | delay_line_pull_f64 (delay_line_t *line) |
static int64_t | delay_line_peek_i64 (const delay_line_t *line) |
static uint64_t | delay_line_peek_u64 (const delay_line_t *line) |
static double | delay_line_peek_f64 (const delay_line_t *line) |
static int64_t | delay_line_peek_i64_new (const delay_line_t *line) |
static uint64_t | delay_line_peek_u64_new (const delay_line_t *line) |
static double | delay_line_peek_f64_new (const delay_line_t *line) |
static int64_t | delay_line_push_i64 (delay_line_t *line, int64_t value) |
static uint64_t | delay_line_push_u64 (delay_line_t *line, uint64_t value) |
static double | delay_line_push_f64 (delay_line_t *line, double value) |
static int64_t | delay_line_push_imm_i64 (delay_line_t *line, int64_t value) |
static uint64_t | delay_line_push_imm_u64 (delay_line_t *line, uint64_t value) |
static double | delay_line_push_imm_f64 (delay_line_t *line, double value) |
static uint64_t | delay_line_get_time_since_change (const delay_line_t *line) |
Implements a generic variable that changes after a short delay. You need to initialize the variable using delay_line_init(). Subsequently, you can push changes to it and read the current value. When a change is made, it is propagated into the variable after the delay with which the variable was initialized.
Definition in file delay_line.h.
#define DEF_DELAY_LINE_PEEK | ( | typename, | |
abbrev_type | |||
) |
Definition at line 244 of file delay_line.h.
#define DEF_DELAY_LINE_PULL | ( | typename, | |
abbrev_type | |||
) |
Definition at line 212 of file delay_line.h.
#define DEF_DELAY_LINE_PUSH | ( | typename, | |
abbrev_type | |||
) |
Definition at line 282 of file delay_line.h.
#define DEF_DELAY_LINE_PUSH_IMM | ( | typename, | |
abbrev_type | |||
) |
Definition at line 316 of file delay_line.h.
#define DELAY_LINE_PUSH | ( | line, | |
value | |||
) | DELAY_LINE_PUSH_macro_requires_C11_or_greater |
Generic shorthand for delay_line_push_*. Determines the type of push function to call automatically based on the type of the value passed. Note: this relies on C11 generics and thus requires at least C11 support.
Definition at line 371 of file delay_line.h.
#define DELAY_LINE_PUSH_IMM | ( | line, | |
value | |||
) | DELAY_LINE_PUSH_IMM_macro_requires_C11_or_greater |
Generic shorthand for delay_line_push_imm_*. Determines the type of push function to call automatically based on the type of the value passed. Note: this relies on C11 generics and thus requires at least C11 support.
Definition at line 373 of file delay_line.h.
typedef uint64_t(* delay_line_time_func_t) (void *userinfo) |
Callback function that can be passed to delay_line_init_time_func(). This allows you to provide a custom timing function, instead of relaying on the OS's real time clock.
Definition at line 55 of file delay_line.h.
|
static |
Definition at line 159 of file delay_line.h.
|
static |
Definition at line 172 of file delay_line.h.
|
static |
Definition at line 207 of file delay_line.h.
|
static |
CAUTION: do NOT use this for precise interval timing. Delay lines can be used as simple timed triggers, but they don't keep time accurately, or account for triggering-overshoot. If you try this, your clock will end up slipping and running too slow!
Definition at line 388 of file delay_line.h.
|
static |
Initializes a delay line variable.
line | Pointer to the delay line to initialize. |
delay_us | Microsecond delay between pushing a new value to the delay line before the new value takes effect on read-back. |
Definition at line 89 of file delay_line.h.
|
static |
Same as delay_line_init(), but provides a custom timing function, instead of using the operating system's real time clock. You can use this to implement time delays that respect X-Plane variable simulation rate and thus operate correctly when the sim is running time-accelerated.
time_func | A callback that the delay line uses for timing. This must return the current time in microseconds (the starting point doesn't matter, but it must never wrap around). |
time_func_userinfo | Optional argument which will be passed to time_func every time it is called. |
Definition at line 110 of file delay_line.h.
|
static |
Same as delay_line_peek_i64(), but returns the current value as a double
.
Definition at line 265 of file delay_line.h.
|
static |
Same as delay_line_peek_i64_new(), but returns the new value as a double
.
Definition at line 280 of file delay_line.h.
|
static |
Accessor function to peek at the current value of a delay line as an int64_t. Unlike delay_line_pull_i64(), this will never cause the value to change. Can be used in combination with delay_line_push_i64 to look for a state change in a delay line in response to the passage of time.
Definition at line 257 of file delay_line.h.
|
static |
Same as delay_line_peek_i64(), but instead of looking at the current value in the delay line, this looks at a new incoming value, without causing the delay line to change.
Definition at line 272 of file delay_line.h.
|
static |
Same as delay_line_peek_i64(), but returns the current value as a uint64_t
.
Definition at line 261 of file delay_line.h.
|
static |
Same as delay_line_peek_i64_new(), but returns the new value as a uint64_t
.
Definition at line 276 of file delay_line.h.
|
static |
Same as delay_line_pull_i64(), but returns the current value as a double
.
Definition at line 242 of file delay_line.h.
|
static |
Accessor function to pull the current value from a delay line as an int64_t. If a new value has been pushed to the delay line, this function keeps returning the old value until the delay line's delay has elapsed, after which it will start returning the new value.
Definition at line 234 of file delay_line.h.
|
static |
Same as delay_line_pull_i64(), but returns the current value as a uint64_t
.
Definition at line 238 of file delay_line.h.
|
static |
Same as delay_line_push_i64(), but pushes a new double
value.
Definition at line 314 of file delay_line.h.
|
static |
This function pushes a new int64_t
value to a delay line. If the new value is different from the current value of the delay line, the new value will become the delay line's current value after the delay line's time delay has elapsed.
Definition at line 306 of file delay_line.h.
|
static |
Same as delay_line_push_imm_i64(), but pushes a new double
value.
Definition at line 337 of file delay_line.h.
|
static |
Same as delay_line_push_i64(), but doesn't wait for the time delay. The new value immediately becomes the delay line's current value.
Definition at line 329 of file delay_line.h.
|
static |
Same as delay_line_push_imm_i64(), but pushes a new uint64_t
value.
Definition at line 333 of file delay_line.h.
|
static |
Same as delay_line_push_i64(), but pushes a new uint64_t
value.
Definition at line 310 of file delay_line.h.
|
static |
For delay lines which utilize a randomized factor, causes them to recompute the next firing delay. For delay lines without any randomness to their delay, this does nothing.
Definition at line 128 of file delay_line.h.
|
static |
Changes the time delay of the delay line.
Definition at line 144 of file delay_line.h.
|
static |
Configures randomness for the delay line. Initially, all delay lines are completely fixed-length and deterministic. Sometimes, it is useful to simulate a some variability in the delay of the delay line. The random time delay is recomputed every time the delay line changes state.
rand_fract | The fraction of randomness that should be applied to the delay line's delay. This is applied as a fraction of the base time delay, in both directions equally and linearly. So if you pass rand_fract=0.4 , that means the delay line will fire randomly between 0.6x and 1.4x its base time delay. |
Definition at line 192 of file delay_line.h.