module misty

This commit is contained in:
2025-01-19 14:28:09 -06:00
parent b4d1277a9d
commit 8e95fd2355
7 changed files with 41 additions and 72 deletions

View File

@@ -89,7 +89,7 @@ if get_option('enet')
endif
sources = []
src += ['anim.c', 'config.c', 'datastream.c','font.c','gameobject.c','HandmadeMath.c','jsffi.c','model.c','render.c','script.c','simplex.c','spline.c', 'timer.c', 'transform.c','warp.c','yugine.c', 'wildmatch.c', 'sprite.c', 'quadtree.c', 'aabb.c', 'rtree.c', 'rtree3.c']
src += ['anim.c', 'config.c', 'datastream.c','font.c','gameobject.c','HandmadeMath.c','jsffi.c','model.c','render.c','script.c','simplex.c','spline.c', 'timer.c', 'transform.c','warp.c','yugine.c', 'wildmatch.c', 'sprite.c', 'quadtree.c', 'aabb.c', 'rtree.c']
imsrc = ['GraphEditor.cpp','ImCurveEdit.cpp','ImGradient.cpp','imgui_draw.cpp','imgui_tables.cpp','imgui_widgets.cpp','imgui.cpp','ImGuizmo.cpp','imnodes.cpp','implot_items.cpp','implot.cpp', 'imgui_impl_sdlrenderer3.cpp', 'imgui_impl_sdl3.cpp', 'imgui_impl_sdlgpu3.cpp']

View File

