From c97448e9a87524195862653ae4a5656b3e35ee69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 18 Sep 2018 15:28:43 +0200 Subject: [PATCH] Refactor --- demo1.cpp | 12 +++++------- demo2.cpp | 14 ++++++-------- demo3.cpp | 12 +++++------- general.hpp | 34 ++++++++++++++++++++++------------ 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/demo1.cpp b/demo1.cpp index a7e17d0..59c2733 100644 --- a/demo1.cpp +++ b/demo1.cpp @@ -1026,17 +1026,12 @@ inline void pixelFunc(RCL_PixelInfo *pixel) rgbToIndex(intensity/2,intensity,intensity/3) : rgbToIndex(intensity,intensity/2,0); - putSubsampledPixel // macro + putSubsampledPixel(pixel,c); } void draw() { - RCL_RayConstraints c; - - c.maxHits = 8; - c.maxSteps = 10; - - RCL_render(player.mCamera,floorHeightAt,ceilingHeightAt,textureAt,c); + RCL_render(player.mCamera,floorHeightAt,ceilingHeightAt,textureAt,defaultConstraints); RCL_Unit previousDepth; @@ -1099,6 +1094,9 @@ int main() { initGeneral(); + defaultConstraints.maxHits = 8; + defaultConstraints.maxSteps = 10; + player.setPositionSquare(6,4); sprites[0] = Sprite(spriteStatue,10,5,1,100); diff --git a/demo2.cpp b/demo2.cpp index 29aa8f1..a10921d 100644 --- a/demo2.cpp +++ b/demo2.cpp @@ -961,24 +961,19 @@ inline void pixelFunc(RCL_PixelInfo *pixel) } - putSubsampledPixel // macro + putSubsampledPixel(pixel,c); } void draw() { - RCL_RayConstraints c; - - c.maxHits = 1; - c.maxSteps = 20; - #ifdef HEAD_BOB player.mCamera.height += player.mHeadBob; #endif #ifdef RENDER_PRECISE - RCL_render(player.mCamera,floorHeightAt,0,textureAt,c); + RCL_render(player.mCamera,floorHeightAt,0,textureAt,defaultConstraints); #else - RCL_renderSimple(player.mCamera,floorHeightAt,textureAt,rollAt,c); + RCL_renderSimple(player.mCamera,floorHeightAt,textureAt,rollAt,defaultConstraints); #endif #ifdef HEAD_BOB @@ -1001,6 +996,9 @@ int main() { initGeneral(); + defaultConstraints.maxHits = 1; + defaultConstraints.maxSteps = 20; + for (uint8_t i = 0; i < TEXTURES; ++i) textureAverageColors[i] = computeAverageColor(textures[i]); diff --git a/demo3.cpp b/demo3.cpp index c623eb4..e1de023 100644 --- a/demo3.cpp +++ b/demo3.cpp @@ -494,20 +494,15 @@ inline void pixelFunc(RCL_PixelInfo *pixel) if (intensity != 0) c = addIntensity(c,intensity); - putSubsampledPixel // macro + putSubsampledPixel(pixel,c); } bool flyBy = true; void draw() { - RCL_RayConstraints c; - - c.maxHits = 6; - c.maxSteps = 20; - player.mCamera.height += player.mHeadBob; - RCL_render(player.mCamera,floorHeightAt,0,colorAt,c); + RCL_render(player.mCamera,floorHeightAt,0,colorAt,defaultConstraints); player.mCamera.height -= player.mHeadBob; if (flyBy && (pokitto.frameCount >> 3) % 3 != 0) @@ -554,6 +549,9 @@ int main() { initGeneral(); + defaultConstraints.maxHits = 6; + defaultConstraints.maxSteps = 20; + floorColor = rgbToIndex(4,2,0); squareColors[0] = rgbToIndex(0,0,3); diff --git a/general.hpp b/general.hpp index 1ee3092..a1006f4 100644 --- a/general.hpp +++ b/general.hpp @@ -72,22 +72,30 @@ Pokitto::Core pokitto; RCL_Unit zBuffer[SUBSAMPLED_WIDTH]; ///< 1D z-buffer for visibility determination. +RCL_RayConstraints defaultConstraints; + unsigned short palette[256]; -// helper macro for fast pixel drawing #ifdef POK_SIM - #define putSubsampledPixel\ - pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE,pixel->position.y,c);\ - pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE + 1,pixel->position.y,c); +inline void putSubsampledPixel(RCL_PixelInfo *pixel, uint8_t color) +{ + pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE,pixel->position.y,color); + pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE + 1,pixel->position.y,color); +} #else - // this code breaks the simulator - #define putSubsampledPixel\ - uint8_t *buf = pokitto.display.screenbuffer;\ - buf += pixel->position.x * SUBSAMPLE;\ - buf += pixel->position.y * SCREEN_WIDTH;\ - for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)\ - *buf++ = c;\ - *buf = c; +// This code breaks the simulator. +inline void putSubsampledPixel(RCL_PixelInfo *pixel, uint8_t color) +{ + uint8_t *buf = pokitto.display.screenbuffer; + + buf += pixel->position.x * SUBSAMPLE; + buf += pixel->position.y * SCREEN_WIDTH; + + for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i) + *buf++ = color; + + *buf = color; +} #endif /** @@ -394,6 +402,8 @@ void initGeneral() pokitto.display.setFont(fontTiny); pokitto.display.persistence = 1; + RCL_initRayConstraints(&defaultConstraints); + initPalette(); for (uint8_t i = 0; i < SUBSAMPLED_WIDTH; ++i)