matching actor2js function; sdl_video returns actor now
This commit is contained in:
@@ -46,6 +46,36 @@ prosperon_rt *js2actor(JSContext *js, JSValue v)
|
||||
return actor;
|
||||
}
|
||||
|
||||
JSValue actor2js(JSContext *js, prosperon_rt *actor)
|
||||
{
|
||||
if (!actor)
|
||||
return JS_NULL;
|
||||
|
||||
/* Create the actor object */
|
||||
JSValue actor_obj = JS_NewObject(js);
|
||||
if (JS_IsException(actor_obj))
|
||||
return actor_obj;
|
||||
|
||||
/* Create the __ACTORDATA__ object */
|
||||
JSValue actor_data = JS_NewObject(js);
|
||||
if (JS_IsException(actor_data)) {
|
||||
JS_FreeValue(js, actor_obj);
|
||||
return actor_data;
|
||||
}
|
||||
|
||||
/* Set the id property in __ACTORDATA__ */
|
||||
JS_SetPropertyStr(js, actor_data, "id", JS_NewString(js, actor->id));
|
||||
|
||||
/* TODO: If the actor has network info, we could add address and port here */
|
||||
/* JS_SetPropertyStr(js, actor_data, "address", JS_NewString(js, actor->address)); */
|
||||
/* JS_SetPropertyStr(js, actor_data, "port", JS_NewInt32(js, actor->port)); */
|
||||
|
||||
/* Set __ACTORDATA__ on the actor object */
|
||||
JS_SetPropertyStr(js, actor_obj, "__ACTORDATA__", actor_data);
|
||||
|
||||
return actor_obj;
|
||||
}
|
||||
|
||||
JSC_CCALL(os_createactor,
|
||||
int margc = JS_ArrayLength(js, argv[0]);
|
||||
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
|
||||
JSValue js_actor_use(JSContext *js);
|
||||
prosperon_rt *js2actor(JSContext *js, JSValue v);
|
||||
JSValue actor2js(JSContext *js, prosperon_rt *actor);
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "jsffi.h"
|
||||
#include "qjs_macros.h"
|
||||
#include "qjs_sdl_surface.h"
|
||||
#include "qjs_actor.h"
|
||||
#include "prosperon.h"
|
||||
#include "sprite.h"
|
||||
#include "transform.h"
|
||||
@@ -1850,6 +1851,6 @@ JSValue js_sdl_video_use(JSContext *js) {
|
||||
int argc = 8;
|
||||
|
||||
// Create the actor with the hook to set up endowments
|
||||
create_actor(argc, (char**)argv, video_actor_hook);
|
||||
return JS_NewString(js,id);
|
||||
prosperon_rt *actor = create_actor(argc, (char**)argv, video_actor_hook);
|
||||
return actor2js(js,actor);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ var input = use('input')
|
||||
input.watch($_)
|
||||
|
||||
// Create SDL video actor
|
||||
var video = use('sdl_video');
|
||||
var video_actor = {__ACTORDATA__:{id:video}};
|
||||
var video_actor = use('sdl_video');
|
||||
|
||||
var window_id = null;
|
||||
var renderer_id = null;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
var video = use('sdl_video')
|
||||
|
||||
var window
|
||||
var renderer
|
||||
|
||||
var act = {__ACTORDATA__:{id:video}}
|
||||
|
||||
function handle_response(data)
|
||||
{
|
||||
if (data.error)
|
||||
console.log(json.encode(data))
|
||||
}
|
||||
|
||||
send(act, {kind:"window", op: "create"}, ({id}) => {
|
||||
window = id
|
||||
console.log(`made window id ${id}`)
|
||||
|
||||
send(act, {kind:"window", op:"makeRenderer", id: window}, ({id}) => {
|
||||
renderer = id
|
||||
console.log(`made renderer with id ${id}`)
|
||||
|
||||
send(act, {kind:"renderer", id: renderer, op:"set", prop: "drawColor", value:[0.6,0.4,0.5,1]})
|
||||
send(act, {kind:"renderer", id: renderer, op:"clear"}, handle_response)
|
||||
send(act, {kind:"renderer", id: renderer, op: "present"}, handle_response)
|
||||
})
|
||||
})
|
||||
|
||||
$_.delay($_.stop, 2)
|
||||
Reference in New Issue
Block a user