From b672387bee88471aa47d4736dcc47f01ff812715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 14 Sep 2018 20:17:15 +0200 Subject: [PATCH] Optimize door --- raycastlib.h | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 8e1af3d..d4ad357 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -130,6 +130,7 @@ typedef struct Unit textureCoord; ///< Normalized (0 to UNITS_PER_SQUARE - 1) tex coord. Unit type; ///< Integer identifying type of square. uint8_t direction; ///< Direction of hit. + Unit doorRoll; ///< Holds value of door roll. } HitResult; // TODO: things like FOV could be constants to make them precomp. and faster? @@ -308,6 +309,22 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, //============================================================================= // privates +// global helper variables, for precomputing stuff etc. +PixelFunction _pixelFunction = 0; +Camera _camera; +Unit _horizontalDepthStep = 0; +Unit _startFloorHeight = 0; +Unit _startCeilHeight = 0; +Unit _camResYLimit = 0; +Unit _middleRow = 0; +ArrayFunction _floorFunction = 0; +ArrayFunction _ceilFunction = 0; +uint8_t _computeTextureCoords = 0; +Unit _fHorizontalDepthStart = 0; +Unit _cHorizontalDepthStart = 0; +int16_t _cameraHeightScreen = 0; +ArrayFunction _rollFunction = 0; // says door rolling + #ifdef RAYCASTLIB_PROFILE // function call counters for profiling uint32_t profile_sqrtInt = 0; @@ -665,6 +682,8 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, ArrayFunction typeFunc, HitResult h; + h.doorRoll = 0; + h.position = currentPos; h.square = currentSquare; h.distance = dist(initialPos,currentPos); @@ -697,6 +716,9 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, ArrayFunction typeFunc, wrap(currentPos.y,UNITS_PER_SQUARE) : 0; } + if (_rollFunction != 0) + h.doorRoll = _rollFunction(currentSquare.x,currentSquare.y); + hitResults[*hitResultsLen] = h; *hitResultsLen += 1; @@ -767,22 +789,6 @@ void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc, } } -// global helper variables, for precomputing stuff etc. -PixelFunction _pixelFunction = 0; -Camera _camera; -Unit _horizontalDepthStep = 0; -Unit _startFloorHeight = 0; -Unit _startCeilHeight = 0; -Unit _camResYLimit = 0; -Unit _middleRow = 0; -ArrayFunction _floorFunction = 0; -ArrayFunction _ceilFunction = 0; -uint8_t _computeTextureCoords = 0; -Unit _fHorizontalDepthStart = 0; -Unit _cHorizontalDepthStart = 0; -int16_t _cameraHeightScreen = 0; -ArrayFunction _rollFunction = 0; // says door rolling - /** Helper function that determines intersection with both ceiling and floor. */ @@ -990,7 +996,7 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x, if (_rollFunction != 0) { - Unit doorRoll = _rollFunction(hit.square.x,hit.square.y); + Unit doorRoll = hit.doorRoll; int8_t unrolled = doorRoll >= 0 ? doorRoll > hit.textureCoord :