Skip to content

Commit

Permalink
fixed crash with M key (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
headshot2017 committed Oct 8, 2024
1 parent 8f3893c commit a892b24
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 43 deletions.
9 changes: 7 additions & 2 deletions libsm64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ H_IMPORTED := $(C_IMPORTED:.c=.h)
IMPORTED := $(C_IMPORTED) $(H_IMPORTED)

C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(C_IMPORTED)
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o))
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) $(foreach file,$(CPP_FILES),$(BUILD_DIR)/$(file:.cpp=.o))
DEP_FILES := $(O_FILES:.o=.d)

TEST_SRCS := test/main.c test/context.c test/level.c test/audio.c test/gl33core/gl33core_renderer.c test/gl20/gl20_renderer.c
Expand All @@ -45,8 +46,12 @@ $(BUILD_DIR)/%.o: %.c $(IMPORTED)
@$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CC) -c $(CFLAGS) -I src/decomp/include -o $@ $<

$(BUILD_DIR)/%.o: %.cpp $(IMPORTED)
@$(CXX) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CXX) -c $(CFLAGS) -I src/decomp/include -o $@ $<

$(LIB_FILE): $(O_FILES)
$(CC) $(LDFLAGS) -o $@ $^
$(CXX) $(LDFLAGS) -o $@ $^

$(LIB_H_FILE): src/libsm64.h
cp -f $< $@
Expand Down
8 changes: 5 additions & 3 deletions libsm64/libsm64.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<Project>
<Option title="libsm64" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/libsm64" prefix_auto="1" extension_auto="1" />
<Option working_dir="bin/Debug" />
<Option object_output="obj/Debug/" />
<Option type="3" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
Expand All @@ -22,7 +22,7 @@
<Option output="bin/Release/libsm64" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="3" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
Expand All @@ -35,6 +35,8 @@
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-std=c++17" />
<Add option="-std=c17" />
<Add option="-fPIC" />
<Add option="-DSM64_LIB_EXPORT" />
<Add option="-DGBI_FLOATS" />
Expand Down
2 changes: 1 addition & 1 deletion libsm64/src/decomp/audio/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ void audio_init() {
DEBUG_PRINT("- tbl alloc at %x", gAlTbl);
DEBUG_PRINT("- gSoundDataRaw at %x", gSoundDataRaw);
audio_dma_copy_immediate((uintptr_t) gSoundDataRaw, gAlTbl, size);
alSeqFileNew(gAlTbl, gSoundDataRaw);
alSeqFileNew(gAlTbl, (u8*)gSoundDataRaw);

// Load bank sets for each sequence
gAlBankSets = soundAlloc(&gAudioInitPool, 0x100);
Expand Down
3 changes: 2 additions & 1 deletion libsm64/src/decomp/engine/math_util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "math_util.h"

#define M_PI 3.14159265358979323846
#include <math.h>
#include "../shim.h"

Expand Down Expand Up @@ -1994,7 +1995,7 @@ void mtxf_mul_vec3f(Mat4 mtx, Vec3f b) {
b[0] = x * mtx[0][0] + y * mtx[1][0] + z * mtx[2][0] + mtx[3][0];
b[1] = x * mtx[0][1] + y * mtx[1][1] + z * mtx[2][1] + mtx[3][1];
b[2] = x * mtx[0][2] + y * mtx[1][2] + z * mtx[2][2] + mtx[3][2];
}
}
/**
* Convert float matrix 'src' to fixed point matrix 'dest'.
* The float matrix may not contain entries larger than 65536 or the console
Expand Down
4 changes: 2 additions & 2 deletions libsm64/src/decomp/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// TODO don't handle every individual allocation with malloc, it sucks on windows

struct AllocOnlyPool
struct AllocOnlyPool
{
size_t allocatedCount;
void **allocatedBlocks;
Expand Down Expand Up @@ -56,4 +56,4 @@ void display_list_pool_reset(void)
void *alloc_display_list(u32 size)
{
return alloc_only_pool_alloc( s_display_list_pool, (s32)size );
}
}
26 changes: 13 additions & 13 deletions libsm64/src/decomp/tools/convUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ struct seqFile* parse_seqfile(unsigned char* seq){ /* Read SeqFile data */
for (int i = 0; i < bankCount; i++){
uintptr_t start = pos;
struct CTL* ptr = parse_ctl_data(seq+(seqFile->seqArray[i].offset), &pos);
seqFile->seqArray[i].offset = ptr;
seqFile->seqArray[i].offset = (uintptr_t)ptr;
seqFile->seqArray[i].len = (unsigned int)(pos - start);
}
}else if (revision == TYPE_TBL){
// TBL file, contains raw audio data
for (int i = 0; i < bankCount; i++){
seqFile->seqArray[i].offset = seq+(seqFile->seqArray[i].offset);
seqFile->seqArray[i].offset = (uintptr_t)seq+(seqFile->seqArray[i].offset);
}
}else if (revision == TYPE_SEQ){
// SEQ file, contains music files (*.m64)
for (int i = 0; i < bankCount; i++){
seqFile->seqArray[i].offset = seq+(seqFile->seqArray[i].offset);
seqFile->seqArray[i].offset = (uintptr_t)seq+(seqFile->seqArray[i].offset);
}
}

Expand Down Expand Up @@ -156,8 +156,8 @@ struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t
*pos = ALIGN16(*pos);
samp->zero=read_u32_be(sample);
samp->addr=read_u32_be(sample+4);
samp->loop=read_u32_be(sample+8);// loop address
samp->book=read_u32_be(sample+12);// book address
samp->loop=(struct CLoop*)read_u32_be(sample+8);// loop address
samp->book=(struct CBook*)read_u32_be(sample+12);// book address
samp->sample_size=read_u32_be(sample+16);

samp->book=parse_book(ctl+((uintptr_t)samp->book), pos);
Expand All @@ -167,7 +167,7 @@ struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t

struct CSound* parse_sound(unsigned char* sound,unsigned char* ctl, uintptr_t* pos, uintptr_t sndPos, struct SampleList* samples){
struct CSound* snd = (struct CSound*)(sndPos);
snd->sample_addr=read_u32_be(sound);
snd->sample_addr=(struct CSample*)read_u32_be(sound);
snd->tuning = (float)read_f32_be(sound+4);
// if sample_addr is 0 then the sound is null
if (snd->sample_addr!=0){
Expand Down Expand Up @@ -196,8 +196,8 @@ struct CDrum* parse_drum(unsigned char* drum,unsigned char* ctl, uintptr_t* pos,
drumData->pan = drum[1];
drumData->loaded = drum[2];
drumData->pad = drum[3];
drumData->snd=*parse_sound(drum+4,ctl, pos, &drumData->snd, samples);
drumData->env_addr=read_u32_be(drum+12);
drumData->snd=*parse_sound(drum+4,ctl, pos, (uintptr_t)&drumData->snd, samples);
drumData->env_addr=(struct CEnvelope*)read_u32_be(drum+12);
return drumData;
}

Expand Down Expand Up @@ -226,10 +226,10 @@ struct CInstrument* parse_instrument(unsigned char* instrument,unsigned char* ct
inst->normal_range_lo = instrument[1];
inst->normal_range_hi = instrument[2];
inst->release_rate = instrument[3];
inst->env_addr=read_u32_be(instrument+4);
inst->sound_lo=*parse_sound(instrument+8,ctl, pos, &(inst->sound_lo), samples);
inst->sound_med=*parse_sound(instrument+16,ctl, pos, &(inst->sound_med), samples);
inst->sound_hi=*parse_sound(instrument+24,ctl, pos, &(inst->sound_hi), samples);
inst->env_addr=(struct CEnvelope*)read_u32_be(instrument+4);
inst->sound_lo=*parse_sound(instrument+8,ctl, pos, (uintptr_t)&(inst->sound_lo), samples);
inst->sound_med=*parse_sound(instrument+16,ctl, pos, (uintptr_t)&(inst->sound_med), samples);
inst->sound_hi=*parse_sound(instrument+24,ctl, pos, (uintptr_t)&(inst->sound_hi), samples);

return inst;
}
Expand Down Expand Up @@ -371,4 +371,4 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
//

return ctl;
}
}
5 changes: 4 additions & 1 deletion libsm64/src/load_audio_data.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "load_audio_data.h"

#include <string.h>

#include "decomp/tools/convUtils.h"
#include "decomp/audio/external.h"
#include "decomp/audio/load.h"
#include "decomp/audio/load_dat.h"

Expand All @@ -25,4 +28,4 @@ extern void load_audio_banks( const uint8_t *rom ) {
sound_reset( 0 );

g_is_audio_initialized = true;
}
}
3 changes: 0 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ extern "C" {

using namespace plugin;

template<typename Type1, size_t N1, typename Type2, size_t N2, typename Type3, size_t N3, typename Type4, size_t N4, typename Type5, size_t N5, typename Type6, size_t N6, typename Type7, size_t N7>
using ArgPick7N = ArgPick<ArgTypes<Type1, Type2, Type3, Type4, Type5, Type6, Type7>, N1, N2, N3, N4, N5, N6, N7>;

bool loaded;
uint8_t* marioTexture;
RwImVertexIndex marioIndices[SM64_GEO_MAX_TRIANGLES * 3];
Expand Down
11 changes: 6 additions & 5 deletions mario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,12 @@ void marioSpawn()

loadCollisions(pos, ped->m_nPhysicalFlags.bTouchingWater);

marioGeometry.position = new float[9 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.normal = new float[9 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.color = new float[9 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.uv = new float[6 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.numTrianglesUsed = 0;

CVector sm64pos(pos.x / MARIO_SCALE, pos.z / MARIO_SCALE, -pos.y / MARIO_SCALE);
marioId = sm64_mario_create(sm64pos.x, sm64pos.y, sm64pos.z);
if (!marioSpawned())
Expand All @@ -698,11 +704,6 @@ void marioSpawn()

ticks = 0;
elapsedTicks = 0;
marioGeometry.position = new float[9 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.normal = new float[9 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.color = new float[9 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.uv = new float[6 * SM64_GEO_MAX_TRIANGLES];
marioGeometry.numTrianglesUsed = 0;
memset(&marioInput, 0, sizeof(marioInput));
memset(headAngle, 0, sizeof(headAngle));

Expand Down
2 changes: 1 addition & 1 deletion mario.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MARIO_H_INCLUDED

#define MARIO_SCALE 0.0085f
#define lerp(a, b, amnt) a + (b - a) * amnt
#define LERP(a, b, amnt) (a + (b - a) * amnt)
#define sign(a) (a>0 ? 1 : a<0 ? -1 : 0)

#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion mario_custom_anims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
#include "raw/anim_gunlight_aim_walk.raw.h"
#include "raw/anim_cutscene.raw.h"

#include <libsm64.h>
extern "C" {
#include <libsm64.h>
#include <decomp/include/mario_animation_ids.h>
}

Expand Down
4 changes: 2 additions & 2 deletions mario_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void marioRenderInit()
RpGeometryDestroy(marioRpGeometry);

// finally, add clump to world
RpWorldAddClump(Scene.m_pRpWorld, marioClump);
RpWorldAddClump(Scene.m_pWorld, marioClump);
}

void marioRenderDestroy()
Expand All @@ -135,7 +135,7 @@ void marioRenderDestroy()

// Retained Mode API only

RpWorldRemoveClump(Scene.m_pRpWorld, marioClump);
RpWorldRemoveClump(Scene.m_pWorld, marioClump);
RpClumpRemoveAtomic(marioClump, marioAtomic);
RpAtomicDestroy(marioAtomic);
RpClumpDestroy(marioClump);
Expand Down
14 changes: 6 additions & 8 deletions sm64-san-andreas.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
<Project>
<Option title="sm64-san-andreas" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Build>
<Target title="GTASA Debug">
<Option output='&quot;$(GTA_SA_DIR)&quot;/scripts/sm64_san_andreas.SA_d.asi' prefix_auto="0" extension_auto="0" />
<Option object_output=".obj/Debug" />
<Option type="3" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Compiler>
<Add option="-std=gnu++17" />
<Add option="-m32" />
<Add option="-fpermissive" />
<Add option="-g3" />
Expand Down Expand Up @@ -41,9 +40,8 @@
<Option output='&quot;$(GTA_SA_DIR)&quot;/scripts/sm64_san_andreas.SA.asi' prefix_auto="0" extension_auto="0" />
<Option object_output=".obj/Release" />
<Option type="3" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Compiler>
<Add option="-std=gnu++17" />
<Add option="-m32" />
<Add option="-fpermissive" />
<Add option="-DNDEBUG" />
Expand Down Expand Up @@ -72,9 +70,8 @@
<Option output='&quot;$(GTA_SA_DIR)&quot;/scripts/sm64_san_andreas.SA.asi' prefix_auto="0" extension_auto="0" />
<Option object_output=".obj/Release" />
<Option type="3" />
<Option compiler="gcc" />
<Option compiler="gnu_gcc_compiler_msys2" />
<Compiler>
<Add option="-std=gnu++17" />
<Add option="-m32" />
<Add option="-fpermissive" />
<Add option="-DNDEBUG" />
Expand All @@ -100,7 +97,8 @@
</Target>
</Build>
<Compiler>
<Add option="-fPIC" />
<Add option="-std=gnu++23" />
<Add option="-fno-rtti" />
<Add directory="$(PLUGIN_SDK_DIR)/plugin_sa/" />
<Add directory="$(PLUGIN_SDK_DIR)/plugin_sa/game_sa/" />
<Add directory="$(PLUGIN_SDK_DIR)/shared/" />
Expand Down

0 comments on commit a892b24

Please sign in to comment.