From 5fe7c1a926d159ecc9d36f4033609dabafd5a8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 9 Sep 2018 19:56:12 +0200 Subject: [PATCH] Use Chebyshew instead Euclid --- demo1.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/demo1.cpp b/demo1.cpp index 11181e9..d4b2e11 100644 --- a/demo1.cpp +++ b/demo1.cpp @@ -7,6 +7,7 @@ license: CC0 1.0 */ +// redefine player's height #define CAMERA_COLL_HEIGHT_BELOW ((3 * UNITS_PER_SQUARE) / 2) #include "general.hpp" @@ -665,7 +666,11 @@ void draw() for (uint8_t i = 0; i < SPRITES; ++i) { - if (dist(sprites[i].mPosition,player.mCamera.position) > SPRITE_MAX_DISTANCE) + // use Chebyshew distance instead Euclidean, it's faster + if (absVal(sprites[i].mPosition.x - player.mCamera.position.x) > SPRITE_MAX_DISTANCE) + continue; + + if (absVal(sprites[i].mPosition.y - player.mCamera.position.y) > SPRITE_MAX_DISTANCE) continue; PixelInfo pos = mapToScreen(sprites[i].mPosition,sprites[i].mHeight,player.mCamera);