mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-23 20:49:57 +01:00
Optimize helper functions
This commit is contained in:
parent
eda0106d08
commit
10399c778a
1 changed files with 6 additions and 5 deletions
11
raycastlib.h
11
raycastlib.h
|
@ -26,7 +26,7 @@
|
|||
|
||||
author: Miloslav "drummyfish" Ciz
|
||||
license: CC0 1.0
|
||||
version: 0.88
|
||||
version: 0.89
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -154,7 +154,8 @@
|
|||
|
||||
#define RCL_min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define RCL_max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define RCL_nonZero(v) ((v) != 0 ? (v) : 1) ///< To prevent zero divisions.
|
||||
#define RCL_nonZero(v) (v + (v == 0)) ///< To prevent zero divisions.
|
||||
#define RCL_zeroClamp(x) (x * (x >= 0))
|
||||
|
||||
#define RCL_logV2D(v)\
|
||||
printf("[%d,%d]\n",v.x,v.y);
|
||||
|
@ -542,7 +543,7 @@ static inline RCL_Unit RCL_absVal(RCL_Unit value)
|
|||
{
|
||||
RCL_profileCall(RCL_absVal);
|
||||
|
||||
return value >= 0 ? value : -1 * value;
|
||||
return value * (((value >= 0) << 1) - 1);
|
||||
}
|
||||
|
||||
/// Like mod, but behaves differently for negative values.
|
||||
|
@ -1092,7 +1093,7 @@ static inline int16_t _RCL_drawHorizontalColumn(
|
|||
if (doDepth) /*constant condition - compiler should optimize it out*/\
|
||||
{\
|
||||
depth += depthIncrement;\
|
||||
pixelInfo->depth = depth * (depth > 0); /* fast abs val */ \
|
||||
pixelInfo->depth = RCL_zeroClamp(depth); \
|
||||
/* ^ int comparison is fast, it is not braching! (= test instr.) */\
|
||||
}\
|
||||
if (doCoords) /*constant condition - compiler should optimize it out*/\
|
||||
|
@ -1180,7 +1181,7 @@ static inline int16_t _RCL_drawWall(
|
|||
else
|
||||
{
|
||||
// with floor wall, don't start under 0
|
||||
pixelInfo->texCoords.y = RCL_max(0,pixelInfo->texCoords.y);
|
||||
pixelInfo->texCoords.y = RCL_zeroClamp(pixelInfo->texCoords.y);
|
||||
}
|
||||
|
||||
RCL_Unit textureCoordScaled = pixelInfo->texCoords.y;
|
||||
|
|
Loading…
Reference in a new issue