From 915c9167eb319064207e9d0e8038d45fd0976203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 24 Sep 2018 18:58:16 +0200 Subject: [PATCH] Precompute gradients (FPS++) --- demo1.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/demo1.cpp b/demo1.cpp index 03bc0b2..b10dd1c 100644 --- a/demo1.cpp +++ b/demo1.cpp @@ -38,6 +38,9 @@ Player player; Sprite sprites[SPRITES]; +unsigned char floorGradient[15]; +unsigned char ceilGradient[15]; + /// For each level square says the texture index. const unsigned char levelTexture[] = { @@ -1023,8 +1026,8 @@ inline void pixelFunc(RCL_PixelInfo *pixel) } else color = pixel->isFloor ? - rgbToIndex(intensity/2,intensity,intensity/3) : - rgbToIndex(intensity,intensity/2,0); + floorGradient[RCL_clamp(intensity,0,14)] : + ceilGradient[RCL_clamp(intensity,0,14)]; putSubsampledPixel(pixel->position.x,pixel->position.y,color); } @@ -1094,6 +1097,9 @@ int main() { initGeneral(); + initGradient(floorGradient,rgbToIndex(3,7,0)); + initGradient(ceilGradient,rgbToIndex(6,2,1)); + defaultConstraints.maxHits = 8; defaultConstraints.maxSteps = 10;