Loading animation data from the rom instead of decomp, partial impl
This commit is contained in:
@@ -2,3 +2,5 @@
|
||||
/libsm64.so
|
||||
Makefile
|
||||
/src/mario
|
||||
*.z64
|
||||
/src/anim_datac.h
|
||||
@@ -39,7 +39,6 @@ print_makefile() {
|
||||
make_cmd "$f"
|
||||
done
|
||||
|
||||
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"
|
||||
|
||||
|
||||
+10
-10
@@ -93,15 +93,15 @@ def main():
|
||||
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)
|
||||
# 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()
|
||||
+8
-3
@@ -17,9 +17,10 @@
|
||||
#include "engine/graph_node.h"
|
||||
#include "engine/geo_layout.h"
|
||||
#include "game/rendering_graph_node.h"
|
||||
#include "mario/anim_data.h"
|
||||
//#include "mario/anim_data.h"
|
||||
#include "mario/geo.inc.h"
|
||||
#include "gfx_adapter.h"
|
||||
#include "load_anim_data.h"
|
||||
|
||||
static struct AllocOnlyPool *s_mario_geo_pool;
|
||||
static struct GraphNode *s_mario_graph_node;
|
||||
@@ -75,10 +76,14 @@ static struct Area *hack_build_area( void )
|
||||
return result;
|
||||
}
|
||||
|
||||
void sm64_global_init( SM64DebugPrintFunctionPtr debugPrintFunction )
|
||||
|
||||
|
||||
void sm64_global_init( uint8_t *rom, SM64DebugPrintFunctionPtr debugPrintFunction )
|
||||
{
|
||||
gDebugPrint = debugPrintFunction;
|
||||
|
||||
load_mario_anims_from_rom( rom );
|
||||
|
||||
gMarioObject = hack_allocate_mario();
|
||||
gCurrentArea = hack_build_area();
|
||||
gCurrentObject = gMarioObject;
|
||||
@@ -86,7 +91,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 = mario_anims_ptr;
|
||||
D_80339D10.animDmaTable = gMarioAnimsPtr; // mario_anims_ptr;
|
||||
D_80339D10.currentAnimAddr = NULL;
|
||||
D_80339D10.targetAnim = malloc( 0x4000 );
|
||||
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ struct SM64MarioGeometryBuffers
|
||||
|
||||
typedef void (*SM64DebugPrintFunctionPtr)( const char * );
|
||||
|
||||
extern void sm64_global_init( SM64DebugPrintFunctionPtr debugPrintFunction );
|
||||
extern void sm64_global_init( uint8_t *rom, SM64DebugPrintFunctionPtr debugPrintFunction );
|
||||
extern void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces );
|
||||
extern void sm64_mario_reset( int16_t marioX, int16_t marioY, int16_t marioZ );
|
||||
extern void sm64_mario_tick( const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers );
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
#include "load_anim_data.h"
|
||||
#include "include/types.h"
|
||||
#include "anim_datac.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static struct MarioAnimsObj s_marioAnimsObj;
|
||||
|
||||
#define ANIM_DATA_ADDRESS 0x004EC000
|
||||
|
||||
#define MAX_ANIM_DATA_SIZE ( 1024 * 1024 )
|
||||
|
||||
void *gMarioAnimsPtr;
|
||||
|
||||
uint16_t read_u16_be( uint8_t **ptr )
|
||||
{
|
||||
uint8_t *p = *ptr;
|
||||
|
||||
uint32_t result =
|
||||
(uint32_t)p[0] << 8 |
|
||||
(uint32_t)p[1];
|
||||
|
||||
*ptr += 2;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int16_t read_s16_be( uint8_t **ptr )
|
||||
{
|
||||
return (int16_t)read_u16_be(ptr);
|
||||
}
|
||||
|
||||
uint32_t read_u32_be( uint8_t **ptr )
|
||||
{
|
||||
uint8_t *p = *ptr;
|
||||
|
||||
uint32_t result =
|
||||
(uint32_t)p[0] << 24 |
|
||||
(uint32_t)p[1] << 16 |
|
||||
(uint32_t)p[2] << 8 |
|
||||
(uint32_t)p[3];
|
||||
|
||||
*ptr += 4;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void write_u16_se( uint8_t **ptr, uint16_t val )
|
||||
{
|
||||
while( (size_t)(*ptr) % 2 > 0 )
|
||||
*ptr += 1;
|
||||
|
||||
uint16_t *p = *ptr;
|
||||
*p = val;
|
||||
*ptr += 2;
|
||||
}
|
||||
|
||||
void write_s16_se( uint8_t **ptr, int16_t val )
|
||||
{
|
||||
while( (size_t)(*ptr) % 2 > 0 )
|
||||
*ptr += 1;
|
||||
|
||||
uint16_t *p = *ptr;
|
||||
*p = (uint16_t)val;
|
||||
*ptr += 2;
|
||||
}
|
||||
|
||||
void write_u32_se( uint8_t **ptr, uint32_t val )
|
||||
{
|
||||
while( (size_t)(*ptr) % 4 > 0 )
|
||||
*ptr += 1;
|
||||
|
||||
uint32_t *p = *ptr;
|
||||
*p = val;
|
||||
*ptr += 4;
|
||||
}
|
||||
|
||||
void write_u64_se( uint8_t **ptr, uint64_t val )
|
||||
{
|
||||
while( (size_t)(*ptr) % 8 > 0 )
|
||||
*ptr += 1;
|
||||
|
||||
uint64_t *p = *ptr;
|
||||
*p = val;
|
||||
*ptr += 8;
|
||||
}
|
||||
|
||||
#define GET_OFFSET_SIZE_PAIR_PTR( n ) ((struct OffsetSizePair*)( buffer + 8 + sizeof(void*) + (n)*8 ))
|
||||
#define OVERWRITE_OFFSET( n, v ) do { ((struct OffsetSizePair*)( buffer + 8 + sizeof(void*) + (n)*8 ))->offset = (v); } while(0)
|
||||
#define OVERWRITE_SIZE( n, v ) do { ((struct OffsetSizePair*)( buffer + 8 + sizeof(void*) + (n)*8 ))->size = (v); } while(0)
|
||||
|
||||
|
||||
|
||||
|
||||
void load_mario_anims_from_rom( uint8_t *rom )
|
||||
{
|
||||
uint8_t *buffer = malloc( MAX_ANIM_DATA_SIZE );
|
||||
uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS;
|
||||
uint8_t *write_ptr = buffer;
|
||||
|
||||
uint32_t num_entries = read_u32_be( &read_ptr );
|
||||
write_u32_se( &write_ptr, num_entries );
|
||||
write_u32_se( &write_ptr, 0 );
|
||||
|
||||
read_u32_be( &read_ptr );
|
||||
write_u64_se( &write_ptr, 0 );
|
||||
|
||||
// Read all of the offset/size pairs for animation entries from the ROM.
|
||||
for( int i = 0; i < num_entries; ++i )
|
||||
{
|
||||
uint32_t offset = read_u32_be( &read_ptr );
|
||||
uint32_t size = read_u32_be( &read_ptr );
|
||||
|
||||
write_u32_se( &write_ptr, offset );
|
||||
write_u32_se( &write_ptr, size );
|
||||
}
|
||||
|
||||
int ptr_size_diff = sizeof(void*) - 4;
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
for( int i = 0; i < num_entries; ++i )
|
||||
{
|
||||
struct OffsetSizePair rom_osp = *GET_OFFSET_SIZE_PAIR_PTR(i);
|
||||
read_ptr = rom + ANIM_DATA_ADDRESS + rom_osp.offset;
|
||||
|
||||
//offset = offset(top)
|
||||
//size = offset(values) + size(values) - offset(top)
|
||||
size_t offset = write_ptr - buffer;
|
||||
OVERWRITE_OFFSET(i, offset);
|
||||
|
||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // flags
|
||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // animYTransDivisor
|
||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // startFrame
|
||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // loopStart
|
||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // loopEnd
|
||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // unusedBoneCount
|
||||
|
||||
//values_ptr = offset(values) - offset(top)
|
||||
//index_ptr = offset(indices) - offset(top)
|
||||
//length = offset(values) + size(values) - offset(top)
|
||||
|
||||
uint32_t values_ptr = read_u32_be( &read_ptr ) + 2 * ptr_size_diff;
|
||||
uint32_t index_ptr = read_u32_be( &read_ptr ) + 2 * ptr_size_diff;
|
||||
uint32_t length = read_u32_be( &read_ptr ) + 4 * ptr_size_diff;
|
||||
|
||||
OVERWRITE_SIZE(i, length);
|
||||
|
||||
printf(" > %x %x \n", offset, length);
|
||||
printf(" >>> %x %x \n", gMarioAnims.entries[i].offset, gMarioAnims.entries[i].size);
|
||||
|
||||
write_u64_se( &write_ptr, values_ptr );
|
||||
write_u64_se( &write_ptr, index_ptr );
|
||||
write_u32_se( &write_ptr, length );
|
||||
|
||||
size_t data_bytes = i < num_entries - 1
|
||||
? rom + ANIM_DATA_ADDRESS + GET_OFFSET_SIZE_PAIR_PTR(i + 1)->offset - read_ptr
|
||||
: length;
|
||||
|
||||
for( int i = 0; i < data_bytes; ++i )
|
||||
*write_ptr++ = *read_ptr++;
|
||||
|
||||
write_ptr += 8;
|
||||
}
|
||||
|
||||
gMarioAnimsPtr = buffer; // &gMarioAnims;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "include/types.h"
|
||||
|
||||
extern void *gMarioAnimsPtr;
|
||||
|
||||
extern void load_mario_anims_from_rom( uint8_t *rom );
|
||||
+2
-4
@@ -10,7 +10,7 @@ struct AllocOnlyPool
|
||||
struct AllocOnlyPool *alloc_only_pool_init(void)
|
||||
{
|
||||
struct AllocOnlyPool *result = malloc( sizeof( struct AllocOnlyPool ));
|
||||
result->id = 0x69;
|
||||
result->id = 0x69; // value doesn't matter
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,9 @@ void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size)
|
||||
void *alloc_display_list(u32 size)
|
||||
{
|
||||
return malloc(size);
|
||||
// size = ALIGN8(size);
|
||||
// return alloc_only_pool_alloc(gGfxAllocOnlyPool, size);
|
||||
}
|
||||
|
||||
void main_pool_free(struct AllocOnlyPool *pool)
|
||||
{
|
||||
// TODO
|
||||
// TODO lol
|
||||
}
|
||||
Reference in New Issue
Block a user