1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-12-23 01:26:19 +01:00

Optimize door

This commit is contained in:
Miloslav Číž 2018-09-14 20:17:15 +02:00
parent 910927e24d
commit b672387bee

View file

@ -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 :