Removed hacky bash script, replaced with proper makefile
This commit is contained in:
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
/src/mario
|
/src/mario
|
||||||
/build/
|
/build/
|
||||||
/dist/
|
/dist/
|
||||||
Makefile
|
|
||||||
*.z64
|
*.z64
|
||||||
*.so
|
*.so
|
||||||
@@ -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)
|
||||||
@@ -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
|
|
||||||
+12
-1
@@ -69,13 +69,24 @@ def main():
|
|||||||
|
|
||||||
lines = model_inc_c.splitlines()
|
lines = model_inc_c.splitlines()
|
||||||
|
|
||||||
|
skip = 0
|
||||||
for i in range(len(lines)):
|
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("#include", "//#include")
|
||||||
lines[i] = lines[i].replace("ALIGNED8 static const u8 mario", "static const u8 xxx")
|
lines[i] = lines[i].replace("ALIGNED8 static const u8 mario", "static const u8 xxx")
|
||||||
if lines[i].startswith("const "):
|
if lines[i].startswith("const "):
|
||||||
model_inc_h += "\nextern " + lines[i].replace(" = {", ";")
|
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\"")
|
lines.insert(0, "#include \"../load_tex_data.h\"")
|
||||||
model_inc_c = "\n".join(lines)
|
model_inc_c = "\n".join(lines)
|
||||||
|
|
||||||
|
|||||||
@@ -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 )
|
void sm64_move_object( uint32_t id, const struct SM64ObjectTransform *transform )
|
||||||
{
|
{
|
||||||
|
surface_object_update_transform( id, transform );
|
||||||
}
|
}
|
||||||
|
|
||||||
void sm64_unload_object( uint32_t id )
|
void sm64_unload_object( uint32_t id )
|
||||||
|
|||||||
+17
-16
@@ -24,6 +24,7 @@ static struct LoadedSurfaceObject *s_surface_object_list = NULL;
|
|||||||
static uint32_t s_dynamic_surface_count = 0;
|
static uint32_t s_dynamic_surface_count = 0;
|
||||||
static struct Surface *s_dynamic_surface_list = NULL;
|
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 )
|
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->aAngleVelPitch = 0.0f;
|
||||||
out->aAngleVelYaw = 0.0f;
|
out->aAngleVelYaw = 0.0f;
|
||||||
out->aAngleVelRoll = 0.0f;
|
out->aAngleVelRoll = 0.0f;
|
||||||
out->aFaceAnglePitch = in->eulerRotation[0];
|
out->aFaceAnglePitch = CONVERT_ANGLE(in->eulerRotation[0]);
|
||||||
out->aFaceAngleYaw = in->eulerRotation[1];
|
out->aFaceAngleYaw = CONVERT_ANGLE(in->eulerRotation[1]);
|
||||||
out->aFaceAngleRoll = in->eulerRotation[2];
|
out->aFaceAngleRoll = CONVERT_ANGLE(in->eulerRotation[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_transform( struct SurfaceObjectTransform *out, const struct SM64ObjectTransform *in )
|
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->aPosY = in->position[1];
|
||||||
out->aPosZ = in->position[2];
|
out->aPosZ = in->position[2];
|
||||||
|
|
||||||
out->aFaceAnglePitch = in->eulerRotation[0] - out->aFaceAnglePitch;
|
s16 inX = CONVERT_ANGLE(in->eulerRotation[0]);
|
||||||
out->aFaceAngleYaw = in->eulerRotation[1] - out->aFaceAngleYaw;
|
s16 inY = CONVERT_ANGLE(in->eulerRotation[1]);
|
||||||
out->aFaceAngleRoll = in->eulerRotation[2] - out->aFaceAngleRoll;
|
s16 inZ = CONVERT_ANGLE(in->eulerRotation[2]);
|
||||||
out->aFaceAnglePitch = in->eulerRotation[0];
|
|
||||||
out->aFaceAngleYaw = in->eulerRotation[1];
|
out->aAngleVelPitch = inX - out->aFaceAnglePitch;
|
||||||
out->aFaceAngleRoll = in->eulerRotation[2];
|
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 )
|
if( transform != NULL )
|
||||||
{
|
{
|
||||||
Mat4 m;
|
Mat4 m;
|
||||||
Vec3s rotation = {
|
Vec3s rotation = { transform->aFaceAnglePitch, transform->aFaceAngleYaw, transform->aFaceAngleRoll };
|
||||||
(short)( -transform->aFaceAnglePitch / 180.0f * 32768.0f ),
|
|
||||||
(short)( -transform->aFaceAngleYaw / 180.0f * 32768.0f ),
|
|
||||||
(short)( -transform->aFaceAngleRoll / 180.0f * 32768.0f )
|
|
||||||
};
|
|
||||||
Vec3f position = { transform->aPosX, transform->aPosY, transform->aPosZ };
|
Vec3f position = { transform->aPosX, transform->aPosY, transform->aPosZ };
|
||||||
mtxf_rotate_zxy_and_translate(m, position, rotation);
|
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];
|
x1 = v1[0]; y1 = v1[1]; z1 = v1[2];
|
||||||
x2 = v2[0]; y2 = v2[1]; z2 = v2[2];
|
x2 = v2[0]; y2 = v2[1]; z2 = v2[2];
|
||||||
x3 = v3[0]; y3 = v3[1]; z3 = v3[2];
|
x3 = v3[0]; y3 = v3[1]; z3 = v3[2];
|
||||||
|
|
||||||
|
surface->object = (struct Object *)(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (v2 - v1) x (v3 - v2)
|
// (v2 - v1) x (v3 - v2)
|
||||||
@@ -189,8 +192,6 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru
|
|||||||
} else {
|
} else {
|
||||||
surface->force = 0;
|
surface->force = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return surface;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_dynamic_surface_list( void )
|
void update_dynamic_surface_list( void )
|
||||||
|
|||||||
Reference in New Issue
Block a user