diff --git a/config/rel_slices.yml b/config/rel_slices.yml index c129a041..17ec6fea 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -58,6 +58,10 @@ m_common_data.c: m_controller.c: .text: [0x80395BE8, 0x80396120] .rodata: [0x80641D20, 0x80641D50] +m_debug_display.c: + .text: [0x80396198, 0x803965E4] + .data: [0x806512D8, 0x80651328] + .bss: [0x81294008, 0x81294010] m_debug_hayakawa.c: .text: [0x803965E4, 0x803973E8] .rodata: [0x80641D50, 0x80641D90] diff --git a/include/m_debug_display.h b/include/m_debug_display.h index d0c373e5..e35f10e5 100644 --- a/include/m_debug_display.h +++ b/include/m_debug_display.h @@ -4,8 +4,23 @@ #include "types.h" #include "m_play.h" +typedef struct debug_display_s Debug_display; -extern void Debug_Display_output(GAME_PLAY*); +struct debug_display_s{ + xyz_t pos; + s_xyz rot; + xyz_t scale; + rgba8888_t color; + s16 type; + Debug_display* next; +}; extern void Debug_Display_init(); +extern Debug_display* Debug_Display_new(f32 posX, f32 posY, f32 posZ, f32 scaleX, f32 scaleY, f32 scaleZ, +s16 rotX, s16 rotY, s16 rotZ, s8 r, s8 g, s8 b, s8 alpha, s16 type, GRAPH* graph); +extern void Debug_Display_output(GAME_PLAY* play); + + + +extern Debug_display* debug_display; #endif \ No newline at end of file diff --git a/rel/ef_room_sunshine_minsect.c b/rel/ef_room_sunshine_minsect.c index f7b0c0cd..b254a02f 100644 --- a/rel/ef_room_sunshine_minsect.c +++ b/rel/ef_room_sunshine_minsect.c @@ -320,4 +320,4 @@ void Ef_Room_Sunshine_MinsectR_actor_draw(ACTOR* actor, GAME* game){ CLOSE_DISP(graph); } -} \ No newline at end of file +} diff --git a/rel/m_debug_display.c b/rel/m_debug_display.c new file mode 100644 index 00000000..2d202e6e --- /dev/null +++ b/rel/m_debug_display.c @@ -0,0 +1,114 @@ +#include "m_debug_display.h" +#include "m_rcp.h" +#include "sys_matrix.h" + +typedef void (*DEBUG_DISP_PROC)(Debug_display*, void*, GAME_PLAY*); + +typedef struct debug_display_info_s{ + /* 0x0 */ s16 type; + /* 0x4 */ void* arg; +} Debug_display_info; + +static void debug_display_output_sprite_16x16_I8(Debug_display *, void *, GAME_PLAY *); +static void debug_display_output_polygon(Debug_display *, void *, GAME_PLAY *); + +Debug_display* debug_display; + +void Debug_Display_init(){ + debug_display = NULL; +} + +extern Debug_display* Debug_Display_new(f32 posX, f32 posY, f32 posZ, f32 scaleX, f32 scaleY, f32 scaleZ, +s16 rotX, s16 rotY, s16 rotZ, s8 r, s8 g, s8 b, s8 alpha, s16 type, GRAPH* graph){ + + Debug_display* display = debug_display; + + debug_display = GRAPH_ALLOC(graph, sizeof(Debug_display) + 4); + + debug_display->pos.x = posX; + debug_display->pos.y = posY; + debug_display->pos.z = posZ; + debug_display->rot.x = rotX; + debug_display->rot.y = rotY; + debug_display->rot.z = rotZ; + debug_display->scale.x = scaleX; + debug_display->scale.y = scaleY; + debug_display->scale.z = scaleZ; + debug_display->color.r = r; + debug_display->color.g = g; + debug_display->color.b = b; + debug_display->color.a = alpha; + debug_display->type = type; + debug_display->next = display; + + return debug_display; +} + +extern void* no_txt; +extern void* nx_txt; +extern void* np_txt; +extern void* nt_txt; +extern Gfx darrow_model[]; +extern Gfx camera_model[]; + +#pragma pool_data off +extern void Debug_Display_output(GAME_PLAY* play){ + static DEBUG_DISP_PROC debug_display_output_proc[] = { debug_display_output_sprite_16x16_I8, debug_display_output_polygon}; + static Debug_display_info debug_display_shape_data[] = { + {0, &no_txt}, {0, &nx_txt}, {0, &np_txt}, {0, &nt_txt}, {1, darrow_model}, {1, camera_model}, + }; + + Debug_display_info* data; + Debug_display* display = debug_display; + + while(display != NULL){ + data = &debug_display_shape_data[display->type]; + debug_display_output_proc[data->type](display, data->arg, play); + display = display->next; + } +} + +extern Gfx RCP_debug_texture_16x16_8[]; +#pragma pool_data on + +static void debug_display_output_sprite_16x16_I8(Debug_display* display, void* txt, GAME_PLAY* play){ + + OPEN_DISP(play->game.graph); + + softsprite_prim(play->game.graph); + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, 0, display->color.r, display->color.g, display->color.b, display->color.a); + + Matrix_translate(display->pos.x, display->pos.y, display->pos.z, 0); + Matrix_scale(display->scale.x, display->scale.y, display->scale.z, 1); + Matrix_mult(&play->billboard_matrix, 1); + Matrix_rotateXYZ(display->rot.x, display->rot.y, display->rot.z, 1); + + gDPLoadTextureBlock(NEXT_POLY_XLU_DISP, txt, G_IM_FMT_I, G_IM_SIZ_8b, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + + gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPDisplayList(NEXT_POLY_XLU_DISP, RCP_debug_texture_16x16_8); + CLOSE_DISP(play->game.graph); + +} + +static void debug_display_output_polygon(Debug_display* display, void* dl, GAME_PLAY* play) { + static Lights1 material = gdSPDefLights1(128, 128, 128, 255, 255, 255, 73, 73, 73); + + OPEN_DISP(play->game.graph); + + polygon_z_light_prim(play->game.graph); + + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, 0, display->color.r, display->color.g, display->color.b, display->color.a); + + gSPSetLights1(NEXT_POLY_XLU_DISP, material); + + Matrix_softcv3_load(&display->rot, display->pos.x, display->pos.y, display->pos.z); + Matrix_scale(display->scale.x, display->scale.y, display->scale.z, 1); + gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPDisplayList(NEXT_POLY_XLU_DISP, dl); + CLOSE_DISP(play->game.graph); +} +