diff options
author | Treeki <treeki@gmail.com> | 2012-09-24 00:53:20 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-09-24 00:53:20 +0200 |
commit | ec8ad32b054e7680aec1536b36a02f6aaf154c0b (patch) | |
tree | fc9f598151ac35d72c2aa70c6733de1766615cd1 | |
parent | e739a0171f3efc5791ae32460a341d284efa36be (diff) | |
download | kamek-ec8ad32b054e7680aec1536b36a02f6aaf154c0b.tar.gz kamek-ec8ad32b054e7680aec1536b36a02f6aaf154c0b.zip |
unfinished ActivePhysics debugging
-rw-r--r-- | NewerProjectKP.yaml | 1 | ||||
-rw-r--r-- | apDebug.yaml | 9 | ||||
-rwxr-xr-x | include/game.h | 5 | ||||
-rw-r--r-- | kamek_pal.x | 4 | ||||
-rw-r--r-- | src/apDebug.cpp | 222 |
5 files changed, 241 insertions, 0 deletions
diff --git a/NewerProjectKP.yaml b/NewerProjectKP.yaml index 934ea99..2f66e32 100644 --- a/NewerProjectKP.yaml +++ b/NewerProjectKP.yaml @@ -2,6 +2,7 @@ output_dir: "NewerASM" code_address: 0x808D9000 modules: - processed/prolog.yaml +# - processed/apDebug.yaml # - processed/layoutDebug.yaml - processed/fileselect.yaml - processed/magicplatform.yaml diff --git a/apDebug.yaml b/apDebug.yaml new file mode 100644 index 0000000..25f87fd --- /dev/null +++ b/apDebug.yaml @@ -0,0 +1,9 @@ +--- +source_files: [../src/apDebug.cpp] +hooks: + - name: DrawAPhysics + type: branch_insn + branch_type: b + src_addr_pal: 0x80830BD8 + target_func: 'APDebugDraw(void)' + diff --git a/include/game.h b/include/game.h index 837d340..4695ea6 100755 --- a/include/game.h +++ b/include/game.h @@ -1213,6 +1213,8 @@ public: void update();
+ static Physics *globalListHead;
+ static Physics *globalListTail;
// todo: more stuff that might not be relevant atm
};
@@ -1275,6 +1277,9 @@ public: float xCenter();
// Plus more stuff that isn't needed in the public API, I'm pretty sure.
+
+ static ActivePhysics *globalListHead;
+ static ActivePhysics *globalListTail;
};
diff --git a/kamek_pal.x b/kamek_pal.x index d88df1e..6f7db85 100644 --- a/kamek_pal.x +++ b/kamek_pal.x @@ -648,12 +648,15 @@ SECTIONS { addToList__13ActivePhysicsFv = 0x8008C330; initWithStruct__13ActivePhysicsFP8dActor_cPCQ213ActivePhysics4Info = 0x8008C3E0; + globalListHead__13ActivePhysics = 0x8042A140; + __ct__7PhysicsFv = 0x8007F7A0; __dt__7PhysicsFv = 0x8007F810; baseSetup__7PhysicsFP8dActor_cPvPvPvUcUc = 0x8007F9B0; setup__7PhysicsFP8dActor_cffffPvPvPvUcUcP7Point2d = 0x8007FA40; setup__7PhysicsFP8dActor_cPQ27Physics4InfoUcUcP7Point2d = 0x8007FB10; + globalListHead__7Physics = 0x8042A0C0; spinningPhysicsCallback = 0x808A2380; /* spinningPhysicsCallback__7Physics = 0x808A2380; */ @@ -1192,6 +1195,7 @@ SECTIONS { GXSetTexCoordGen2 = 0x801C4910; GXSetNumTexGens = 0x801C4B60; GXBegin = 0x801C56B0; + GXSetLineWidth = 0x801C58E0; GXSetCullMode = 0x801C59A0; GXInitLightAttn = 0x801C6570; GXInitLightSpot = 0x801C65B0; diff --git a/src/apDebug.cpp b/src/apDebug.cpp new file mode 100644 index 0000000..f534e58 --- /dev/null +++ b/src/apDebug.cpp @@ -0,0 +1,222 @@ +#include <game.h> +#define GEKKO +#include "rvl/mtx.h" +#include "rvl/GXEnum.h" +#include "rvl/GXStruct.h" +#include "rvl/GXTransform.h" +#include "rvl/GXGeometry.h" +#include "rvl/GXDispList.h" +#include "rvl/GXLighting.h" +#include "rvl/GXTev.h" +#include "rvl/GXTexture.h" +#include "rvl/GXCull.h" +#include "rvl/GXPixel.h" +#include "rvl/GXBump.h" +#include "rvl/GXVert.h" +#include "rvl/vifuncs.h" + +class APDebugDrawer : public m3d::proc_c { + public: + APDebugDrawer(); + + bool amISetUp; + mHeapAllocator_c allocator; + + void setMeUp(); + + void drawMe(); + + void drawOpa(); + void drawXlu(); +}; + + +static APDebugDrawer defaultInstance; + +int APDebugDraw() { + defaultInstance.drawMe(); + return 1; +} + + +APDebugDrawer::APDebugDrawer() { + amISetUp = false; +} + +void APDebugDrawer::setMeUp() { + allocator.setup(GameHeaps[0], 0x20); + setup(&allocator); +} + +void APDebugDrawer::drawMe() { + if (!amISetUp) { + setMeUp(); + amISetUp = true; + } + + scheduleForDrawing(); +} + +void APDebugDrawer::drawOpa() { +} +void APDebugDrawer::drawXlu() { + GXClearVtxDesc(); + + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); + + GXSetNumIndStages(0); + for (int i = 0; i < 0x10; i++) + GXSetTevDirect((GXTevStageID)i); + + GXSetNumChans(1); + GXSetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + GXSetChanAmbColor(GX_COLOR0A0, (GXColor){255,255,255,255}); + GXSetChanMatColor(GX_COLOR0A0, (GXColor){255,255,255,255}); + GXSetNumTexGens(0); + + GXSetNumTevStages(1); + GXSetNumIndStages(0); + + GXSetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA); + + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); +// GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C1, GX_CC_C0, GX_CC_RASC, GX_CC_ZERO); +// GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); +// GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_A0, GX_CA_RASA, GX_CA_ZERO); +// GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + + GXSetZCompLoc(GX_FALSE); + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); + GXSetZMode(GX_TRUE, GX_LEQUAL, GX_FALSE); + GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_OR, GX_GREATER, 0); + + GXSetFog(GX_FOG_NONE, 0, 0, 0, 0, (GXColor){0,0,0,0}); + GXSetFogRangeAdj(GX_FALSE, 0, 0); + + GXSetCullMode(GX_CULL_NONE); + + GXSetDither(GX_TRUE); + GXSetLineWidth(18, GX_TO_ZERO); + + GXSetTevColor(GX_TEVREG0, (GXColor){255,255,255,255}); + GXSetTevColor(GX_TEVREG1, (GXColor){0,0,0,255}); + + ActivePhysics *ap = ActivePhysics::globalListHead; + + while (ap) { + u32 uptr = (u32)ap; + u8 r = (uptr>>16)&0xFF; + u8 g = (uptr>>8)&0xFF; + u8 b = uptr&0xFF; + u8 a = 0xFF; + + GXBegin(GX_LINES, GX_VTXFMT0, 10); + + float centreX = ap->owner->pos.x + ap->info.xDistToCenter; + float centreY = ap->owner->pos.y + ap->info.yDistToCenter; + float edgeDistX = ap->info.xDistToEdge; + float edgeDistY = ap->info.yDistToEdge; + + float tlX = centreX - edgeDistX, tlY = centreY + edgeDistY; + float trX = centreX + edgeDistX, trY = centreY + edgeDistY; + + float blX = centreX - edgeDistX, blY = centreY - edgeDistY; + float brX = centreX + edgeDistX, brY = centreY - edgeDistY; + + // Top + GXPosition3f32(tlX, tlY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(trX, trY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Left + GXPosition3f32(tlX, tlY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(blX, blY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Right + GXPosition3f32(trX, trY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(brX, brY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Bottom + GXPosition3f32(blX, blY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(brX, brY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Diagonal + GXPosition3f32(trX, trY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(blX, blY, 8000.0f); + GXColor4u8(r,g,b,a); + + GXEnd(); + + ap = ap->listPrev; + } + + Physics *p = Physics::globalListHead; + + while (p) { + u32 uptr = (u32)p; + u8 r = (uptr>>16)&0xFF; + u8 g = (uptr>>8)&0xFF; + u8 b = uptr&0xFF; + u8 a = 0xFF; + + GXBegin(GX_LINES, GX_VTXFMT0, 10); + + float centreX = p->owner->pos.x; + float centreY = p->owner->pos.y; + float edgeDistX = p->_88; + float edgeDistY = p->_8C; + + float tlX = centreX + p->x, tlY = centreY + p->y; + float trX = centreX + p->_88, trY = centreY + p->y; + + float blX = centreX + p->x, blY = centreY + p->_8C; + float brX = centreX + p->_88, brY = centreY + p->_8C; + + // Top + GXPosition3f32(tlX, tlY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(trX, trY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Left + GXPosition3f32(tlX, tlY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(blX, blY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Right + GXPosition3f32(trX, trY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(brX, brY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Bottom + GXPosition3f32(blX, blY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(brX, brY, 8000.0f); + GXColor4u8(r,g,b,a); + + // Diagonal + GXPosition3f32(trX, trY, 8000.0f); + GXColor4u8(r,g,b,a); + GXPosition3f32(blX, blY, 8000.0f); + GXColor4u8(r,g,b,a); + + GXEnd(); + + p = p->next; + } +} |