rtrees are now created as a constructor
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
/* main.js – runs the demo with your prototype-based grid */
|
||||
|
||||
var rtree = use('rtree')
|
||||
|
||||
var mytree = new rtree
|
||||
|
||||
mytree.add()
|
||||
mytree.kill()
|
||||
|
||||
for (var i in mytree) console.log(i)
|
||||
|
||||
var moth = use('moth')
|
||||
var json = use('json')
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ src += [
|
||||
'anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c',
|
||||
'render.c','simplex.c','spline.c', 'transform.c','prosperon.c', 'wildmatch.c',
|
||||
'sprite.c', 'rtree.c', 'qjs_nota.c', 'qjs_soloud.c', 'qjs_sdl.c', 'qjs_math.c', 'qjs_geometry.c', 'qjs_transform.c', 'qjs_sprite.c', 'qjs_io.c', 'qjs_os.c',
|
||||
'qjs_qr.c', 'qjs_wota.c', 'monocypher.c', 'qjs_blob.c', 'qjs_crypto.c', 'qjs_time.c', 'qjs_http.c', 'qjs_rtree.c', 'qjs_spline.c', 'qjs_js.c'
|
||||
'qjs_qr.c', 'qjs_wota.c', 'monocypher.c', 'qjs_blob.c', 'qjs_crypto.c', 'qjs_time.c', 'qjs_http.c', 'qjs_rtree.c', 'qjs_spline.c', 'qjs_js.c', 'qjs_debug.c'
|
||||
]
|
||||
# quirc src
|
||||
src += [
|
||||
|
||||
@@ -184,7 +184,9 @@ sprite.inputs.kp1 = function () {
|
||||
this.setanchor("ul");
|
||||
};
|
||||
|
||||
var tree = graphics.make_rtree()
|
||||
var rtree = use('rtree')
|
||||
|
||||
var tree = new rtree
|
||||
sprite.tree = tree;
|
||||
|
||||
var IN = Symbol()
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "stb_dxt.h"
|
||||
#include "stb_image_write.h"
|
||||
#include "string.h"
|
||||
#include "spline.h"
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
@@ -47,6 +46,7 @@
|
||||
#include "qjs_rtree.h"
|
||||
#include "qjs_spline.h"
|
||||
#include "qjs_js.h"
|
||||
#include "qjs_debug.h"
|
||||
|
||||
SDL_Window *global_window;
|
||||
|
||||
@@ -800,7 +800,6 @@ JSC_CCALL(os_make_text_buffer,
|
||||
arrfree(buffer);
|
||||
)
|
||||
|
||||
|
||||
shader_globals camera_globals(JSContext *js, JSValue camera)
|
||||
{
|
||||
shader_globals data = {0};
|
||||
@@ -1919,24 +1918,6 @@ static const JSCFunctionListEntry js_console_funcs[] = {
|
||||
MIST_FUNC_DEF(console,print,1),
|
||||
};
|
||||
|
||||
JSC_CCALL(debug_stack_depth, return number2js(js,js_debugger_stack_depth(js)))
|
||||
JSC_CCALL(debug_build_backtrace, return js_debugger_build_backtrace(js,NULL))
|
||||
JSC_CCALL(debug_closure_vars, return js_debugger_closure_variables(js,argv[0]))
|
||||
JSC_CCALL(debug_local_vars, return js_debugger_local_variables(js, js2number(js,argv[0])))
|
||||
JSC_CCALL(debug_fn_info, return js_debugger_fn_info(js, argv[0]))
|
||||
JSC_CCALL(debug_backtrace_fns, return js_debugger_backtrace_fns(js,NULL))
|
||||
JSC_CCALL(debug_dump_obj, return js_dump_value(js, argv[0]))
|
||||
|
||||
static const JSCFunctionListEntry js_debug_funcs[] = {
|
||||
MIST_FUNC_DEF(debug, stack_depth, 0),
|
||||
MIST_FUNC_DEF(debug, build_backtrace, 0),
|
||||
MIST_FUNC_DEF(debug, closure_vars, 1),
|
||||
MIST_FUNC_DEF(debug, local_vars, 1),
|
||||
MIST_FUNC_DEF(debug, fn_info, 1),
|
||||
MIST_FUNC_DEF(debug, backtrace_fns,0),
|
||||
MIST_FUNC_DEF(debug, dump_obj, 1),
|
||||
};
|
||||
|
||||
JSC_CCALL(datastream_time, return number2js(js,plm_get_time(js2datastream(js,self)->plm)); )
|
||||
JSC_CCALL(datastream_seek, ds_seek(js2datastream(js,self), js2number(js,argv[0])))
|
||||
JSC_CCALL(datastream_advance, ds_advance(js2datastream(js,self), js2number(js,argv[0])))
|
||||
@@ -2622,7 +2603,6 @@ JSC_CCALL(gpu_make_sprite_queue,
|
||||
JS_FreeValue(js, mesh);
|
||||
)
|
||||
|
||||
|
||||
typedef struct {
|
||||
JSValue val;
|
||||
void *ptr;
|
||||
@@ -2833,7 +2813,6 @@ JSC_SCALL(os_use_dyn,
|
||||
SDL_UnloadObject(ptr);
|
||||
)
|
||||
|
||||
|
||||
#define JSSTATIC(NAME, PARENT) \
|
||||
js_##NAME = JS_NewObject(js); \
|
||||
JS_SetPropertyFunctionList(js, js_##NAME, js_##NAME##_funcs, countof(js_##NAME##_funcs)); \
|
||||
@@ -2846,8 +2825,6 @@ JSValue js_miniz_use(JSContext *js);
|
||||
JSValue js_tracy_use(JSContext *js);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
JSValue js_graphics_use(JSContext *js) {
|
||||
JSValue mod = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js,mod,js_graphics_funcs,countof(js_graphics_funcs));
|
||||
@@ -2866,12 +2843,6 @@ JSValue js_video_use(JSContext *js) {
|
||||
return mod;
|
||||
}
|
||||
|
||||
JSValue js_debug_use(JSContext *js) {
|
||||
JSValue mod = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js,mod,js_debug_funcs,countof(js_debug_funcs));
|
||||
return mod;
|
||||
}
|
||||
|
||||
JSValue js_console_use(JSContext *js) {
|
||||
JSValue mod = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js,mod,js_console_funcs,countof(js_console_funcs));
|
||||
|
||||
@@ -170,11 +170,12 @@ JSC_CCALL(rtree_values,
|
||||
ret = data.arr;
|
||||
)
|
||||
|
||||
JSC_CCALL(os_make_rtree,
|
||||
// Constructor function for rtree
|
||||
static JSValue js_rtree_constructor(JSContext *js, JSValueConst new_target, int argc, JSValueConst *argv) {
|
||||
struct rtree *tree = rtree_new();
|
||||
if (!tree) return JS_ThrowOutOfMemory(js);
|
||||
return rtree2js(js,tree);
|
||||
)
|
||||
}
|
||||
|
||||
static const JSCFunctionListEntry js_rtree_funcs[] = {
|
||||
MIST_FUNC_DEF(rtree, add, 1),
|
||||
@@ -186,16 +187,17 @@ static const JSCFunctionListEntry js_rtree_funcs[] = {
|
||||
MIST_FUNC_DEF(rtree,values,0),
|
||||
};
|
||||
|
||||
static const JSCFunctionListEntry js_rtree_module_funcs[] = {
|
||||
MIST_FUNC_DEF(os, make_rtree, 0),
|
||||
};
|
||||
|
||||
JSValue js_rtree_use(JSContext *js) {
|
||||
// Register the rtree class
|
||||
QJSCLASSPREP_FUNCS(rtree);
|
||||
|
||||
// Create and return the module object
|
||||
JSValue mod = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js, mod, js_rtree_module_funcs, countof(js_rtree_module_funcs));
|
||||
return mod;
|
||||
// Create the constructor function
|
||||
JSValue ctor = JS_NewCFunction2(js, js_rtree_constructor, "RTree", 0, JS_CFUNC_constructor, 0);
|
||||
|
||||
// Set the prototype on the constructor
|
||||
JSValue proto = JS_GetClassProto(js, js_rtree_id);
|
||||
JS_SetConstructor(js, ctor, proto);
|
||||
JS_FreeValue(js, proto);
|
||||
|
||||
return ctor;
|
||||
}
|
||||
Reference in New Issue
Block a user