Compare commits
No commits in common. "5bb7ea32bf7ecbe6d536d18ccd7b85edf17033bf" and "7e04937c8b85c4039aecadd701e6e59f8eeb37c1" have entirely different histories.
5bb7ea32bf
...
7e04937c8b
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -27,6 +27,6 @@ primum*
|
|||
Prosperon*
|
||||
prosperon*
|
||||
*.icns
|
||||
game.zip
|
||||
game.cdb
|
||||
icon.ico
|
||||
steam/
|
51
Makefile
51
Makefile
|
@ -4,10 +4,6 @@ MAKEDIR != pwd
|
|||
# Options
|
||||
# NDEBUG --- build with debugging symbols and logging
|
||||
|
||||
ifeq ($(ARCH),)
|
||||
ARCH != uname -m
|
||||
endif
|
||||
|
||||
CXX:=$(CC)
|
||||
|
||||
# Temp to strip long emcc paths to just emcc
|
||||
|
@ -19,16 +15,7 @@ INFO :=
|
|||
LD = $(CC)
|
||||
|
||||
STEAM = steam/sdk
|
||||
STEAMAPI =
|
||||
|
||||
ifeq ($(CC), emcc)
|
||||
LDFLAGS += -sUSE_WEBGPU --shell-file shell.html
|
||||
CPPFLAGS += -Wbad-function-cast -Wcast-function-type -sSTACK_SIZE=5MB -sALLOW_MEMORY_GROWTH
|
||||
OPT = 0
|
||||
NDEBUG = 1
|
||||
AR = emar
|
||||
ARCH:= wasm
|
||||
endif
|
||||
STEAMAPI = steam_api
|
||||
|
||||
CCC != $(CC) -v
|
||||
ifneq ($(findstring clangcc , $(CCC)),)
|
||||
|
@ -55,6 +42,14 @@ ifdef NQOA
|
|||
CPPFLAGS += -DNQOA
|
||||
endif
|
||||
|
||||
ifeq ($(CC), emcc)
|
||||
LDFLAGS += #--closure 1 --emrun
|
||||
CPPFLAGS += -O0
|
||||
OPT = 0
|
||||
NDEBUG = 1
|
||||
AR = emar
|
||||
endif
|
||||
|
||||
ifdef NDEBUG
|
||||
CPPFLAGS += -DNDEBUG
|
||||
else
|
||||
|
@ -64,7 +59,6 @@ endif
|
|||
|
||||
ifdef LEAK
|
||||
CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK
|
||||
INFO := $(INFO)_leak
|
||||
endif
|
||||
|
||||
ifeq ($(OPT),small)
|
||||
|
@ -94,7 +88,11 @@ PKGCMD = tar --directory --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(D
|
|||
ZIP = .tar.gz
|
||||
UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST)
|
||||
|
||||
INFO := $(INFO)_$(ARCH)
|
||||
ifeq ($(ARCH),)
|
||||
ARCH != uname -m
|
||||
endif
|
||||
|
||||
INFO :=$(INFO)_$(ARCH)
|
||||
|
||||
ifeq ($(OS), Windows_NT) # then WINDOWS
|
||||
PLATFORM := win64
|
||||
|
@ -120,10 +118,9 @@ else ifeq ($(OS), IOS)
|
|||
INFO :=$(INFO)_ios
|
||||
else ifeq ($(CC), emcc) # Then WEB
|
||||
OS := Web
|
||||
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
|
||||
CPPFLAGS += -DNSTEAM
|
||||
LDLIBS += GL openal c m dl
|
||||
STEAMAPI :=
|
||||
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sTOTAL_MEMORY=128MB
|
||||
CPPFLAGS += -pthread
|
||||
LDLIBS += pthread quickjs GL openal c m dl
|
||||
EXT = .html
|
||||
else
|
||||
UNAME != uname -s
|
||||
|
@ -167,9 +164,6 @@ includeflag := $(addprefix -I, $(includeflag))
|
|||
|
||||
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types
|
||||
|
||||
ifeq ($(INFO),_)
|
||||
INFO :=
|
||||
endif
|
||||
APP = prosperon
|
||||
NAME = $(APP)$(INFO)$(EXT)
|
||||
SEM != git describe --tags --abbrev=0
|
||||
|
@ -225,13 +219,13 @@ SCRIPTS := $(shell ls scripts/*.js*)
|
|||
CORE != (ls icons/* fonts/*)
|
||||
CORE := $(CORE) $(SCRIPTS)
|
||||
|
||||
packer: tools/packer.c source/engine/miniz.c
|
||||
packer$(EXT): tools/packer.c source/engine/miniz.c
|
||||
@echo Making packer
|
||||
$(CC) -O2 $^ -Isource/engine -o packer
|
||||
|
||||
core.cdb: packer $(CORE)
|
||||
core.cdb: packer$(EXT) $(CORE)
|
||||
@echo Packing core.cdb
|
||||
./packer $@ $(CORE)
|
||||
./packer$(EXT) $@ $(CORE)
|
||||
|
||||
source/engine/core.cdb.h: core.cdb
|
||||
@echo Making $@
|
||||
|
@ -274,7 +268,10 @@ crossmac: Prosperon.icns
|
|||
|
||||
crossweb:
|
||||
make CC=emcc
|
||||
mv $(APP).html index.html
|
||||
|
||||
playweb:
|
||||
make crossweb
|
||||
emrun $(NAME).html
|
||||
|
||||
clean:
|
||||
@echo Cleaning project
|
||||
|
|
10
config.js
10
config.js
|
@ -1,10 +0,0 @@
|
|||
console.stdout_lvl = 4;
|
||||
say(`config after std`);
|
||||
window.size = [600,600];
|
||||
window.rendersize = [200,200];
|
||||
say(`config after window size`);
|
||||
|
||||
globalThis.gamestate = {};
|
||||
gamestate.grid = 10;
|
||||
//window.title = "Accio!";
|
||||
say(`end of config`);
|
|
@ -302,7 +302,7 @@ SpriteAnim.aseprite = function(path) {
|
|||
function aseframeset2anim(frameset, meta) {
|
||||
var anim = {};
|
||||
anim.frames = [];
|
||||
anim.path = path.folder() + meta.image;
|
||||
anim.path = path.dir() + "/" + meta.image;
|
||||
var dim = meta.size;
|
||||
|
||||
var ase_make_frame = function(ase_frame) {
|
||||
|
@ -329,10 +329,6 @@ SpriteAnim.aseprite = function(path) {
|
|||
var anims = {};
|
||||
var frames = Array.isArray(data.frames) ? data.frames : Object.values(data.frames);
|
||||
var f = 0;
|
||||
if (data.meta.frameTags.length === 0) {
|
||||
anims[0] = aseframeset2anim(frames, data.meta);
|
||||
return anims;
|
||||
}
|
||||
for (var tag of data.meta.frameTags) {
|
||||
anims[tag.name] = aseframeset2anim(frames.slice(tag.from, tag.to+1), data.meta);
|
||||
anims[f] = anims[tag.name];
|
||||
|
|
|
@ -8,7 +8,6 @@ game.loadurs();
|
|||
console.info(`window size: ${window.size}, render size: ${window.rendersize}`);
|
||||
|
||||
player[0].control(debug);
|
||||
render.clear_color([35,60,92,255].map(x => x/255));
|
||||
|
||||
var show_frame = true;
|
||||
|
||||
|
@ -487,7 +486,7 @@ var editor = {
|
|||
render.text("lock", obj,screenpos());
|
||||
});
|
||||
|
||||
render.grid(1, editor.grid_size, editor.grid_color);
|
||||
render.grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3));
|
||||
var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); });
|
||||
var endgrid = game.camera.view2world([window.width, window.height]);
|
||||
|
||||
|
|
|
@ -15,14 +15,6 @@ Object.defineProperty(String.prototype, 'dir', {
|
|||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(String.prototype, 'folder', {
|
||||
value: function() {
|
||||
var dir = this.dir();
|
||||
if (!dir) return "";
|
||||
else return dir + "/";
|
||||
}
|
||||
});
|
||||
|
||||
globalThis.Resources = {};
|
||||
|
||||
Resources.replpath = function(str, path)
|
||||
|
@ -155,17 +147,15 @@ console.say = function(msg) {
|
|||
console.transcript += msg;
|
||||
};
|
||||
console.log = console.say;
|
||||
globalThis.say = console.say;
|
||||
globalThis.print = console.print;
|
||||
var say = console.say;
|
||||
var print = console.print;
|
||||
|
||||
console.pprint = function(msg,lvl = 0) {
|
||||
|
||||
if (typeof msg === 'object')
|
||||
msg = JSON.stringify(msg, null, 2);
|
||||
|
||||
var file = "nofile";
|
||||
var line = 0;
|
||||
console.rec(0,msg,file,line);
|
||||
|
||||
var caller = (new Error()).stack.split('\n')[2];
|
||||
if (caller) {
|
||||
|
@ -223,14 +213,17 @@ function use(file, env = {}, script)
|
|||
|
||||
if (use.cache[file]) {
|
||||
var ret = use.cache[file].call(env);
|
||||
profile.report(st, `CACHE eval ${file}`);
|
||||
profile.addreport(profcache, file, st);
|
||||
return;
|
||||
}
|
||||
console.info(`slurping ${file}`);
|
||||
script ??= Resources.replstrs(file);
|
||||
script = `(function() { var self = this; ${script}; })`;
|
||||
var fn = os.eval(file,script);
|
||||
use.cache[file] = fn;
|
||||
var ret = fn.call(env);
|
||||
profile.report(st, `eval ${file}`);
|
||||
profile.addreport(profcache, file, st);
|
||||
return ret;
|
||||
}
|
||||
|
@ -463,12 +456,12 @@ prosperon.touchrelease = function(touches){};
|
|||
prosperon.touchmove = function(touches){};
|
||||
prosperon.clipboardpaste = function(str){};
|
||||
prosperon.quit = function(){
|
||||
say(profile.printreport(profcache, "USE REPORT"));
|
||||
say(profile.printreport(entityreport, "ENTITY REPORT"));
|
||||
console.info(profile.printreport(profcache, "USE REPORT"));
|
||||
console.info(profile.printreport(entityreport, "ENTITY REPORT"));
|
||||
|
||||
console.info("QUITTING");
|
||||
for (var i in debug.log.time)
|
||||
say(debug.log.time[i].map(x=>profile.ms(x)));
|
||||
console.warn(debug.log.time[i].map(x=>profile.ms(x)));
|
||||
};
|
||||
|
||||
global.mixin("scripts/input");
|
||||
|
|
|
@ -16,17 +16,17 @@ if (os.sys() === 'macos') {
|
|||
|
||||
player[0].control(appy);
|
||||
|
||||
//steam.appid = 480;
|
||||
//steam.userid = 8437843;
|
||||
steam.appid = 480;
|
||||
steam.userid = 8437843;
|
||||
|
||||
os.home = os.env("HOME");
|
||||
|
||||
/*steam.path = {
|
||||
steam.path = {
|
||||
windows: `C:/Program Files (x86)/Steam/userdata/${steam.userid}/${steam.appid}`,
|
||||
macos: `${os.home}/Library/Application Support/Steam/userdata/${steam.userid}/${steam.appid}`,
|
||||
linux: `${os.home}/.local/share/Steam/userdata/${steam.userid}/${steam.appid}`
|
||||
};
|
||||
*/
|
||||
|
||||
var otherpath = {
|
||||
windows:`C:/Users/${os.user}/Saved Games`,
|
||||
macos: `${os.home}/Library/Application Support`,
|
||||
|
@ -230,7 +230,7 @@ Cmdline.register_order("debug", function() {
|
|||
Cmdline.register_order("play", function(argv) {
|
||||
if (argv[0])
|
||||
io.chdir(argv[0]);
|
||||
|
||||
|
||||
game.loadurs();
|
||||
|
||||
if (!io.exists(projectfile)) {
|
||||
|
@ -244,12 +244,11 @@ Cmdline.register_order("play", function(argv) {
|
|||
global.mixin("config.js");
|
||||
if (project.title) window.title = project.title;
|
||||
|
||||
|
||||
if (window.rendersize.equal([0,0])) window.rendersize = window.size;
|
||||
console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`);
|
||||
|
||||
game.engine_start(function() {
|
||||
render.set_font("fonts/c64.ttf", 8);
|
||||
render.set_font("fonts/c64.ttf", 8);
|
||||
global.app = actor.spawn("game.js");
|
||||
if (project.icon) window.set_icon(game.texture(project.icon));
|
||||
game.camera = world.spawn("scripts/camera2d");
|
||||
|
@ -259,7 +258,7 @@ Cmdline.register_order("play", function(argv) {
|
|||
Cmdline.register_order("pack", function(str) {
|
||||
var packname;
|
||||
if (str.length === 0)
|
||||
packname = "game.zip";
|
||||
packname = "game.cdb";
|
||||
else if (str.length > 1) {
|
||||
console.warn("Give me a single filename for the pack.");
|
||||
return;
|
||||
|
@ -267,23 +266,15 @@ Cmdline.register_order("pack", function(str) {
|
|||
packname = str[0];
|
||||
|
||||
say(`Packing into ${packname}`);
|
||||
|
||||
io.pack_start(packname);
|
||||
var files = io.ls('.');
|
||||
files = files.filter(f => !f.startsWith('.git'));
|
||||
files = files.filter(f => !f.startsWith('.nova'));
|
||||
files = files.filter(f => !f.includes('.DS_Store'));
|
||||
files = files.filter(f => !f.startsWith('.gitignore'));
|
||||
say(files);
|
||||
for (var f of files)
|
||||
io.pack_add(f);
|
||||
io.pack_end();
|
||||
|
||||
// io.pack_engine(packname);
|
||||
io.chmod(packname, 666);
|
||||
}, "Pack the game into the given name.", "NAME");
|
||||
|
||||
Cmdline.register_order("cdb", function(argv) {
|
||||
var cdb = "game.zip";
|
||||
var cdb = "game.cdb";
|
||||
if (!io.exists(cdb)) {
|
||||
say(`No 'game.zip' present.`);
|
||||
say(`No 'game.cdb' present.`);
|
||||
return;
|
||||
}
|
||||
if (argv.length === 0) {
|
||||
|
@ -477,6 +468,6 @@ Cmdline.register_cmd("l", function(n) {
|
|||
return {
|
||||
Resources,
|
||||
Cmdline,
|
||||
cmd_args
|
||||
cmd_args,
|
||||
steam
|
||||
};
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
raise(SIGTRAP);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -104,13 +105,9 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
void log_print(const char *str)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf(stdout, str);
|
||||
fprintf(writeout, str);
|
||||
fflush(stdout);
|
||||
#else
|
||||
printf(str);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {
|
||||
|
|
|
@ -101,6 +101,14 @@ JSValue js_getpropidx(JSValue v, uint32_t i)
|
|||
return p;
|
||||
}
|
||||
|
||||
JSValue gos2ref(gameobject **go)
|
||||
{
|
||||
JSValue array = JS_NewArray(js);
|
||||
for (int i = 0; i < arrlen(go); i++)
|
||||
js_setprop_num(array,i,JS_DupValue(js,go[i]->ref));
|
||||
return array;
|
||||
}
|
||||
|
||||
void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertyStr(js, obj, prop, v); }
|
||||
JSValue js_getpropstr(JSValue v, const char *str)
|
||||
{
|
||||
|
@ -120,11 +128,6 @@ JSValue strarr2js(char **c)
|
|||
return arr;
|
||||
}
|
||||
|
||||
JSValue js2strarr(JSValue v)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JSValue number2js(double g) { return JS_NewFloat64(js,g); }
|
||||
double js2number(JSValue v) {
|
||||
double g;
|
||||
|
@ -370,7 +373,6 @@ JSValue vecarr2js(HMM_Vec2 *points, int n) {
|
|||
|
||||
int js_print_exception(JSValue v)
|
||||
{
|
||||
if (!js) return 0;
|
||||
#ifndef NDEBUG
|
||||
if (!JS_IsException(v))
|
||||
return 0;
|
||||
|
@ -611,11 +613,6 @@ JSC_CCALL(render_end_pass,
|
|||
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1)))
|
||||
JSC_CCALL(render_set_camera, useproj = projection)
|
||||
JSC_CCALL(render_set_window, useproj = hudproj)
|
||||
JSC_CCALL(render_clear_color,
|
||||
sg_color c;
|
||||
rgba2floats(&c, js2color(argv[0]));
|
||||
pass_action.colors[0].clear_value = c;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_render_funcs[] = {
|
||||
MIST_FUNC_DEF(render, grid, 3),
|
||||
|
@ -631,7 +628,6 @@ static const JSCFunctionListEntry js_render_funcs[] = {
|
|||
MIST_FUNC_DEF(render, text_size, 3),
|
||||
MIST_FUNC_DEF(render, set_camera, 0),
|
||||
MIST_FUNC_DEF(render, set_window, 0),
|
||||
MIST_FUNC_DEF(render, clear_color, 1),
|
||||
};
|
||||
|
||||
JSC_CCALL(gui_flush, text_flush(&useproj));
|
||||
|
@ -880,10 +876,6 @@ JSValue js_io_chmod(JSContext *js, JSValue this, int argc, JSValue *argv)
|
|||
|
||||
JSC_SCALL(io_save_qoa, save_qoa(str))
|
||||
|
||||
JSC_SCALL(io_pack_start, pack_start(str))
|
||||
JSC_SCALL(io_pack_add, pack_add(str))
|
||||
JSC_CCALL(io_pack_end, pack_end())
|
||||
|
||||
static const JSCFunctionListEntry js_io_funcs[] = {
|
||||
MIST_FUNC_DEF(io, exists,1),
|
||||
MIST_FUNC_DEF(io, ls, 0),
|
||||
|
@ -897,26 +889,12 @@ static const JSCFunctionListEntry js_io_funcs[] = {
|
|||
MIST_FUNC_DEF(io, slurpbytes, 1),
|
||||
MIST_FUNC_DEF(io, slurpwrite, 2),
|
||||
MIST_FUNC_DEF(io, save_qoa,1),
|
||||
MIST_FUNC_DEF(io, pack_start, 1),
|
||||
MIST_FUNC_DEF(io, pack_add, 1),
|
||||
MIST_FUNC_DEF(io, pack_end, 0)
|
||||
};
|
||||
|
||||
JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));)
|
||||
|
||||
JSC_GETSET_GLOBAL(disabled_color, color)
|
||||
JSC_GETSET_GLOBAL(sleep_color, color)
|
||||
JSC_GETSET_GLOBAL(dynamic_color, color)
|
||||
JSC_GETSET_GLOBAL(kinematic_color, color)
|
||||
JSC_GETSET_GLOBAL(static_color, color)
|
||||
|
||||
static const JSCFunctionListEntry js_debug_funcs[] = {
|
||||
MIST_FUNC_DEF(debug, draw_gameobject, 1),
|
||||
CGETSET_ADD(global, disabled_color),
|
||||
CGETSET_ADD(global, sleep_color),
|
||||
CGETSET_ADD(global, dynamic_color),
|
||||
CGETSET_ADD(global, kinematic_color),
|
||||
CGETSET_ADD(global, static_color),
|
||||
MIST_FUNC_DEF(debug, draw_gameobject, 1)
|
||||
};
|
||||
|
||||
JSC_CCALL(physics_sgscale,
|
||||
|
@ -1092,11 +1070,10 @@ static JSValue js_window_get_rendersize(JSContext *js, JSValue this) {
|
|||
}
|
||||
static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) {
|
||||
js2window(this)->rendersize = js2vec2(v);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
JSC_GETSET(window, mode, number)
|
||||
static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); }
|
||||
static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); return JS_UNDEFINED; }
|
||||
static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); }
|
||||
|
||||
static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v)
|
||||
{
|
||||
|
@ -1137,12 +1114,12 @@ JSValue js_gameobject_set_rpos(JSContext *js, JSValue this, JSValue val) {
|
|||
return JS_UNDEFINED;
|
||||
}
|
||||
JSValue js_gameobject_get_rpos(JSContext *js, JSValue this) { return cvec22js(cpBodyGetPosition(js2gameobject(this)->body)); }
|
||||
JSValue js_gameobject_set_rangle (JSContext *js, JSValue this, JSValue val) { cpBodySetAngle(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); return JS_UNDEFINED; }
|
||||
JSValue js_gameobject_set_rangle (JSContext *js, JSValue this, JSValue val) { cpBodySetAngle(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); }
|
||||
JSValue js_gameobject_get_rangle (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngle(js2gameobject(this)->body)); }
|
||||
JSValue js_gameobject_get_rscale(JSContext *js, JSValue this) { return vec32js(js2gameobject(this)->scale); }
|
||||
JSValue js_gameobject_set_rscale(JSContext *js, JSValue this, JSValue val) { js2gameobject(this)->scale = js2vec3(val); return JS_UNDEFINED; }
|
||||
JSValue js_gameobject_set_rscale(JSContext *js, JSValue this, JSValue val) { js2gameobject(this)->scale = js2vec3(val); }
|
||||
JSC_GETSET_BODY(velocity, Velocity, cvec2)
|
||||
JSValue js_gameobject_set_angularvelocity (JSContext *js, JSValue this, JSValue val) { cpBodySetAngularVelocity(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); return JS_UNDEFINED;}
|
||||
JSValue js_gameobject_set_angularvelocity (JSContext *js, JSValue this, JSValue val) { cpBodySetAngularVelocity(js2gameobject(this)->body, HMM_TurnToRad*js2number(val)); }
|
||||
JSValue js_gameobject_get_angularvelocity (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngularVelocity(js2gameobject(this)->body)); }
|
||||
//JSC_GETSET_BODY(moi, Moment, number)
|
||||
JSC_GETSET_BODY(torque, Torque, number)
|
||||
|
@ -1572,6 +1549,7 @@ void ffi_load() {
|
|||
QJSGLOBALCLASS(dspsound);
|
||||
QJSGLOBALCLASS(pshape);
|
||||
QJSGLOBALCLASS(performance);
|
||||
|
||||
QJSGLOBALCLASS(circle2d);
|
||||
QJSGLOBALCLASS(poly2d);
|
||||
QJSGLOBALCLASS(edge2d);
|
||||
|
@ -1581,8 +1559,8 @@ void ffi_load() {
|
|||
JS_SetPropertyStr(js, globalThis, "window", window2js(&mainwin));
|
||||
JS_SetPropertyStr(js, globalThis, "texture", JS_DupValue(js,texture_proto));
|
||||
|
||||
//JS_SetPropertyStr(js, globalThis, "steam", js_init_steam(js));
|
||||
|
||||
JS_SetPropertyStr(js, globalThis, "steam", js_init_steam(js));
|
||||
|
||||
sound_proto = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js,globalThis, "sound_proto", sound_proto);
|
||||
JS_SetPropertyFunctionList(js, sound_proto, js_sound_funcs, countof(js_sound_funcs));
|
||||
|
@ -1590,3 +1568,7 @@ void ffi_load() {
|
|||
|
||||
JS_FreeValue(js,globalThis);
|
||||
}
|
||||
|
||||
void ffi_stop()
|
||||
{
|
||||
}
|
|
@ -120,6 +120,7 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
|
|||
#define countof(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
void ffi_load();
|
||||
void ffi_stop();
|
||||
|
||||
JSValue vec22js(HMM_Vec2 v);
|
||||
HMM_Vec2 js2vec2(JSValue v);
|
||||
|
|
|
@ -121,6 +121,8 @@ void capture_screen(int x, int y, int w, int h, const char *path)
|
|||
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
struct rgba editorClearColor = {35,60,92,255};
|
||||
|
||||
sg_pass_action pass_action = {0};
|
||||
|
||||
static struct {
|
||||
|
@ -224,17 +226,16 @@ void render_init() {
|
|||
.buffer_pool_size = 1024
|
||||
});
|
||||
|
||||
#ifndef NDEBUG
|
||||
sg_trace_hooks hh = sg_install_trace_hooks(&hooks);
|
||||
#endif
|
||||
|
||||
font_init();
|
||||
debugdraw_init();
|
||||
sprite_initialize();
|
||||
|
||||
model_init();
|
||||
sg_color c;
|
||||
rgba2floats((float*)&c, editorClearColor);
|
||||
|
||||
sg_color c = (sg_color){0,0,0,1};
|
||||
pass_action = (sg_pass_action){
|
||||
.colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c},
|
||||
};
|
||||
|
|
|
@ -30,7 +30,6 @@ extern HMM_Vec3 dirl_pos;
|
|||
extern HMM_Mat4 projection;
|
||||
extern HMM_Mat4 hudproj;
|
||||
extern HMM_Mat4 useproj;
|
||||
extern sg_pass_action pass_action;
|
||||
|
||||
struct draw_p {
|
||||
float x;
|
||||
|
|
|
@ -45,29 +45,21 @@ static mz_zip_archive game_cdb;
|
|||
|
||||
int LOADED_GAME = 0;
|
||||
uint8_t *gamebuf;
|
||||
void *zipbuf;
|
||||
|
||||
sfetch_handle_t game_h;
|
||||
|
||||
static void response_cb(const sfetch_response_t *r)
|
||||
{
|
||||
if (r->fetched) {
|
||||
zipbuf = malloc(r->data.size);
|
||||
memcpy(zipbuf, r->data.ptr, r->data.size);
|
||||
mz_zip_reader_init_mem(&game_cdb, zipbuf, r->data.size,0);
|
||||
|
||||
mz_zip_reader_init_mem(&game_cdb, r->data.ptr, r->data.size,0);
|
||||
LOADED_GAME = 1;
|
||||
}
|
||||
if (r->finished) {
|
||||
LOADED_GAME = 1;
|
||||
void *buf = sfetch_unbind_buffer(r->handle);
|
||||
free(buf);
|
||||
if (r->failed)
|
||||
LOADED_GAME = -1;
|
||||
if (r->failed) {
|
||||
LOADED_GAME = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *gamedata;
|
||||
|
||||
void resources_init() {
|
||||
sfetch_setup(&(sfetch_desc_t){
|
||||
.max_requests = 1024,
|
||||
|
@ -75,27 +67,18 @@ void resources_init() {
|
|||
.num_lanes = 8,
|
||||
.logger = { .func = sg_logging },
|
||||
});
|
||||
mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
gamebuf = malloc(8*1024*1024);
|
||||
game_h = sfetch_send(&(sfetch_request_t){
|
||||
.path="game.zip",
|
||||
gamebuf = malloc(64*1024*1024);
|
||||
|
||||
sfetch_handle_t h = sfetch_send(&(sfetch_request_t){
|
||||
.path="game.cdb",
|
||||
.callback = response_cb,
|
||||
.buffer = {
|
||||
.ptr = gamebuf,
|
||||
.size = 8*1024*1024
|
||||
.size = 64*1024*1024
|
||||
}
|
||||
});
|
||||
#else
|
||||
size_t gamesize;
|
||||
gamebuf = slurp_file("game.zip", &gamesize);
|
||||
if (gamebuf) {
|
||||
mz_zip_reader_init_mem(&game_cdb, gamebuf, gamesize, 0);
|
||||
free(gamebuf);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0);
|
||||
}
|
||||
|
||||
char *get_filename_from_path(char *path, int extension) {
|
||||
|
@ -174,31 +157,10 @@ char **ls(const char *path)
|
|||
return ls_paths;
|
||||
}
|
||||
|
||||
static mz_zip_archive ar;
|
||||
|
||||
void pack_start(const char *name)
|
||||
{
|
||||
memset(&ar, 0, sizeof(ar));
|
||||
int status = mz_zip_writer_init_file(&ar, name, 0);
|
||||
|
||||
}
|
||||
|
||||
void pack_add(const char *path)
|
||||
{
|
||||
mz_zip_writer_add_file(&ar, path, path, NULL, 0, MZ_BEST_COMPRESSION);
|
||||
}
|
||||
|
||||
void pack_end()
|
||||
{
|
||||
mz_zip_writer_finalize_archive(&ar);
|
||||
mz_zip_writer_end(&ar);
|
||||
}
|
||||
|
||||
#else
|
||||
void fill_extensions(char *paths, const char *path, const char *ext)
|
||||
{};
|
||||
char **ls(const char *path) { return NULL; }
|
||||
void pack(const char *name, const char *dir) {}
|
||||
#endif
|
||||
|
||||
char *str_replace_ext(const char *s, const char *newext) {
|
||||
|
|
|
@ -18,9 +18,6 @@ char **ls(const char *path);
|
|||
int cp(const char *p1, const char *p2);
|
||||
int fexists(const char *path);
|
||||
time_t file_mod_secs(const char *file);
|
||||
void pack_start(const char *name);
|
||||
void pack_add(const char *path);
|
||||
void pack_end();
|
||||
|
||||
char *dirname(const char *path);
|
||||
|
||||
|
@ -30,4 +27,14 @@ int slurp_write(const char *txt, const char *filename, size_t len);
|
|||
|
||||
char *seprint(char *fmt, ...);
|
||||
|
||||
static inline void *stbarrdup(void *mem, size_t size, int len) {
|
||||
void *out = NULL;
|
||||
arrsetlen(out, len);
|
||||
memcpy(out,mem,size*len);
|
||||
return out;
|
||||
}
|
||||
|
||||
#define arrconcat(a,b) do{for (int i = 0; i < arrlen(b); i++) arrput(a,b[i]);}while(0)
|
||||
#define arrdup(a) (stbarrdup(a, sizeof(*a), arrlen(a)))
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,7 +24,7 @@ void script_startup() {
|
|||
size_t len;
|
||||
char *eng = slurp_text("scripts/engine.js", &len);
|
||||
JSValue v = script_eval("scripts/engine.js", eng);
|
||||
JS_FreeValue(js, v);
|
||||
JS_FreeValue(js,v);
|
||||
free(eng);
|
||||
}
|
||||
static int stopped = 0;
|
||||
|
@ -34,18 +34,18 @@ void script_stop()
|
|||
#ifndef LEAK
|
||||
return;
|
||||
#endif
|
||||
|
||||
script_gc();
|
||||
printf("FREEING CONTEXT\n");
|
||||
ffi_stop();
|
||||
JS_FreeContext(js);
|
||||
js = NULL;
|
||||
script_gc();
|
||||
JS_FreeRuntime(rt);
|
||||
js = NULL;
|
||||
rt = NULL;
|
||||
}
|
||||
|
||||
void script_gc() { JS_RunGC(rt); }
|
||||
|
||||
void js_stacktrace() {
|
||||
if (!js) return;
|
||||
#ifndef NDEBUG
|
||||
script_evalf("console.stack();");
|
||||
#endif
|
||||
|
@ -53,19 +53,13 @@ void js_stacktrace() {
|
|||
|
||||
void script_evalf(const char *format, ...)
|
||||
{
|
||||
JSValue obj;
|
||||
char fmtbuf[4096];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int len = vsnprintf(NULL, 0, format, args);
|
||||
va_end(args);
|
||||
|
||||
char *eval = malloc(len+1);
|
||||
va_start(args, format);
|
||||
vsnprintf(eval, len+1, format, args);
|
||||
vsnprintf(fmtbuf, 4096, format, args);
|
||||
va_end(args);
|
||||
|
||||
obj = JS_Eval(js, eval, len, "C eval", JS_EVAL_FLAGS);
|
||||
free(eval);
|
||||
JSValue obj = JS_Eval(js, fmtbuf, strlen(fmtbuf), "C eval", JS_EVAL_FLAGS);
|
||||
js_print_exception(obj);
|
||||
JS_FreeValue(js,obj);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "steam.h"
|
||||
/*
|
||||
|
||||
#include <steam/steam_api.h>
|
||||
#include <steam/steam_api_flat.h>
|
||||
|
||||
|
@ -18,5 +18,4 @@ JSValue js_init_steam(JSContext *js)
|
|||
JSValue steam = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js, steam, js_steam_funcs, countof(js_steam_funcs));
|
||||
return steam;
|
||||
}
|
||||
*/
|
||||
}
|
20
source/engine/thirdparty/quickjs/quickjs.c
vendored
20
source/engine/thirdparty/quickjs/quickjs.c
vendored
|
@ -114,17 +114,17 @@ void quickjs_set_dumpout(FILE *f)
|
|||
#ifdef DUMP
|
||||
//#define DUMP_FREE
|
||||
#define DUMP_MEM
|
||||
//#define DUMP_CLOSURE
|
||||
#define DUMP_GC
|
||||
//#define DUMP_GC_FREE
|
||||
#define DUMP_LEAKS 1
|
||||
//#define DUMP_OBJECTS
|
||||
#define DUMP_CLOSURE
|
||||
//#define DUMP_OBJECTS
|
||||
//#define DUMP_ATOMS
|
||||
//#define DUMP_SHAPES
|
||||
//#define DUMP_MODULE_RESOLVE
|
||||
//#define DUMP_PROMISE
|
||||
#define DUMP_GC
|
||||
#define DUMP_GC_FREE
|
||||
#define DUMP_LEAKS 1
|
||||
#define DUMP_OBJECTS
|
||||
#define DUMP_CLOSURE
|
||||
#define DUMP_OBJECTS
|
||||
#define DUMP_ATOMS
|
||||
#define DUMP_SHAPES
|
||||
#define DUMP_MODULE_RESOLVE
|
||||
#define DUMP_PROMISE
|
||||
#endif
|
||||
|
||||
/* test the GC by forcing it before each object allocation */
|
||||
|
|
|
@ -20,8 +20,6 @@ struct window mainwin = {
|
|||
.vsync = 1,
|
||||
.enable_clipboard = 0,
|
||||
.enable_dragndrop = 0,
|
||||
.size = (HMM_Vec2){640,400},
|
||||
.rendersize = (HMM_Vec2){640,400},
|
||||
};
|
||||
|
||||
static struct window *windows = NULL;
|
||||
|
|
|
@ -53,10 +53,8 @@ static int sim_play = SIM_PLAY;
|
|||
static int argc;
|
||||
static char **args;
|
||||
|
||||
static JSValue c_start = JS_UNDEFINED;
|
||||
static JSValue c_process_fn = JS_UNDEFINED;
|
||||
|
||||
static int PLAYSTART = 0;
|
||||
static JSValue c_start;
|
||||
static JSValue c_process_fn;
|
||||
|
||||
void c_init() {
|
||||
mainwin.start = 1;
|
||||
|
@ -64,28 +62,13 @@ void c_init() {
|
|||
phys2d_init();
|
||||
render_init();
|
||||
particle_init();
|
||||
if (!JS_IsUndefined(c_start)) {
|
||||
script_call_sym(c_start,0,NULL);
|
||||
JS_FreeValue(js, c_start);
|
||||
}
|
||||
script_call_sym(c_start,0,NULL);
|
||||
JS_FreeValue(js, c_start);
|
||||
}
|
||||
|
||||
void c_frame() {
|
||||
sfetch_dowork();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (PLAYSTART)
|
||||
script_call_sym(c_process_fn,0,NULL);
|
||||
else if (LOADED_GAME) {
|
||||
PLAYSTART = 1;
|
||||
printf("LOADED GAME\n");
|
||||
script_evalf("cmd_args('play');");
|
||||
script_call_sym(c_start,0,NULL);
|
||||
JS_FreeValue(js, c_start);
|
||||
window_resize(sapp_width(), sapp_height());
|
||||
}
|
||||
#else
|
||||
script_call_sym(c_process_fn,0,NULL);
|
||||
#endif
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
|
@ -102,7 +85,6 @@ void seghandle()
|
|||
}
|
||||
|
||||
void c_clean() {
|
||||
JS_FreeValue(js, c_process_fn);
|
||||
cleanup();
|
||||
gif_rec_end("out.gif");
|
||||
saudio_shutdown();
|
||||
|
@ -217,8 +199,8 @@ static sapp_desc start_desc = {
|
|||
.frame_cb = c_frame,
|
||||
.cleanup_cb = c_clean,
|
||||
.event_cb = c_event,
|
||||
.logger.func = sg_logging,
|
||||
.win32_console_create = false,
|
||||
.logger.func = sg_logging
|
||||
};
|
||||
|
||||
sapp_desc sokol_main(int argc, char **argv) {
|
||||
|
@ -233,7 +215,6 @@ sapp_desc sokol_main(int argc, char **argv) {
|
|||
stm_setup(); /* time */
|
||||
script_startup();
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
int argsize = 0;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
argsize += strlen(argv[i]);
|
||||
|
@ -247,10 +228,11 @@ sapp_desc sokol_main(int argc, char **argv) {
|
|||
strcat(cmdstr, argv[i]);
|
||||
if (argc > i+1) strcat(cmdstr, " ");
|
||||
}
|
||||
|
||||
|
||||
while (!LOADED_GAME)
|
||||
sfetch_dowork();
|
||||
|
||||
script_evalf("cmd_args('%s');", cmdstr);
|
||||
#endif
|
||||
|
||||
return start_desc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue