sdl renderer backend
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
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
This commit is contained in:
@@ -850,7 +850,7 @@ $_.send = function(actor, message, reply) {
|
||||
$_.send[prosperon.DOC] = "sends a message to another actor..."
|
||||
|
||||
var cmd = use('cmd')
|
||||
cmd.process(prosperon.argv)
|
||||
cmd.process(prosperon.argv.slice())
|
||||
|
||||
if (!prosperon.args.id) prosperon.id = util.guid()
|
||||
else prosperon.id = prosperon.args.id
|
||||
@@ -863,7 +863,7 @@ os.register_actor(prosperon.id, function(msg) {
|
||||
message_queue = []
|
||||
throw err
|
||||
}
|
||||
})
|
||||
}, prosperon.args.main)
|
||||
|
||||
$_.__ACTORDATA__.id = prosperon.id
|
||||
|
||||
|
||||
@@ -205,16 +205,10 @@ Cmdline.register_order(
|
||||
|
||||
function cmd_args(cmds) {
|
||||
cmds.shift()
|
||||
if (cmds.length === 0) {
|
||||
cmds[0] = "spawn";
|
||||
cmds[1] = "--program"
|
||||
cmds[2] = "main.js"
|
||||
}
|
||||
else if (!Cmdline.orders[cmds[0]]) {
|
||||
if (!Cmdline.orders[cmds[0]]) {
|
||||
// assume it's a script
|
||||
cmds[2] = cmds[0]
|
||||
cmds[1] = "--program"
|
||||
cmds[0] = "spawn"
|
||||
cmds.unshift("--program")
|
||||
cmds.unshift("spawn")
|
||||
}
|
||||
|
||||
Cmdline.orders[cmds[0]](cmds.slice(1));
|
||||
|
||||
@@ -2780,7 +2780,8 @@ JSC_CCALL(SDL_Renderer_fillrect,
|
||||
if (!SDL_RenderFillRects(r,rects,len))
|
||||
return JS_ThrowReferenceError(js, "Could not render rectangle: %s", SDL_GetError());
|
||||
}
|
||||
rect rect = transform_rect(r,js2rect(js,argv[0]),&cam_mat);
|
||||
//rect rect = transform_rect(r,js2rect(js,argv[0]),&cam_mat);
|
||||
rect rect = js2rect(js, argv[0]);
|
||||
|
||||
if (!SDL_RenderFillRect(r, &rect))
|
||||
return JS_ThrowReferenceError(js, "Could not render rectangle: %s", SDL_GetError());
|
||||
@@ -6723,7 +6724,7 @@ JSC_CCALL(os_mailbox_push,
|
||||
JSC_CCALL(os_register_actor,
|
||||
prosperon_rt *rt = JS_GetContextOpaque(js);
|
||||
char *id = JS_ToCString(js, argv[0]);
|
||||
char *err = register_actor(id, rt);
|
||||
char *err = register_actor(id, rt, JS_ToBool(js, argv[2]));
|
||||
if (err) return JS_ThrowInternalError(js, "Could not register actor: %s", err);
|
||||
rt->message_handle = JS_DupValue(js, argv[1]);
|
||||
rt->context = js;
|
||||
|
||||
@@ -215,6 +215,7 @@ prosperon_rt *create_actor(int argc, char **argv)
|
||||
|
||||
actor->mutex = SDL_CreateMutex(); /* Protects JSContext + state */
|
||||
actor->msg_mutex = SDL_CreateMutex(); /* Mailbox queue lock */
|
||||
actor->turn = SDL_CreateMutex();
|
||||
|
||||
/* Lock actor->mutex while initializing JS runtime. */
|
||||
SDL_LockMutex(actor->mutex);
|
||||
@@ -237,11 +238,10 @@ prosperon_rt *get_actor(char *id)
|
||||
return actor;
|
||||
}
|
||||
|
||||
char *register_actor(char *id, prosperon_rt *actor)
|
||||
char *register_actor(char *id, prosperon_rt *actor, int mainthread)
|
||||
{
|
||||
if (shgeti(actors, id) != -1) return "Actor with given ID already exists.";
|
||||
if (shlen(actors) == 0)
|
||||
actor->main_thread_only = 1;
|
||||
actor->main_thread_only = mainthread;
|
||||
actor->id = strdup(id);
|
||||
SDL_LockMutex(actors_mutex);
|
||||
shput(actors, id, actor);
|
||||
@@ -324,18 +324,17 @@ void set_actor_state(prosperon_rt *actor)
|
||||
|
||||
void actor_turn(prosperon_rt *actor, int greedy)
|
||||
{
|
||||
SDL_LockMutex(actor->turn);
|
||||
TracyCFiberEnter(actor->id);
|
||||
|
||||
SDL_LockMutex(actor->msg_mutex);
|
||||
actor->state = ACTOR_RUNNING;
|
||||
SDL_UnlockMutex(actor->msg_mutex);
|
||||
|
||||
TracyCFiberEnter(actor->id);
|
||||
|
||||
int msgs = 0;
|
||||
int events = 0;
|
||||
int need_stop = 0;
|
||||
JSValue result;
|
||||
|
||||
SDL_LockMutex(actor->msg_mutex);
|
||||
msgs = arrlen(actor->messages);
|
||||
events = arrlen(actor->events);
|
||||
need_stop = actor->need_stop;
|
||||
@@ -414,11 +413,13 @@ void actor_turn(prosperon_rt *actor, int greedy)
|
||||
|
||||
END:
|
||||
TracyCFiberLeave(actor->id);
|
||||
SDL_UnlockMutex(actor->turn);
|
||||
set_actor_state(actor);
|
||||
return;
|
||||
|
||||
KILL:
|
||||
TracyCFiberLeave(actor->id);
|
||||
SDL_UnlockMutex(actor->turn);
|
||||
actor_free(actor);
|
||||
}
|
||||
|
||||
@@ -444,6 +445,7 @@ void actor_free(prosperon_rt *actor)
|
||||
// Do not go forward with actor destruction until the actor is completely free
|
||||
SDL_LockMutex(actor->mutex);
|
||||
SDL_LockMutex(actor->msg_mutex);
|
||||
SDL_LockMutex(actor->turn);
|
||||
|
||||
JSContext *js = actor->context;
|
||||
|
||||
@@ -475,7 +477,6 @@ void actor_free(prosperon_rt *actor)
|
||||
for (int i = 0; i < arrlen(actor->events); i++)
|
||||
JS_FreeValue(js, actor->events[i]);
|
||||
|
||||
printf("FREEIN ACTOR EVENTS\n");
|
||||
arrfree(actor->events);
|
||||
|
||||
JSRuntime *rt = JS_GetRuntime(js);
|
||||
@@ -487,6 +488,8 @@ void actor_free(prosperon_rt *actor)
|
||||
SDL_DestroyMutex(actor->mutex);
|
||||
SDL_UnlockMutex(actor->msg_mutex);
|
||||
SDL_DestroyMutex(actor->msg_mutex);
|
||||
SDL_UnlockMutex(actor->turn);
|
||||
SDL_DestroyMutex(actor->turn);
|
||||
|
||||
free(actor);
|
||||
|
||||
@@ -1361,9 +1364,11 @@ int main(int argc, char **argv)
|
||||
io_actor = create_actor(2, io_argv);
|
||||
|
||||
/* Create the initial actor from the main command line. */
|
||||
char **margv = malloc(sizeof(char *) * argc);
|
||||
char **margv = malloc(sizeof(char *) * argc + 2);
|
||||
for (int i = 0; i < argc; i++) margv[i] = strdup(argv[i]);
|
||||
create_actor(argc, margv);
|
||||
margv[argc] = "--main";
|
||||
margv[argc+1] = "1";
|
||||
create_actor(argc+2, margv);
|
||||
|
||||
/* Start the thread that pumps ready actors, one per logical core. */
|
||||
for (int i = 0; i < cores; i++) {
|
||||
@@ -1400,8 +1405,6 @@ int main(int argc, char **argv)
|
||||
SDL_UnlockMutex(queue_mutex);
|
||||
|
||||
actor_turn(actor, 0);
|
||||
|
||||
END:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ typedef struct prosperon_rt {
|
||||
/* Protects JSContext usage */
|
||||
SDL_Mutex *mutex;
|
||||
|
||||
SDL_Mutex *turn;
|
||||
|
||||
char *id;
|
||||
MTRand mrand;
|
||||
double unneeded_secs;
|
||||
@@ -69,7 +71,7 @@ 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);
|
||||
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);
|
||||
|
||||
@@ -21,10 +21,13 @@ prosperon.win = prosperon.engine_start({
|
||||
url: "https://prosperon.dev"
|
||||
})
|
||||
|
||||
var ren = prosperon.win.make_renderer("opengl")
|
||||
var ren = prosperon.win.make_renderer("metal")
|
||||
|
||||
function loop() {
|
||||
ren.draw_color([1,1,1,1])
|
||||
|
||||
ren.clear()
|
||||
ren.draw_color([0,0,0,1])
|
||||
ren.fillrect({x:50,y:50,height:50,width:50})
|
||||
ren.present()
|
||||
$_.delay(loop, 1/60)
|
||||
|
||||
Reference in New Issue
Block a user