diff --git a/.gitignore b/.gitignore index e1ab439..f9e1927 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /build/ /libsm64.so Makefile +/src/mario diff --git a/configure b/configure index dc95e54..1342002 100755 --- a/configure +++ b/configure @@ -7,6 +7,11 @@ CFLAGS='-Wall -fPIC' BIN_FILE='libsm64.so' LDFLAGS='' +prepare() { + git submodule update --init --recursive + ./extract-decomp-source.py +} + c_to_obj() { printf 'build/' echo "$1" | sed 's/cp*$/o/;s:/:_:g' @@ -34,9 +39,14 @@ print_makefile() { make_cmd "$f" done - echo '.PHONY: clean run' + echo -e "src/mario/anim_data.inc.c: extract-decomp-source.py\n\t ./extract-decomp-source.py" + echo -e "src/mario/geo.inc.c: extract-decomp-source.py\n\t ./extract-decomp-source.py" + echo -e "src/mario/model.inc.c: extract-decomp-source.py\n\t ./extract-decomp-source.py" + + echo '.PHONY: clean run .FORCE' echo -e "clean:\n\t find . -iname '*.o' | xargs rm && rm -f ./$BIN_FILE" } +prepare mkdir -p build -print_makefile > Makefile +print_makefile > Makefile \ No newline at end of file diff --git a/extract-decomp-source.py b/extract-decomp-source.py new file mode 100755 index 0000000..b189e76 --- /dev/null +++ b/extract-decomp-source.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +import sys +import os +import subprocess +import shutil + +geo_inc_c_header = """ +#include "../include/sm64.h" +#include "../include/types.h" +#include "../include/geo_commands.h" +#include "../game/rendering_graph_node.h" +#include "../shim.h" +#include "../game/object_stuff.h" +#include "../game/behavior_actions.h" +#include "model.inc.h" + +#define SHADOW_CIRCLE_PLAYER 99 +""" + +geo_inc_c_footer = """ +const GeoLayout mario_geo_libsm64[] = { + GEO_SHADOW(SHADOW_CIRCLE_PLAYER, 0xB4, 100), + GEO_OPEN_NODE(), + GEO_ZBUFFER(1), + GEO_OPEN_NODE(), + GEO_SCALE(0x00, 16384), + GEO_OPEN_NODE(), + GEO_ASM(0, geo_mirror_mario_backface_culling), + GEO_ASM(0, geo_mirror_mario_set_alpha), + GEO_BRANCH(1, mario_geo_load_body), + GEO_ASM(1, geo_mirror_mario_backface_culling), + GEO_CLOSE_NODE(), + GEO_CLOSE_NODE(), + GEO_CLOSE_NODE(), + GEO_END(), +}; + +void *mario_geo_ptr = (void*)mario_geo_libsm64; +""" + +geo_inc_h = """ +#pragma once + +extern void *mario_geo_ptr; +""" + +anim_data_h = """ +#pragma once + +extern void *mario_anims_ptr; +""" + +anim_data_c_footer = """ +void *mario_anims_ptr = &gMarioAnims; +""" + +def main(): + os.chdir(os.path.dirname(sys.argv[0])) + shutil.rmtree("src/mario", ignore_errors=True) + os.makedirs("src/mario", exist_ok=True) + + geo_inc_c = "" + model_inc_c = "" + model_inc_h_lines = [ + "#pragma once", + '#include "../include/types.h"', + '#include "../include/PR/gbi.h"' + ] + + with open("sm64-port/actors/mario/geo.inc.c", "r") as file: + geo_inc_c = file.read() + + with open("sm64-port/actors/mario/model.inc.c", "r") as file: + lines = file.read().splitlines() + + for line in lines: + if line.startswith("const "): + model_inc_h_lines.append("extern " + line.replace(" = {", ";")) + + lines = [ x.replace("#include", "//#include") for x in lines ] + lines.insert(0, "#include \"../model_hack.h\"") + model_inc_c = "\n".join(lines) + + with open("src/mario/geo.inc.c", "w") as file: + file.write(geo_inc_c_header + geo_inc_c + geo_inc_c_footer) + + with open("src/mario/model.inc.c", "w") as file: + file.write(model_inc_c) + + with open("src/mario/model.inc.h", "w") as file: + file.write("\n".join(model_inc_h_lines)) + + with open("src/mario/geo.inc.h", "w") as file: + file.write(geo_inc_h) + + os.chdir("sm64-port") + mario_anims_pipe = subprocess.run(["tools/mario_anims_converter.py", "-l"], stdout=subprocess.PIPE) + mario_anims_string = mario_anims_pipe.stdout.decode('utf-8') + os.chdir("..") + + with open("src/mario/anim_data.c", "w") as file: + file.write(mario_anims_string.replace('#include "types.h"', '#include "../include/types.h"\n#include "anim_data.h"') + anim_data_c_footer) + + with open("src/mario/anim_data.h", "w") as file: + file.write(anim_data_h) + +main() \ No newline at end of file diff --git a/src/game/behavior_actions.c b/src/game/behavior_actions.c new file mode 100644 index 0000000..2445c2b --- /dev/null +++ b/src/game/behavior_actions.c @@ -0,0 +1,19 @@ +#include "behavior_actions.h" +#include "rendering_graph_node.h" +#include "../shim.h" + +// not sure what this is doing here. not in a behavior file. +Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { + Mat4 sp20; + struct Object *sp1C; + + if (run == TRUE) { + sp1C = (struct Object *) gCurGraphNodeObject; + if (sp1C == gMarioObject && sp1C->prevObj != NULL) { + create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr); + obj_update_pos_from_parent_transformation(sp20, sp1C->prevObj); + obj_set_gfx_pos_from_pos(sp1C->prevObj); + } + } + return NULL; +} \ No newline at end of file diff --git a/src/game/behavior_actions.h b/src/game/behavior_actions.h new file mode 100644 index 0000000..d949fed --- /dev/null +++ b/src/game/behavior_actions.h @@ -0,0 +1,6 @@ +#pragma once + +#include "../include/types.h" +#include "../mario/model.inc.h" + +extern Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx); \ No newline at end of file diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 87360f0..9853556 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -18,7 +18,7 @@ -#include "../model/model.inc.h" +#include "../mario/model.inc.h" // PATCH diff --git a/src/libsm64.c b/src/libsm64.c index ea6a9d8..45c96c9 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -16,9 +16,9 @@ #include "engine/surface_collision.h" #include "engine/graph_node.h" #include "engine/geo_layout.h" -#include "assets/mario_anim_data.h" #include "game/rendering_graph_node.h" -#include "model/geo.inc.h" +#include "mario/anim_data.h" +#include "mario/geo.inc.h" #include "gfx_adapter.h" static struct AllocOnlyPool *s_mario_geo_pool; @@ -86,7 +86,7 @@ void sm64_global_init( SM64DebugPrintFunctionPtr debugPrintFunction ) s_mario_geo_pool = alloc_only_pool_init(); s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr ); - D_80339D10.animDmaTable = (void*)(&gMarioAnims); + D_80339D10.animDmaTable = mario_anims_ptr; D_80339D10.currentAnimAddr = NULL; D_80339D10.targetAnim = malloc( 0x4000 ); diff --git a/src/model_hack.h b/src/model_hack.h new file mode 100644 index 0000000..a01fa80 --- /dev/null +++ b/src/model_hack.h @@ -0,0 +1,115 @@ +#pragma once + +#include "include/types.h" +#include "gfx_adapter_commands.h" + +/* + * Vertex (set up for use with colors) + */ +typedef struct { +#ifndef GBI_FLOATS + short ob[3]; /* x, y, z */ +#else + float ob[3]; /* x, y, z */ +#endif + unsigned short flag; + short tc[2]; /* texture coord */ + unsigned char cn[4]; /* color & alpha */ +} Vtx_t; + +/* + * Vertex (set up for use with normals) + */ +typedef struct { +#ifndef GBI_FLOATS + short ob[3]; /* x, y, z */ +#else + float ob[3]; /* x, y, z */ +#endif + unsigned short flag; + short tc[2]; /* texture coord */ + signed char n[3]; /* normal */ + unsigned char a; /* alpha */ +} Vtx_tn; + +typedef union { + Vtx_t v; /* Use this one for colors */ + Vtx_tn n; /* Use this one for normals */ + long long int force_structure_alignment; +} Vtx; + +typedef struct { + unsigned char col[3]; /* diffuse light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of diffuse light value (rgba) */ + char pad2; + signed char dir[3]; /* direction of light (normalized) */ + char pad3; +} Light_t; + +typedef struct { + unsigned char col[3]; /* ambient light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of ambient light value (rgba) */ + char pad2; +} Ambient_t; + +typedef union { + Light_t l; + long long int force_structure_alignment[2]; +} Light; + +typedef union { + Ambient_t l; + long long int force_structure_alignment[1]; +} Ambient; + +typedef struct { + Ambient a; + Light l[1]; +} Lights1; + +//static const Lights1 mario_blue_lights_group = gdSPDefLights1( 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x28, 0x28, 0x28); +#define gdSPDefLights1(ar,ag,ab,r1,g1,b1,x1,y1,z1) {{{ {ar,ag,ab},0,{ar,ag,ab},0}}, {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}} } + +#define gsSPVertex(v, n, v0) \ + GFXCMD_VertexData, \ + (int64_t)v, n, v0 + +#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ + GFXCMD_Triangle, \ + v00, v01, v02, flag0, \ + GFXCMD_Triangle, \ + v10, v11, v12, flag1 + +#define gsSP1Triangle(v00, v01, v02, flag0) \ + GFXCMD_Triangle, \ + v00, v01, v02, flag0 + +#define gsSPEndDisplayList() \ + GFXCMD_EndDisplayList + +#define gsSPDisplayList(dl) \ + GFXCMD_SubDisplayList, \ + (int64_t)dl + +#define gsSPLight(l, n) \ + GFXCMD_Light, \ + (int64_t)l, n + +#define gsDPPipeSync() (GFXCMD_None) +#define gsDPSetCombineMode(a, b) (GFXCMD_None) +#define gsSPSetGeometryMode(word) (GFXCMD_None) +#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) (GFXCMD_None) +#define gsSPTexture(s, t, level, tile, on) (GFXCMD_None) +#define gsSPClearGeometryMode(word) (GFXCMD_None) +#define gsDPSetEnvColor(r, g, b, a) (GFXCMD_None) +#define gsDPSetAlphaCompare(type) (GFXCMD_None) +#define gsDPTileSync() (GFXCMD_None) +#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, maskt, shiftt, cms, masks, shifts) (GFXCMD_None) +#define gsDPSetTileSize(t, uls, ult, lrs, lrt) (GFXCMD_None) +#define gsDPSetTextureImage(f, s, w, i) (GFXCMD_None) +#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) (GFXCMD_None) +#define gsDPLoadSync() (GFXCMD_None) + +typedef int64_t Gfx; \ No newline at end of file