Files
cell/source/prosperon.h
John Alanbrook 34035ae6ac
Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
sdl renderer backend
2025-03-28 12:29:15 -05:00

92 lines
2.2 KiB
C

#ifndef PROSPERON_H
#define PROSPERON_H
#include <SDL3/SDL.h>
#include "quickjs.h"
#define STATE_VECTOR_LENGTH 624
#define STATE_VECTOR_M 397
#define ACTOR_IDLE 0
#define ACTOR_READY 1
#define ACTOR_RUNNING 2
#define ACTOR_EXHAUSTED 3
#define ACTOR_RECLAIMING 4
#define ACTOR_SLOW 5
typedef JSValue (*MODULEFN)(JSContext *js);
typedef struct tagMTRand {
uint32_t mt[STATE_VECTOR_LENGTH];
int32_t index;
} MTRand;
typedef struct {
const char *name;
MODULEFN fn;
} ModuleEntry;
typedef struct {
int argc;
char **argv;
} cmdargs;
typedef struct prosperon_rt {
cmdargs cmd;
JSContext *context;
JSValue cycle_fn;
JSValue idx_buffer;
JSValue on_exception;
JSValue message_handle;
JSValue unneeded;
ModuleEntry *module_registry;
JSValue *js_swapchains;
/* Protects JSContext usage */
SDL_Mutex *mutex;
SDL_Mutex *turn;
char *id;
MTRand mrand;
double unneeded_secs;
int idx_count;
/* The “mailbox” for incoming messages + a dedicated lock for it: */
void **messages;
JSValue *events;
SDL_Mutex *msg_mutex; /* For messages queue only */
/* CHANGED FOR EVENTS: a separate lock for the actor->events queue */
struct { Uint32 key; JSValue value; } *timers;
int state;
Uint32 ar;
int need_stop;
int main_thread_only;
} prosperon_rt;
extern SDL_ThreadID main_thread;
extern SDL_TLSID prosperon_id;
prosperon_rt *create_actor(int argc, char **argv);
char *register_actor(char *id, prosperon_rt *actor, int mainthread);
void actor_free(prosperon_rt *actor);
char *send_message(char *id, void *msg);
Uint32 actor_timer_cb(prosperon_rt *actor, SDL_TimerID id, Uint32 interval);
JSValue js_actor_delay(JSContext *js, JSValue self, int argc, JSValue *argv);
JSValue js_actor_removetimer(JSContext *js, JSValue self, int argc, JSValue *argv);
void script_startup(prosperon_rt *rt);
void script_evalf(JSContext *js, const char *format, ...);
JSValue script_eval(JSContext *js, const char *file, const char *script);
int uncaught_exception(JSContext *js, JSValue v);
int actor_exists(char *id);
void set_actor_state(prosperon_rt *actor);
int prosperon_mount_core(void);
JSValue js_os_ioactor(JSContext *js, JSValue self, int argc, JSValue *argv);
#endif