From 40bee0f2248993bbec313ff6da52aa292a3fa036 Mon Sep 17 00:00:00 2001 From: NepuShiro Date: Sun, 31 May 2026 21:57:50 -0500 Subject: [PATCH] :( --- .github/workflows/main.yml | 5 ++ Makefile | 5 +- src/decomp/game/mario.c | 3 +- src/decomp/game/mario.h | 2 +- src/decomp/game/mario_actions_automatic.c | 71 +++++++++++++++-------- src/decomp/include/types.h | 1 + src/libsm64.c | 4 +- src/libsm64.h | 2 +- test/main.cpp | 17 +++--- 9 files changed, 68 insertions(+), 42 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f383da..76aaa10 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,9 +51,14 @@ jobs: uses: mymindstorm/setup-emsdk@v14 - name: Build shared library + shell: bash run: | if [[ "${{ matrix.identifier }}" == "web" ]]; then emmake make lib -j $(nproc) CC=emcc + elif [[ "${{ matrix.identifier }}" == "windows" ]]; then + make lib -j $(nproc 2>/dev/null || sysctl -n hw.ncpu) \ + CC=x86_64-w64-mingw32-gcc \ + CXX=x86_64-w64-mingw32-g++ else make lib -j $(nproc 2>/dev/null || sysctl -n hw.ncpu) fi diff --git a/Makefile b/Makefile index 79408c7..bb96ede 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,8 @@ test/level.c: ./import-test-collision.py test/main.cpp test/gl20/gl20_renderer.c test/gl33core/gl33core_renderer.c: test/level.c -SDL2_CFLAGS := $(shell sdl2-config --cflags) +SDL2_RAW_CFLAGS := $(shell sdl2-config --cflags) +SDL2_CFLAGS := $(filter-out -Dmain=SDL_main,$(SDL2_RAW_CFLAGS)) $(BUILD_DIR)/test/%.o: test/%.c $(CC) -c $(CFLAGS) $(SDL2_CFLAGS) -I src/decomp/include -o $@ $< @@ -105,7 +106,7 @@ $(BUILD_DIR)/test/%.o: test/%.cpp $(TEST_FILE): $(LIB_FILE) $(TEST_OBJS) ifdef WINDOWS_BUILD - $(CXX) -o $@ $(TEST_OBJS) $(LIB_FILE) -lglew32 -lopengl32 -lSDL2 -lSDL2main -lm + $(CXX) -o $@ $(TEST_OBJS) $(LIB_FILE) -lglew32 -lopengl32 -lSDL2 -lm else ifdef MACOS_BUILD $(CXX) -o $@ $(TEST_OBJS) $(LIB_FILE) -framework OpenGL -lGLEW -lSDL2 -lSDL2main -lm -lpthread else diff --git a/src/decomp/game/mario.c b/src/decomp/game/mario.c index 40e847f..03267b8 100644 --- a/src/decomp/game/mario.c +++ b/src/decomp/game/mario.c @@ -2093,10 +2093,11 @@ s32 execute_mario_action(UNUSED struct Object * o) * INITIALIZATION * **************************************************/ -int init_mario(void) +int init_mario(uint8_t isLocal) { //Vec3s capPos; //struct Object *capObject; + gMarioState->isLocal = isLocal; gMarioState->actionTimer = 0; gMarioState->framesSinceA = 0xFF; diff --git a/src/decomp/game/mario.h b/src/decomp/game/mario.h index 198af44..0553f91 100644 --- a/src/decomp/game/mario.h +++ b/src/decomp/game/mario.h @@ -90,7 +90,7 @@ s32 set_water_plunge_action(struct MarioState *m); s32 execute_mario_action(UNUSED struct Object *o); -int init_mario(void); +int init_mario(uint8_t isLocal); void init_mario_from_save_file(void); diff --git a/src/decomp/game/mario_actions_automatic.c b/src/decomp/game/mario_actions_automatic.c index 93effd8..eef46b2 100644 --- a/src/decomp/game/mario_actions_automatic.c +++ b/src/decomp/game/mario_actions_automatic.c @@ -34,38 +34,44 @@ static Vec3f gVec3fZero = {0.0f, 0.0f, 0.0f}; void add_tree_leaf_particles(struct MarioState *m) { - // f32 leafHeight; + f32 leafHeight; + s32 isOnTree = false;//(m->usedObj->behavior == segmented_to_virtual(bhvTree)); - // if (m->usedObj->behavior == segmented_to_virtual(bhvTree)) { - // // make leaf effect spawn higher on the Shifting Sand Land palm tree - // if (gCurrLevelNum == LEVEL_SSL) { - // leafHeight = 250.0f; - // } else { - // leafHeight = 100.0f; - // } - // if (m->pos[1] - m->floorHeight > leafHeight) { - // m->particleFlags |= PARTICLE_LEAF; - // } - // } + if (isOnTree) { + // make leaf effect spawn higher on the Shifting Sand Land palm tree + if (gCurrLevelNum == LEVEL_SSL) { + leafHeight = 250.0f; + } else { + leafHeight = 100.0f; + } + if (m->pos[1] - m->floorHeight > leafHeight) { + m->particleFlags |= PARTICLE_LEAF; + } + } } void play_climbing_sounds(struct MarioState *m, s32 b) { - // s32 isOnTree = (m->usedObj->behavior == segmented_to_virtual(bhvTree)); + s32 isOnTree = false;//(m->usedObj->behavior == segmented_to_virtual(bhvTree)); - // if (b == 1) { - // if (is_anim_past_frame(m, 1)) { - // play_sound(isOnTree ? SOUND_ACTION_CLIMB_UP_TREE : SOUND_ACTION_CLIMB_UP_POLE, - // m->marioObj->header.gfx.cameraToObject); - // } - // } else { - // play_sound(isOnTree ? SOUND_MOVING_SLIDE_DOWN_TREE : SOUND_MOVING_SLIDE_DOWN_POLE, - // m->marioObj->header.gfx.cameraToObject); - // } + if (b == 1) { + if (is_anim_past_frame(m, 1)) { + play_sound(isOnTree ? SOUND_ACTION_CLIMB_UP_TREE : SOUND_ACTION_CLIMB_UP_POLE, + m->marioObj->header.gfx.cameraToObject); + } + } else { + play_sound(isOnTree ? SOUND_MOVING_SLIDE_DOWN_TREE : SOUND_MOVING_SLIDE_DOWN_POLE, + m->marioObj->header.gfx.cameraToObject); + } } s32 set_pole_position(struct MarioState *m, f32 offsetY) { + if (!m->isLocal && m->usedObj == NULL) + { + return POLE_NONE; + } + UNUSED s32 unused1; UNUSED s32 unused2; UNUSED s32 unused3; @@ -95,6 +101,7 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) } f32 floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &floor); + f32 floorHeight2 = find_floor(m->pos[0], m->pos[1] + 100, m->pos[2], &floor); if (m->pos[1] < floorHeight) { m->pos[1] = floorHeight; @@ -104,8 +111,17 @@ s32 set_pole_position(struct MarioState *m, f32 offsetY) else if (marioObj->oMarioPolePos < -m->usedObj->hitboxDownOffset) { m->pos[1] = m->usedObj->oPosY - m->usedObj->hitboxDownOffset; - set_mario_action(m, ACT_FREEFALL, 0); - result = POLE_FELL_OFF; + if (m->pos[1] < floorHeight2) + { + m->pos[1] = floorHeight2; + set_mario_action(m, ACT_IDLE, 0); + result = POLE_TOUCHED_FLOOR; + } + else + { + set_mario_action(m, ACT_FREEFALL, 0); + result = POLE_FELL_OFF; + } } else if (collided) { @@ -165,7 +181,12 @@ s32 act_holding_pole(struct MarioState *m) if (poleStickY > 16.0f) { - f32 poleTop = m->usedObj->hitboxHeight - 100.0f; + f32 poleTop = m->pos[1] + 1000; + + if (m->usedObj != NULL) + { + poleTop = m->usedObj->hitboxHeight - 100.0f; + } // const BehaviorScript *poleBehavior = virtual_to_segmented(0x13, m->usedObj->behavior); if (marioObj->oMarioPolePos < poleTop - 0.4f) diff --git a/src/decomp/include/types.h b/src/decomp/include/types.h index b7bc2dd..f0802b3 100644 --- a/src/decomp/include/types.h +++ b/src/decomp/include/types.h @@ -477,6 +477,7 @@ struct MarioState u16 curTerrain; // libsm64: added field s32 gasLevel; // libsm64: added field + uint8_t isLocal; }; #endif // TYPES_H diff --git a/src/libsm64.c b/src/libsm64.c index 920de43..449008f 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -182,7 +182,7 @@ SM64_LIB_FN void sm64_static_surfaces_load(const struct SM64Surface *surfaceArra surfaces_load_static(surfaceArray, numSurfaces); } -SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z) +SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z, uint8_t isLocal) { int32_t marioIndex = obj_pool_alloc_index(&s_mario_instance_pool, sizeof(struct MarioInstance)); struct MarioInstance *newInstance = s_mario_instance_pool.objects[marioIndex]; @@ -220,7 +220,7 @@ SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z) init_mario_from_save_file(); - if (init_mario() < 0) + if (init_mario(isLocal) < 0) { sm64_mario_delete(marioIndex); return -1; diff --git a/src/libsm64.h b/src/libsm64.h index 8496724..085865b 100644 --- a/src/libsm64.h +++ b/src/libsm64.h @@ -176,7 +176,7 @@ extern SM64_LIB_FN uint32_t sm64_audio_tick(uint32_t numQueuedSamples, uint32_t extern SM64_LIB_FN void sm64_static_surfaces_load(const struct SM64Surface *surfaceArray, uint32_t numSurfaces); -extern SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z); +extern SM64_LIB_FN int32_t sm64_mario_create(float x, float y, float z, uint8_t isLocal); extern SM64_LIB_FN void sm64_mario_tick(int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers); diff --git a/test/main.cpp b/test/main.cpp index 7402050..ad47e43 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -28,13 +28,8 @@ extern "C" #include "audio.h" #include "sm64.h" +#include "../src/decomp/include/types.h" -// Add this include near the top, after libsm64.h -// AnimInfo is defined in the decomp headers, not the public API -#include "../src/decomp/include/types.h" // or wherever AnimInfo is fully defined in your tree - -// ------------------------------------------------------- -// Named struct so it can be used as a parameter type struct FlagEntry { uint32_t bit; @@ -568,9 +563,6 @@ static const char *GetActionName(uint32_t action) } } -// ------------------------------------------------------- -// All helpers defined BEFORE DrawMarioState - static void DrawBitFlags( const char *label, uint32_t value, const FlagEntry *table, int count) @@ -776,8 +768,13 @@ static void Rumble(int32_t marioId, int16_t level, int16_t time) SDL_HapticRumblePlay(gHaptic, strength, duration); } +#ifdef WINDOWS_BUILD +constexpr float M_PI = 3.14159265358979323846f; +#endif + int main(void) { + SDL_SetMainReady(); size_t romSize; uint8_t *rom = utils_read_file_alloc("baserom.us.z64", &romSize); @@ -798,7 +795,7 @@ int main(void) sm64_register_rumble_callback_function(Rumble); sm64_static_surfaces_load(surfaces, surfaces_count); - int32_t marioId = sm64_mario_create(-6558, 0, 6464); + int32_t marioId = sm64_mario_create(-6558, 0, 6464, true); int thing = sm64_fake_object_create(-6558.0f, 0.0f, 6200.0f, 1); sm64_fake_object_set_hitbox(thing, 32.0f, 800.0f * 2, 800);