Compare commits

...

12 commits

19 changed files with 238 additions and 126 deletions

2
.gitignore vendored
View file

@ -27,6 +27,6 @@ primum*
Prosperon* Prosperon*
prosperon* prosperon*
*.icns *.icns
game.cdb game.zip
icon.ico icon.ico
steam/ steam/

View file

@ -4,6 +4,10 @@ MAKEDIR != pwd
# Options # Options
# NDEBUG --- build with debugging symbols and logging # NDEBUG --- build with debugging symbols and logging
ifeq ($(ARCH),)
ARCH != uname -m
endif
CXX:=$(CC) CXX:=$(CC)
# Temp to strip long emcc paths to just emcc # Temp to strip long emcc paths to just emcc
@ -15,7 +19,16 @@ INFO :=
LD = $(CC) LD = $(CC)
STEAM = steam/sdk STEAM = steam/sdk
STEAMAPI = steam_api 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
CCC != $(CC) -v CCC != $(CC) -v
ifneq ($(findstring clangcc , $(CCC)),) ifneq ($(findstring clangcc , $(CCC)),)
@ -42,14 +55,6 @@ ifdef NQOA
CPPFLAGS += -DNQOA CPPFLAGS += -DNQOA
endif endif
ifeq ($(CC), emcc)
LDFLAGS += #--closure 1 --emrun
CPPFLAGS += -O0
OPT = 0
NDEBUG = 1
AR = emar
endif
ifdef NDEBUG ifdef NDEBUG
CPPFLAGS += -DNDEBUG CPPFLAGS += -DNDEBUG
else else
@ -59,6 +64,7 @@ endif
ifdef LEAK ifdef LEAK
CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK
INFO := $(INFO)_leak
endif endif
ifeq ($(OPT),small) ifeq ($(OPT),small)
@ -88,11 +94,7 @@ PKGCMD = tar --directory --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(D
ZIP = .tar.gz ZIP = .tar.gz
UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST) UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST)
ifeq ($(ARCH),) INFO := $(INFO)_$(ARCH)
ARCH != uname -m
endif
INFO :=$(INFO)_$(ARCH)
ifeq ($(OS), Windows_NT) # then WINDOWS ifeq ($(OS), Windows_NT) # then WINDOWS
PLATFORM := win64 PLATFORM := win64
@ -118,9 +120,10 @@ else ifeq ($(OS), IOS)
INFO :=$(INFO)_ios INFO :=$(INFO)_ios
else ifeq ($(CC), emcc) # Then WEB else ifeq ($(CC), emcc) # Then WEB
OS := Web OS := Web
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sTOTAL_MEMORY=128MB LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
CPPFLAGS += -pthread CPPFLAGS += -DNSTEAM
LDLIBS += pthread quickjs GL openal c m dl LDLIBS += GL openal c m dl
STEAMAPI :=
EXT = .html EXT = .html
else else
UNAME != uname -s UNAME != uname -s
@ -164,6 +167,9 @@ includeflag := $(addprefix -I, $(includeflag))
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types
ifeq ($(INFO),_)
INFO :=
endif
APP = prosperon APP = prosperon
NAME = $(APP)$(INFO)$(EXT) NAME = $(APP)$(INFO)$(EXT)
SEM != git describe --tags --abbrev=0 SEM != git describe --tags --abbrev=0
@ -219,13 +225,13 @@ SCRIPTS := $(shell ls scripts/*.js*)
CORE != (ls icons/* fonts/*) CORE != (ls icons/* fonts/*)
CORE := $(CORE) $(SCRIPTS) CORE := $(CORE) $(SCRIPTS)
packer$(EXT): tools/packer.c source/engine/miniz.c packer: tools/packer.c source/engine/miniz.c
@echo Making packer @echo Making packer
$(CC) -O2 $^ -Isource/engine -o packer $(CC) -O2 $^ -Isource/engine -o packer
core.cdb: packer$(EXT) $(CORE) core.cdb: packer $(CORE)
@echo Packing core.cdb @echo Packing core.cdb
./packer$(EXT) $@ $(CORE) ./packer $@ $(CORE)
source/engine/core.cdb.h: core.cdb source/engine/core.cdb.h: core.cdb
@echo Making $@ @echo Making $@
@ -268,10 +274,7 @@ crossmac: Prosperon.icns
crossweb: crossweb:
make CC=emcc make CC=emcc
mv $(APP).html index.html
playweb:
make crossweb
emrun $(NAME).html
clean: clean:
@echo Cleaning project @echo Cleaning project

10
config.js Normal file
View file

@ -0,0 +1,10 @@
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`);

View file

@ -302,7 +302,7 @@ SpriteAnim.aseprite = function(path) {
function aseframeset2anim(frameset, meta) { function aseframeset2anim(frameset, meta) {
var anim = {}; var anim = {};
anim.frames = []; anim.frames = [];
anim.path = path.dir() + "/" + meta.image; anim.path = path.folder() + meta.image;
var dim = meta.size; var dim = meta.size;
var ase_make_frame = function(ase_frame) { var ase_make_frame = function(ase_frame) {
@ -329,6 +329,10 @@ SpriteAnim.aseprite = function(path) {
var anims = {}; var anims = {};
var frames = Array.isArray(data.frames) ? data.frames : Object.values(data.frames); var frames = Array.isArray(data.frames) ? data.frames : Object.values(data.frames);
var f = 0; var f = 0;
if (data.meta.frameTags.length === 0) {
anims[0] = aseframeset2anim(frames, data.meta);
return anims;
}
for (var tag of data.meta.frameTags) { for (var tag of data.meta.frameTags) {
anims[tag.name] = aseframeset2anim(frames.slice(tag.from, tag.to+1), data.meta); anims[tag.name] = aseframeset2anim(frames.slice(tag.from, tag.to+1), data.meta);
anims[f] = anims[tag.name]; anims[f] = anims[tag.name];

View file

@ -8,6 +8,7 @@ game.loadurs();
console.info(`window size: ${window.size}, render size: ${window.rendersize}`); console.info(`window size: ${window.size}, render size: ${window.rendersize}`);
player[0].control(debug); player[0].control(debug);
render.clear_color([35,60,92,255].map(x => x/255));
var show_frame = true; var show_frame = true;
@ -486,7 +487,7 @@ var editor = {
render.text("lock", obj,screenpos()); render.text("lock", obj,screenpos());
}); });
render.grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3)); render.grid(1, editor.grid_size, editor.grid_color);
var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); }); 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]); var endgrid = game.camera.view2world([window.width, window.height]);

View file

@ -15,6 +15,14 @@ Object.defineProperty(String.prototype, 'dir', {
} }
}); });
Object.defineProperty(String.prototype, 'folder', {
value: function() {
var dir = this.dir();
if (!dir) return "";
else return dir + "/";
}
});
globalThis.Resources = {}; globalThis.Resources = {};
Resources.replpath = function(str, path) Resources.replpath = function(str, path)
@ -147,15 +155,17 @@ console.say = function(msg) {
console.transcript += msg; console.transcript += msg;
}; };
console.log = console.say; console.log = console.say;
var say = console.say; globalThis.say = console.say;
var print = console.print; globalThis.print = console.print;
console.pprint = function(msg,lvl = 0) { console.pprint = function(msg,lvl = 0) {
if (typeof msg === 'object') if (typeof msg === 'object')
msg = JSON.stringify(msg, null, 2); msg = JSON.stringify(msg, null, 2);
var file = "nofile"; var file = "nofile";
var line = 0; var line = 0;
console.rec(0,msg,file,line);
var caller = (new Error()).stack.split('\n')[2]; var caller = (new Error()).stack.split('\n')[2];
if (caller) { if (caller) {
@ -213,17 +223,14 @@ function use(file, env = {}, script)
if (use.cache[file]) { if (use.cache[file]) {
var ret = use.cache[file].call(env); var ret = use.cache[file].call(env);
profile.report(st, `CACHE eval ${file}`);
profile.addreport(profcache, file, st); profile.addreport(profcache, file, st);
return; return;
} }
console.info(`slurping ${file}`);
script ??= Resources.replstrs(file); script ??= Resources.replstrs(file);
script = `(function() { var self = this; ${script}; })`; script = `(function() { var self = this; ${script}; })`;
var fn = os.eval(file,script); var fn = os.eval(file,script);
use.cache[file] = fn; use.cache[file] = fn;
var ret = fn.call(env); var ret = fn.call(env);
profile.report(st, `eval ${file}`);
profile.addreport(profcache, file, st); profile.addreport(profcache, file, st);
return ret; return ret;
} }
@ -456,12 +463,12 @@ prosperon.touchrelease = function(touches){};
prosperon.touchmove = function(touches){}; prosperon.touchmove = function(touches){};
prosperon.clipboardpaste = function(str){}; prosperon.clipboardpaste = function(str){};
prosperon.quit = function(){ prosperon.quit = function(){
console.info(profile.printreport(profcache, "USE REPORT")); say(profile.printreport(profcache, "USE REPORT"));
console.info(profile.printreport(entityreport, "ENTITY REPORT")); say(profile.printreport(entityreport, "ENTITY REPORT"));
console.info("QUITTING"); console.info("QUITTING");
for (var i in debug.log.time) for (var i in debug.log.time)
console.warn(debug.log.time[i].map(x=>profile.ms(x))); say(debug.log.time[i].map(x=>profile.ms(x)));
}; };
global.mixin("scripts/input"); global.mixin("scripts/input");

View file

@ -16,17 +16,17 @@ if (os.sys() === 'macos') {
player[0].control(appy); player[0].control(appy);
steam.appid = 480; //steam.appid = 480;
steam.userid = 8437843; //steam.userid = 8437843;
os.home = os.env("HOME"); os.home = os.env("HOME");
steam.path = { /*steam.path = {
windows: `C:/Program Files (x86)/Steam/userdata/${steam.userid}/${steam.appid}`, windows: `C:/Program Files (x86)/Steam/userdata/${steam.userid}/${steam.appid}`,
macos: `${os.home}/Library/Application Support/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}` linux: `${os.home}/.local/share/Steam/userdata/${steam.userid}/${steam.appid}`
}; };
*/
var otherpath = { var otherpath = {
windows:`C:/Users/${os.user}/Saved Games`, windows:`C:/Users/${os.user}/Saved Games`,
macos: `${os.home}/Library/Application Support`, macos: `${os.home}/Library/Application Support`,
@ -244,6 +244,7 @@ Cmdline.register_order("play", function(argv) {
global.mixin("config.js"); global.mixin("config.js");
if (project.title) window.title = project.title; if (project.title) window.title = project.title;
if (window.rendersize.equal([0,0])) window.rendersize = window.size; if (window.rendersize.equal([0,0])) window.rendersize = window.size;
console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`); console.info(`Starting game with window size ${window.size} and render ${window.rendersize}.`);
@ -258,7 +259,7 @@ Cmdline.register_order("play", function(argv) {
Cmdline.register_order("pack", function(str) { Cmdline.register_order("pack", function(str) {
var packname; var packname;
if (str.length === 0) if (str.length === 0)
packname = "game.cdb"; packname = "game.zip";
else if (str.length > 1) { else if (str.length > 1) {
console.warn("Give me a single filename for the pack."); console.warn("Give me a single filename for the pack.");
return; return;
@ -267,14 +268,22 @@ Cmdline.register_order("pack", function(str) {
say(`Packing into ${packname}`); say(`Packing into ${packname}`);
// io.pack_engine(packname); io.pack_start(packname);
io.chmod(packname, 666); 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();
}, "Pack the game into the given name.", "NAME"); }, "Pack the game into the given name.", "NAME");
Cmdline.register_order("cdb", function(argv) { Cmdline.register_order("cdb", function(argv) {
var cdb = "game.cdb"; var cdb = "game.zip";
if (!io.exists(cdb)) { if (!io.exists(cdb)) {
say(`No 'game.cdb' present.`); say(`No 'game.zip' present.`);
return; return;
} }
if (argv.length === 0) { if (argv.length === 0) {
@ -468,6 +477,6 @@ Cmdline.register_cmd("l", function(n) {
return { return {
Resources, Resources,
Cmdline, Cmdline,
cmd_args, cmd_args
steam
}; };

View file

@ -97,7 +97,6 @@ void mYughLog(int category, int priority, int line, const char *file, const char
raise(SIGTRAP); raise(SIGTRAP);
#endif #endif
} }
#endif #endif
} }
@ -105,9 +104,13 @@ void mYughLog(int category, int priority, int line, const char *file, const char
void log_print(const char *str) void log_print(const char *str)
{ {
#ifndef NDEBUG #ifndef NDEBUG
fprintf(stdout, str);
fprintf(writeout, str); fprintf(writeout, str);
#endif
fflush(stdout); fflush(stdout);
#else
printf(str);
fflush(stdout);
#endif
} }
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) { void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {

View file

@ -101,14 +101,6 @@ JSValue js_getpropidx(JSValue v, uint32_t i)
return p; 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); } 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) JSValue js_getpropstr(JSValue v, const char *str)
{ {
@ -128,6 +120,11 @@ JSValue strarr2js(char **c)
return arr; return arr;
} }
JSValue js2strarr(JSValue v)
{
}
JSValue number2js(double g) { return JS_NewFloat64(js,g); } JSValue number2js(double g) { return JS_NewFloat64(js,g); }
double js2number(JSValue v) { double js2number(JSValue v) {
double g; double g;
@ -373,6 +370,7 @@ JSValue vecarr2js(HMM_Vec2 *points, int n) {
int js_print_exception(JSValue v) int js_print_exception(JSValue v)
{ {
if (!js) return 0;
#ifndef NDEBUG #ifndef NDEBUG
if (!JS_IsException(v)) if (!JS_IsException(v))
return 0; return 0;
@ -613,6 +611,11 @@ JSC_CCALL(render_end_pass,
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1))) 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_camera, useproj = projection)
JSC_CCALL(render_set_window, useproj = hudproj) 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[] = { static const JSCFunctionListEntry js_render_funcs[] = {
MIST_FUNC_DEF(render, grid, 3), MIST_FUNC_DEF(render, grid, 3),
@ -628,6 +631,7 @@ static const JSCFunctionListEntry js_render_funcs[] = {
MIST_FUNC_DEF(render, text_size, 3), MIST_FUNC_DEF(render, text_size, 3),
MIST_FUNC_DEF(render, set_camera, 0), MIST_FUNC_DEF(render, set_camera, 0),
MIST_FUNC_DEF(render, set_window, 0), MIST_FUNC_DEF(render, set_window, 0),
MIST_FUNC_DEF(render, clear_color, 1),
}; };
JSC_CCALL(gui_flush, text_flush(&useproj)); JSC_CCALL(gui_flush, text_flush(&useproj));
@ -876,6 +880,10 @@ JSValue js_io_chmod(JSContext *js, JSValue this, int argc, JSValue *argv)
JSC_SCALL(io_save_qoa, save_qoa(str)) 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[] = { static const JSCFunctionListEntry js_io_funcs[] = {
MIST_FUNC_DEF(io, exists,1), MIST_FUNC_DEF(io, exists,1),
MIST_FUNC_DEF(io, ls, 0), MIST_FUNC_DEF(io, ls, 0),
@ -889,12 +897,26 @@ static const JSCFunctionListEntry js_io_funcs[] = {
MIST_FUNC_DEF(io, slurpbytes, 1), MIST_FUNC_DEF(io, slurpbytes, 1),
MIST_FUNC_DEF(io, slurpwrite, 2), MIST_FUNC_DEF(io, slurpwrite, 2),
MIST_FUNC_DEF(io, save_qoa,1), 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_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[] = { static const JSCFunctionListEntry js_debug_funcs[] = {
MIST_FUNC_DEF(debug, draw_gameobject, 1) 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),
}; };
JSC_CCALL(physics_sgscale, JSC_CCALL(physics_sgscale,
@ -1070,10 +1092,11 @@ static JSValue js_window_get_rendersize(JSContext *js, JSValue this) {
} }
static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) { static JSValue js_window_set_rendersize(JSContext *js, JSValue this, JSValue v) {
js2window(this)->rendersize = js2vec2(v); js2window(this)->rendersize = js2vec2(v);
return JS_UNDEFINED;
} }
JSC_GETSET(window, mode, number) JSC_GETSET(window, mode, number)
static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); } 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)); } 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_title(JSContext *js, JSValue this, JSValue v) static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v)
{ {
@ -1114,12 +1137,12 @@ JSValue js_gameobject_set_rpos(JSContext *js, JSValue this, JSValue val) {
return JS_UNDEFINED; return JS_UNDEFINED;
} }
JSValue js_gameobject_get_rpos(JSContext *js, JSValue this) { return cvec22js(cpBodyGetPosition(js2gameobject(this)->body)); } 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)); } 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_get_rangle (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngle(js2gameobject(this)->body)); } 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_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); } JSValue js_gameobject_set_rscale(JSContext *js, JSValue this, JSValue val) { js2gameobject(this)->scale = js2vec3(val); return JS_UNDEFINED; }
JSC_GETSET_BODY(velocity, Velocity, cvec2) 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)); } 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_get_angularvelocity (JSContext *js, JSValue this) { return number2js(HMM_RadToTurn*cpBodyGetAngularVelocity(js2gameobject(this)->body)); } 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(moi, Moment, number)
JSC_GETSET_BODY(torque, Torque, number) JSC_GETSET_BODY(torque, Torque, number)
@ -1549,7 +1572,6 @@ void ffi_load() {
QJSGLOBALCLASS(dspsound); QJSGLOBALCLASS(dspsound);
QJSGLOBALCLASS(pshape); QJSGLOBALCLASS(pshape);
QJSGLOBALCLASS(performance); QJSGLOBALCLASS(performance);
QJSGLOBALCLASS(circle2d); QJSGLOBALCLASS(circle2d);
QJSGLOBALCLASS(poly2d); QJSGLOBALCLASS(poly2d);
QJSGLOBALCLASS(edge2d); QJSGLOBALCLASS(edge2d);
@ -1559,7 +1581,7 @@ void ffi_load() {
JS_SetPropertyStr(js, globalThis, "window", window2js(&mainwin)); JS_SetPropertyStr(js, globalThis, "window", window2js(&mainwin));
JS_SetPropertyStr(js, globalThis, "texture", JS_DupValue(js,texture_proto)); 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); sound_proto = JS_NewObject(js);
JS_SetPropertyStr(js,globalThis, "sound_proto", sound_proto); JS_SetPropertyStr(js,globalThis, "sound_proto", sound_proto);
@ -1568,7 +1590,3 @@ void ffi_load() {
JS_FreeValue(js,globalThis); JS_FreeValue(js,globalThis);
} }
void ffi_stop()
{
}

View file

@ -120,7 +120,6 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
#define countof(x) (sizeof(x)/sizeof((x)[0])) #define countof(x) (sizeof(x)/sizeof((x)[0]))
void ffi_load(); void ffi_load();
void ffi_stop();
JSValue vec22js(HMM_Vec2 v); JSValue vec22js(HMM_Vec2 v);
HMM_Vec2 js2vec2(JSValue v); HMM_Vec2 js2vec2(JSValue v);

View file

@ -121,8 +121,6 @@ void capture_screen(int x, int y, int w, int h, const char *path)
#include "HandmadeMath.h" #include "HandmadeMath.h"
struct rgba editorClearColor = {35,60,92,255};
sg_pass_action pass_action = {0}; sg_pass_action pass_action = {0};
static struct { static struct {
@ -226,16 +224,17 @@ void render_init() {
.buffer_pool_size = 1024 .buffer_pool_size = 1024
}); });
#ifndef NDEBUG
sg_trace_hooks hh = sg_install_trace_hooks(&hooks); sg_trace_hooks hh = sg_install_trace_hooks(&hooks);
#endif
font_init(); font_init();
debugdraw_init(); debugdraw_init();
sprite_initialize(); sprite_initialize();
model_init(); model_init();
sg_color c;
rgba2floats((float*)&c, editorClearColor);
sg_color c = (sg_color){0,0,0,1};
pass_action = (sg_pass_action){ pass_action = (sg_pass_action){
.colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c}, .colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c},
}; };

View file

@ -30,6 +30,7 @@ extern HMM_Vec3 dirl_pos;
extern HMM_Mat4 projection; extern HMM_Mat4 projection;
extern HMM_Mat4 hudproj; extern HMM_Mat4 hudproj;
extern HMM_Mat4 useproj; extern HMM_Mat4 useproj;
extern sg_pass_action pass_action;
struct draw_p { struct draw_p {
float x; float x;

View file

@ -45,21 +45,29 @@ static mz_zip_archive game_cdb;
int LOADED_GAME = 0; int LOADED_GAME = 0;
uint8_t *gamebuf; uint8_t *gamebuf;
void *zipbuf;
sfetch_handle_t game_h;
static void response_cb(const sfetch_response_t *r) static void response_cb(const sfetch_response_t *r)
{ {
if (r->fetched) { if (r->fetched) {
mz_zip_reader_init_mem(&game_cdb, r->data.ptr, r->data.size,0); zipbuf = malloc(r->data.size);
LOADED_GAME = 1; memcpy(zipbuf, r->data.ptr, r->data.size);
mz_zip_reader_init_mem(&game_cdb, zipbuf, r->data.size,0);
} }
if (r->finished) { if (r->finished) {
LOADED_GAME = 1;
void *buf = sfetch_unbind_buffer(r->handle);
free(buf);
if (r->failed)
LOADED_GAME = -1; LOADED_GAME = -1;
if (r->failed) {
LOADED_GAME = -1;
}
} }
} }
void *gamedata;
void resources_init() { void resources_init() {
sfetch_setup(&(sfetch_desc_t){ sfetch_setup(&(sfetch_desc_t){
.max_requests = 1024, .max_requests = 1024,
@ -67,18 +75,27 @@ void resources_init() {
.num_lanes = 8, .num_lanes = 8,
.logger = { .func = sg_logging }, .logger = { .func = sg_logging },
}); });
gamebuf = malloc(64*1024*1024); mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0);
sfetch_handle_t h = sfetch_send(&(sfetch_request_t){ #ifdef __EMSCRIPTEN__
.path="game.cdb", gamebuf = malloc(8*1024*1024);
game_h = sfetch_send(&(sfetch_request_t){
.path="game.zip",
.callback = response_cb, .callback = response_cb,
.buffer = { .buffer = {
.ptr = gamebuf, .ptr = gamebuf,
.size = 64*1024*1024 .size = 8*1024*1024
} }
}); });
#else
mz_zip_reader_init_mem(&corecdb, core_cdb, core_cdb_len, 0); 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
} }
char *get_filename_from_path(char *path, int extension) { char *get_filename_from_path(char *path, int extension) {
@ -157,10 +174,31 @@ char **ls(const char *path)
return ls_paths; 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 #else
void fill_extensions(char *paths, const char *path, const char *ext) void fill_extensions(char *paths, const char *path, const char *ext)
{}; {};
char **ls(const char *path) { return NULL; } char **ls(const char *path) { return NULL; }
void pack(const char *name, const char *dir) {}
#endif #endif
char *str_replace_ext(const char *s, const char *newext) { char *str_replace_ext(const char *s, const char *newext) {

View file

@ -18,6 +18,9 @@ char **ls(const char *path);
int cp(const char *p1, const char *p2); int cp(const char *p1, const char *p2);
int fexists(const char *path); int fexists(const char *path);
time_t file_mod_secs(const char *file); 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); char *dirname(const char *path);
@ -27,14 +30,4 @@ int slurp_write(const char *txt, const char *filename, size_t len);
char *seprint(char *fmt, ...); 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 #endif

View file

@ -24,7 +24,7 @@ void script_startup() {
size_t len; size_t len;
char *eng = slurp_text("scripts/engine.js", &len); char *eng = slurp_text("scripts/engine.js", &len);
JSValue v = script_eval("scripts/engine.js", eng); JSValue v = script_eval("scripts/engine.js", eng);
JS_FreeValue(js,v); JS_FreeValue(js, v);
free(eng); free(eng);
} }
static int stopped = 0; static int stopped = 0;
@ -34,18 +34,18 @@ void script_stop()
#ifndef LEAK #ifndef LEAK
return; return;
#endif #endif
printf("FREEING CONTEXT\n");
ffi_stop();
JS_FreeContext(js);
script_gc(); script_gc();
JS_FreeRuntime(rt); JS_FreeContext(js);
js = NULL; js = NULL;
JS_FreeRuntime(rt);
rt = NULL; rt = NULL;
} }
void script_gc() { JS_RunGC(rt); } void script_gc() { JS_RunGC(rt); }
void js_stacktrace() { void js_stacktrace() {
if (!js) return;
#ifndef NDEBUG #ifndef NDEBUG
script_evalf("console.stack();"); script_evalf("console.stack();");
#endif #endif
@ -53,13 +53,19 @@ void js_stacktrace() {
void script_evalf(const char *format, ...) void script_evalf(const char *format, ...)
{ {
char fmtbuf[4096]; JSValue obj;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsnprintf(fmtbuf, 4096, format, args); int len = vsnprintf(NULL, 0, format, args);
va_end(args); va_end(args);
JSValue obj = JS_Eval(js, fmtbuf, strlen(fmtbuf), "C eval", JS_EVAL_FLAGS); char *eval = malloc(len+1);
va_start(args, format);
vsnprintf(eval, len+1, format, args);
va_end(args);
obj = JS_Eval(js, eval, len, "C eval", JS_EVAL_FLAGS);
free(eval);
js_print_exception(obj); js_print_exception(obj);
JS_FreeValue(js,obj); JS_FreeValue(js,obj);
} }

View file

@ -1,5 +1,5 @@
#include "steam.h" #include "steam.h"
/*
#include <steam/steam_api.h> #include <steam/steam_api.h>
#include <steam/steam_api_flat.h> #include <steam/steam_api_flat.h>
@ -19,3 +19,4 @@ JSValue js_init_steam(JSContext *js)
JS_SetPropertyFunctionList(js, steam, js_steam_funcs, countof(js_steam_funcs)); JS_SetPropertyFunctionList(js, steam, js_steam_funcs, countof(js_steam_funcs));
return steam; return steam;
} }
*/

View file

@ -114,17 +114,17 @@ void quickjs_set_dumpout(FILE *f)
#ifdef DUMP #ifdef DUMP
//#define DUMP_FREE //#define DUMP_FREE
#define DUMP_MEM #define DUMP_MEM
#define DUMP_CLOSURE //#define DUMP_CLOSURE
#define DUMP_GC #define DUMP_GC
#define DUMP_GC_FREE //#define DUMP_GC_FREE
#define DUMP_LEAKS 1 #define DUMP_LEAKS 1
#define DUMP_OBJECTS //#define DUMP_OBJECTS
#define DUMP_CLOSURE #define DUMP_CLOSURE
#define DUMP_OBJECTS //#define DUMP_OBJECTS
#define DUMP_ATOMS //#define DUMP_ATOMS
#define DUMP_SHAPES //#define DUMP_SHAPES
#define DUMP_MODULE_RESOLVE //#define DUMP_MODULE_RESOLVE
#define DUMP_PROMISE //#define DUMP_PROMISE
#endif #endif
/* test the GC by forcing it before each object allocation */ /* test the GC by forcing it before each object allocation */

View file

@ -20,6 +20,8 @@ struct window mainwin = {
.vsync = 1, .vsync = 1,
.enable_clipboard = 0, .enable_clipboard = 0,
.enable_dragndrop = 0, .enable_dragndrop = 0,
.size = (HMM_Vec2){640,400},
.rendersize = (HMM_Vec2){640,400},
}; };
static struct window *windows = NULL; static struct window *windows = NULL;

View file

@ -53,8 +53,10 @@ static int sim_play = SIM_PLAY;
static int argc; static int argc;
static char **args; static char **args;
static JSValue c_start; static JSValue c_start = JS_UNDEFINED;
static JSValue c_process_fn; static JSValue c_process_fn = JS_UNDEFINED;
static int PLAYSTART = 0;
void c_init() { void c_init() {
mainwin.start = 1; mainwin.start = 1;
@ -62,13 +64,28 @@ void c_init() {
phys2d_init(); phys2d_init();
render_init(); render_init();
particle_init(); particle_init();
if (!JS_IsUndefined(c_start)) {
script_call_sym(c_start,0,NULL); script_call_sym(c_start,0,NULL);
JS_FreeValue(js, c_start); JS_FreeValue(js, c_start);
}
} }
void c_frame() { void c_frame() {
sfetch_dowork();
#ifdef __EMSCRIPTEN__
if (PLAYSTART)
script_call_sym(c_process_fn,0,NULL); script_call_sym(c_process_fn,0,NULL);
fflush(stdout); 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
} }
void cleanup() void cleanup()
@ -85,6 +102,7 @@ void seghandle()
} }
void c_clean() { void c_clean() {
JS_FreeValue(js, c_process_fn);
cleanup(); cleanup();
gif_rec_end("out.gif"); gif_rec_end("out.gif");
saudio_shutdown(); saudio_shutdown();
@ -199,8 +217,8 @@ static sapp_desc start_desc = {
.frame_cb = c_frame, .frame_cb = c_frame,
.cleanup_cb = c_clean, .cleanup_cb = c_clean,
.event_cb = c_event, .event_cb = c_event,
.logger.func = sg_logging,
.win32_console_create = false, .win32_console_create = false,
.logger.func = sg_logging
}; };
sapp_desc sokol_main(int argc, char **argv) { sapp_desc sokol_main(int argc, char **argv) {
@ -215,6 +233,7 @@ sapp_desc sokol_main(int argc, char **argv) {
stm_setup(); /* time */ stm_setup(); /* time */
script_startup(); script_startup();
#ifndef __EMSCRIPTEN__
int argsize = 0; int argsize = 0;
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
argsize += strlen(argv[i]); argsize += strlen(argv[i]);
@ -229,10 +248,9 @@ sapp_desc sokol_main(int argc, char **argv) {
if (argc > i+1) strcat(cmdstr, " "); if (argc > i+1) strcat(cmdstr, " ");
} }
while (!LOADED_GAME)
sfetch_dowork();
script_evalf("cmd_args('%s');", cmdstr); script_evalf("cmd_args('%s');", cmdstr);
#endif
return start_desc; return start_desc;
} }