start steam integration; bug fixes

This commit is contained in:
John Alanbrook 2023-11-20 13:49:14 +00:00
parent cccd472f12
commit ec8b3c97c4
13 changed files with 150 additions and 63 deletions

View file

@ -5,6 +5,9 @@ MAKEDIR != pwd
# Options # Options
# DBG --- build with debugging symbols and logging # DBG --- build with debugging symbols and logging
ifeq ($(CC),cc)
CC=clang
endif
# Temp to strip long emcc paths to just emcc # Temp to strip long emcc paths to just emcc
CC := $(notdir $(CC)) CC := $(notdir $(CC))
@ -14,9 +17,9 @@ OPT ?= 0
INFO := INFO :=
LD = $(CC) LD = $(CC)
ifeq ($(CC), clang) #ifeq ($(CC), clang)
AR = llvm-ar # AR = llvm-ar
endif #endif
ifeq ($(CC), x86_64-w64-mingw32-gcc) ifeq ($(CC), x86_64-w64-mingw32-gcc)
AR = x86_64-w64-mingw32-ar AR = x86_64-w64-mingw32-ar
endif endif
@ -63,6 +66,7 @@ endif
CFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" CFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\"
PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) . PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) .
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)
@ -80,11 +84,13 @@ ifeq ($(OS), Windows_NT)
PKGCMD = cd $(BIN); zip -q -r $(MAKEDIR)/$(DISTDIR)/$(DIST) . -x \*.a ./obj/\* PKGCMD = cd $(BIN); 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)
else ifeq ($(OS), ios) else ifeq ($(OS), ios)
TTARGET = arm64-apple-ios13.1 TTARGET = arm64-apple-ios13.1
SYSRT := /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk SYSRT := /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
CFLAGS += --target=$(TTARGET) -isysroot $(SYSRT) -DTARGET_OS_IPHONE -x objective-c CFLAGS += --target=$(TTARGET) -isysroot $(SYSRT) -DTARGET_OS_IPHONE -x objective-c
LDFLAGS += --target=$(TTARGET) -isysroot $(SYSRT) -framework Foundation -framework UIKit -framework Metal -framework MetalKit -framework AudioToolbox -framework AVFoundation LDFLAGS += --target=$(TTARGET) -isysroot $(SYSRT) -framework Foundation -framework UIKit -framework Metal -framework MetalKit -framework AudioToolbox -framework AVFoundation
else ifeq ($(CC), emcc) else ifeq ($(CC), emcc)
OS := Web OS := Web
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sTOTAL_MEMORY=450MB LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sTOTAL_MEMORY=450MB
@ -92,6 +98,7 @@ else ifeq ($(CC), emcc)
LDLIBS += pthread quickjs GL openal c m dl LDLIBS += pthread quickjs GL openal c m dl
CC = emcc CC = emcc
EXT = .html EXT = .html
else else
UNAME != uname -s UNAME != uname -s
ifeq ($(UNAME), Linux) ifeq ($(UNAME), Linux)
@ -113,7 +120,11 @@ OBJDIR = $(BIN)/obj
# All other sources # All other sources
OBJS != find source/engine -type f -name '*.c' OBJS != find source/engine -type f -name '*.c'
#OBJS += $(shell find source/engine -type f -name '*.cpp')
OBJS += $(shell find source/engine -type f -name '*.m')
#OBJS := $(patsubst %.cpp, %.o, $(OBJS))
OBJS := $(patsubst %.c, %.o,$(OBJS)) OBJS := $(patsubst %.c, %.o,$(OBJS))
OBJS := $(patsubst %.m, %.o, $(OBJS))
OBJS := $(addprefix $(BIN)/obj/, $(OBJS)) OBJS := $(addprefix $(BIN)/obj/, $(OBJS))
engineincs != find source/engine -maxdepth 1 -type d engineincs != find source/engine -maxdepth 1 -type d
@ -121,7 +132,15 @@ includeflag != find source -type d -name include
includeflag += $(engineincs) source/engine/thirdparty/tinycdb source/shaders includeflag += $(engineincs) source/engine/thirdparty/tinycdb source/shaders
includeflag := $(addprefix -I, $(includeflag)) includeflag := $(addprefix -I, $(includeflag))
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function -Wno-unused-const-variable # Adding different SDKs
ifdef STEAM
LDLIBS += steam_api
LDPATHS += steam/sdk/redistributable_bin/osx
includeflag += -Isteam/sdk/public
CFLAGS += -DSTEAM
endif
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function -Wno-unused-const-variable -Wno-address-of-temporary
NAME = primum$(EXT) NAME = primum$(EXT)
SEM = 0.0.1 SEM = 0.0.1
@ -129,6 +148,7 @@ COM != fossil describe
VER = $(SEM)-$(COM) VER = $(SEM)-$(COM)
LDLIBS := $(addprefix -l, $(LDLIBS)) LDLIBS := $(addprefix -l, $(LDLIBS))
LDPATHS := $(addprefix -L, $(LDPATHS))
DEPENDS = $(OBJS:.o=.d) DEPENDS = $(OBJS:.o=.d)
-include $(DEPENDS) -include $(DEPENDS)
@ -152,7 +172,7 @@ install: $(BIN)/$(NAME)
$(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a $(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a
@echo Linking $(NAME) @echo Linking $(NAME)
$(LD) $^ $(LDFLAGS) -L$(BIN) $(LDLIBS) -o $@ $(LD) $^ $(LDFLAGS) -L$(BIN) $(LDPATHS) $(LDLIBS) -o $@
@echo Finished build @echo Finished build
$(DISTDIR)/$(DIST): $(BIN)/$(NAME) $(DISTDIR)/$(DIST): $(BIN)/$(NAME)
@ -196,9 +216,9 @@ input.md: $(INPUTMD)
@echo Printing api for $* @echo Printing api for $*
@./primum -d $* > $@ @./primum -d $* > $@
$(BIN)/libquickjs.a: $(BIN)/libquickjs.a: $(QUICKJS_O)
make -C quickjs clean make -C quickjs clean
make -C quickjs SYSRT=$(SYSRT) TTARGET=$(TTARGET) ARCH=$(ARCH) DBG=$(DBG) OPT=$(OPT) HOST_CC=$(CC) CCC=$(CC) AR=$(AR) libquickjs.a libquickjs.lto.a CC=$(CC) make -C quickjs SYSRT=$(SYSRT) TTARGET=$(TTARGET) ARCH=$(ARCH) DBG=$(DBG) OPT=$(OPT) AR=$(AR) OS=$(OS) libquickjs.a libquickjs.lto.a HOST_CC=$(CC)
@mkdir -p $(BIN) @mkdir -p $(BIN)
cp -rf quickjs/libquickjs.* $(BIN) cp -rf quickjs/libquickjs.* $(BIN)
@ -207,6 +227,16 @@ $(OBJDIR)/%.o: %.c
@echo Making C object $@ @echo Making C object $@
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: %.cpp
@mkdir -p $(@D)
@echo Making C++ object $@
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: %.m
@mkdir -p $(@D)
@echo Making Objective-C object $@
@$(CC) $(CFLAGS) -c $< -o $@
shaders: $(SHADERS) shaders: $(SHADERS)
@echo Making shaders @echo Making shaders

View file

@ -15,3 +15,6 @@ For these controls, pawn control order can matter. Pawns that are controlled lat
## actions & input maps ## actions & input maps
Actions are a named input, ideal for game controls. Rather than say that "x" jumps, it might be better to name a "jump" action. Actions are a named input, ideal for game controls. Rather than say that "x" jumps, it might be better to name a "jump" action.
## Blocking
If 'block' is set to false on the input object, it will not block lower inputs from using the controls.

View file

@ -22,6 +22,16 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
ifeq ($(shell uname -s),Darwin)
ifeq ($(HOST_CC),clang)
CFLAGS += -arch $(ARCH)
endif
endif
$(info $$CFLAGS is [${CFLAGS}])
$(info HOST_CC is $(HOST_CC))
$(info shell is $(shell uname -s))
# Windows cross compilation from Linux # Windows cross compilation from Linux
#CONFIG_WIN32=y #CONFIG_WIN32=y
# use link time optimization (smaller and faster executables but slower build) # use link time optimization (smaller and faster executables but slower build)
@ -32,7 +42,7 @@ CONFIG_LTO=y
#CONFIG_M32=y #CONFIG_M32=y
# use clang instead of gcc # use clang instead of gcc
ifeq ($(CCC),clang) ifeq ($(HOST_CC),clang)
CONFIG_CLANG=y CONFIG_CLANG=y
CONFIG_DEFAULT_AR=y CONFIG_DEFAULT_AR=y
endif endif
@ -61,7 +71,7 @@ else
CROSS_PREFIX= CROSS_PREFIX=
EXE= EXE=
endif endif
ifeq ($(CCC), clang) ifeq ($(CC), clang)
CC=$(CROSS_PREFIX)clang CC=$(CROSS_PREFIX)clang
CFLAGS += -g -Wall -MMD -MF $(OBJDIR)/$(@F).d CFLAGS += -g -Wall -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS += -Wextra CFLAGS += -Wextra
@ -73,7 +83,6 @@ ifeq ($(CCC), clang)
CFLAGS += -Wwrite-strings CFLAGS += -Wwrite-strings
CFLAGS += -Wchar-subscripts -funsigned-char CFLAGS += -Wchar-subscripts -funsigned-char
CFLAGS += -MMD -MF $(OBJDIR)/$(@F).d CFLAGS += -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS += -arch $(ARCH)
ifneq ($(TTARGET),) ifneq ($(TTARGET),)
CFLAGS += --target=$(TTARGET) CFLAGS += --target=$(TTARGET)
CFLAGS += -isysroot $(SYSRT) CFLAGS += -isysroot $(SYSRT)

View file

@ -53,7 +53,7 @@ var editor = {
/* Tries to select id */ /* Tries to select id */
do_select(go) { do_select(go) {
var obj = go >= 0 ? Game.object(go) : undefined; var obj = (go >= 0 ? Game.object(go) : undefined);
if (!obj || !obj._ed.selectable) return undefined; if (!obj || !obj._ed.selectable) return undefined;
if (obj.level !== this.edit_level) { if (obj.level !== this.edit_level) {
@ -273,14 +273,17 @@ var editor = {
}, },
snapshot() { snapshot() {
var cur = this.edit_level.json_obj(); var dif = this.edit_level.json_obj();
var dif = ediff(cur, this.curlvl); if (!dif) return;
if (dif.empty) return; if (this.snapshots.length !== 0) {
var ddif = ediff(dif, this.snapshots.last);
if (!ddif) return;
dif = ddif;
}
this.snapshots.push(this.curlvl); this.snapshots.push(dif);
this.backshots = []; this.backshots = [];
this.curlvl = cur;
return; return;
this.snapshots.push(dif); this.snapshots.push(dif);
@ -342,12 +345,10 @@ var editor = {
return; return;
} }
this.unselect(); this.unselect();
this.backshots.push(this.edit_level.save()); // this.backshots.push(this.edit_level.save());
var dd = this.snapshots.pop(); var dd = this.snapshots.pop();
this.edit_level.clear(); Object.dainty_assign(this.edit_level, dd);
this.edit_level.load(dd); this.edit_level._ed.check_dirty();
this.edit_level.check_dirty();
this.curlvl = dd;
return; return;
this.backshots.push(dd); this.backshots.push(dd);
@ -487,9 +488,9 @@ var editor = {
x._ed.check_dirty(); x._ed.check_dirty();
if (x._ed.dirty) sname += "*"; if (x._ed.dirty) sname += "*";
GUI.text(sname, world2screen(x.worldpos()).add([0, 16]), 1, Color.editor.ur); GUI.text(sname, world2screen(x.worldpos()).add([0, 32]), 1, Color.editor.ur);
GUI.text(x.worldpos().map(function(x) { return Math.round(x); }), world2screen(x.worldpos()), 1, Color.white); GUI.text(x.worldpos().map(function(x) { return Math.round(x); }), world2screen(x.worldpos()), 1, Color.white);
Debug.arrow(world2screen(x.worldpos()), world2screen(x.worldpos().add(x.up().scale(40))), Color.yellow, 1); // Debug.arrow(world2screen(x.worldpos()), world2screen(x.worldpos().add(x.up().scale(40))), Color.yellow, 1);
if ('gizmo' in x && typeof x['gizmo'] === 'function' ) if ('gizmo' in x && typeof x['gizmo'] === 'function' )
x.gizmo(); x.gizmo();
@ -497,7 +498,7 @@ var editor = {
Object.entries(thiso.objects).forEach(function(x) { Object.entries(thiso.objects).forEach(function(x) {
var p = x[1]._ed.namestr(); var p = x[1]._ed.namestr();
GUI.text(p, world2screen(x[1].worldpos()),1,editor.color_depths[depth]); GUI.text(p, world2screen(x[1].worldpos().add([0,16])),1,editor.color_depths[depth]);
}); });
var mg = Game.obj_at(Mouse.worldpos); var mg = Game.obj_at(Mouse.worldpos);
@ -670,7 +671,7 @@ editor.inputs.post = function() {
}; };
editor.inputs.release_post = function() { editor.inputs.release_post = function() {
editor.snapshot(); editor.snapshot();
editor.edit_level.check_dirty(); editor.edit_level._ed.check_dirty();
}; };
editor.inputs['C-a'] = function() { editor.inputs['C-a'] = function() {
if (!editor.selectlist.empty) { editor.unselect(); return; } if (!editor.selectlist.empty) { editor.unselect(); return; }
@ -782,6 +783,7 @@ editor.inputs['C-f'] = function() {
editor.edit_level = editor.selectlist[0]; editor.edit_level = editor.selectlist[0];
editor.unselect(); editor.unselect();
editor.reset_undos();
}; };
editor.inputs['C-f'].doc = "Tunnel into the selected level object to edit it."; editor.inputs['C-f'].doc = "Tunnel into the selected level object to edit it.";
@ -791,8 +793,6 @@ editor.inputs['C-F'] = function() {
editor.edit_level = editor.edit_level.level; editor.edit_level = editor.edit_level.level;
editor.unselect(); editor.unselect();
editor.reset_undos(); editor.reset_undos();
// editor.curlvl = editor.edit_level.save();
// editor.edit_level.check_dirty();
}; };
editor.inputs['C-F'].doc = "Tunnel out of the level you are editing, saving it in the process."; editor.inputs['C-F'].doc = "Tunnel out of the level you are editing, saving it in the process.";
@ -1027,7 +1027,7 @@ editor.inputs.lm.released = function() {
var selects = []; var selects = [];
/* TODO: selects somehow gets undefined objects in here */ /* TODO: selects somehow gets undefined objects in here */
if (Mouse.worldpos.equal(editor.sel_start)) { if (Vector.equal(Mouse.worldpos, editor.sel_start, 5)) {
var sel = editor.try_select(); var sel = editor.try_select();
if (sel) selects.push(sel); if (sel) selects.push(sel);
} else { } else {
@ -1168,9 +1168,13 @@ editor.inputs.mouse.move = function(pos, dpos)
editor.scalelist?.forEach(function(x) { editor.scalelist?.forEach(function(x) {
var scalediff = dist / x.scaleoffset; var scalediff = dist / x.scaleoffset;
if (typeof x.obj.scale === 'number')
x.obj.scale = x.scale * scalediff;
else {
x.obj.scale = x.scale.map(x=> x * scalediff); x.obj.scale = x.scale.map(x=> x * scalediff);
if (x.offset) if (x.offset)
x.obj.pos = editor.cursor.add(x.offset.scale(scalediff)); x.obj.pos = editor.cursor.add(x.offset.scale(scalediff));
}
}); });
editor.rotlist?.forEach(function(x) { editor.rotlist?.forEach(function(x) {
@ -1362,7 +1366,6 @@ editor.inputs.s = function() {
if (editor.sel_comp) { if (editor.sel_comp) {
if (!('scale' in editor.sel_comp)) return; if (!('scale' in editor.sel_comp)) return;
Log.warn(`scaling ${editor.sel_comp.toString()}`);
editor.scalelist.push({ editor.scalelist.push({
obj: editor.sel_comp, obj: editor.sel_comp,
scale: editor.sel_comp.scale, scale: editor.sel_comp.scale,

View file

@ -101,7 +101,6 @@ var gameobject = {
}, },
set pos(x) { set pos(x) {
if (!x[0] || !x[1]) return;
this.set_worldpos(this.level.this2world(x)); this.set_worldpos(this.level.this2world(x));
}, },
@ -125,6 +124,9 @@ var gameobject = {
}, },
set gravity(x) { cmd(158,this.body, x); }, set gravity(x) { cmd(158,this.body, x); },
get gravity() { return cmd(159,this.body); }, get gravity() { return cmd(159,this.body); },
set_gravity(x) { cmd(167, this.body, x); },
set timescale(x) { cmd(168,this.body,x); },
get timescale() { return cmd(169,this.body); },
set phys(x) { set_body(1, this.body, x); }, set phys(x) { set_body(1, this.body, x); },
get phys() { return q_body(0,this.body); }, get phys() { return q_body(0,this.body); },
@ -134,6 +136,8 @@ var gameobject = {
// get category() { return cmd(42, this.body); }, // get category() { return cmd(42, this.body); },
get velocity() { return q_body(3, this.body); }, get velocity() { return q_body(3, this.body); },
set velocity(x) { set_body(9, this.body, x); }, set velocity(x) { set_body(9, this.body, x); },
// get damping() { return cmd(157,this.body); },
set_damping(x) { cmd(156, this.body, x); },
get angularvelocity() { return Math.rad2deg(q_body(4, this.body)); }, get angularvelocity() { return Math.rad2deg(q_body(4, this.body)); },
set angularvelocity(x) { set_body(8, this.body, Math.deg2rad(x)); }, set angularvelocity(x) { set_body(8, this.body, Math.deg2rad(x)); },
worldpos() { return q_body(1,this.body); }, worldpos() { return q_body(1,this.body); },
@ -241,7 +245,7 @@ var gameobject = {
pulse(vec) { set_body(4, this.body, vec);}, pulse(vec) { set_body(4, this.body, vec);},
shove(vec) { set_body(12,this.body,vec);}, shove(vec) { set_body(12,this.body,vec);},
shove_at(vec, at) { set_body(14,this.body,vec,at); }, shove_at(vec, at) { set_body(14,this.body,vec,at); },
torque(val) { cmd(153, this.body, val); }, // torque(val) { cmd(153, this.body, val); },
world2this(pos) { return cmd(70, this.body, pos); }, world2this(pos) { return cmd(70, this.body, pos); },
this2world(pos) { return cmd(71, this.body,pos); }, this2world(pos) { return cmd(71, this.body,pos); },
dir_world2this(dir) { return cmd(160, this.body, dir); }, dir_world2this(dir) { return cmd(160, this.body, dir); },
@ -329,6 +333,7 @@ var gameobject = {
phys:Physics.static, phys:Physics.static,
flipx() { return this.scale.x < 0; }, flipx() { return this.scale.x < 0; },
flipy() { return this.scale.y < 0; }, flipy() { return this.scale.y < 0; },
timescale: 1,
scale:[1,1], scale:[1,1],
mirror(plane) { mirror(plane) {
this.scale = Vector.reflect(this.scale, plane); this.scale = Vector.reflect(this.scale, plane);
@ -573,7 +578,7 @@ var gameobject = {
obj.level = undefined; obj.level = undefined;
obj.reparent(level); obj.reparent(level);
Object.hide(obj, 'ur','body', 'components', 'objects', '_ed', 'level', 'timers'); Object.hide(obj, 'ur','body', 'components', 'objects', '_ed', 'level', 'timers', 'timescale');
Object.dainty_assign(obj, this); Object.dainty_assign(obj, this);
obj.sync(); obj.sync();
@ -697,12 +702,13 @@ prototypes.from_file = function(file)
var upperur = gameobject; var upperur = gameobject;
if (path.length > 1) { if (path.length > 1) {
var upur = undefined;
var upperpath = path.slice(0,-1); var upperpath = path.slice(0,-1);
upperur = prototypes.get_ur(upperpath.join('/')); while (!upur && upperpath) {
if (!upperur) { upur = prototypes.get_ur(upperpath.join('/'));
Log.error(`Attempted to create an UR ${urpath}, but ${upperpath} is not a defined UR.`); upperpath = upperpath.slice(0,-1);
return undefined;
} }
if (upur) upperur = upur;
} }
var newur = {}; var newur = {};

View file

@ -160,6 +160,12 @@ var Player = {
pawn.inputs.post?.call(pawn); pawn.inputs.post?.call(pawn);
} }
switch (state) {
case 'released':
pawn.inputs.release_post?.call(pawn);
break;
}
if (!pawn.inputs.fallthru) return; if (!pawn.inputs.fallthru) return;
if (pawn.inputs.block) return; if (pawn.inputs.block) return;
} }

View file

@ -45,7 +45,6 @@ cpShape *phys2d_query_pos(cpVect pos) {
filter.mask = CP_ALL_CATEGORIES; filter.mask = CP_ALL_CATEGORIES;
filter.categories = CP_ALL_CATEGORIES; filter.categories = CP_ALL_CATEGORIES;
cpShape *find = cpSpacePointQueryNearest(space, pos, 0.f, filter, NULL); cpShape *find = cpSpacePointQueryNearest(space, pos, 0.f, filter, NULL);
// cpShape *find = cpSpaceSegmentQueryFirst(space, pos, pos, 0.f, filter, NULL);
return find; return find;
} }

View file

@ -45,21 +45,21 @@ int ispow2(int num)
struct circbuf *circbuf_make(size_t size, unsigned int len) struct circbuf *circbuf_make(size_t size, unsigned int len)
{ {
struct circbuf *new = malloc(sizeof(*new)); struct circbuf *self = malloc(sizeof(*self));
new->len = powof2(len); self->len = powof2(len);
new->data = calloc(sizeof(short), new->len); self->data = calloc(sizeof(short), self->len);
new->read = new->write = 0; self->read = self->write = 0;
return new; return self;
} }
struct circbuf circbuf_init(size_t size, unsigned int len) struct circbuf circbuf_init(size_t size, unsigned int len)
{ {
struct circbuf new; struct circbuf self;
new.len = powof2(len); self.len = powof2(len);
new.data = calloc(sizeof(short), new.len); self.data = calloc(sizeof(short), self.len);
new.read = new.write = 0; self.read = self.write = 0;
return new; return self;
} }
int cbuf_size(struct circbuf *buf) { int cbuf_size(struct circbuf *buf) {

View file

@ -1,9 +1,9 @@
#ifndef DEBUG_GUI_H #ifndef DEBUG_GUI_H
#define DEBUG_GUI_H #define DEBUG_GUI_H
#ifndef static_assert //#ifndef static_assert
#define static_assert(pred) switch(0){case 0:case pred:;} //#define static_assert(pred) switch(0){case 0:case pred:;}
#endif //#endif
#include <stdint.h> #include <stdint.h>

View file

@ -208,6 +208,8 @@ uint32_t go2mask(struct gameobject *go)
return 0; return 0;
} }
unsigned int editor_cat = 1<<31;
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) { void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
cpShapeSetFriction(shape, go->f); cpShapeSetFriction(shape, go->f);
cpShapeSetElasticity(shape, go->e); cpShapeSetElasticity(shape, go->e);
@ -215,8 +217,10 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
cpShapeFilter filter; cpShapeFilter filter;
filter.group = go2id(go); filter.group = go2id(go);
filter.categories = 1<<go->layer; filter.categories = 1<<go->layer | editor_cat;
filter.mask = category_masks[go->layer]; // filter.mask = CP_ALL_CATEGORIES;
filter.mask = category_masks[go->layer] | editor_cat;
// filter.mask = CP_ALL_CATEGORIES;
cpShapeSetFilter(shape, filter); cpShapeSetFilter(shape, filter);
struct phys2d_shape *ape = cpShapeGetUserData(shape); struct phys2d_shape *ape = cpShapeGetUserData(shape);
@ -268,13 +272,16 @@ static void gameobject_setpickcolor(struct gameobject *go) {
static void velocityFn(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt) static void velocityFn(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{ {
struct gameobject *go = id2go((int)cpBodyGetUserData(body)); struct gameobject *go = id2go((int)cpBodyGetUserData(body));
if (!go) if (!go) {
cpBodyUpdateVelocity(body,gravity,damping,dt); cpBodyUpdateVelocity(body,gravity,damping,dt);
return;
}
// cpFloat d = isnan(go->damping) ? damping : d; cpFloat d = isnan(go->damping) ? damping : d;
cpVect g = go->gravity ? gravity : cpvzero; cpVect g = go->gravity ? gravity : go->cgravity.cp;
cpBodyUpdateVelocity(body,g,d,dt*go->timescale);
cpBodyUpdateVelocity(body,g,damping,dt);
if (!isinf(go->maxvelocity)) if (!isinf(go->maxvelocity))
cpBodySetVelocity(body, cpvclamp(cpBodyGetVelocity(body), go->maxvelocity)); cpBodySetVelocity(body, cpvclamp(cpBodyGetVelocity(body), go->maxvelocity));
@ -295,6 +302,10 @@ int MakeGameobject() {
.next = -1, .next = -1,
.sensor = 0, .sensor = 0,
.shape_cbs = NULL, .shape_cbs = NULL,
.gravity = 1,
.cgravity = (HMM_Vec2){0,0},
.damping = NAN,
.timescale = 1.0,
.ref = JS_NULL, .ref = JS_NULL,
}; };

View file

@ -29,9 +29,11 @@ typedef struct gameobject {
float mass; float mass;
float f; /* friction */ float f; /* friction */
float e; /* elasticity */ float e; /* elasticity */
float timescale;
float maxvelocity; float maxvelocity;
float maxangularvelocity; float maxangularvelocity;
int gravity; int gravity;
HMM_Vec2 cgravity;
float damping; float damping;
int sensor; int sensor;
unsigned int layer; unsigned int layer;

View file

@ -353,7 +353,7 @@ JSValue bb2js(struct boundingbox bb)
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) { JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
static_assert(sizeof(tsReal) * 2 == sizeof(HMM_Vec2)); // static_assert(sizeof(tsReal) * 2 == sizeof(HMM_Vec2));
tsBSpline spline; tsBSpline spline;
@ -1126,7 +1126,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 153: case 153:
cpBodySetTorque(js2go(argv[1])->body, js2number(argv[2])); cpBodySetTorque(js2go(argv[1])->body, js2number(argv[2]));
break; break;
case 154: case 154:
js2go(argv[1])->maxangularvelocity = js2number(argv[2]); js2go(argv[1])->maxangularvelocity = js2number(argv[2]);
break; break;
@ -1172,6 +1171,15 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
str2 = js2str(argv[2]); str2 = js2str(argv[2]);
ret = int2js(cp(str, str2)); ret = int2js(cp(str, str2));
break; break;
case 167:
js2go(argv[1])->cgravity = js2vec2(argv[2]);
break;
case 168:
js2go(argv[1])->timescale = js2number(argv[2]);
break;
case 169:
ret = num2js(js2go(argv[1])->timescale);
break;
} }
if (str) if (str)

View file

@ -32,6 +32,11 @@
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#ifdef STEAM
#include "steam/steam_api_flat.h"
//#include "steam/steam_api.h"
#endif
#include "string.h" #include "string.h"
#include "render.h" #include "render.h"
@ -342,6 +347,11 @@ int main(int argc, char **argv) {
// signal(SIGBUS, seghandle); // signal(SIGBUS, seghandle);
#endif #endif
#ifdef STEAM
SteamAPI_Init();
#endif
stm_setup(); /* time */ stm_setup(); /* time */
start_t = frame_t = stm_now(); start_t = frame_t = stm_now();
physlast = updatelast = start_t; physlast = updatelast = start_t;