Update raycastlib

This commit is contained in:
Miloslav Číž 2019-09-30 17:15:15 +02:00
parent b1a6cdb114
commit 88daf8dd34
2 changed files with 36 additions and 74 deletions

6
main.c
View File

@ -188,7 +188,7 @@ RCL_Unit SFG_texturesAt(int16_t x, int16_t y)
{ {
uint8_t p; uint8_t p;
SFG_TileDefinition tile = SFG_getMapTile(&SFG_level0,x,y,&p); SFG_TileDefinition tile = SFG_getMapTile(SFG_currentLevel.levelPointer,x,y,&p);
return return
SFG_TILE_FLOOR_TEXTURE(tile) | (SFG_TILE_CEILING_TEXTURE(tile) << 3) | p; SFG_TILE_FLOOR_TEXTURE(tile) | (SFG_TILE_CEILING_TEXTURE(tile) << 3) | p;
// ^ store both textures (floor and ceiling) and properties in one number // ^ store both textures (floor and ceiling) and properties in one number
@ -215,7 +215,7 @@ RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y)
{ {
uint8_t properties; uint8_t properties;
SFG_TileDefinition tile = SFG_getMapTile(&SFG_level0,x,y,&properties); SFG_TileDefinition tile = SFG_getMapTile(SFG_currentLevel.levelPointer,x,y,&properties);
return properties != SFG_TILE_PROPERTY_ELEVATOR ? return properties != SFG_TILE_PROPERTY_ELEVATOR ?
SFG_TILE_FLOOR_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP : SFG_TILE_FLOOR_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP :
@ -230,7 +230,7 @@ RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y)
RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y) RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y)
{ {
uint8_t properties; uint8_t properties;
SFG_TileDefinition tile = SFG_getMapTile(&SFG_level0,x,y,&properties); SFG_TileDefinition tile = SFG_getMapTile(SFG_currentLevel.levelPointer,x,y,&properties);
if (properties == SFG_TILE_PROPERTY_ELEVATOR) if (properties == SFG_TILE_PROPERTY_ELEVATOR)
return SFG_CEILING_MAX_HEIGHT; return SFG_CEILING_MAX_HEIGHT;

View File

@ -26,7 +26,7 @@
author: Miloslav "drummyfish" Ciz author: Miloslav "drummyfish" Ciz
license: CC0 1.0 license: CC0 1.0
version: 0.84 version: 0.85
*/ */
#include <stdint.h> #include <stdint.h>
@ -89,14 +89,6 @@
slightly slower if on). */ slightly slower if on). */
#endif #endif
#ifndef RCL_ACCURATE_WALL_TEXTURING
#define RCL_ACCURATE_WALL_TEXTURING 0 /**< If turned on, vertical wall texture
coordinates will always be calculated
with more precise (but slower) method,
otherwise RCL_MIN_TEXTURE_STEP will be
used to decide the method. */
#endif
#ifndef RCL_COMPUTE_FLOOR_DEPTH #ifndef RCL_COMPUTE_FLOOR_DEPTH
#define RCL_COMPUTE_FLOOR_DEPTH 1 /**< Whether depth should be computed for #define RCL_COMPUTE_FLOOR_DEPTH 1 /**< Whether depth should be computed for
floor pixels - turns this off if not floor pixels - turns this off if not
@ -140,15 +132,12 @@
#define RCL_CAMERA_COLL_STEP_HEIGHT (RCL_UNITS_PER_SQUARE / 2) #define RCL_CAMERA_COLL_STEP_HEIGHT (RCL_UNITS_PER_SQUARE / 2)
#endif #endif
#ifndef RCL_MIN_TEXTURE_STEP #ifndef RCL_TEXTURE_INTERPOLATION_SCALE
#if RCL_TEXTURE_VERTICAL_STRETCH == 1 #define RCL_TEXTURE_INTERPOLATION_SCALE 1024 /**< This says scaling of fixed
#define RCL_MIN_TEXTURE_STEP 12 /**< Specifies the minimum step in pixels poit vertical texture coord
that can be used to compute texture computation. This should be power
coordinates in a fast way. Smallet step of two! Higher number can look more
should be faster (but less accurate). */ accurate but may cause overflow. */
#else
#define RCL_MIN_TEXTURE_STEP 24
#endif
#endif #endif
#define RCL_HORIZON_DEPTH (11 * RCL_UNITS_PER_SQUARE) /**< What depth the #define RCL_HORIZON_DEPTH (11 * RCL_UNITS_PER_SQUARE) /**< What depth the
@ -1139,85 +1128,58 @@ static inline int16_t _RCL_drawWall(
{ {
_RCL_UNUSED(height) _RCL_UNUSED(height)
height = RCL_absVal(height);
pixelInfo->isWall = 1; pixelInfo->isWall = 1;
RCL_Unit limit = RCL_clamp(yTo,limit1,limit2); RCL_Unit limit = RCL_clamp(yTo,limit1,limit2);
RCL_Unit wallLength = RCL_absVal(yTo - yFrom - 1); RCL_Unit wallLength = RCL_nonZero(RCL_absVal(yTo - yFrom - 1));
wallLength = RCL_nonZero(wallLength);
RCL_Unit wallPosition = RCL_absVal(yFrom - yCurrent) - increment; RCL_Unit wallPosition = RCL_absVal(yFrom - yCurrent) - increment;
RCL_Unit coordStep = RCL_COMPUTE_WALL_TEXCOORDS ? RCL_Unit heightScaled = height * RCL_TEXTURE_INTERPOLATION_SCALE;
_RCL_UNUSED(heightScaled);
RCL_Unit coordStepScaled = RCL_COMPUTE_WALL_TEXCOORDS ?
#if RCL_TEXTURE_VERTICAL_STRETCH == 1 #if RCL_TEXTURE_VERTICAL_STRETCH == 1
RCL_UNITS_PER_SQUARE / wallLength ((RCL_UNITS_PER_SQUARE * RCL_TEXTURE_INTERPOLATION_SCALE) / wallLength)
#else #else
height / wallLength (heightScaled / wallLength)
#endif #endif
: 1; : 0;
pixelInfo->texCoords.y = RCL_COMPUTE_WALL_TEXCOORDS ? pixelInfo->texCoords.y = RCL_COMPUTE_WALL_TEXCOORDS ?
wallPosition * coordStep : 0; (wallPosition * coordStepScaled) : 0;
if (increment < 0) if (increment < 0)
{ {
coordStep *= -1; coordStepScaled *= -1;
pixelInfo->texCoords.y = pixelInfo->texCoords.y =
#if RCL_TEXTURE_VERTICAL_STRETCH == 1 #if RCL_TEXTURE_VERTICAL_STRETCH == 1
RCL_UNITS_PER_SQUARE - pixelInfo->texCoords.y; (RCL_UNITS_PER_SQUARE * RCL_TEXTURE_INTERPOLATION_SCALE)
- pixelInfo->texCoords.y;
#else #else
height - pixelInfo->texCoords.y; heightScaled - pixelInfo->texCoords.y;
#endif #endif
wallPosition = wallLength - wallPosition;
} }
#if RCL_ACCURATE_WALL_TEXTURING == 1 RCL_Unit textureCoordScaled = pixelInfo->texCoords.y;
if (1)
#else for (RCL_Unit i = yCurrent + increment;
if (RCL_absVal(coordStep) < RCL_MIN_TEXTURE_STEP) increment == -1 ? i >= limit : i <= limit; // TODO: is efficient?
/* for the sake of performance there are two-versions of the loop - it's i += increment)
better to branch early than inside the loop */
#endif
{ {
for (RCL_Unit i = yCurrent + increment; pixelInfo->position.y = i;
increment == -1 ? i >= limit : i <= limit; // TODO: is efficient?
i += increment)
{
// more expensive texture coord computing
pixelInfo->position.y = i;
#if RCL_COMPUTE_WALL_TEXCOORDS == 1 #if RCL_COMPUTE_WALL_TEXCOORDS == 1
#if RCL_TEXTURE_VERTICAL_STRETCH == 1 pixelInfo->texCoords.y =
pixelInfo->texCoords.y = textureCoordScaled / RCL_TEXTURE_INTERPOLATION_SCALE;
(wallPosition * RCL_UNITS_PER_SQUARE) / wallLength;
#else textureCoordScaled += coordStepScaled;
pixelInfo->texCoords.y = (wallPosition * height) / wallLength;
#endif
#endif #endif
wallPosition += increment; RCL_PIXEL_FUNCTION(pixelInfo);
RCL_PIXEL_FUNCTION(pixelInfo);
}
}
else
{
for (RCL_Unit i = yCurrent + increment;
increment == -1 ? i >= limit : i <= limit; // TODO: is efficient?
i += increment)
{
// cheaper texture coord computing
pixelInfo->position.y = i;
#if RCL_COMPUTE_WALL_TEXCOORDS == 1
pixelInfo->texCoords.y += coordStep;
#endif
RCL_PIXEL_FUNCTION(pixelInfo);
}
} }
return limit; return limit;