Merge pull request #35 from Reonu/puppycamera2

Visual Collision Debug
This commit is contained in:
Fazana
2021-08-20 18:03:52 +01:00
committed by GitHub
9 changed files with 623 additions and 4 deletions

View File

@@ -117,7 +117,10 @@
//#define CUSTOM_DEBUG
// Include Puppyprint, a display library for text and large images. Also includes a custom, enhanced performance profiler.
//#define PUPPYPRINT
//#define PUPPYPRINT_DEBUG 0
#define PUPPYPRINT_DEBUG 0
//Visual debug enables some collision visuals. Tapping Right on the dpad will cycle between visual hitboxes, visual surfaces, both, and neither.
//If puppyprint is enabled, then this can be cycled only while the screen is active.
//#define VISUAL_DEBUG
// BUG/GAME QOL FIXES
// Fix instant warp offset not working when warping across different areas

View File

@@ -24,6 +24,7 @@
#include "level_table.h"
#include "dialog_ids.h"
#include "puppyprint.h"
#include "debug_box.h"
struct SpawnInfo gPlayerSpawnInfos[1];
struct GraphNode *gGraphNodePointers[MODEL_ID_COUNT];
@@ -366,6 +367,13 @@ void render_game(void) {
if (gCurrentArea != NULL && !gWarpTransition.pauseRendering) {
geo_process_root(gCurrentArea->unk04, D_8032CE74, D_8032CE78, gFBSetColor);
#ifdef VISUAL_DEBUG
if (hitboxView)
render_debug_boxes();
if (surfaceView)
visual_surface_loop();
#endif
gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_8032CF00));
gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, gBorderHeight, SCREEN_WIDTH,

511
src/game/debug_box.c Normal file

File diff suppressed because it is too large Load Diff

38
src/game/debug_box.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef DEBUG_BOX_H
#define DEBUG_BOX_H
#ifdef VISUAL_DEBUG
/**
* @file debug_box.h
* Draws debug boxes, see debug_box.c for details
*/
#include "types.h"
/**
* The max amount of debug boxes before debug_box() just returns.
* You can set this to something higher, but you might run out of space in the gfx pool.
*/
#define MAX_DEBUG_BOXES 512
#define DEBUG_SHAPE_BOX 0x0
#define DEBUG_SHAPE_CYLINDER 0x1
extern u8 hitboxView;
extern u8 surfaceView;
extern void debug_box_input(void);
void debug_box_color(u32 color);
void debug_box(Vec3f center, Vec3f bounds, s32 type);
void debug_box_rot(Vec3f center, Vec3f bounds, s16 yaw, s32 type);
void debug_box_pos(Vec3f pMin, Vec3f pMax, s32 type);
void debug_box_pos_rot(Vec3f pMin, Vec3f pMax, s16 yaw, s32 type);
void render_debug_boxes(void);
extern void visual_surface_loop(void);
#endif
#endif /* DEBUG_BOX_H */

View File

