From 4d5594a834a55a94d794e80e62a2d99bec369227 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Tue, 14 Jan 2025 13:50:13 +0100 Subject: [PATCH] Move physics debug draw function --- game.h | 15 ++++++++++++++- racing.h | 21 +++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/game.h b/game.h index 6851851..5da8d1f 100644 --- a/game.h +++ b/game.h @@ -257,6 +257,19 @@ void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y, #endif } +void _LCR_physicdDebugDrawPixel(uint16_t x, uint16_t y, uint8_t color) +{ + if (x > 1 && x < LCR_EFFECTIVE_RESOLUTION_X - 2 && + y > 1 && y < LCR_EFFECTIVE_RESOLUTION_Y - 2) + { + uint16_t c = 0x8101 | (0x8f1f << (2 * color)); + + for (int j = -1; j <= 2; ++j) + for (int i = -1; i <= 2; ++i) + LCR_drawPixelXYUnsafe(x + i,y + j,c); + } +} + static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y, uint_fast16_t color) { @@ -577,7 +590,7 @@ void LCR_gameDraw3DView(void) #if LCR_SETTING_DEBUG_PHYSICS_DRAW LCR_GameUnit camTr[7]; LCR_rendererGetCameraTransform(camTr,camTr + 3,camTr + 6); - LCR_physicsDebugDraw(camTr,camTr + 3,camTr[6]); + LCR_physicsDebugDraw(camTr,camTr + 3,camTr[6],_LCR_physicdDebugDrawPixel); #endif // GUI/HUD: diff --git a/racing.h b/racing.h index 82bff8d..7bbc479 100644 --- a/racing.h +++ b/racing.h @@ -887,19 +887,6 @@ void LCR_racingGetCarBlockCoords(int coords[3]) (LCR_GAME_UNIT * LCR_MAP_SIZE_BLOCKS) / 2) / LCR_GAME_UNIT; } -void _LCR_drawPhysicsDebugPixel(uint16_t x, uint16_t y, uint8_t color) -{ - if (x > 1 && x < LCR_EFFECTIVE_RESOLUTION_X - 2 && - y > 1 && y < LCR_EFFECTIVE_RESOLUTION_Y - 2) - { - uint16_t c = 0x8101 | (0x8f1f << (2 * color)); - - for (int j = -1; j <= 2; ++j) - for (int i = -1; i <= 2; ++i) - LCR_drawPixelXYUnsafe(x + i,y + j,c); // TODO: should be separated, make this independent of game module - } -} - int LCR_racingCarWheelTouchesGround(int wheel) { return ((LCR_racing.wheelCollisions & (LCR_racing.wheelCollisions >> 4)) @@ -1395,7 +1382,8 @@ uint32_t LCR_racingStep(unsigned int input) Draws a simple 3D debug overlap of the physics world. */ void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2], - LCR_GameUnit camFov) + LCR_GameUnit camFov, + void (*drawPixel)(uint16_t, uint16_t, uint8_t)) { #if LCR_SETTING_DEBUG_PHYSICS_DRAW LCR_LOG2("drawing physics debug"); @@ -1414,8 +1402,13 @@ void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2], cView.y = LCR_EFFECTIVE_RESOLUTION_Y; cView.z = (camFov * TPE_F) / LCR_GAME_UNIT; + TPE_worldDebugDraw(&(LCR_racing.physicsWorld),drawPixel, + cPos,cRot,cView,16,LCR_PHYSICS_UNIT / 4,LCR_racing.tick * 4); + +/* TPE_worldDebugDraw(&(LCR_racing.physicsWorld),_LCR_drawPhysicsDebugPixel, cPos,cRot,cView,16,LCR_PHYSICS_UNIT / 4,LCR_racing.tick * 4); +*/ #endif }