actor detection
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m42s
Build and Deploy / build-windows (CLANG64) (push) Failing after 8m47s
Build and Deploy / package-dist (push) Has been skipped
Build and Deploy / deploy-itch (push) Has been skipped
Build and Deploy / deploy-gitea (push) Has been skipped
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m42s
Build and Deploy / build-windows (CLANG64) (push) Failing after 8m47s
Build and Deploy / package-dist (push) Has been skipped
Build and Deploy / deploy-itch (push) Has been skipped
Build and Deploy / deploy-gitea (push) Has been skipped
This commit is contained in:
@@ -134,7 +134,7 @@ deps += dependency('soloud', static:true)
|
||||
|
||||
#deps += dependency('qjs-chipmunk', static:false)
|
||||
|
||||
deps += dependency('libqrencode', static: false)
|
||||
deps += dependency('libqrencode', static: true)
|
||||
|
||||
sources = []
|
||||
src += ['anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c','render.c','script.c','simplex.c','spline.c', 'timer.c', 'transform.c','prosperon.c', 'wildmatch.c', 'sprite.c', 'rtree.c', 'qjs_dmon.c', 'qjs_nota.c', 'qjs_enet.c', 'qjs_soloud.c', 'qjs_qr.c', 'qjs_wota.c']
|
||||
|
||||
@@ -520,6 +520,7 @@ script = `(function ${fnname}() { ${script}; })`
|
||||
js.eval(DOCPATH, script)()
|
||||
|
||||
var enet = use('enet')
|
||||
var util = use('util')
|
||||
|
||||
var $_ = {}
|
||||
|
||||
@@ -554,14 +555,23 @@ $_.receiver = function(fn)
|
||||
receive_fn = fn;
|
||||
}
|
||||
|
||||
var underlings = {}
|
||||
|
||||
$_.start = function(cb, prg, arg)
|
||||
{
|
||||
var guid = util.guid()
|
||||
underlings[guid] = cb
|
||||
os.createprocess(["./prosperon", "spawn", "--program", prg, "--overling", $_.host.port(), "--guid", guid])
|
||||
}
|
||||
|
||||
$_.stop = function(actor)
|
||||
{
|
||||
if (!actor)
|
||||
os.exit(0)
|
||||
|
||||
actor.peer.send({
|
||||
type:"stop",
|
||||
})
|
||||
}
|
||||
|
||||
$_.unneeded = function(fn, seconds)
|
||||
@@ -577,4 +587,44 @@ $_.delay = function(fn, seconds)
|
||||
|
||||
use('cmd')(prosperon.argv)
|
||||
|
||||
function handle_receive(e)
|
||||
{
|
||||
var data = e.data
|
||||
switch(data.type) {
|
||||
case "greet":
|
||||
if (underlings[data.guid]) underlings[data.guid]({
|
||||
type: "greet",
|
||||
data: {peer:e.peer}
|
||||
})
|
||||
break
|
||||
case "stop":
|
||||
console.log("STOPPING!")
|
||||
os.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
var hang = 0.016
|
||||
while (1) {
|
||||
os.waitevent(_ => {}, hang)
|
||||
host.service(e => {
|
||||
switch(e.type) {
|
||||
case "connect":
|
||||
console.log(`connected. sending greet with guid ${prosperon.guid} to peer ${e.peer}`)
|
||||
e.peer.send({
|
||||
type: "greet",
|
||||
guid: prosperon.guid
|
||||
});
|
||||
break;
|
||||
|
||||
case "receive":
|
||||
handle_receive(e);
|
||||
break;
|
||||
|
||||
case "disconnect":
|
||||
console.log(`this peer left: ${e.peer}`)
|
||||
break
|
||||
}
|
||||
}, hang);
|
||||
}
|
||||
|
||||
})()
|
||||
|
||||
@@ -189,18 +189,13 @@ Cmdline.register_order(
|
||||
console.log(json.encode(args));
|
||||
if (!args.program)
|
||||
os.exit()
|
||||
|
||||
|
||||
prosperon.guid = args.guid
|
||||
console.log(`going to connect to ${args.overling}`)
|
||||
if (args.overling) {
|
||||
// connect to the port
|
||||
if (args.overling)
|
||||
$_.host.connect("localhost", args.overling);
|
||||
console.log("CONNECTING TO " + args.overling);
|
||||
while(1) {
|
||||
os.waitevent(_ => {}, 0.016)
|
||||
$_.host.service(e => { console.log(json.encode(e)) }, 0.016)
|
||||
}
|
||||
}
|
||||
spawn_root(args.program)
|
||||
|
||||
// spawn_root(args.program)
|
||||
},
|
||||
"Spawn a new prosperon actor.",
|
||||
"TOPIC"
|
||||
|
||||
@@ -127,23 +127,19 @@ static JSValue js_enet_host_service(JSContext *ctx, JSValueConst this_val,
|
||||
ENetEvent event;
|
||||
while (enet_host_service(host, &event, secs*1000.0f) > 0) {
|
||||
JSValue event_obj = JS_NewObject(ctx);
|
||||
JSValue peer_obj = JS_NewObjectClass(ctx, enet_peer_class_id);
|
||||
JS_SetOpaque(peer_obj, event.peer);
|
||||
JS_SetPropertyStr(ctx, event_obj, "peer", peer_obj);
|
||||
|
||||
switch (event.type) {
|
||||
case ENET_EVENT_TYPE_CONNECT: {
|
||||
JS_SetPropertyStr(ctx, event_obj, "type", JS_NewString(ctx, "connect"));
|
||||
JSValue peer_obj = JS_NewObjectClass(ctx, enet_peer_class_id);
|
||||
if (JS_IsException(peer_obj)) {
|
||||
JS_FreeValue(ctx, event_obj);
|
||||
JS_FreeValue(ctx, callback);
|
||||
return peer_obj;
|
||||
}
|
||||
JS_SetOpaque(peer_obj, event.peer);
|
||||
JS_SetPropertyStr(ctx, event_obj, "peer", peer_obj);
|
||||
break;
|
||||
}
|
||||
case ENET_EVENT_TYPE_RECEIVE: {
|
||||
JS_SetPropertyStr(ctx, event_obj, "type", JS_NewString(ctx, "receive"));
|
||||
JS_SetPropertyStr(ctx, event_obj, "channelID", JS_NewInt32(ctx, event.channelID));
|
||||
|
||||
char *tmp = js_mallocz(ctx, event.packet->dataLength+1);
|
||||
memcpy(tmp, event.packet->data, event.packet->dataLength);
|
||||
tmp[event.packet->dataLength] = '\0';
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
var os = use('os')
|
||||
|
||||
var newguy = os.createprocess(["./prosperon", "spawn", "--program", "spawn2.js", "--overling", $_.host.port()])
|
||||
var hang = 0.016
|
||||
var guy
|
||||
|
||||
while (1) {
|
||||
os.waitevent(_ => {}, hang)
|
||||
$_.host.service(e => {console.log(json.encode(e))}, hang)
|
||||
}
|
||||
$_.start(e => {
|
||||
console.log("Got a message: " + json.encode(e))
|
||||
switch(e.type) {
|
||||
case "greet":
|
||||
$_.delay(_ => {
|
||||
console.log(`sending stop message to ${json.encode(e.data)}`)
|
||||
$_.stop(e.data)
|
||||
}, 1);
|
||||
}
|
||||
console.log(json.encode(e))
|
||||
}, "tests/underling.js");
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
var os = use('os')
|
||||
|
||||
console.log("Created underling")
|
||||
|
||||
os.exit()
|
||||
console.log(`started underling`)
|
||||
Reference in New Issue
Block a user