@@ -32,6 +32,7 @@
#include "puppyprint.h"
#include <prevent_bss_reordering.h>
#include "puppycam2.h"
#include "debug_box.h"
// First 3 controller slots
struct Controller gControllers[3];
@@ -773,6 +774,9 @@ void thread5_game_loop(UNUSED void *arg) {
select_gfx_pool();
read_controller_inputs();
addr = level_script_execute(addr);
#if defined(VISUAL_DEBUG) && !defined(PUPPYPRINT)
debug_box_input();
#endif
#ifdef PUPPYPRINT
profiler_update(scriptTime, lastTime);
if (benchmarkLoop > 0 && benchOption == 0)

View File

@@ -23,6 +23,7 @@
#include "save_file.h"
#include "mario.h"
#include "puppyprint.h"
#include "debug_box.h"
#ifdef PUPPYCAM
@@ -1156,7 +1157,13 @@ static s32 puppycam_check_volume_bounds(struct sPuppyVolume *volume, s32 index)
//Use the dark, forbidden arts of trig to rotate the volume.
pos[0] = rel[2] * sins(sPuppyVolumeStack[index]->rot) + rel[0] * coss(sPuppyVolumeStack[index]->rot);
pos[1] = rel[2] * coss(sPuppyVolumeStack[index]->rot) - rel[0] * sins(sPuppyVolumeStack[index]->rot);
#ifdef VISUAL_DEBUG
Vec3f debugPos[2];
vec3f_set(debugPos[0], sPuppyVolumeStack[index]->pos[0], sPuppyVolumeStack[index]->pos[1], sPuppyVolumeStack[index]->pos[2]);
vec3f_set(debugPos[1], sPuppyVolumeStack[index]->radius[0], sPuppyVolumeStack[index]->radius[1], sPuppyVolumeStack[index]->radius[2]);
debug_box_color(0x0000FF00);
debug_box_rot(debugPos[0], debugPos[1], sPuppyVolumeStack[index]->rot, DEBUG_SHAPE_BOX);
#endif
//Now compare values.
if (-sPuppyVolumeStack[index]->radius[0] < pos[0] && pos[0] < sPuppyVolumeStack[index]->radius[0] &&
-sPuppyVolumeStack[index]->radius[1] < rel[1] && rel[1] < sPuppyVolumeStack[index]->radius[1] &&
@@ -1175,7 +1182,13 @@ static s32 puppycam_check_volume_bounds(struct sPuppyVolume *volume, s32 index)
rel[1] = sPuppyVolumeStack[index]->pos[1] - gPuppyCam.targetObj->oPosY;
rel[2] = sPuppyVolumeStack[index]->pos[2] - gPuppyCam.targetObj->oPosZ;
dist = sqrtf((rel[0] * rel[0]) + (rel[2] * rel[2]));
#ifdef VISUAL_DEBUG
Vec3f debugPos[2];
vec3f_set(debugPos[0], sPuppyVolumeStack[index]->pos[0], sPuppyVolumeStack[index]->pos[1], sPuppyVolumeStack[index]->pos[2]);
vec3f_set(debugPos[1], sPuppyVolumeStack[index]->radius[0], sPuppyVolumeStack[index]->radius[1], sPuppyVolumeStack[index]->radius[2]);
debug_box_color(0x0000FF00);
debug_box_rot(debugPos[0], debugPos[1], sPuppyVolumeStack[index]->rot, DEBUG_SHAPE_CYLINDER);
#endif
distCheck = (dist < sPuppyVolumeStack[index]->radius[0]);
if (-sPuppyVolumeStack[index]->radius[1] < rel[1] && rel[1] < sPuppyVolumeStack[index]->radius[1] && distCheck)

View File

@@ -163,6 +163,7 @@ enum gPuppyCamBeh
PUPPYCAM_BEHAVIOUR_HEIGHT_HELPER | PUPPYCAM_BEHAVIOUR_TURN_HELPER | PUPPYCAM_BEHAVIOUR_INPUT_NORMAL | PUPPYCAM_BEHAVIOUR_PANSHIFT | PUPPYCAM_BEHAVIOUR_COLLISION
};
extern const struct sPuppyAngles puppyAnglesNull;
extern u8 gPCOptionOpen;
extern s32 gPuppyError;
extern struct gPuppyStruct gPuppyCam;

View File

@@ -38,6 +38,7 @@ There's also a custom option that's left blank. It runs benchmark_custom which c
#include "engine/surface_load.h"
#include "audio/data.h"
#include "hud.h"
#include "debug_box.h"
u8 currEnv[4];
u8 fDebug = 0;
@@ -79,6 +80,9 @@ s8 ramViewer = 0;
s32 ramsizeSegment[33] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
s32 audioPool[12];
s32 mempool;
//Collision
u8 collisionViewer = 0;
s32 numSurfaces = 0;
extern u8 _mainSegmentStart[];
extern u8 _mainSegmentEnd[];
@@ -451,13 +455,22 @@ void puppyprint_profiler_process(void)
{
benchViewer ^= 1;
ramViewer = 0;
collisionViewer = 0;
}
else
if (gPlayer1Controller->buttonPressed & U_JPAD && !(gPlayer1Controller->buttonPressed & L_TRIG))
if (gPlayer1Controller->buttonPressed & U_JPAD)
{
ramViewer ^= 1;
benchViewer = 0;
collisionViewer = 0;
}
#ifdef VISUAL_DEBUG
else
if (!benchViewer && !ramViewer)
{
debug_box_input();
}
#endif
if (benchViewer)
{
if (gPlayer1Controller->buttonPressed & R_JPAD)

View File

@@ -13,6 +13,7 @@
#include "game_init.h"
#include "engine/extended_bounds.h"
#include "puppyprint.h"
#include "debug_box.h"
#include "config.h"
@@ -854,6 +855,33 @@ static void geo_process_object(struct Object *node) {
mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]);
gMatStackFixed[gMatStackIndex] = mtx;
if (node->header.gfx.sharedChild != NULL) {
#ifdef VISUAL_DEBUG
if (hitboxView)
{
Vec3f bnds1;
Vec3f bnds2;
//This will create a cylinder that visualises their hitbox.
//If they do not have a hitbox, it will be a small white cube instead.
if (node->oIntangibleTimer != -1)
{
vec3f_set(bnds1, node->oPosX, node->oPosY - node->hitboxDownOffset, node->oPosZ);
vec3f_set(bnds2, node->hitboxRadius, node->hitboxHeight-node->hitboxDownOffset, node->hitboxRadius);
debug_box_color(0x800000FF);
debug_box(bnds1, bnds2, DEBUG_SHAPE_CYLINDER);
vec3f_set(bnds1, node->oPosX, node->oPosY - node->hitboxDownOffset, node->oPosZ);
vec3f_set(bnds2, node->hurtboxRadius, node->hurtboxHeight, node->hurtboxRadius);
debug_box_color(0x8FF00000);
debug_box(bnds1, bnds2, DEBUG_SHAPE_CYLINDER);
}
else
{
vec3f_set(bnds1, node->oPosX, node->oPosY - 15, node->oPosZ);
vec3f_set(bnds2, 30, 30, 30);
debug_box_color(0x80FFFFFF);
debug_box(bnds1, bnds2, DEBUG_SHAPE_BOX);
}
}
#endif
gCurGraphNodeObject = (struct GraphNodeObject *) node;
node->header.gfx.sharedChild->parent = &node->header.gfx.node;
geo_process_node_and_siblings(node->header.gfx.sharedChild);