Fix makefile; smaller wasm; generalize widgets
This commit is contained in:
parent
5bb7ea32bf
commit
17d89f6314
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
||||||
.obj/
|
.obj/
|
||||||
bin/
|
bin/
|
||||||
build/
|
build/
|
||||||
|
*.zip
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.d
|
*.d
|
||||||
|
|
46
Makefile
46
Makefile
|
@ -10,29 +10,18 @@ endif
|
||||||
|
|
||||||
CXX:=$(CC)
|
CXX:=$(CC)
|
||||||
|
|
||||||
# Temp to strip long emcc paths to just emcc
|
|
||||||
CC := $(notdir $(CC))
|
|
||||||
|
|
||||||
OPT ?= 0
|
OPT ?= 0
|
||||||
|
|
||||||
INFO :=
|
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
|
|
||||||
STEAM = steam/sdk
|
STEAM = steam/sdk
|
||||||
STEAMAPI =
|
STEAMAPI =
|
||||||
|
|
||||||
ifeq ($(CC), emcc)
|
ifeq ($(CROSS)$(CC), emcc)
|
||||||
LDFLAGS += -sUSE_WEBGPU --shell-file shell.html
|
LDFLAGS += --shell-file shell.html --closure 1
|
||||||
CPPFLAGS += -Wbad-function-cast -Wcast-function-type -sSTACK_SIZE=5MB -sALLOW_MEMORY_GROWTH
|
CPPFLAGS += -Wbad-function-cast -Wcast-function-type -sSTACK_SIZE=1MB -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=128MB
|
||||||
OPT = 0
|
|
||||||
NDEBUG = 1
|
NDEBUG = 1
|
||||||
AR = emar
|
|
||||||
ARCH:= wasm
|
ARCH:= wasm
|
||||||
endif
|
OPT=small
|
||||||
|
|
||||||
CCC != $(CC) -v
|
|
||||||
ifneq ($(findstring clangcc , $(CCC)),)
|
|
||||||
LDFLAGS += -Wl,-rpath=./
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef NEDITOR
|
ifdef NEDITOR
|
||||||
|
@ -68,17 +57,13 @@ ifdef LEAK
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(OPT),small)
|
ifeq ($(OPT),small)
|
||||||
CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections
|
CPPFLAGS += -Os -flto -fno-ident -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections
|
||||||
|
|
||||||
LDFLAGS += -flto
|
LDFLAGS += -flto
|
||||||
|
|
||||||
ifeq ($(CC), emcc)
|
|
||||||
LDFLAGS += --closure 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
INFO :=$(INFO)_small
|
INFO :=$(INFO)_small
|
||||||
else ifeq ($(OPT), 1)
|
else ifeq ($(OPT), 1)
|
||||||
CPPFLAGS += -O2 -flto
|
CPPFLAGS += -O3 -flto
|
||||||
INFO :=$(INFO)_opt
|
INFO :=$(INFO)_opt
|
||||||
else
|
else
|
||||||
CPPFLAGS += -O2
|
CPPFLAGS += -O2
|
||||||
|
@ -103,11 +88,11 @@ ifeq ($(OS), Windows_NT) # then WINDOWS
|
||||||
LDFLAGS += -mwin32 -static
|
LDFLAGS += -mwin32 -static
|
||||||
CPPFLAGS += -mwin32
|
CPPFLAGS += -mwin32
|
||||||
LDLIBS += mingw32 kernel32 d3d11 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m pthread
|
LDLIBS += mingw32 kernel32 d3d11 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m pthread
|
||||||
|
|
||||||
PKGCMD = zip -q -r $(MAKEDIR)/$(DISTDIR)/$(DIST) . -x \*.a ./obj/\*
|
PKGCMD = zip -q -r $(MAKEDIR)/$(DISTDIR)/$(DIST) . -x \*.a ./obj/\*
|
||||||
ZIP = .zip
|
ZIP = .zip
|
||||||
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
||||||
INFO :=$(INFO)_win
|
INFO :=$(INFO)_win
|
||||||
|
EXT = .exe
|
||||||
else ifeq ($(OS), IOS)
|
else ifeq ($(OS), IOS)
|
||||||
CC = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
|
CC = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
|
||||||
SDK = iphoneos
|
SDK = iphoneos
|
||||||
|
@ -118,7 +103,7 @@ else ifeq ($(OS), IOS)
|
||||||
CXXFLAGS += -std=c++11
|
CXXFLAGS += -std=c++11
|
||||||
CFLAGS += -x objective-c
|
CFLAGS += -x objective-c
|
||||||
INFO :=$(INFO)_ios
|
INFO :=$(INFO)_ios
|
||||||
else ifeq ($(CC), emcc) # Then WEB
|
else ifeq ($(OS), wasm) # Then WEB
|
||||||
OS := Web
|
OS := Web
|
||||||
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
|
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
|
||||||
CPPFLAGS += -DNSTEAM
|
CPPFLAGS += -DNSTEAM
|
||||||
|
@ -199,20 +184,20 @@ install: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJS) $(DEPS)
|
$(NAME): $(OBJS) $(DEPS)
|
||||||
@echo Linking $(NAME)
|
@echo Linking $(NAME)
|
||||||
$(LD) $^ $(CPPFLAGS) $(LDFLAGS) -L. $(LDPATHS) $(LDLIBS) -o $@
|
$(CROSS)$(LD) $^ $(CPPFLAGS) $(LDFLAGS) -L. $(LDPATHS) $(LDLIBS) -o $@
|
||||||
@echo Finished build
|
@echo Finished build
|
||||||
|
|
||||||
%$(INFO).o: %.c
|
%$(INFO).o: %.c
|
||||||
@echo Making C object $@
|
@echo Making C object $@
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
$(CROSS)$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
%$(INFO).o: %.cpp
|
%$(INFO).o: %.cpp
|
||||||
@echo Making C++ object $@
|
@echo Making C++ object $@
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -fpermissive -c $< -o $@
|
$(CROSS)$(CXX) $(CPPFLAGS) $(CXXFLAGS) -fpermissive -c $< -o $@
|
||||||
|
|
||||||
%$(INFO).o: %.m
|
%$(INFO).o: %.m
|
||||||
@echo Making Objective-C object $@
|
@echo Making Objective-C object $@
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
$(CROSS)$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
shaders: $(SHADERS)
|
shaders: $(SHADERS)
|
||||||
@echo Making shaders
|
@echo Making shaders
|
||||||
|
@ -246,7 +231,7 @@ icon.ico: $(ICON)
|
||||||
rm $(ICNNAME)
|
rm $(ICNNAME)
|
||||||
|
|
||||||
resource.o: resource.rc resource.manifest icon.ico
|
resource.o: resource.rc resource.manifest icon.ico
|
||||||
windres -i $< -o $@
|
$(CROSS)windres -i $< -o $@
|
||||||
|
|
||||||
crossios:
|
crossios:
|
||||||
make OS=IOS ARCH=arm64 DEBUG=$(DEBUG) OPT=$(OPT)
|
make OS=IOS ARCH=arm64 DEBUG=$(DEBUG) OPT=$(OPT)
|
||||||
|
@ -272,8 +257,11 @@ crossmac: Prosperon.icns
|
||||||
cp Info.plist Prosperon.app/Contents
|
cp Info.plist Prosperon.app/Contents
|
||||||
cp Prosperon.icns Prosperon.app/Contents/Resources
|
cp Prosperon.icns Prosperon.app/Contents/Resources
|
||||||
|
|
||||||
|
crosswin:
|
||||||
|
make CROSS=x86_64-w64-mingw32- OS=Windows_NT CC=gcc
|
||||||
|
|
||||||
crossweb:
|
crossweb:
|
||||||
make CC=emcc
|
make CROSS=em OS=wasm
|
||||||
mv $(APP).html index.html
|
mv $(APP).html index.html
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -1372,129 +1372,6 @@ editor.inputs.s.doc = "Scale selected.";
|
||||||
|
|
||||||
editor.inputs.s.released = function() { this.scalelist = []; };
|
editor.inputs.s.released = function() { this.scalelist = []; };
|
||||||
|
|
||||||
var inputpanel = {
|
|
||||||
title: "untitled",
|
|
||||||
toString() { return this.title; },
|
|
||||||
value: "",
|
|
||||||
on: false,
|
|
||||||
pos:[100,window.size.y-50],
|
|
||||||
wh:[350,600],
|
|
||||||
anchor: [0,1],
|
|
||||||
padding:[5,-15],
|
|
||||||
|
|
||||||
gui() {
|
|
||||||
this.win ??= Mum.window({width:this.wh.x,height:this.wh.y, color:Color.black.alpha(0.1), anchor:this.anchor, padding:this.padding});
|
|
||||||
var itms = this.guibody();
|
|
||||||
if (!Array.isArray(itms)) itms = [itms];
|
|
||||||
if (this.title)
|
|
||||||
this.win.items = [
|
|
||||||
Mum.column({items: [Mum.text({str:this.title}), ...itms ]})
|
|
||||||
];
|
|
||||||
else
|
|
||||||
this.win.items = itms;
|
|
||||||
|
|
||||||
this.win.draw([100, window.size.y-50]);
|
|
||||||
},
|
|
||||||
|
|
||||||
guibody() {
|
|
||||||
return [
|
|
||||||
Mum.text({str:this.value, color:Color.green}),
|
|
||||||
Mum.button({str:"SUBMIT", action:this.submit.bind(this)})
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
open() {
|
|
||||||
this.on = true;
|
|
||||||
this.value = "";
|
|
||||||
this.start();
|
|
||||||
this.keycb();
|
|
||||||
},
|
|
||||||
|
|
||||||
start() {},
|
|
||||||
|
|
||||||
close() {
|
|
||||||
player[0].uncontrol(this);
|
|
||||||
this.on = false;
|
|
||||||
if ('on_close' in this)
|
|
||||||
this.on_close();
|
|
||||||
},
|
|
||||||
|
|
||||||
action() {
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
closeonsubmit: true,
|
|
||||||
submit() {
|
|
||||||
if (!this.submit_check()) return;
|
|
||||||
this.action();
|
|
||||||
if (this.closeonsubmit)
|
|
||||||
this.close();
|
|
||||||
},
|
|
||||||
|
|
||||||
submit_check() { return true; },
|
|
||||||
|
|
||||||
keycb() {},
|
|
||||||
|
|
||||||
caret: 0,
|
|
||||||
|
|
||||||
reset_value() {
|
|
||||||
this.value = "";
|
|
||||||
this.caret = 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
input_backspace_pressrep() {
|
|
||||||
this.value = this.value.slice(0,-1);
|
|
||||||
this.keycb();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
inputpanel.inputs = {};
|
|
||||||
inputpanel.inputs.block = true;
|
|
||||||
|
|
||||||
inputpanel.inputs.post = function() { this.keycb(); }
|
|
||||||
|
|
||||||
inputpanel.inputs.char = function(c) {
|
|
||||||
this.value = this.value.slice(0,this.caret) + c + this.value.slice(this.caret);
|
|
||||||
this.caret++;
|
|
||||||
}
|
|
||||||
inputpanel.inputs['C-d'] = function() { this.value = this.value.slice(0,this.caret) + this.value.slice(this.caret+1); };
|
|
||||||
inputpanel.inputs['C-d'].rep = true;
|
|
||||||
inputpanel.inputs.tab = function() {
|
|
||||||
this.value = tab_complete(this.value, this.assets);
|
|
||||||
this.caret = this.value.length;
|
|
||||||
}
|
|
||||||
inputpanel.inputs.escape = function() { this.close(); }
|
|
||||||
inputpanel.inputs['C-b'] = function() {
|
|
||||||
if (this.caret === 0) return;
|
|
||||||
this.caret--;
|
|
||||||
};
|
|
||||||
inputpanel.inputs['C-b'].rep = true;
|
|
||||||
inputpanel.inputs['C-u'] = function()
|
|
||||||
{
|
|
||||||
this.value = this.value.slice(this.caret);
|
|
||||||
this.caret = 0;
|
|
||||||
}
|
|
||||||
inputpanel.inputs['C-f'] = function() {
|
|
||||||
if (this.caret === this.value.length) return;
|
|
||||||
this.caret++;
|
|
||||||
};
|
|
||||||
inputpanel.inputs['C-f'].rep = true;
|
|
||||||
inputpanel.inputs['C-a'] = function() { this.caret = 0; };
|
|
||||||
inputpanel.inputs['C-e'] = function() { this.caret = this.value.length; };
|
|
||||||
inputpanel.inputs.backspace = function() {
|
|
||||||
if (this.caret === 0) return;
|
|
||||||
this.value = this.value.slice(0,this.caret-1) + this.value.slice(this.caret);
|
|
||||||
this.caret--;
|
|
||||||
};
|
|
||||||
inputpanel.inputs.backspace.rep = true;
|
|
||||||
inputpanel.inputs.enter = function() { this.submit(); }
|
|
||||||
|
|
||||||
inputpanel.inputs['C-k'] = function() {
|
|
||||||
this.value = this.value.slice(0,this.caret);
|
|
||||||
};
|
|
||||||
|
|
||||||
inputpanel.inputs.lm = function() { gui.controls.check_submit(); }
|
|
||||||
|
|
||||||
var replpanel = Object.copy(inputpanel, {
|
var replpanel = Object.copy(inputpanel, {
|
||||||
title: "",
|
title: "",
|
||||||
closeonsubmit:false,
|
closeonsubmit:false,
|
||||||
|
@ -1579,11 +1456,11 @@ replpanel.inputs.tab = function() {
|
||||||
|
|
||||||
var comp = "";
|
var comp = "";
|
||||||
if (stub)
|
if (stub)
|
||||||
comp = tab_complete(stub, keys);
|
comp = input.tabcomplete(stub, keys);
|
||||||
else if (!this.value.includes('.'))
|
else if (!this.value.includes('.'))
|
||||||
comp = tab_complete(o, keys);
|
comp = input.tabcomplete(o, keys);
|
||||||
else
|
else
|
||||||
comp = tab_complete("",keys);
|
comp = input.tabcomplete("",keys);
|
||||||
|
|
||||||
if (stub)
|
if (stub)
|
||||||
this.value = o + '.' + comp;
|
this.value = o + '.' + comp;
|
||||||
|
@ -1848,33 +1725,6 @@ var quitpanel = Object.copy(inputpanel, {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var notifypanel = Object.copy(inputpanel, {
|
|
||||||
title: "notification",
|
|
||||||
msg: "Refusing to save. File already exists.",
|
|
||||||
action() {
|
|
||||||
this.close();
|
|
||||||
},
|
|
||||||
|
|
||||||
guibody() {
|
|
||||||
return Mum.column({items: [
|
|
||||||
Mum.text({str:this.msg}),
|
|
||||||
Mum.button({str:"OK", action:this.close.bind(this)})
|
|
||||||
]});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
var gen_notify = function(val, fn) {
|
|
||||||
var panel = Object.create(notifypanel);
|
|
||||||
panel.msg = val;
|
|
||||||
panel.yes = fn;
|
|
||||||
panel.inputs = {};
|
|
||||||
panel.inputs.y = function() { panel.yes(); panel.close(); };
|
|
||||||
panel.inputs.y.doc = "Confirm yes.";
|
|
||||||
panel.inputs.enter = function() { panel.close(); };
|
|
||||||
panel.inputs.enter.doc = "Close.";
|
|
||||||
return panel;
|
|
||||||
};
|
|
||||||
|
|
||||||
var allfiles = [];
|
var allfiles = [];
|
||||||
allfiles.push(Resources.scripts, Resources.images, Resources.sounds);
|
allfiles.push(Resources.scripts, Resources.images, Resources.sounds);
|
||||||
allfiles = allfiles.flat();
|
allfiles = allfiles.flat();
|
||||||
|
@ -1904,29 +1754,6 @@ var componentexplorer = Object.copy(inputpanel, {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function tab_complete(val, list) {
|
|
||||||
if (!val) return val;
|
|
||||||
list.dofilter(function(x) { return x.startsWith(val); });
|
|
||||||
|
|
||||||
if (list.length === 1) {
|
|
||||||
return list[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
var ret = undefined;
|
|
||||||
var i = val.length;
|
|
||||||
while (!ret && !Object.empty(list)) {
|
|
||||||
var char = list[0][i];
|
|
||||||
if (!list.every(function(x) { return x[i] === char; }))
|
|
||||||
ret = list[0].slice(0, i);
|
|
||||||
else {
|
|
||||||
i++;
|
|
||||||
list.dofilter(function(x) { return x.length-1 > i; });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret ? ret : val;
|
|
||||||
}
|
|
||||||
|
|
||||||
var entitylistpanel = Object.copy(inputpanel, {
|
var entitylistpanel = Object.copy(inputpanel, {
|
||||||
title: "Level object list",
|
title: "Level object list",
|
||||||
level: {},
|
level: {},
|
||||||
|
|
|
@ -254,6 +254,9 @@ global.check_registers = function(obj)
|
||||||
if (typeof obj.gui === 'function')
|
if (typeof obj.gui === 'function')
|
||||||
obj.timers.push(Register.gui.register(obj.gui.bind(obj)));
|
obj.timers.push(Register.gui.register(obj.gui.bind(obj)));
|
||||||
|
|
||||||
|
if (typeof obj.screengui === 'function')
|
||||||
|
obj.timers.push(Register.screengui.register(obj.screengui.bind(obj)));
|
||||||
|
|
||||||
for (var k in obj) {
|
for (var k in obj) {
|
||||||
if (!k.startswith("on_")) continue;
|
if (!k.startswith("on_")) continue;
|
||||||
var signal = k.fromfirst("on_");
|
var signal = k.fromfirst("on_");
|
||||||
|
@ -335,9 +338,12 @@ function process()
|
||||||
debug.draw(); // calls needed debugs
|
debug.draw(); // calls needed debugs
|
||||||
render.flush();
|
render.flush();
|
||||||
|
|
||||||
render.set_window();
|
render.hud_res(window.rendersize);
|
||||||
prosperon.gui();
|
prosperon.gui();
|
||||||
render.flush();
|
render.flush();
|
||||||
|
render.hud_res(window.size);
|
||||||
|
prosperon.screengui();
|
||||||
|
render.flush();
|
||||||
|
|
||||||
render.end_pass();
|
render.end_pass();
|
||||||
}
|
}
|
||||||
|
@ -379,7 +385,7 @@ game.tag_clear_guid = function(guid)
|
||||||
|
|
||||||
game.objects_with_tag = function(tag)
|
game.objects_with_tag = function(tag)
|
||||||
{
|
{
|
||||||
if (!game.tags[tag]) return;
|
if (!game.tags[tag]) return [];
|
||||||
return Object.values(game.tags[tag]);
|
return Object.values(game.tags[tag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,6 +551,7 @@ Register.add_cb("physupdate");
|
||||||
Register.add_cb("gui");
|
Register.add_cb("gui");
|
||||||
Register.add_cb("debug");
|
Register.add_cb("debug");
|
||||||
Register.add_cb("draw");
|
Register.add_cb("draw");
|
||||||
|
Register.add_cb("screengui");
|
||||||
|
|
||||||
var Event = {
|
var Event = {
|
||||||
events: {},
|
events: {},
|
||||||
|
@ -611,6 +618,9 @@ function world_start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
global.mixin("scripts/physics");
|
global.mixin("scripts/physics");
|
||||||
|
global.mixin("scripts/widget");
|
||||||
|
|
||||||
|
globalThis.mum = app.spawn("scripts/mum");
|
||||||
|
|
||||||
window.title = `Prosperon v${prosperon.version}`;
|
window.title = `Prosperon v${prosperon.version}`;
|
||||||
window.size = [500,500];
|
window.size = [500,500];
|
||||||
|
|
|
@ -245,6 +245,29 @@ input.action = {
|
||||||
actions: [],
|
actions: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
input.tabcomplete = function(val, list) {
|
||||||
|
if (!val) return val;
|
||||||
|
list.dofilter(function(x) { return x.startsWith(val); });
|
||||||
|
|
||||||
|
if (list.length === 1) {
|
||||||
|
return list[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = undefined;
|
||||||
|
var i = val.length;
|
||||||
|
while (!ret && !Object.empty(list)) {
|
||||||
|
var char = list[0][i];
|
||||||
|
if (!list.every(function(x) { return x[i] === char; }))
|
||||||
|
ret = list[0].slice(0, i);
|
||||||
|
else {
|
||||||
|
i++;
|
||||||
|
list.dofilter(function(x) { return x.length-1 > i; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret ? ret : val;
|
||||||
|
}
|
||||||
|
|
||||||
/* May be a human player; may be an AI player */
|
/* May be a human player; may be an AI player */
|
||||||
var Player = {
|
var Player = {
|
||||||
players: [],
|
players: [],
|
||||||
|
|
21
scripts/mum.js
Normal file
21
scripts/mum.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
var panel;
|
||||||
|
|
||||||
|
self.screengui = function()
|
||||||
|
{
|
||||||
|
if (panel) panel.gui();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.prompt = function(msg = "prompt", value = "", list = [], cb = function() {})
|
||||||
|
{
|
||||||
|
console.info(`creating popup`);
|
||||||
|
panel = Object.create(listpanel);
|
||||||
|
panel.title = msg;
|
||||||
|
panel.value = value;
|
||||||
|
panel.allassets = list;
|
||||||
|
panel.action = function() {
|
||||||
|
cb(panel.value);
|
||||||
|
panel = undefined;
|
||||||
|
}
|
||||||
|
panel.start();
|
||||||
|
player[0].control(panel);
|
||||||
|
}
|
|
@ -44,7 +44,7 @@ os.openurl = function(url) {
|
||||||
os.system(`open ${url}`);
|
os.system(`open ${url}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var projectfile = ".prosperon/project.json";
|
var projectfile = "project.prosperon";
|
||||||
|
|
||||||
Resources.is_sound = function(path) {
|
Resources.is_sound = function(path) {
|
||||||
var ext = path.ext();
|
var ext = path.ext();
|
||||||
|
@ -204,29 +204,31 @@ Cmdline.register_order("edit", function() {
|
||||||
}, "Edit the project in this folder. Give it the name of an UR to edit that specific object.", "?UR?");
|
}, "Edit the project in this folder. Give it the name of an UR to edit that specific object.", "?UR?");
|
||||||
|
|
||||||
Cmdline.register_order("init", function() {
|
Cmdline.register_order("init", function() {
|
||||||
say('top of init');
|
|
||||||
if (io.exists(projectfile)) {
|
if (io.exists(projectfile)) {
|
||||||
say("Already a game here.");
|
say("Already a game here.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
say('top of ls');
|
|
||||||
if (!(io.ls().length === 0)) {
|
if (!(io.ls().length === 0)) {
|
||||||
say("Directory is not empty. Make an empty one and init there.");
|
say("Directory is not empty. Make an empty one and init there.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
say('top of mkdir');
|
|
||||||
io.mkdir(".prosperon");
|
io.mkdir(".prosperon");
|
||||||
var project = {};
|
var project = {};
|
||||||
project.version = prosperon.version;
|
project.version = prosperon.version;
|
||||||
project.revision = prosperon.revision;
|
project.revision = prosperon.revision;
|
||||||
io.slurpwrite(projectfile, json.encode(project));
|
io.slurpwrite(projectfile, json.encode(project));
|
||||||
|
|
||||||
}, "Turn the directory into a Prosperon game.");
|
}, "Turn the directory into a Prosperon game.");
|
||||||
|
|
||||||
Cmdline.register_order("debug", function() {
|
Cmdline.register_order("debug", function() {
|
||||||
Cmdline.orders.play([]);
|
Cmdline.orders.play([]);
|
||||||
}, "Play the game with debugging enabled.");
|
}, "Play the game with debugging enabled.");
|
||||||
|
|
||||||
|
Cmdline.register_order("web", function() {
|
||||||
|
Cmdline.orders.play([]);
|
||||||
|
}, "Play the game in a web browser.");
|
||||||
|
|
||||||
Cmdline.register_order("play", function(argv) {
|
Cmdline.register_order("play", function(argv) {
|
||||||
if (argv[0])
|
if (argv[0])
|
||||||
io.chdir(argv[0]);
|
io.chdir(argv[0]);
|
||||||
|
@ -244,7 +246,6 @@ 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}.`);
|
||||||
|
|
||||||
|
|
192
scripts/widget.js
Normal file
192
scripts/widget.js
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
|
||||||
|
var inputpanel = {
|
||||||
|
title: "untitled",
|
||||||
|
toString() { return this.title; },
|
||||||
|
value: "",
|
||||||
|
on: false,
|
||||||
|
pos:[20,window.size.y-20],
|
||||||
|
wh:[100,100],
|
||||||
|
anchor: [0,1],
|
||||||
|
padding:[5,-15],
|
||||||
|
|
||||||
|
gui() {
|
||||||
|
this.win ??= Mum.window({width:this.wh.x,height:this.wh.y, color:Color.black.alpha(0.1), anchor:this.anchor, padding:this.padding});
|
||||||
|
var itms = this.guibody();
|
||||||
|
if (!Array.isArray(itms)) itms = [itms];
|
||||||
|
if (this.title)
|
||||||
|
this.win.items = [
|
||||||
|
Mum.column({items: [Mum.text({str:this.title}), ...itms ]})
|
||||||
|
];
|
||||||
|
else
|
||||||
|
this.win.items = itms;
|
||||||
|
|
||||||
|
this.win.draw([100, window.size.y-50]);
|
||||||
|
},
|
||||||
|
|
||||||
|
guibody() {
|
||||||
|
return [
|
||||||
|
Mum.text({str:this.value, color:Color.green}),
|
||||||
|
Mum.button({str:"SUBMIT", action:this.submit.bind(this)})
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
open() {
|
||||||
|
this.on = true;
|
||||||
|
this.value = "";
|
||||||
|
this.start();
|
||||||
|
this.keycb();
|
||||||
|
},
|
||||||
|
|
||||||
|
start() {},
|
||||||
|
|
||||||
|
close() {
|
||||||
|
player[0].uncontrol(this);
|
||||||
|
this.on = false;
|
||||||
|
if ('on_close' in this)
|
||||||
|
this.on_close();
|
||||||
|
},
|
||||||
|
|
||||||
|
action() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
closeonsubmit: true,
|
||||||
|
submit() {
|
||||||
|
if (!this.submit_check()) return;
|
||||||
|
this.action();
|
||||||
|
if (this.closeonsubmit)
|
||||||
|
this.close();
|
||||||
|
},
|
||||||
|
|
||||||
|
submit_check() { return true; },
|
||||||
|
|
||||||
|
keycb() {},
|
||||||
|
|
||||||
|
caret: 0,
|
||||||
|
|
||||||
|
reset_value() {
|
||||||
|
this.value = "";
|
||||||
|
this.caret = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
input_backspace_pressrep() {
|
||||||
|
this.value = this.value.slice(0,-1);
|
||||||
|
this.keycb();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
inputpanel.inputs = {};
|
||||||
|
inputpanel.inputs.block = true;
|
||||||
|
|
||||||
|
inputpanel.inputs.post = function() { this.keycb(); }
|
||||||
|
|
||||||
|
inputpanel.inputs.char = function(c) {
|
||||||
|
this.value = this.value.slice(0,this.caret) + c + this.value.slice(this.caret);
|
||||||
|
this.caret++;
|
||||||
|
}
|
||||||
|
inputpanel.inputs['C-d'] = function() { this.value = this.value.slice(0,this.caret) + this.value.slice(this.caret+1); };
|
||||||
|
inputpanel.inputs['C-d'].rep = true;
|
||||||
|
inputpanel.inputs.tab = function() {
|
||||||
|
this.value = input.tabcomplete(this.value, this.assets);
|
||||||
|
this.caret = this.value.length;
|
||||||
|
}
|
||||||
|
inputpanel.inputs.escape = function() { this.close(); }
|
||||||
|
inputpanel.inputs['C-b'] = function() {
|
||||||
|
if (this.caret === 0) return;
|
||||||
|
this.caret--;
|
||||||
|
};
|
||||||
|
inputpanel.inputs['C-b'].rep = true;
|
||||||
|
inputpanel.inputs['C-u'] = function()
|
||||||
|
{
|
||||||
|
this.value = this.value.slice(this.caret);
|
||||||
|
this.caret = 0;
|
||||||
|
}
|
||||||
|
inputpanel.inputs['C-f'] = function() {
|
||||||
|
if (this.caret === this.value.length) return;
|
||||||
|
this.caret++;
|
||||||
|
};
|
||||||
|
inputpanel.inputs['C-f'].rep = true;
|
||||||
|
inputpanel.inputs['C-a'] = function() { this.caret = 0; };
|
||||||
|
inputpanel.inputs['C-e'] = function() { this.caret = this.value.length; };
|
||||||
|
inputpanel.inputs.backspace = function() {
|
||||||
|
if (this.caret === 0) return;
|
||||||
|
this.value = this.value.slice(0,this.caret-1) + this.value.slice(this.caret);
|
||||||
|
this.caret--;
|
||||||
|
};
|
||||||
|
inputpanel.inputs.backspace.rep = true;
|
||||||
|
inputpanel.inputs.enter = function() { this.submit(); }
|
||||||
|
|
||||||
|
inputpanel.inputs['C-k'] = function() {
|
||||||
|
this.value = this.value.slice(0,this.caret);
|
||||||
|
};
|
||||||
|
|
||||||
|
inputpanel.inputs.lm = function() { gui.controls.check_submit(); }
|
||||||
|
|
||||||
|
var notifypanel = Object.copy(inputpanel, {
|
||||||
|
title: "notification",
|
||||||
|
msg: "Refusing to save. File already exists.",
|
||||||
|
action() {
|
||||||
|
this.close();
|
||||||
|
},
|
||||||
|
|
||||||
|
guibody() {
|
||||||
|
return Mum.column({items: [
|
||||||
|
Mum.text({str:this.msg}),
|
||||||
|
Mum.button({str:"OK", action:this.close.bind(this)})
|
||||||
|
]});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
var gen_notify = function(val, fn) {
|
||||||
|
var panel = Object.create(notifypanel);
|
||||||
|
panel.msg = val;
|
||||||
|
panel.yes = fn;
|
||||||
|
panel.inputs = {};
|
||||||
|
panel.inputs.y = function() { panel.yes(); panel.close(); };
|
||||||
|
panel.inputs.y.doc = "Confirm yes.";
|
||||||
|
panel.inputs.enter = function() { panel.close(); };
|
||||||
|
panel.inputs.enter.doc = "Close.";
|
||||||
|
return panel;
|
||||||
|
};
|
||||||
|
|
||||||
|
var listpanel = Object.copy(inputpanel, {
|
||||||
|
assets: [],
|
||||||
|
allassets: [],
|
||||||
|
mumlist: {},
|
||||||
|
|
||||||
|
submit_check() {
|
||||||
|
if (this.assets.length === 0) return false;
|
||||||
|
|
||||||
|
this.value = this.assets[0];
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
start() {
|
||||||
|
this.assets = this.allassets.slice();
|
||||||
|
this.caret = 0;
|
||||||
|
this.mumlist = [];
|
||||||
|
this.assets.forEach(function(x) {
|
||||||
|
this.mumlist[x] = Mum.text({str:x, action:this.action, color: Color.blue, hovered: {color:Color.red}, selectable:true});
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
|
||||||
|
keycb() {
|
||||||
|
if(this.value)
|
||||||
|
this.assets = this.allassets.filter(x => x.startswith(this.value));
|
||||||
|
else
|
||||||
|
this.assets = this.allassets.slice();
|
||||||
|
for (var m in this.mumlist)
|
||||||
|
this.mumlist[m].hide = true;
|
||||||
|
this.assets.forEach(function(x) {
|
||||||
|
this.mumlist[x].hide = false;
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
|
||||||
|
guibody() {
|
||||||
|
var a = [Mum.text({str:this.value,color:Color.green, caret:this.caret})];
|
||||||
|
var b = a.concat(Object.values(this.mumlist));
|
||||||
|
return Mum.column({items:b, offset:[0,-10]});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {inputpanel, gen_notify, notifypanel, listpanel}
|
62
shell.html
Normal file
62
shell.html
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Emscripten-Generated Code</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
#canvas-container {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type='text/javascript'>
|
||||||
|
window.onload = function () { window.focus(); }
|
||||||
|
window.onclick = function () { window.focus(); }
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="canvas-container">
|
||||||
|
<canvas class="game" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var Module = {
|
||||||
|
preRun: [],
|
||||||
|
postRun: [],
|
||||||
|
print: (function() {
|
||||||
|
return function(text) {
|
||||||
|
text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
console.log(text);
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
printErr: function(text) {
|
||||||
|
text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
console.error(text);
|
||||||
|
},
|
||||||
|
canvas: (function() {
|
||||||
|
var canvas = document.getElementById('canvas');
|
||||||
|
canvas.addEventListener("webglcontextlost", function(e) { alert('FIXME: WebGL context lost, please reload the page'); e.preventDefault(); }, false);
|
||||||
|
return canvas;
|
||||||
|
})(),
|
||||||
|
setStatus: function(text) { },
|
||||||
|
monitorRunDependencies: function(left) { },
|
||||||
|
};
|
||||||
|
window.onerror = function(event) {
|
||||||
|
console.log("onerror: " + event.message);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
{{{ SCRIPT }}}
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -610,7 +610,10 @@ 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_hud_res,
|
||||||
|
HMM_Vec2 xy = js2vec2(argv[0]);
|
||||||
|
useproj = HMM_Orthographic_LH_ZO(0, xy.x, 0, xy.y, -1, 1);
|
||||||
|
)
|
||||||
JSC_CCALL(render_clear_color,
|
JSC_CCALL(render_clear_color,
|
||||||
sg_color c;
|
sg_color c;
|
||||||
rgba2floats(&c, js2color(argv[0]));
|
rgba2floats(&c, js2color(argv[0]));
|
||||||
|
@ -630,7 +633,7 @@ static const JSCFunctionListEntry js_render_funcs[] = {
|
||||||
MIST_FUNC_DEF(render, end_pass, 0),
|
MIST_FUNC_DEF(render, end_pass, 0),
|
||||||
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, hud_res, 1),
|
||||||
MIST_FUNC_DEF(render, clear_color, 1),
|
MIST_FUNC_DEF(render, clear_color, 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -304,8 +304,6 @@ HMM_Mat4 projection = {0.f};
|
||||||
HMM_Mat4 hudproj = {0.f};
|
HMM_Mat4 hudproj = {0.f};
|
||||||
HMM_Mat4 useproj = {0};
|
HMM_Mat4 useproj = {0};
|
||||||
|
|
||||||
HMM_Vec3 dirl_pos = {4, 100, 20};
|
|
||||||
|
|
||||||
#define MODE_STRETCH 0
|
#define MODE_STRETCH 0
|
||||||
#define MODE_KEEP 1
|
#define MODE_KEEP 1
|
||||||
#define MODE_WIDTH 2
|
#define MODE_WIDTH 2
|
||||||
|
@ -357,8 +355,6 @@ void openglRender(struct window *window, gameobject *cam, float zoom) {
|
||||||
campos.y - camzoom * usesize.y / 2,
|
campos.y - camzoom * usesize.y / 2,
|
||||||
campos.y + camzoom * usesize.y / 2, -10000.f, 10000.f);
|
campos.y + camzoom * usesize.y / 2, -10000.f, 10000.f);
|
||||||
|
|
||||||
hudproj = HMM_Orthographic_LH_ZO(0, usesize.x, 0, usesize.y, -1.f, 1.f);
|
|
||||||
|
|
||||||
/* if (gif.rec && (apptime() - gif.timer) > gif.spf) {
|
/* if (gif.rec && (apptime() - gif.timer) > gif.spf) {
|
||||||
sg_begin_pass(&(sg_pass){
|
sg_begin_pass(&(sg_pass){
|
||||||
.action = pass_action,
|
.action = pass_action,
|
||||||
|
|
|
@ -195,6 +195,9 @@ void pack_end()
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
void pack_start(const char *name){}
|
||||||
|
void pack_add(const char *path){}
|
||||||
|
void pack_end() {}
|
||||||
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; }
|
||||||
|
|
Loading…
Reference in a new issue