From f05e0e59f08b4545184a727eba6dc8055adb78ec Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Tue, 28 Feb 2023 15:40:53 +0000 Subject: [PATCH] Fix windows build --- Makefile | 2 +- source/engine/2dphysics.c | 20 ++++++++++---- source/engine/2dphysics.h | 2 ++ source/engine/gameobject.c | 26 ++++++++++++------ source/engine/input.c | 31 +++++++++++++++++++--- source/engine/texture.c | 1 + source/engine/thirdparty/Nuklear/nuklear.h | 4 +-- source/engine/yugine.c | 2 ++ 8 files changed, 69 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index ee40c04..c853aa3 100755 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ ifeq ($(OS), WIN32) EXT = .exe else LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib -rdynamic - ELIBS = engine pthread yughc portaudio asound glfw3 c m dl samplerate + ELIBS = engine pthread yughc portaudio asound glfw3 c m dl CLIBS = endif diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index 67f4a75..55d17f4 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -341,8 +341,11 @@ void phys2d_dbgdrawbox(struct phys2d_box *box) int n = cpPolyShapeGetCount(box->shape.shape); float points[n * 2]; - for (int i = 0; i < n; i++) - points[i] = bodytransformpoint(cpShapeGetBody(box->shape.shape), cpPolyShapeGetVert(box->shape.shape, i)); + for (int i = 0; i < n; i++) { + cpVect p = bodytransformpoint(cpShapeGetBody(box->shape.shape), cpPolyShapeGetVert(box->shape.shape, i)); + points[i*2] = p.x; + points[i*2+1] = p.y; + } draw_poly(points, n, shape_color(box->shape.shape)); } @@ -413,8 +416,11 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly) int n = cpPolyShapeGetCount(poly->shape.shape); float points[n * 2]; - for (int i = 0; i < n; i++) - points[i*2] = bodytransformpoint(cpShapeGetBody(poly->shape.shape), cpPolyShapeGetVert(poly->shape.shape, i)); + for (int i = 0; i < n; i++) { + cpVect p = bodytransformpoint(cpShapeGetBody(poly->shape.shape), cpPolyShapeGetVert(poly->shape.shape, i)); + points[i*2] = p.x; + points[i*2+1] = p.y; + } draw_poly(points, n, color); } @@ -442,7 +448,11 @@ struct phys2d_edge *Make2DEdge(int go) float phys2d_edge_moi(struct phys2d_edge *edge, float m) { - return m; + float moi = 0; + for (int i = 0; i < arrlen(edge->points)-1; i++) + moi += cpMomentForSegment(m, edge->points[i], edge->points[i+1], edge->thickness); + + return moi; } void phys2d_edgedel(struct phys2d_edge *edge) diff --git a/source/engine/2dphysics.h b/source/engine/2dphysics.h index 5064129..bf145a6 100644 --- a/source/engine/2dphysics.h +++ b/source/engine/2dphysics.h @@ -4,6 +4,8 @@ #include #include "script.h" +struct gameobject; + extern float phys2d_gravity; extern int physOn; extern cpSpace *space; diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 76ffa57..cff9647 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -98,6 +98,12 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) // cpShapeSetSensor(shape, go->sensor); cpShapeSetCollisionType(shape, go2id(go)); + +// cpShapeSetFilter(shape, go->filter); +} + +void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go) +{ float moment = cpBodyGetMoment(go->body); struct phys2d_shape *s = cpShapeGetUserData(shape); if (!s) { @@ -106,21 +112,25 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) } moment += s->moi(s->data, go->mass); - cpBodySetMoment(go->body, moment); -// cpShapeSetFilter(shape, go->filter); + cpBodySetMoment(go->body, moment); } void gameobject_apply(struct gameobject *go) { cpBodySetType(go->body, go->bodytype); - cpBodySetMoment(go->body, 0.f); cpBodyEachShape(go->body, go_shape_apply, go); - if (go->bodytype == CP_BODY_TYPE_DYNAMIC) + + if (go->bodytype == CP_BODY_TYPE_DYNAMIC) { cpBodySetMass(go->body, go->mass); - - if (cpBodyGetMoment(go->body) <= 0.f) { - YughError("Moment for object %d is zero. Setting to one.", go2id(go)); - cpBodySetMoment(go->body, 1.f); + cpBodySetMoment(go->body, 0.f); + cpBodyEachShape(go->body, go_shape_moi, go); + + if (cpBodyGetMoment(go->body) <= 0.f) { + YughError("Moment for object %d is zero. Setting to one.", go2id(go)); + cpBodySetMoment(go->body, 1.f); + } + + return; } } diff --git a/source/engine/input.c b/source/engine/input.c index de7df00..d0b3031 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -156,8 +156,32 @@ const char *keyname_extd(int key, int scancode) { const char *kkey = NULL; if (key > 289 && key < 302) { - sprintf(keybuf, "f%d", key-289); - return keybuf; + switch(key) { + case 290: + return "f1"; + case 291: + return "f2"; + case 292: + return "f3"; + case 293: + return "f4"; + case 294: + return "f5"; + case 295: + return "f6"; + case 296: + return "f7"; + case 297: + return "f8"; + case 298: + return "f9"; + case 299: + return "f10"; + case 300: + return "f11"; + case 301: + return "f12"; + } } else { switch(key) { case GLFW_KEY_ENTER: @@ -298,7 +322,8 @@ int key_is_num(int key) { void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods) { char keystr[50] = {'\0'}; - const char *kkey = keyname_extd(key, scancode); + char kkey[50] = {'\0'}; + snprintf(kkey, 50, "%s", keyname_extd(key,scancode)); switch (action) { case GLFW_PRESS: diff --git a/source/engine/texture.c b/source/engine/texture.c index 41e22bc..a307cf3 100644 --- a/source/engine/texture.c +++ b/source/engine/texture.c @@ -26,6 +26,7 @@ struct Texture *texture_pullfromfile(const char *path) if (index != -1) return texhash[index].value; + YughInfo("Loading texture %s.", path); struct Texture *tex = calloc(1, sizeof(*tex)); /* Find texture's asset; otherwise load default asset */ diff --git a/source/engine/thirdparty/Nuklear/nuklear.h b/source/engine/thirdparty/Nuklear/nuklear.h index 0de0d00..2d7b7ab 100644 --- a/source/engine/thirdparty/Nuklear/nuklear.h +++ b/source/engine/thirdparty/Nuklear/nuklear.h @@ -432,8 +432,8 @@ NK_STATIC_ASSERT(sizeof(nk_int) == 4); NK_STATIC_ASSERT(sizeof(nk_byte) == 1); NK_STATIC_ASSERT(sizeof(nk_flags) >= 4); NK_STATIC_ASSERT(sizeof(nk_rune) >= 4); -NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*)); -NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*)); +//NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*)); +//NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*)); #ifdef NK_INCLUDE_STANDARD_BOOL NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool)); #else diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 906adba..16b2234 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -129,6 +129,8 @@ int main(int argc, char **args) { } } + ed = 0; + #if DBG if (logout) {