Compare commits
4 commits
127569ee03
...
5bb7ea32bf
Author | SHA1 | Date | |
---|---|---|---|
John Alanbrook | 5bb7ea32bf | ||
John Alanbrook | 3b3cb14421 | ||
John Alanbrook | e6ec506512 | ||
John Alanbrook | a7d4dd1406 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -27,6 +27,6 @@ primum*
|
||||||
Prosperon*
|
Prosperon*
|
||||||
prosperon*
|
prosperon*
|
||||||
*.icns
|
*.icns
|
||||||
game.cdb
|
game.zip
|
||||||
icon.ico
|
icon.ico
|
||||||
steam/
|
steam/
|
39
Makefile
39
Makefile
|
@ -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
|
||||||
|
@ -17,6 +21,15 @@ LD = $(CC)
|
||||||
STEAM = steam/sdk
|
STEAM = steam/sdk
|
||||||
STEAMAPI =
|
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)),)
|
||||||
LDFLAGS += -Wl,-rpath=./
|
LDFLAGS += -Wl,-rpath=./
|
||||||
|
@ -42,13 +55,6 @@ ifdef NQOA
|
||||||
CPPFLAGS += -DNQOA
|
CPPFLAGS += -DNQOA
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CC), emcc)
|
|
||||||
LDFLAGS += --closure 1 --emrun --preload-file game.cdb
|
|
||||||
OPT = 0
|
|
||||||
NDEBUG = 1
|
|
||||||
AR = emar
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef NDEBUG
|
ifdef NDEBUG
|
||||||
CPPFLAGS += -DNDEBUG
|
CPPFLAGS += -DNDEBUG
|
||||||
else
|
else
|
||||||
|
@ -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,8 +120,8 @@ 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 -sTOTAL_MEMORY=128MB -sSTACK_SIZE=5MB
|
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
|
||||||
CPPFLAGS += -dNSTEAM -sASSERTIONS=2
|
CPPFLAGS += -DNSTEAM
|
||||||
LDLIBS += GL openal c m dl
|
LDLIBS += GL openal c m dl
|
||||||
STEAMAPI :=
|
STEAMAPI :=
|
||||||
EXT = .html
|
EXT = .html
|
||||||
|
@ -165,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
|
||||||
|
@ -269,11 +274,7 @@ crossmac: Prosperon.icns
|
||||||
|
|
||||||
crossweb:
|
crossweb:
|
||||||
make CC=emcc
|
make CC=emcc
|
||||||
mv $(APP)_$(ARCH).html index.html
|
mv $(APP).html index.html
|
||||||
|
|
||||||
playweb:
|
|
||||||
make crossweb
|
|
||||||
emrun index.html
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo Cleaning project
|
@echo Cleaning project
|
||||||
|
|
10
config.js
Normal file
10
config.js
Normal 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`);
|
|
@ -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]);
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,7 @@ globalThis.say = console.say;
|
||||||
globalThis.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);
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,10 +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(writeout, str);
|
|
||||||
fprintf(stdout, str);
|
fprintf(stdout, str);
|
||||||
#endif
|
fprintf(writeout, str);
|
||||||
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) {
|
||||||
|
|
|
@ -120,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;
|
||||||
|
@ -606,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),
|
||||||
|
@ -621,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));
|
||||||
|
@ -869,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),
|
||||||
|
@ -882,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,
|
||||||
|
@ -1063,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)
|
||||||
{
|
{
|
||||||
|
@ -1107,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)
|
||||||
|
|
|
@ -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},
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -34,10 +34,8 @@ void script_stop()
|
||||||
#ifndef LEAK
|
#ifndef LEAK
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
printf("FREEING CONTEXT\n");
|
|
||||||
|
|
||||||
script_gc();
|
script_gc();
|
||||||
|
|
||||||
JS_FreeContext(js);
|
JS_FreeContext(js);
|
||||||
js = NULL;
|
js = NULL;
|
||||||
JS_FreeRuntime(rt);
|
JS_FreeRuntime(rt);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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()
|
||||||
|
@ -200,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) {
|
||||||
|
@ -216,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]);
|
||||||
|
@ -230,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue