Make Surfaces Float
Build libsm64 / Build libsm64 for linux (push) Successful in 29s
Build libsm64 / Build libsm64 for web (push) Successful in 31s
Build libsm64 / Build libsm64 for windows (push) Successful in 24s

This commit is contained in:
2026-05-23 15:08:00 -05:00
parent aa092bebfe
commit 4328104536
5 changed files with 45 additions and 30 deletions
+6 -6
View File
@@ -22,7 +22,7 @@ BUILD_DIR := build
DIST_DIR := dist
ALL_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS))
LIB_FILE := $(DIST_DIR)/libsm64.so
LIB_FILE := $(DIST_DIR)/sm64.so
LIB_H_FILE := $(DIST_DIR)/include/libsm64.h
TEST_FILE := run-test
@@ -48,7 +48,7 @@ ifdef WINDOWS_BUILD
LIB_FILE := $(DIST_DIR)/sm64.dll
TEST_FILE := $(DIST_DIR)/run-test.exe
else ifdef MACOS_BUILD
LIB_FILE := $(DIST_DIR)/libsm64.dylib
LIB_FILE := $(DIST_DIR)/sm64.dylib
endif
DUMMY := $(shell mkdir -p $(ALL_DIRS) build/test build/test/gl33core build/test/gl20 src/decomp/mario $(DIST_DIR)/include)
@@ -89,12 +89,12 @@ test/level.c: ./import-test-collision.py
test/main.cpp test/gl20/gl20_renderer.c test/gl33core/gl33core_renderer.c: test/level.c
$(BUILD_DIR)/test/%.o: test/%.c
@$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/test/$*.d $<
$(CC) -c $(CFLAGS) -o $@ $<
@$(CC) $(CFLAGS) -I src/decomp/include -MM -MP -MT $@ -MF $(BUILD_DIR)/test/$*.d $<
$(CC) -c $(CFLAGS) -I src/decomp/include -o $@ $<
$(BUILD_DIR)/test/%.o: test/%.cpp
@$(CXX) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/test/$*.d $<
$(CXX) -c $(CFLAGS) -o $@ $<
@$(CXX) $(CFLAGS) -I src/decomp/include -MM -MP -MT $@ -MF $(BUILD_DIR)/test/$*.d $<
$(CXX) -c $(CFLAGS) -I src/decomp/include -std=c++17 -o $@ $<
$(TEST_FILE): $(LIB_FILE) $(TEST_OBJS)
ifdef WINDOWS_BUILD
+4 -4
View File
@@ -8,9 +8,9 @@
/**
* Iterate through the list of ceilings and find the first ceiling over a given point.
*/
static struct SM64SurfaceCollisionData *find_ceil_from_list( s32 x, s32 y, s32 z, f32 *pheight) {
static struct SM64SurfaceCollisionData *find_ceil_from_list( f32 x, f32 y, f32 z, f32 *pheight) {
register struct SM64SurfaceCollisionData *surf;
register s32 x1, z1, x2, z2, x3, z3;
register f32 x1, z1, x2, z2, x3, z3;
struct SM64SurfaceCollisionData *ceil = NULL;
ceil = NULL;
@@ -83,9 +83,9 @@ static struct SM64SurfaceCollisionData *find_ceil_from_list( s32 x, s32 y, s32 z
/**
* Iterate through the list of floors and find the first floor under a given point.
*/
static struct SM64SurfaceCollisionData *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight) {
static struct SM64SurfaceCollisionData *find_floor_from_list( f32 x, f32 y, f32 z, f32 *pheight) {
register struct SM64SurfaceCollisionData *surf;
register s32 x1, z1, x2, z2, x3, z3;
register f32 x1, z1, x2, z2, x3, z3;
f32 nx, ny, nz;
f32 oo;
f32 height;
+6 -6
View File
@@ -30,7 +30,7 @@ struct SM64Surface
int16_t type;
int16_t force;
uint16_t terrain;
int32_t vertices[3][3];
float vertices[3][3]; // world-space coordinates
};
struct SM64MarioInputs
@@ -115,11 +115,11 @@ struct SM64SurfaceCollisionData
int16_t force;
int8_t flags;
int8_t room;
int32_t lowerY; // libsm64: 32 bit
int32_t upperY; // libsm64: 32 bit
int32_t vertex1[3]; // libsm64: 32 bit
int32_t vertex2[3]; // libsm64: 32 bit
int32_t vertex3[3]; // libsm64: 32 bit
float lowerY;
float upperY;
float vertex1[3];
float vertex2[3];
float vertex3[3];
struct {
float x;
float y;
+13 -13
View File
@@ -93,17 +93,17 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
{
int16_t type = libSurf->type;
int16_t force = libSurf->force;
s32 x1 = libSurf->vertices[0][0];
s32 y1 = libSurf->vertices[0][1];
s32 z1 = libSurf->vertices[0][2];
s32 x2 = libSurf->vertices[1][0];
s32 y2 = libSurf->vertices[1][1];
s32 z2 = libSurf->vertices[1][2];
s32 x3 = libSurf->vertices[2][0];
s32 y3 = libSurf->vertices[2][1];
s32 z3 = libSurf->vertices[2][2];
f32 x1 = libSurf->vertices[0][0];
f32 y1 = libSurf->vertices[0][1];
f32 z1 = libSurf->vertices[0][2];
f32 x2 = libSurf->vertices[1][0];
f32 y2 = libSurf->vertices[1][1];
f32 z2 = libSurf->vertices[1][2];
f32 x3 = libSurf->vertices[2][0];
f32 y3 = libSurf->vertices[2][1];
f32 z3 = libSurf->vertices[2][2];
s32 maxY, minY;
f32 maxY, minY;
f32 nx, ny, nz;
f32 mag;
@@ -158,9 +158,9 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
if (mag < 0.0001) {
DEBUG_PRINT("ERROR: normal magnitude is very close to zero:");
DEBUG_PRINT("v1 %i %i %i", x1, y1, z1 );
DEBUG_PRINT("v2 %i %i %i", x2, y2, z2 );
DEBUG_PRINT("v3 %i %i %i", x3, y3, z3 );
DEBUG_PRINT("v1 %f %f %f", x1, y1, z1 );
DEBUG_PRINT("v2 %f %f %f", x2, y2, z2 );
DEBUG_PRINT("v3 %f %f %f", x3, y3, z3 );
surface->isValid = 0;
return;
}
+16 -1
View File
@@ -56,6 +56,17 @@ float lerp(float a, float b, float amount)
return a + (b - a) * amount;
}
static void DebugPrint(const char *message)
{
if (message == nullptr)
{
return;
}
printf("[SM64] %s\n", message);
fflush(stdout);
}
int main( void )
{
size_t romSize;
@@ -73,9 +84,13 @@ int main( void )
sm64_global_terminate();
sm64_global_init( rom, texture );
sm64_audio_init(rom);
// sm64_register_debug_print_function(DebugPrint);
sm64_static_surfaces_load( surfaces, surfaces_count );
int32_t marioId = sm64_mario_create( 0, 1000, 0 );
printf("MarioID: %i\n", marioId);
free( rom );
RenderState renderState;
@@ -94,7 +109,7 @@ int main( void )
renderer = &gl20_renderer;
#endif
context_init( "libsm64", 800, 600, major, minor );
context_init( "libsm64", 1280, 720, major, minor );
renderer->init( &renderState, texture );
struct SM64MarioInputs marioInputs;