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

FPS++! (call pix func directly)

This commit is contained in:
Miloslav Číž 2018-09-17 07:15:06 +02:00
parent a4492a3656
commit f77522efb6

View file

@ -9,6 +9,9 @@
Check the defines below to fine-tune accuracy vs performance! Don't forget Check the defines below to fine-tune accuracy vs performance! Don't forget
to compile with optimizations. to compile with optimizations.
Before includinf the library efine PIXEL_FUNCTION to the name of the
function (with PixelFunction signature) that will render your pixels!
author: Miloslav "drummyfish" Ciz author: Miloslav "drummyfish" Ciz
license: CC0 license: CC0
version: 0.1 version: 0.1
@ -180,6 +183,8 @@ typedef struct
coordinates. */ coordinates. */
} PixelInfo; } PixelInfo;
void PIXEL_FUNCTION (PixelInfo *p);
typedef struct typedef struct
{ {
uint16_t maxHits; uint16_t maxHits;
@ -296,7 +301,7 @@ void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc,
*/ */
void render(Camera cam, ArrayFunction floorHeightFunc, void render(Camera cam, ArrayFunction floorHeightFunc,
ArrayFunction ceilingHeightFunc, ArrayFunction typeFunction, ArrayFunction ceilingHeightFunc, ArrayFunction typeFunction,
PixelFunction pixelFunc, RayConstraints constraints); RayConstraints constraints);
/** /**
Renders given camera view, with help of provided functions. This function is Renders given camera view, with help of provided functions. This function is
@ -315,7 +320,7 @@ void render(Camera cam, ArrayFunction floorHeightFunc,
be faster as fewer intersections will be tested) be faster as fewer intersections will be tested)
*/ */
void renderSimple(Camera cam, ArrayFunction floorHeightFunc, void renderSimple(Camera cam, ArrayFunction floorHeightFunc,
ArrayFunction typeFunc, PixelFunction pixelFunc, ArrayFunction rollFunc, ArrayFunction typeFunc, ArrayFunction rollFunc,
RayConstraints constraints); RayConstraints constraints);
/** /**
@ -347,7 +352,6 @@ void initRayConstraints(RayConstraints *constraints);
// privates // privates
// global helper variables, for precomputing stuff etc. // global helper variables, for precomputing stuff etc.
PixelFunction _pixelFunction = 0;
Camera _camera; Camera _camera;
Unit _horizontalDepthStep = 0; Unit _horizontalDepthStep = 0;
Unit _startFloorHeight = 0; Unit _startFloorHeight = 0;
@ -966,7 +970,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
{\ {\
p.position.y = i;\ p.position.y = i;\
p.depth += _horizontalDepthStep;\ p.depth += _horizontalDepthStep;\
_pixelFunction(&p);\ PIXEL_FUNCTION(&p);\
}\ }\
if (pref##PosY comp limit)\ if (pref##PosY comp limit)\
pref##PosY = limit; pref##PosY = limit;
@ -1015,7 +1019,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
p.texCoords.y = (wallPosition * UNITS_PER_SQUARE)/wallLength;\ p.texCoords.y = (wallPosition * UNITS_PER_SQUARE)/wallLength;\
}\ }\
wallPosition++;\ wallPosition++;\
_pixelFunction(&p);\ PIXEL_FUNCTION(&p);\
}\ }\
else\ else\
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\ for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
@ -1027,7 +1031,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
p.texCoords.x = hit.textureCoord;\ p.texCoords.x = hit.textureCoord;\
p.texCoords.y += coordStep;\ p.texCoords.y += coordStep;\
}\ }\
_pixelFunction(&p);\ PIXEL_FUNCTION(&p);\
}\ }\
if (pref##PosY comp limit)\ if (pref##PosY comp limit)\
pref##PosY = limit;\ pref##PosY = limit;\
@ -1160,7 +1164,7 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
while (y < wallStart) while (y < wallStart)
{ {
p.position.y = y; p.position.y = y;
_pixelFunction(&p); PIXEL_FUNCTION(&p);
++y; ++y;
p.depth += _horizontalDepthStep; p.depth += _horizontalDepthStep;
} }
@ -1195,7 +1199,7 @@ Unit coordStep = 1;
#if COMPUTE_WALL_TEXCOORDS == 1 #if COMPUTE_WALL_TEXCOORDS == 1
p.texCoords.y = (UNITS_PER_SQUARE * coordHelper) / wallHeightScreen; p.texCoords.y = (UNITS_PER_SQUARE * coordHelper) / wallHeightScreen;
#endif #endif
_pixelFunction(&p); PIXEL_FUNCTION(&p);
++coordHelper; ++coordHelper;
++y; ++y;
} }
@ -1207,7 +1211,7 @@ Unit coordStep = 1;
// cheaper texture coord computation // cheaper texture coord computation
p.position.y = y; p.position.y = y;
_pixelFunction(&p); PIXEL_FUNCTION(&p);
#if COMPUTE_WALL_TEXCOORDS == 1 #if COMPUTE_WALL_TEXCOORDS == 1
p.texCoords.y += coordStep; p.texCoords.y += coordStep;
#endif #endif
@ -1223,7 +1227,7 @@ Unit coordStep = 1;
while (y < _camera.resolution.y) while (y < _camera.resolution.y)
{ {
p.position.y = y; p.position.y = y;
_pixelFunction(&p); PIXEL_FUNCTION(&p);
++y; ++y;
p.depth -= _horizontalDepthStep; p.depth -= _horizontalDepthStep;
} }
@ -1231,9 +1235,8 @@ Unit coordStep = 1;
void render(Camera cam, ArrayFunction floorHeightFunc, void render(Camera cam, ArrayFunction floorHeightFunc,
ArrayFunction ceilingHeightFunc, ArrayFunction typeFunction, ArrayFunction ceilingHeightFunc, ArrayFunction typeFunction,
PixelFunction pixelFunc, RayConstraints constraints) RayConstraints constraints)
{ {
_pixelFunction = pixelFunc;
_floorFunction = floorHeightFunc; _floorFunction = floorHeightFunc;
_ceilFunction = ceilingHeightFunc; _ceilFunction = ceilingHeightFunc;
_camera = cam; _camera = cam;
@ -1265,10 +1268,9 @@ void render(Camera cam, ArrayFunction floorHeightFunc,
} }
void renderSimple(Camera cam, ArrayFunction floorHeightFunc, void renderSimple(Camera cam, ArrayFunction floorHeightFunc,
ArrayFunction typeFunc, PixelFunction pixelFunc, ArrayFunction rollFunc, ArrayFunction typeFunc, ArrayFunction rollFunc,
RayConstraints constraints) RayConstraints constraints)
{ {
_pixelFunction = pixelFunc;
_floorFunction = floorHeightFunc; _floorFunction = floorHeightFunc;
_camera = cam; _camera = cam;
_camResYLimit = cam.resolution.y - 1; _camResYLimit = cam.resolution.y - 1;