diff --git a/Makefile b/Makefile index ae0d729..eac1125 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ default: lib CC := cc -CFLAGS := -g -Wall -fPIC +CFLAGS := -g -Wall -fPIC -DSM64_LIB_EXPORT LDFLAGS := -lm -shared SRC_DIRS := src src/decomp src/decomp/engine src/decomp/game src/decomp/mario src/decomp/tools @@ -26,7 +26,6 @@ TEST_OBJS := $(foreach file,$(TEST_SRCS),$(BUILD_DIR)/$(file:.c=.o)) ifeq ($(OS),Windows_NT) LIB_FILE := $(DIST_DIR)/sm64.dll - CFLAGS := $(CFLAGS) -DBUILDING_SM64_DLL endif DUMMY != mkdir -p $(ALL_DIRS) build/test src/decomp/mario $(DIST_DIR)/include diff --git a/src/decomp/game/object_stuff.c b/src/decomp/game/object_stuff.c index 9f10fb2..d7b77dd 100644 --- a/src/decomp/game/object_stuff.c +++ b/src/decomp/game/object_stuff.c @@ -61,44 +61,11 @@ static Vec3f gVec3fZero = { 0.0f, 0.0f, 0.0f }; static Vec3s gVec3sZero = { 0, 0, 0 }; static Vec3f gVec3fOne = { 1.0f, 1.0f, 1.0f }; -static struct GraphNodeObject *init_graph_node_object( Vec3f pos, Vec3s angle, Vec3f scale) { - struct GraphNodeObject *graphNode = malloc(sizeof(struct GraphNodeObject)); - - //init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_OBJECT); - - graphNode->node.type = GRAPH_NODE_TYPE_OBJECT; - graphNode->node.flags = GRAPH_RENDER_ACTIVE; - graphNode->node.prev = &graphNode->node; - graphNode->node.next = &graphNode->node; - graphNode->node.parent = NULL; - graphNode->node.children = NULL; - - vec3f_copy(graphNode->pos, pos); - vec3f_copy(graphNode->scale, scale); - vec3s_copy(graphNode->angle, angle); - vec3f_copy(graphNode->cameraToObject, gVec3fZero); - - graphNode->sharedChild = NULL; - graphNode->throwMatrix = NULL; - graphNode->animInfo.animID = 0; - graphNode->animInfo.curAnim = NULL; - graphNode->animInfo.animFrame = 0; - graphNode->animInfo.animFrameAccelAssist = 0; - graphNode->animInfo.animAccel = 0x10000; - graphNode->animInfo.animTimer = 0; - graphNode->node.flags |= GRAPH_RENDER_HAS_ANIMATION; - - return graphNode; -} - static struct Object *try_allocate_object(void) { struct ObjectNode *nextObj; nextObj = (struct ObjectNode *) malloc(sizeof(struct Object)); nextObj->prev = NULL; nextObj->next = NULL; - - init_graph_node_object(gVec3fZero, gVec3sZero, gVec3fOne); - return (struct Object *) nextObj; } @@ -191,7 +158,6 @@ static struct Object *spawn_object_at_origin(void) { obj->parentObj = NULL; obj->header.gfx.areaIndex = 0; obj->header.gfx.activeAreaIndex = 0; -// geo_obj_init((struct GraphNodeObject *) &obj->header.gfx, gLoadedGraphNodes[model], gVec3fZero, gVec3sZero); geo_obj_init((struct GraphNodeObject *) &obj->header.gfx, NULL, gVec3fZero, gVec3sZero); return obj; diff --git a/src/libsm64.c b/src/libsm64.c index 746b62b..d85bca6 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -1,7 +1,7 @@ -#include - +#define SM64_LIB_EXPORT #include "libsm64.h" +#include #include #include #include @@ -50,38 +50,22 @@ static void update_button( bool on, u16 button ) } } -static struct Camera *hack_build_camera( void ) +static struct Area *allocate_area( void ) { - struct Camera *result = malloc( sizeof( struct Camera )); - memset( result, 0, sizeof( struct Camera )); + struct Area *result = malloc( sizeof( struct Area )); + memset( result, 0, sizeof( struct Area )); + + result->flags = 1; + result->camera = malloc( sizeof( struct Camera )); + memset( result->camera, 0, sizeof( struct Camera )); + return result; } -static struct Area *hack_build_area( void ) +static void free_area( struct Area *area ) { - struct Area *result = malloc( sizeof( struct Area )); - - result->index = 0; - result->flags = 1; - result->terrainType = TERRAIN_GRASS; - result->unk04 = NULL; - result->terrainData = NULL; - result->surfaceRooms = NULL; - result->macroObjects = NULL; - result->warpNodes = NULL; - result->paintingWarpNodes = NULL; - result->instantWarps = NULL; - result->objectSpawnInfos = NULL; - result->camera = hack_build_camera(); - result->unused28 = NULL; - result->whirlpools[0] = NULL; - result->whirlpools[1] = NULL; - result->dialog[0] = 0; - result->dialog[1] = 0; - result->musicParam = 0; - result->musicParam2 = 0; - - return result; + free( area->camera ); + free( area ); } SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugPrintFunctionPtr debugPrintFunction ) @@ -98,7 +82,7 @@ SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugP gCurrSaveFileNum = 1; gMarioObject = hack_allocate_mario(); - gCurrentArea = hack_build_area(); + gCurrentArea = allocate_area(); gCurrentObject = gMarioObject; s_mario_geo_pool = alloc_only_pool_init(); @@ -186,8 +170,8 @@ SM64_LIB_FN void sm64_mario_tick( const struct SM64MarioInputs *inputs, struct S SM64_LIB_FN void sm64_global_terminate( void ) { - //deallocate area, - //deallocate mario object and graph node + free( gMarioObject ); + free_area( gCurrentArea ); global_state_bind( NULL ); global_state_destroy( s_global_state ); diff --git a/src/libsm64.h b/src/libsm64.h index 54d3039..9a85ecd 100644 --- a/src/libsm64.h +++ b/src/libsm64.h @@ -6,7 +6,7 @@ #include #ifdef _WIN32 - #ifdef BUILDING_SM64_DLL + #ifdef SM64_LIB_EXPORT #define SM64_LIB_FN __declspec(dllexport) #else #define SM64_LIB_FN __declspec(dllimport)