Files
cell/source/prosperon.h
John Alanbrook 8627fc52ef
Some checks failed
Build and Deploy / package-dist (push) Blocked by required conditions
Build and Deploy / deploy-itch (push) Blocked by required conditions
Build and Deploy / deploy-gitea (push) Blocked by required conditions
Build and Deploy / build-linux (push) Successful in 1m15s
Build and Deploy / build-windows (CLANG64) (push) Failing after 11m46s
actors in C now
2025-03-18 18:18:56 -05:00

68 lines
1.6 KiB
C

#ifndef PROSPERON_H
#define PROSPERON_H
#include <SDL3/SDL.h>
#include "quickjs.h"
typedef JSValue (*MODULEFN)(JSContext *js);
#define STATE_VECTOR_LENGTH 624
#define STATE_VECTOR_M 397 /* changes to STATE_VECTOR_LENGTH also require changes to this */
typedef struct tagMTRand {
uint32_t mt[STATE_VECTOR_LENGTH];
int32_t index;
} MTRand;
extern SDL_ThreadID main_thread;
extern SDL_TLSID prosperon_id;
typedef struct {
const char *name;
MODULEFN fn;
} ModuleEntry;
typedef struct {
int argc;
char **argv;
} cmdargs;
struct message {
void *data;
size_t size;
};
#define ACTOR_IDLE 0
#define ACTOR_READY 1
#define ACTOR_RUNNING 2
#define ACTOR_EXHAUSTED 3 // flagged when the actor is running GC
#define ACTOR_RECLAIMING 4
#define ACTOR_SLOW 5
typedef struct prosperon_rt {
cmdargs cmd; // args this actor was started with
JSContext *context; // The context this actor uses
MTRand mrand;
JSValue cycle_fn;
JSValue idx_buffer;
JSValue on_exception;
JSValue message_handle;
int idx_count;
ModuleEntry *module_registry;
JSValue *js_swapchains;
struct { Uint32 key; JSValue value; } *timers;
JSValue *events; // stack of events that need triggered on this actor
SDL_Mutex *mutex; // blocks access to modifying this actor
struct message *messages;
int state; //
} prosperon_rt;
prosperon_rt *get_actor(char *id);
char *register_actor(char *id, prosperon_rt *actor);
prosperon_rt *create_actor();
void actor_signal(prosperon_rt *actor);
void actor_turn(prosperon_rt *actor);
void send_message(prosperon_rt *actor, struct message msg);
#endif