@@ -36,8 +36,8 @@ var script_fn = function script_fn(file) {
parsed.prog_fn = os.eval(file, prog_script);
}
return fn;
}
return parsed;
}.hashify()
function parse_file(content) {
var parts = content.split(/\n\s*---\s*\n/)
@@ -45,10 +45,9 @@ function parse_file(content) {
return {
program: parts[0]
}
}
var module = parts[0].trim();
if (!moduleCode.match(/return\s+[^;]+;?\s*$/))
if (!module.match(/return\s+[^;]+;?\s*$/))
throw new Error("Module section must end with a return statement");
return {
@@ -66,7 +65,7 @@ globalThis.actor_use = function actor_use(script)
return use(file)
}
globalThis.class_use = function class_use(script, config, base, callback) {
globalThis.class_use = function class_use(script, config, base = actor, callback, overling) {
var file = Resources.find_script(script);
if (!file) {
@@ -77,14 +76,17 @@ globalThis.class_use = function class_use(script, config, base, callback) {
var prog = script_fn(file);
var padawan;
if (prog.module_ret)
if (prog.module_ret) {
prog.module_ret.__proto__ = base;
padawan = Object.create(prog.module_ret);
}
else
padawan = {};
padawan = Object.create(base);
padawan.overling = overling;
if (callback) callback(padawan)
prog.prog_fn.call(padawan)
if (typeof config === 'object') Object.merge(padawan,config);
if (typeof config === 'object') Object.assign(padawan,config);
return padawan;
};
@@ -130,7 +132,7 @@ actor.hotreload = function hotreload(file) {
actor.spawn = function (script, config) {
if (typeof script !== "string") return undefined;
var padawan = class_use(script, config, actor);
var padawan = class_use(script, config, actor, undefined, this);
padawan.padawans = [];
padawan.timers = [];

View File

@@ -126,7 +126,7 @@ var entity = {
ent.timers = [];
// ent.ur = {};
// ent.urname = text;
});
}, this);
/*
if (!text)
ent.ur = emptyur;

View File

@@ -383,7 +383,6 @@ global.mixin("tween");
global.mixin("particle");
//global.mixin("physics");
global.mixin("geometry");
/*
Factory for creating registries. Register one with 'X.register',
which returns a function that, when invoked, cancels the registry.
@@ -512,7 +511,6 @@ prosperon.add_timer = function(obj, fn, seconds)
}
global.mixin("spline");
global.mixin("actor");
global.mixin("entity");
@@ -532,7 +530,6 @@ function world_start() {
world._ed = { selectable: false };
world.ur = {};
world.ur.fresh = {};
game.cam = world;
}
function make_spritesheet(paths, width, height)

View File

@@ -769,58 +769,14 @@ function sprites_to_queue(ysort = false)
height:size.y
};
var culled = sprite_qt.query(camrect)
if (globalThis.so_sprite_qt) {
var cull2 = so_sprite_qt.query(camrect)
culled = culled.concat(cull2)
}
if (culled.length == 0) return [];
//var culled = spritetree.find(prosperon.camera.pos, prosperon.camera.size);
//var culled = spritetree.find(prosperon.camera.transform.pos,prosperon.camera.size)
// var culled = os.cull_sprites(allsprites,prosperon.camera);
var cmd = render._main.make_sprite_queue(culled, prosperon.camera, sprite_pipeline, 1);
return cmd;
var sprites = allsprites;
// for (var i = 0; i < sprites.length; i++)
// sprites[i].transform.clean();
var dirtysprites = allsprites.filter(x=>x.transform.dirty());
if (dirtysprites.length > 0) console.log(`there was ${dirtysprites.length} dirty sprites`)
// var sprites = os.cull_sprites(allsprites, prosperon.camera);
os.insertion_sort(sprites,render._main.sort_sprite)
// sprites.sort(render._main.sort_sprite)
var mesh = render._main.make_sprite_mesh(sprites);
var queue = [];
var image;
var first_index = 0;
var count = 0;
for (var i = 0; i < sprites.length; i++) {
var spr = sprites[i];
if (spr.image !== image) {
if (count > 0) queue.push({
type:'geometry',
mesh,
pipeline:sprite_pipeline,
image,
first_index,
num_indices:count*6
});
image = spr.image;
first_index = i*6;
count = 1;
} else count++
}
if (count > 0) queue.push({
type:'geometry',
mesh,
pipeline:sprite_pipeline,
image,
first_index,
num_indices: count*6
});
return queue;
}
render.circle = function render_circle(pos, radius, color, inner_radius = 1, pipeline = circle_pipeline) {

View File

@@ -7359,12 +7359,14 @@ JSC_CCALL(rtree_insert,
JSValue v = argv[0];
rect r;
JS_GETATOM(js,r,v,rect_atom,rect)
NUMTYPE min[2];
NUMTYPE max[2];
NUMTYPE min[3];
NUMTYPE max[3];
min[0] = r.x;
min[1] = r.y;
min[2] = 0;
max[0] = r.x+r.w;
max[1] = r.y+r.h;
max[2] = 0;
JSValue *ins = malloc(sizeof(*ins));
*ins = JS_DupValue(js,v);
if (!rtree_insert(tree, min, max, ins)) {
@@ -7387,12 +7389,14 @@ JSC_CCALL(rtree_remove,
JSValue v = argv[0];
rect r;
JS_GETATOM(js,r,v,rect_atom,rect)
NUMTYPE min[2];
NUMTYPE max[2];
NUMTYPE min[3];
NUMTYPE max[3];
min[0] = r.x;
min[1] = r.y;
min[2] = 0;
max[0] = r.x+r.w;
max[1] = r.y+r.h;
max[2] = 0;
if (!rtree_delete_with_comparator(tree, min, max, &v, rtree_cmp, js))
return JS_ThrowOutOfMemory(js);
@@ -7421,12 +7425,14 @@ bool rtree_array_iter(const NUMTYPE *min, const NUMTYPE *max, const JSValue *dat
JSC_CCALL(rtree_query,
rtree *tree = js2rtree(js,self);
rect r = js2rect(js,argv[0]);
NUMTYPE min[2];
NUMTYPE max[2];
NUMTYPE min[3];
NUMTYPE max[3];
min[0] = r.x;
min[1] = r.y;
min[2] = 0;
max[0] = r.x+r.w;
max[1] = r.y+r.h;
max[2] = 0;
struct rtree_iter_data data = {0};
data.js = js;

View File

@@ -17,7 +17,6 @@ JSContext *global_js = NULL;
JSValue on_exception = JS_UNDEFINED;
#ifndef NDEBUG
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT
#else
@@ -82,7 +81,7 @@ void script_startup() {
char *eng = read_file("core/scripts/engine.js");
JSValue v = script_eval(js, "core/scripts/engine.js", eng);
JS_FreeValue(js, v);
uncaught_exception(js,v);
free(eng);
}
@@ -97,11 +96,20 @@ void script_stop()
void uncaught_exception(JSContext *js, JSValue v)
{
if (!JS_IsUndefined(on_exception) && JS_IsException(v)) {
if (!JS_IsException(v)) return;
if (!JS_IsUndefined(on_exception)) {
JSValue ex = JS_GetException(js);
JSValue ret = JS_Call(js, on_exception, JS_UNDEFINED, 1, &ex);
JS_FreeValue(js,ret);
JS_FreeValue(js,ex);
} else {
JSValue ex = JS_GetException(js);
JSValue stack = JS_GetPropertyStr(js,ex,"stack");
const char *st = JS_ToCString(js,stack);
printf("Unhandled exception:\n%s\n", st);
JS_FreeValue(js,stack);
JS_FreeValue(js,ex);
}
JS_FreeValue(js,v);