mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-24 20:59:58 +01:00
Get rid of weird type
This commit is contained in:
parent
5df1b4f4ac
commit
54ee5502be
1 changed files with 16 additions and 21 deletions
37
raycastlib.h
37
raycastlib.h
|
@ -27,15 +27,10 @@
|
||||||
units in a square's length. This effectively
|
units in a square's length. This effectively
|
||||||
serves the purpose of a fixed-point arithmetic. */
|
serves the purpose of a fixed-point arithmetic. */
|
||||||
#define UNIT_INFINITY 5000000;
|
#define UNIT_INFINITY 5000000;
|
||||||
|
|
||||||
typedef int32_t int_maybe32_t;
|
|
||||||
typedef uint32_t uint_maybe32_t;
|
|
||||||
#else
|
#else
|
||||||
#define UNITS_PER_SQUARE 64
|
#define UNITS_PER_SQUARE 64
|
||||||
typedef int16_t Unit;
|
typedef int16_t Unit;
|
||||||
#define UNIT_INFINITY 32767;
|
#define UNIT_INFINITY 32767;
|
||||||
typedef int16_t int_maybe32_t;
|
|
||||||
typedef uint16_t uint_maybe32_t;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef USE_COS_LUT
|
#ifndef USE_COS_LUT
|
||||||
|
@ -218,7 +213,7 @@ Vector2D normalize(Vector2D v);
|
||||||
/// Computes a cos of an angle between two vectors.
|
/// Computes a cos of an angle between two vectors.
|
||||||
Unit vectorsAngleCos(Vector2D v1, Vector2D v2);
|
Unit vectorsAngleCos(Vector2D v1, Vector2D v2);
|
||||||
|
|
||||||
uint16_t sqrtInt(uint_maybe32_t value);
|
uint16_t sqrtInt(Unit value);
|
||||||
Unit dist(Vector2D p1, Vector2D p2);
|
Unit dist(Vector2D p1, Vector2D p2);
|
||||||
Unit len(Vector2D v);
|
Unit len(Vector2D v);
|
||||||
|
|
||||||
|
@ -445,17 +440,17 @@ Vector2D angleToDirection(Unit angle)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t sqrtInt(uint_maybe32_t value)
|
uint16_t sqrtInt(Unit value)
|
||||||
{
|
{
|
||||||
profileCall(sqrtInt);
|
profileCall(sqrtInt);
|
||||||
|
|
||||||
uint_maybe32_t result = 0;
|
Unit result = 0;
|
||||||
uint_maybe32_t a = value;
|
Unit a = value;
|
||||||
|
|
||||||
#ifdef RAYCAST_TINY
|
#ifdef RAYCAST_TINY
|
||||||
uint_maybe32_t b = 1u << 14;
|
Unit b = 1u << 14;
|
||||||
#else
|
#else
|
||||||
uint_maybe32_t b = 1u << 30;
|
Unit b = 1u << 30;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (b > a)
|
while (b > a)
|
||||||
|
@ -480,13 +475,13 @@ Unit dist(Vector2D p1, Vector2D p2)
|
||||||
{
|
{
|
||||||
profileCall(dist);
|
profileCall(dist);
|
||||||
|
|
||||||
int_maybe32_t dx = p2.x - p1.x;
|
Unit dx = p2.x - p1.x;
|
||||||
int_maybe32_t dy = p2.y - p1.y;
|
Unit dy = p2.y - p1.y;
|
||||||
|
|
||||||
dx = dx * dx;
|
dx = dx * dx;
|
||||||
dy = dy * dy;
|
dy = dy * dy;
|
||||||
|
|
||||||
return sqrtInt((uint_maybe32_t) (dx + dy));
|
return sqrtInt((Unit) (dx + dy));
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit len(Vector2D v)
|
Unit len(Vector2D v)
|
||||||
|
@ -496,7 +491,7 @@ Unit len(Vector2D v)
|
||||||
v.x *= v.x;
|
v.x *= v.x;
|
||||||
v.y *= v.y;
|
v.y *= v.y;
|
||||||
|
|
||||||
return sqrtInt(((uint_maybe32_t) v.x) + ((uint_maybe32_t) v.y));
|
return sqrtInt(((Unit) v.x) + ((Unit) v.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t pointIsLeftOfRay(Vector2D point, Ray ray)
|
int8_t pointIsLeftOfRay(Vector2D point, Ray ray)
|
||||||
|
@ -528,7 +523,7 @@ void castRaySquare(Ray *localRay, Vector2D *nextCellOff, Vector2D *collOff)
|
||||||
nextCellOff->c1 = n;\
|
nextCellOff->c1 = n;\
|
||||||
collOff->c1 = criticalLine.start.c1 - localRay->start.c1;\
|
collOff->c1 = criticalLine.start.c1 - localRay->start.c1;\
|
||||||
collOff->c2 = \
|
collOff->c2 = \
|
||||||
(((int_maybe32_t) collOff->c1) * localRay->direction.c2) /\
|
(((Unit) collOff->c1) * localRay->direction.c2) /\
|
||||||
((localRay->direction.c1 == 0) ? 1 : localRay->direction.c1);\
|
((localRay->direction.c1 == 0) ? 1 : localRay->direction.c1);\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,7 +717,7 @@ Camera _camera;
|
||||||
Unit _horizontalDepthStep = 0;
|
Unit _horizontalDepthStep = 0;
|
||||||
Unit _startFloorHeight = 0;
|
Unit _startFloorHeight = 0;
|
||||||
Unit _startCeilHeight = 0;
|
Unit _startCeilHeight = 0;
|
||||||
int_maybe32_t _camResYLimit = 0;
|
Unit _camResYLimit = 0;
|
||||||
Unit _middleRow = 0;
|
Unit _middleRow = 0;
|
||||||
ArrayFunction _floorFunction = 0;
|
ArrayFunction _floorFunction = 0;
|
||||||
ArrayFunction _ceilFunction = 0;
|
ArrayFunction _ceilFunction = 0;
|
||||||
|
@ -767,8 +762,8 @@ Unit adjustDistance(Unit distance, Camera *camera, Ray *ray)
|
||||||
void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
||||||
{
|
{
|
||||||
// last written Y position, can never go backwards
|
// last written Y position, can never go backwards
|
||||||
int_maybe32_t fPosY = _camera.resolution.y;
|
Unit fPosY = _camera.resolution.y;
|
||||||
int_maybe32_t cPosY = -1;
|
Unit cPosY = -1;
|
||||||
|
|
||||||
// world coordinates
|
// world coordinates
|
||||||
Unit fZ1World = _startFloorHeight;
|
Unit fZ1World = _startFloorHeight;
|
||||||
|
@ -777,10 +772,10 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
||||||
PixelInfo p;
|
PixelInfo p;
|
||||||
p.position.x = x;
|
p.position.x = x;
|
||||||
|
|
||||||
int_maybe32_t i;
|
Unit i;
|
||||||
|
|
||||||
// we'll be simulatenously drawing the floor and the ceiling now
|
// we'll be simulatenously drawing the floor and the ceiling now
|
||||||
for (uint_maybe32_t j = 0; j <= hitCount; ++j)
|
for (Unit j = 0; j <= hitCount; ++j)
|
||||||
{ // ^ = add extra iteration for horizon plane
|
{ // ^ = add extra iteration for horizon plane
|
||||||
int8_t drawingHorizon = j == hitCount;
|
int8_t drawingHorizon = j == hitCount;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue