picom/src/script.h

59 lines
1.8 KiB
C

#include <assert.h>
#include <stdalign.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <uthash.h>
#include "compiler.h"
struct script_context_info {
UT_hash_handle hh;
const char *name;
ptrdiff_t offset;
};
struct script;
struct script_instance {
const struct script *script;
double elapsed;
struct {
union {
/// For a expression or immediate variable
double result;
/// For a transition variable
struct {
double start;
double end;
double current;
};
};
uint8_t evaluated;
} vars[];
};
enum script_evaluation_result {
/// Script contains cyclic references
SCRIPT_EVAL_ERROR_CYCLIC,
/// +/-inf in results
SCRIPT_EVAL_ERROR_INF,
/// NaN in results
SCRIPT_EVAL_ERROR_NAN,
/// OK
SCRIPT_EVAL_OK,
};
static_assert(alignof(typeof(((struct script_instance *)NULL)->vars)) >= alignof(double),
"vars has unexpected alignment");
static_assert(alignof(double) > alignof(unsigned), "double/unsigned has unexpected "
"alignment");
struct script_instance *script_instance_new(const struct script *script);
enum script_evaluation_result
script_instance_evaluate(struct script_instance *instance, void *context, unsigned **cycle);
void script_instance_reset(struct script_instance *instance);
void script_instance_advance(struct script_instance *instance, double elapsed);
bool script_instance_is_finished(const struct script_instance *instance);
/// Interrupt a script that is currently running, and "steer" it towards a new script.
/// For transition functions in `new_` that has a match in `old`, the current value of
/// that function in `old` will be used as the start value in `new_`. Unless that
/// transition function has the `reset` property enabled.
struct script_instance *
script_instance_steer(struct script_instance *old, struct script *script);