From 06bc6e750315c977452966dbb6f8b7f42557f2fe Mon Sep 17 00:00:00 2001 From: jaburns Date: Mon, 19 Oct 2020 12:59:50 -0600 Subject: [PATCH] Removed hacky bash script, replaced with proper makefile --- .gitignore | 3 +- .gitmodules | 0 Makefile | 42 +++++++++++++++++++++++++ configure | 50 ------------------------------ import-mario-geo.py | 13 +++++++- src/{model_hack.h => gfx_macros.h} | 0 src/libsm64.c | 1 + src/load_surfaces.c | 33 ++++++++++---------- 8 files changed, 73 insertions(+), 69 deletions(-) delete mode 100644 .gitmodules create mode 100644 Makefile delete mode 100755 configure rename src/{model_hack.h => gfx_macros.h} (100%) diff --git a/.gitignore b/.gitignore index ed31a43..8e1db0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /src/mario /build/ /dist/ -Makefile *.z64 -*.so +*.so \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..29aa889 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +default: all + +CC := cc +CFLAGS := -g -Wall -fPIC +LDFLAGS := -lm -shared + +SRC_DIRS := src src/engine src/game src/mario src/tools +BUILD_DIR := build +DIST_DIR := dist +ALL_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS)) + +BIN_FILE := $(DIST_DIR)/libsm64.so +LIB_H_FILE := $(DIST_DIR)/include/libsm64.h + +C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) +O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) +DEP_FILES := $(O_FILES:.o=.d) + +DUMMY != mkdir -p $(ALL_DIRS) +DUMMY != mkdir -p $(DIST_DIR)/include + +DUMMY != ./import-mario-geo.py >&2 || echo FAIL +ifeq ($(DUMMY),FAIL) + $(error Script import-mario-geo.py failed) +endif + +$(BUILD_DIR)/%.o: %.c + $(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< + $(CC) -c $(CFLAGS) -o $@ $< + +$(BIN_FILE): $(O_FILES) + $(CC) $(LDFLAGS) -o $@ $^ + +dist/include/libsm64.h: src/libsm64.h + cp -f $< $@ + +all: $(BIN_FILE) $(LIB_H_FILE) + +clean: + rm -rf $(BUILD_DIR) $(DIST_DIR) src/mario + +-include $(DEP_FILES) \ No newline at end of file diff --git a/configure b/configure deleted file mode 100755 index 442483e..0000000 --- a/configure +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -set -e -cd "$(dirname "${BASH_SOURCE[0]}")" - -CC='cc -g' -CFLAGS='-Wall -fPIC' -BIN_FILE='dist/libsm64.so' -LDFLAGS='-lm' - -c_to_obj() { - printf 'build/' - echo "$1" | sed 's/cp*$/o/;s:/:_:g' -} - -make_cmd() { - local obj_file="$(c_to_obj "$1")" - $CC $CFLAGS -MM -MT "$obj_file" -c "$1" - echo -e "\t$CC $CFLAGS -o $obj_file -c $1" -} - -file_list() { - find src -iname '*.c' -} - -print_makefile() { - local all_objs='' - for f in $(file_list); do - all_objs="$all_objs $(c_to_obj $f)" - done - echo "$BIN_FILE: $all_objs dist/include/libsm64.h" - echo -e "\t$CC -shared -o $BIN_FILE $all_objs $LDFLAGS" - - for f in $(file_list); do - make_cmd "$f" - done - - echo -e "src/mario/geo.inc.c: import-mario-geo.py\n\t ./import-mario-geo.py" - echo -e "src/mario/model.inc.c: import-mario-geo.py\n\t ./import-mario-geo.py" - - echo -e "dist/include/libsm64.h: src/libsm64.h\n\t cp src/libsm64.h dist/include/libsm64.h" - - echo -e "clean:\n\t rm -rf build && rm -rf dist && mkdir -p build && mkdir -p dist/include" - - echo '.PHONY: clean' -} - -./import-mario-geo.py -mkdir -p build -mkdir -p dist/include -print_makefile > Makefile \ No newline at end of file diff --git a/import-mario-geo.py b/import-mario-geo.py index ea6644a..b57be25 100755 --- a/import-mario-geo.py +++ b/import-mario-geo.py @@ -69,13 +69,24 @@ def main(): lines = model_inc_c.splitlines() + skip = 0 for i in range(len(lines)): + if skip > 0: + skip = skip - 1 + lines[i] = "//" + lines[i] + continue + + if lines[i].startswith("ALIGNED8 static const u8 mario_"): + skip = 2 + lines[i] = "//" + lines[i] + continue + lines[i] = lines[i].replace("#include", "//#include") lines[i] = lines[i].replace("ALIGNED8 static const u8 mario", "static const u8 xxx") if lines[i].startswith("const "): model_inc_h += "\nextern " + lines[i].replace(" = {", ";") - lines.insert(0, "#include \"../model_hack.h\"") + lines.insert(0, "#include \"../gfx_macros.h\"") lines.insert(0, "#include \"../load_tex_data.h\"") model_inc_c = "\n".join(lines) diff --git a/src/model_hack.h b/src/gfx_macros.h similarity index 100% rename from src/model_hack.h rename to src/gfx_macros.h diff --git a/src/libsm64.c b/src/libsm64.c index 1793e64..aff8a70 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -187,6 +187,7 @@ uint32_t sm64_load_surface_object( const struct SM64SurfaceObject *surfaceObject void sm64_move_object( uint32_t id, const struct SM64ObjectTransform *transform ) { + surface_object_update_transform( id, transform ); } void sm64_unload_object( uint32_t id ) diff --git a/src/load_surfaces.c b/src/load_surfaces.c index ab0a025..1e8d891 100644 --- a/src/load_surfaces.c +++ b/src/load_surfaces.c @@ -24,6 +24,7 @@ static struct LoadedSurfaceObject *s_surface_object_list = NULL; static uint32_t s_dynamic_surface_count = 0; static struct Surface *s_dynamic_surface_list = NULL; +#define CONVERT_ANGLE( x ) ((s16)( -(x) / 180.0f * 32768.0f )) static void init_transform( struct SurfaceObjectTransform *out, const struct SM64ObjectTransform *in ) { @@ -37,9 +38,9 @@ static void init_transform( struct SurfaceObjectTransform *out, const struct SM6 out->aAngleVelPitch = 0.0f; out->aAngleVelYaw = 0.0f; out->aAngleVelRoll = 0.0f; - out->aFaceAnglePitch = in->eulerRotation[0]; - out->aFaceAngleYaw = in->eulerRotation[1]; - out->aFaceAngleRoll = in->eulerRotation[2]; + out->aFaceAnglePitch = CONVERT_ANGLE(in->eulerRotation[0]); + out->aFaceAngleYaw = CONVERT_ANGLE(in->eulerRotation[1]); + out->aFaceAngleRoll = CONVERT_ANGLE(in->eulerRotation[2]); } static void update_transform( struct SurfaceObjectTransform *out, const struct SM64ObjectTransform *in ) @@ -51,12 +52,16 @@ static void update_transform( struct SurfaceObjectTransform *out, const struct S out->aPosY = in->position[1]; out->aPosZ = in->position[2]; - out->aFaceAnglePitch = in->eulerRotation[0] - out->aFaceAnglePitch; - out->aFaceAngleYaw = in->eulerRotation[1] - out->aFaceAngleYaw; - out->aFaceAngleRoll = in->eulerRotation[2] - out->aFaceAngleRoll; - out->aFaceAnglePitch = in->eulerRotation[0]; - out->aFaceAngleYaw = in->eulerRotation[1]; - out->aFaceAngleRoll = in->eulerRotation[2]; + s16 inX = CONVERT_ANGLE(in->eulerRotation[0]); + s16 inY = CONVERT_ANGLE(in->eulerRotation[1]); + s16 inZ = CONVERT_ANGLE(in->eulerRotation[2]); + + out->aAngleVelPitch = inX - out->aFaceAnglePitch; + out->aAngleVelYaw = inY - out->aFaceAngleYaw; + out->aAngleVelRoll = inZ - out->aFaceAngleRoll; + out->aFaceAnglePitch = inX; + out->aFaceAngleYaw = inY; + out->aFaceAngleRoll = inZ; } /** @@ -104,11 +109,7 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru if( transform != NULL ) { Mat4 m; - Vec3s rotation = { - (short)( -transform->aFaceAnglePitch / 180.0f * 32768.0f ), - (short)( -transform->aFaceAngleYaw / 180.0f * 32768.0f ), - (short)( -transform->aFaceAngleRoll / 180.0f * 32768.0f ) - }; + Vec3s rotation = { transform->aFaceAnglePitch, transform->aFaceAngleYaw, transform->aFaceAngleRoll }; Vec3f position = { transform->aPosX, transform->aPosY, transform->aPosZ }; mtxf_rotate_zxy_and_translate(m, position, rotation); @@ -123,6 +124,8 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru x1 = v1[0]; y1 = v1[1]; z1 = v1[2]; x2 = v2[0]; y2 = v2[1]; z2 = v2[2]; x3 = v3[0]; y3 = v3[1]; z3 = v3[2]; + + surface->object = (struct Object *)(transform); } // (v2 - v1) x (v3 - v2) @@ -189,8 +192,6 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru } else { surface->force = 0; } - - return surface; } void update_dynamic_surface_list( void )