1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-21 20:29:59 +01:00

Add wrap function

This commit is contained in:
Miloslav Číž 2018-09-03 16:55:30 +02:00
parent 1dc3f2f763
commit 695f921c2d

View file

@ -221,6 +221,12 @@ inline Unit absVal(Unit value)
return value < 0 ? -1 * value : value; return value < 0 ? -1 * value : value;
} }
/// Like mod, but behaves differently for negative values.
inline Unit wrap(Unit value, Unit mod)
{
return value < 0 ? (mod + (value % mod) - 1) : (value % mod);
}
/// Performs division, rounding down, NOT towards zero. /// Performs division, rounding down, NOT towards zero.
inline Unit divRoundDown(Unit value, Unit divisor) inline Unit divRoundDown(Unit value, Unit divisor)
{ {
@ -238,10 +244,7 @@ Unit cosInt(Unit input)
// TODO: could be optimized with LUT // TODO: could be optimized with LUT
input = input % UNITS_PER_SQUARE; input = wrap(input,UNITS_PER_SQUARE);
if (input < 0)
input = UNITS_PER_SQUARE + input;
if (input < UNITS_PER_SQUARE / 4) if (input < UNITS_PER_SQUARE / 4)
return trigHelper(input); return trigHelper(input);
@ -473,13 +476,8 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, HitResult *hitResults,
break; break;
} }
ray.start.x = currentPos.x < 0 ? ray.start.x = wrap(currentPos.x,UNITS_PER_SQUARE);
(UNITS_PER_SQUARE + currentPos.x % UNITS_PER_SQUARE - 1) : ray.start.y = wrap(currentPos.y,UNITS_PER_SQUARE);
(currentPos.x % UNITS_PER_SQUARE);
ray.start.y = currentPos.y < 0 ?
(UNITS_PER_SQUARE + currentPos.y % UNITS_PER_SQUARE - 1) :
(currentPos.y % UNITS_PER_SQUARE);
castRaySquare(ray,&no,&co); castRaySquare(ray,&no,&co);
@ -554,7 +552,8 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
int_maybe32_t y2 = 0; // screen y (for ceil), will only fo down int_maybe32_t y2 = 0; // screen y (for ceil), will only fo down
Unit worldZPrev = _startHeight; Unit worldZPrev = _startHeight;
Unit worldZPrevCeil = UNITS_PER_SQUARE * 5 - _startHeight - 2 * _camera.height; Unit worldZPrevCeil =
UNITS_PER_SQUARE * 5 - _startHeight - 2 * _camera.height;
PixelInfo p; PixelInfo p;
p.position.x = x; p.position.x = x;