start steam integration; bug fixes
This commit is contained in:
parent
cccd472f12
commit
ec8b3c97c4
44
Makefile
44
Makefile
|
@ -5,6 +5,9 @@ MAKEDIR != pwd
|
|||
# Options
|
||||
# DBG --- build with debugging symbols and logging
|
||||
|
||||
ifeq ($(CC),cc)
|
||||
CC=clang
|
||||
endif
|
||||
# Temp to strip long emcc paths to just emcc
|
||||
CC := $(notdir $(CC))
|
||||
|
||||
|
@ -14,9 +17,9 @@ OPT ?= 0
|
|||
INFO :=
|
||||
LD = $(CC)
|
||||
|
||||
ifeq ($(CC), clang)
|
||||
AR = llvm-ar
|
||||
endif
|
||||
#ifeq ($(CC), clang)
|
||||
# AR = llvm-ar
|
||||
#endif
|
||||
ifeq ($(CC), x86_64-w64-mingw32-gcc)
|
||||
AR = x86_64-w64-mingw32-ar
|
||||
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)\"
|
||||
|
||||
|
||||
PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) .
|
||||
ZIP = .tar.gz
|
||||
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/\*
|
||||
ZIP = .zip
|
||||
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
||||
|
||||
else ifeq ($(OS), ios)
|
||||
TTARGET = arm64-apple-ios13.1
|
||||
SYSRT := /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
|
||||
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
|
||||
|
||||
else ifeq ($(CC), emcc)
|
||||
OS := Web
|
||||
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
|
||||
CC = emcc
|
||||
EXT = .html
|
||||
|
||||
else
|
||||
UNAME != uname -s
|
||||
ifeq ($(UNAME), Linux)
|
||||
|
@ -113,7 +120,11 @@ OBJDIR = $(BIN)/obj
|
|||
|
||||
# All other sources
|
||||
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 %.m, %.o, $(OBJS))
|
||||
OBJS := $(addprefix $(BIN)/obj/, $(OBJS))
|
||||
|
||||
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 := $(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)
|
||||
SEM = 0.0.1
|
||||
|
@ -129,6 +148,7 @@ COM != fossil describe
|
|||
VER = $(SEM)-$(COM)
|
||||
|
||||
LDLIBS := $(addprefix -l, $(LDLIBS))
|
||||
LDPATHS := $(addprefix -L, $(LDPATHS))
|
||||
|
||||
DEPENDS = $(OBJS:.o=.d)
|
||||
-include $(DEPENDS)
|
||||
|
@ -152,7 +172,7 @@ install: $(BIN)/$(NAME)
|
|||
|
||||
$(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a
|
||||
@echo Linking $(NAME)
|
||||
$(LD) $^ $(LDFLAGS) -L$(BIN) $(LDLIBS) -o $@
|
||||
$(LD) $^ $(LDFLAGS) -L$(BIN) $(LDPATHS) $(LDLIBS) -o $@
|
||||
@echo Finished build
|
||||
|
||||
$(DISTDIR)/$(DIST): $(BIN)/$(NAME)
|
||||
|
@ -196,9 +216,9 @@ input.md: $(INPUTMD)
|
|||
@echo Printing api for $*
|
||||
@./primum -d $* > $@
|
||||
|
||||
$(BIN)/libquickjs.a:
|
||||
$(BIN)/libquickjs.a: $(QUICKJS_O)
|
||||
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)
|
||||
cp -rf quickjs/libquickjs.* $(BIN)
|
||||
|
||||
|
@ -207,6 +227,16 @@ $(OBJDIR)/%.o: %.c
|
|||
@echo Making C object $@
|
||||
@$(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)
|
||||
@echo Making shaders
|
||||
|
||||
|
|
|
@ -15,3 +15,6 @@ For these controls, pawn control order can matter. Pawns that are controlled lat
|
|||
|
||||
## 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.
|
||||
|
||||
## Blocking
|
||||
If 'block' is set to false on the input object, it will not block lower inputs from using the controls.
|
|
@ -22,6 +22,16 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# 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
|
||||
#CONFIG_WIN32=y
|
||||
# use link time optimization (smaller and faster executables but slower build)
|
||||
|
@ -32,7 +42,7 @@ CONFIG_LTO=y
|
|||
#CONFIG_M32=y
|
||||
|
||||
# use clang instead of gcc
|
||||
ifeq ($(CCC),clang)
|
||||
ifeq ($(HOST_CC),clang)
|
||||
CONFIG_CLANG=y
|
||||
CONFIG_DEFAULT_AR=y
|
||||
endif
|
||||
|
@ -61,7 +71,7 @@ else
|
|||
CROSS_PREFIX=
|
||||
EXE=
|
||||
endif
|
||||
ifeq ($(CCC), clang)
|
||||
ifeq ($(CC), clang)
|
||||
CC=$(CROSS_PREFIX)clang
|
||||
CFLAGS += -g -Wall -MMD -MF $(OBJDIR)/$(@F).d
|
||||
CFLAGS += -Wextra
|
||||
|
@ -73,7 +83,6 @@ ifeq ($(CCC), clang)
|
|||
CFLAGS += -Wwrite-strings
|
||||
CFLAGS += -Wchar-subscripts -funsigned-char
|
||||
CFLAGS += -MMD -MF $(OBJDIR)/$(@F).d
|
||||
CFLAGS += -arch $(ARCH)
|
||||
ifneq ($(TTARGET),)
|
||||
CFLAGS += --target=$(TTARGET)
|
||||
CFLAGS += -isysroot $(SYSRT)
|
||||
|
|
|
@ -53,7 +53,7 @@ var editor = {
|
|||
|
||||
/* Tries to select id */
|
||||
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.level !== this.edit_level) {
|
||||
|
@ -273,14 +273,17 @@ var editor = {
|
|||
},
|
||||
|
||||
snapshot() {
|
||||
var cur = this.edit_level.json_obj();
|
||||
var dif = ediff(cur, this.curlvl);
|
||||
var dif = this.edit_level.json_obj();
|
||||
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.curlvl = cur;
|
||||
return;
|
||||
|
||||
this.snapshots.push(dif);
|
||||
|
@ -342,12 +345,10 @@ var editor = {
|
|||
return;
|
||||
}
|
||||
this.unselect();
|
||||
this.backshots.push(this.edit_level.save());
|
||||
// this.backshots.push(this.edit_level.save());
|
||||
var dd = this.snapshots.pop();
|
||||
this.edit_level.clear();
|
||||
this.edit_level.load(dd);
|
||||
this.edit_level.check_dirty();
|
||||
this.curlvl = dd;
|
||||
Object.dainty_assign(this.edit_level, dd);
|
||||
this.edit_level._ed.check_dirty();
|
||||
return;
|
||||
|
||||
this.backshots.push(dd);
|
||||
|
@ -487,9 +488,9 @@ var editor = {
|
|||
x._ed.check_dirty();
|
||||
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);
|
||||
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' )
|
||||
x.gizmo();
|
||||
|
@ -497,7 +498,7 @@ var editor = {
|
|||
|
||||
Object.entries(thiso.objects).forEach(function(x) {
|
||||
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);
|
||||
|
@ -670,7 +671,7 @@ editor.inputs.post = function() {
|
|||
};
|
||||
editor.inputs.release_post = function() {
|
||||
editor.snapshot();
|
||||
editor.edit_level.check_dirty();
|
||||
editor.edit_level._ed.check_dirty();
|
||||
};
|
||||
editor.inputs['C-a'] = function() {
|
||||
if (!editor.selectlist.empty) { editor.unselect(); return; }
|
||||
|
@ -782,6 +783,7 @@ editor.inputs['C-f'] = function() {
|
|||
|
||||
editor.edit_level = editor.selectlist[0];
|
||||
editor.unselect();
|
||||
editor.reset_undos();
|
||||
};
|
||||
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.unselect();
|
||||
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.";
|
||||
|
||||
|
@ -1027,7 +1027,7 @@ editor.inputs.lm.released = function() {
|
|||
var selects = [];
|
||||
|
||||
/* 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();
|
||||
if (sel) selects.push(sel);
|
||||
} else {
|
||||
|
@ -1168,9 +1168,13 @@ editor.inputs.mouse.move = function(pos, dpos)
|
|||
|
||||
editor.scalelist?.forEach(function(x) {
|
||||
var scalediff = dist / x.scaleoffset;
|
||||
x.obj.scale = x.scale.map(x=> x * scalediff);
|
||||
if (x.offset)
|
||||
x.obj.pos = editor.cursor.add(x.offset.scale(scalediff));
|
||||
if (typeof x.obj.scale === 'number')
|
||||
x.obj.scale = x.scale * scalediff;
|
||||
else {
|
||||
x.obj.scale = x.scale.map(x=> x * scalediff);
|
||||
if (x.offset)
|
||||
x.obj.pos = editor.cursor.add(x.offset.scale(scalediff));
|
||||
}
|
||||
});
|
||||
|
||||
editor.rotlist?.forEach(function(x) {
|
||||
|
@ -1362,7 +1366,6 @@ editor.inputs.s = function() {
|
|||
|
||||
if (editor.sel_comp) {
|
||||
if (!('scale' in editor.sel_comp)) return;
|
||||
Log.warn(`scaling ${editor.sel_comp.toString()}`);
|
||||
editor.scalelist.push({
|
||||
obj: editor.sel_comp,
|
||||
scale: editor.sel_comp.scale,
|
||||
|
|
|
@ -101,7 +101,6 @@ var gameobject = {
|
|||
},
|
||||
|
||||
set pos(x) {
|
||||
if (!x[0] || !x[1]) return;
|
||||
this.set_worldpos(this.level.this2world(x));
|
||||
},
|
||||
|
||||
|
@ -125,6 +124,9 @@ var gameobject = {
|
|||
},
|
||||
set gravity(x) { cmd(158,this.body, x); },
|
||||
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); },
|
||||
get phys() { return q_body(0,this.body); },
|
||||
|
@ -134,6 +136,8 @@ var gameobject = {
|
|||
// get category() { return cmd(42, this.body); },
|
||||
get velocity() { return q_body(3, this.body); },
|
||||
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)); },
|
||||
set angularvelocity(x) { set_body(8, this.body, Math.deg2rad(x)); },
|
||||
worldpos() { return q_body(1,this.body); },
|
||||
|
@ -241,7 +245,7 @@ var gameobject = {
|
|||
pulse(vec) { set_body(4, this.body, vec);},
|
||||
shove(vec) { set_body(12,this.body,vec);},
|
||||
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); },
|
||||
this2world(pos) { return cmd(71, this.body,pos); },
|
||||
dir_world2this(dir) { return cmd(160, this.body, dir); },
|
||||
|
@ -329,6 +333,7 @@ var gameobject = {
|
|||
phys:Physics.static,
|
||||
flipx() { return this.scale.x < 0; },
|
||||
flipy() { return this.scale.y < 0; },
|
||||
timescale: 1,
|
||||
scale:[1,1],
|
||||
mirror(plane) {
|
||||
this.scale = Vector.reflect(this.scale, plane);
|
||||
|
@ -573,7 +578,7 @@ var gameobject = {
|
|||
obj.level = undefined;
|
||||
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);
|
||||
obj.sync();
|
||||
|
@ -697,12 +702,13 @@ prototypes.from_file = function(file)
|
|||
var upperur = gameobject;
|
||||
|
||||
if (path.length > 1) {
|
||||
var upur = undefined;
|
||||
var upperpath = path.slice(0,-1);
|
||||
upperur = prototypes.get_ur(upperpath.join('/'));
|
||||
if (!upperur) {
|
||||
Log.error(`Attempted to create an UR ${urpath}, but ${upperpath} is not a defined UR.`);
|
||||
return undefined;
|
||||
while (!upur && upperpath) {
|
||||
upur = prototypes.get_ur(upperpath.join('/'));
|
||||
upperpath = upperpath.slice(0,-1);
|
||||
}
|
||||
if (upur) upperur = upur;
|
||||
}
|
||||
|
||||
var newur = {};
|
||||
|
|
|
@ -160,6 +160,12 @@ var Player = {
|
|||
pawn.inputs.post?.call(pawn);
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case 'released':
|
||||
pawn.inputs.release_post?.call(pawn);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!pawn.inputs.fallthru) return;
|
||||
if (pawn.inputs.block) return;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ cpShape *phys2d_query_pos(cpVect pos) {
|
|||
filter.mask = CP_ALL_CATEGORIES;
|
||||
filter.categories = CP_ALL_CATEGORIES;
|
||||
cpShape *find = cpSpacePointQueryNearest(space, pos, 0.f, filter, NULL);
|
||||
// cpShape *find = cpSpaceSegmentQueryFirst(space, pos, pos, 0.f, filter, NULL);
|
||||
|
||||
return find;
|
||||
}
|
||||
|
|
|
@ -45,21 +45,21 @@ int ispow2(int num)
|
|||
|
||||
struct circbuf *circbuf_make(size_t size, unsigned int len)
|
||||
{
|
||||
struct circbuf *new = malloc(sizeof(*new));
|
||||
new->len = powof2(len);
|
||||
new->data = calloc(sizeof(short), new->len);
|
||||
new->read = new->write = 0;
|
||||
return new;
|
||||
struct circbuf *self = malloc(sizeof(*self));
|
||||
self->len = powof2(len);
|
||||
self->data = calloc(sizeof(short), self->len);
|
||||
self->read = self->write = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
struct circbuf circbuf_init(size_t size, unsigned int len)
|
||||
{
|
||||
struct circbuf new;
|
||||
new.len = powof2(len);
|
||||
new.data = calloc(sizeof(short), new.len);
|
||||
new.read = new.write = 0;
|
||||
struct circbuf self;
|
||||
self.len = powof2(len);
|
||||
self.data = calloc(sizeof(short), self.len);
|
||||
self.read = self.write = 0;
|
||||
|
||||
return new;
|
||||
return self;
|
||||
}
|
||||
|
||||
int cbuf_size(struct circbuf *buf) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef DEBUG_GUI_H
|
||||
#define DEBUG_GUI_H
|
||||
|
||||
#ifndef static_assert
|
||||
#define static_assert(pred) switch(0){case 0:case pred:;}
|
||||
#endif
|
||||
//#ifndef static_assert
|
||||
//#define static_assert(pred) switch(0){case 0:case pred:;}
|
||||
//#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
|
@ -208,6 +208,8 @@ uint32_t go2mask(struct gameobject *go)
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned int editor_cat = 1<<31;
|
||||
|
||||
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
|
||||
cpShapeSetFriction(shape, go->f);
|
||||
cpShapeSetElasticity(shape, go->e);
|
||||
|
@ -215,8 +217,10 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
|
|||
|
||||
cpShapeFilter filter;
|
||||
filter.group = go2id(go);
|
||||
filter.categories = 1<<go->layer;
|
||||
filter.mask = category_masks[go->layer];
|
||||
filter.categories = 1<<go->layer | editor_cat;
|
||||
// filter.mask = CP_ALL_CATEGORIES;
|
||||
filter.mask = category_masks[go->layer] | editor_cat;
|
||||
// filter.mask = CP_ALL_CATEGORIES;
|
||||
cpShapeSetFilter(shape, filter);
|
||||
|
||||
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)
|
||||
{
|
||||
struct gameobject *go = id2go((int)cpBodyGetUserData(body));
|
||||
if (!go)
|
||||
if (!go) {
|
||||
cpBodyUpdateVelocity(body,gravity,damping,dt);
|
||||
return;
|
||||
}
|
||||
|
||||
// cpFloat d = isnan(go->damping) ? damping : d;
|
||||
cpVect g = go->gravity ? gravity : cpvzero;
|
||||
cpFloat d = isnan(go->damping) ? damping : d;
|
||||
cpVect g = go->gravity ? gravity : go->cgravity.cp;
|
||||
|
||||
cpBodyUpdateVelocity(body,g,d,dt*go->timescale);
|
||||
|
||||
cpBodyUpdateVelocity(body,g,damping,dt);
|
||||
if (!isinf(go->maxvelocity))
|
||||
cpBodySetVelocity(body, cpvclamp(cpBodyGetVelocity(body), go->maxvelocity));
|
||||
|
||||
|
@ -295,6 +302,10 @@ int MakeGameobject() {
|
|||
.next = -1,
|
||||
.sensor = 0,
|
||||
.shape_cbs = NULL,
|
||||
.gravity = 1,
|
||||
.cgravity = (HMM_Vec2){0,0},
|
||||
.damping = NAN,
|
||||
.timescale = 1.0,
|
||||
.ref = JS_NULL,
|
||||
};
|
||||
|
||||
|
|
|
@ -29,9 +29,11 @@ typedef struct gameobject {
|
|||
float mass;
|
||||
float f; /* friction */
|
||||
float e; /* elasticity */
|
||||
float timescale;
|
||||
float maxvelocity;
|
||||
float maxangularvelocity;
|
||||
int gravity;
|
||||
HMM_Vec2 cgravity;
|
||||
float damping;
|
||||
int sensor;
|
||||
unsigned int layer;
|
||||
|
|
|
@ -353,7 +353,7 @@ JSValue bb2js(struct boundingbox bb)
|
|||
|
||||
|
||||
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;
|
||||
|
||||
|
@ -1126,7 +1126,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
case 153:
|
||||
cpBodySetTorque(js2go(argv[1])->body, js2number(argv[2]));
|
||||
break;
|
||||
|
||||
case 154:
|
||||
js2go(argv[1])->maxangularvelocity = js2number(argv[2]);
|
||||
break;
|
||||
|
@ -1172,6 +1171,15 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
str2 = js2str(argv[2]);
|
||||
ret = int2js(cp(str, str2));
|
||||
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)
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef STEAM
|
||||
#include "steam/steam_api_flat.h"
|
||||
//#include "steam/steam_api.h"
|
||||
#endif
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "render.h"
|
||||
|
@ -342,6 +347,11 @@ int main(int argc, char **argv) {
|
|||
// signal(SIGBUS, seghandle);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef STEAM
|
||||
SteamAPI_Init();
|
||||
#endif
|
||||
|
||||
stm_setup(); /* time */
|
||||
start_t = frame_t = stm_now();
|
||||
physlast = updatelast = start_t;
|
||||
|
|
Loading…
Reference in a new issue