Update RCL

This commit is contained in:
Miloslav Číž 2020-02-27 12:07:27 +01:00
parent 14ff63a2ef
commit 92608269d3
3 changed files with 28 additions and 32 deletions

View File

@ -188,7 +188,7 @@
#define SFG_MS_PER_FRAME (1000 / SFG_FPS) // ms per frame with target FPS #define SFG_MS_PER_FRAME (1000 / SFG_FPS) // ms per frame with target FPS
#define SFG_BASE_SPRITE_SIZE \ #define SFG_BASE_SPRITE_SIZE \
((SFG_GAME_RESOLUTION_Y * 2) / 3) (SFG_GAME_RESOLUTION_Y)
#if SFG_MS_PER_FRAME == 0 #if SFG_MS_PER_FRAME == 0
#define SFG_MS_PER_FRAME 1 #define SFG_MS_PER_FRAME 1

9
main.c
View File

@ -151,8 +151,9 @@ typedef struct
#define SFG_SPRITE_SIZE(size0to3) \ #define SFG_SPRITE_SIZE(size0to3) \
(((size0to3 + 3) * SFG_BASE_SPRITE_SIZE) / 4) (((size0to3 + 3) * SFG_BASE_SPRITE_SIZE) / 4)
#define SFG_SPRITE_SIZE_TO_HEIGH_ABOVE_GROUND(size0to3) \ #define SFG_SPRITE_SIZE_TO_HEIGHT_ABOVE_GROUND(size0to3) \
((((size0to3) + 3) * (RCL_UNITS_PER_SQUARE / 2)) / 4) ((SFG_SPRITE_SIZE(size0to3) * 2) / 3)
// ^TODO: why 3/4 and not 1/2?
/** /**
Holds information about one instance of a level item (a type of level element, Holds information about one instance of a level item (a type of level element,
@ -3621,7 +3622,7 @@ void SFG_draw()
SFG_MONSTER_COORD_TO_SQUARES(m.coords[0]), SFG_MONSTER_COORD_TO_SQUARES(m.coords[0]),
SFG_MONSTER_COORD_TO_SQUARES(m.coords[1])) SFG_MONSTER_COORD_TO_SQUARES(m.coords[1]))
+ +
SFG_SPRITE_SIZE_TO_HEIGH_ABOVE_GROUND(spriteSize), SFG_SPRITE_SIZE_TO_HEIGHT_ABOVE_GROUND(spriteSize),
SFG_player.camera); SFG_player.camera);
if (p.depth > 0) if (p.depth > 0)
@ -3669,7 +3670,7 @@ void SFG_draw()
RCL_mapToScreen( RCL_mapToScreen(
worldPosition, worldPosition,
SFG_floorHeightAt(e.coords[0],e.coords[1]) SFG_floorHeightAt(e.coords[0],e.coords[1])
+ SFG_SPRITE_SIZE_TO_HEIGH_ABOVE_GROUND(spriteSize), + SFG_SPRITE_SIZE_TO_HEIGHT_ABOVE_GROUND(spriteSize),
SFG_player.camera); SFG_player.camera);
if (p.depth > 0) if (p.depth > 0)

View File

@ -26,7 +26,7 @@
author: Miloslav "drummyfish" Ciz author: Miloslav "drummyfish" Ciz
license: CC0 1.0 license: CC0 1.0
version: 0.902 version: 0.903
*/ */
#include <stdint.h> #include <stdint.h>
@ -107,9 +107,11 @@
#endif #endif
#ifndef RCL_VERTICAL_FOV #ifndef RCL_VERTICAL_FOV
#define RCL_VERTICAL_FOV (RCL_UNITS_PER_SQUARE / 2) #define RCL_VERTICAL_FOV (RCL_UNITS_PER_SQUARE / 5)
#endif #endif
#define RCL_VERTICAL_FOV_TAN (RCL_VERTICAL_FOV * 4) ///< tan approximation
#ifndef RCL_HORIZONTAL_FOV #ifndef RCL_HORIZONTAL_FOV
#define RCL_HORIZONTAL_FOV (RCL_UNITS_PER_SQUARE / 4) #define RCL_HORIZONTAL_FOV (RCL_UNITS_PER_SQUARE / 4)
#endif #endif
@ -890,8 +892,18 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc,
#if !RCL_RECTILINEAR #if !RCL_RECTILINEAR
h.distance = RCL_dist(h.position,ray.start); h.distance = RCL_dist(h.position,ray.start);
#endif #else
h.distance = (h.distance * 23) / 32;
/* ^ UGLY HACK
For some reason the computed distance with rectilinear is larger, the
correct distance is about 0.711 (~= 23/32) of the computed distance, so
we correct it here in this ugly way.
TODO: investigate why, fix nicely
*/
#endif
if (typeFunc != 0) if (typeFunc != 0)
h.type = typeFunc(currentSquare.x,currentSquare.y); h.type = typeFunc(currentSquare.x,currentSquare.y);
@ -1202,20 +1214,6 @@ static inline int16_t _RCL_drawWall(
RCL_Unit textureCoordScaled = pixelInfo->texCoords.y; RCL_Unit textureCoordScaled = pixelInfo->texCoords.y;
#if RCL_RECTILINEAR
RCL_Unit tmp = pixelInfo->depth;
pixelInfo->depth = (pixelInfo->depth * 23) / 32;
/* ^ UGLY HACK
For some reason the computed distance with rectilinear is larger, the
correct distance is about 0.711 (~= 23/32) of the computed distance, so
we correct it here in this ugly way.
TODO: investigate why, fix nicely
*/
#endif
for (RCL_Unit i = yCurrent + increment; for (RCL_Unit i = yCurrent + increment;
increment == -1 ? i >= limit : i <= limit; // TODO: is efficient? increment == -1 ? i >= limit : i <= limit; // TODO: is efficient?
i += increment) i += increment)
@ -1232,10 +1230,6 @@ static inline int16_t _RCL_drawWall(
RCL_PIXEL_FUNCTION(pixelInfo); RCL_PIXEL_FUNCTION(pixelInfo);
} }
#if RCL_RECTILINEAR
pixelInfo->depth = tmp;
#endif
return limit; return limit;
} }
@ -1697,10 +1691,11 @@ RCL_PixelInfo RCL_mapToScreen(RCL_Vector2D worldPosition, RCL_Unit height,
result.position.x = result.position.x =
middleColumn + (-1 * toPoint.y * middleColumn) / RCL_nonZero(result.depth); middleColumn + (-1 * toPoint.y * middleColumn) / RCL_nonZero(result.depth);
result.position.y = camera.resolution.y / 2 - result.position.y =
(((3 * camera.resolution.y) / 4 ) * camera.resolution.y / 2 -
RCL_perspectiveScale(height - camera.height,result.depth)) (RCL_perspectiveScale(height - camera.height,result.depth)
/ RCL_UNITS_PER_SQUARE + camera.shear; * camera.resolution.y) / RCL_UNITS_PER_SQUARE
+ camera.shear;
return result; return result;
} }
@ -1716,7 +1711,7 @@ RCL_Unit RCL_perspectiveScale(RCL_Unit originalSize, RCL_Unit distance)
return distance != 0 ? return distance != 0 ?
(originalSize * RCL_UNITS_PER_SQUARE) / (originalSize * RCL_UNITS_PER_SQUARE) /
((RCL_VERTICAL_FOV * 2 * distance) / RCL_UNITS_PER_SQUARE) ((RCL_VERTICAL_FOV_TAN * 2 * distance) / RCL_UNITS_PER_SQUARE)
: 0; : 0;
} }
@ -1726,7 +1721,7 @@ RCL_Unit RCL_perspectiveScaleInverse(RCL_Unit originalSize,
return scaledSize != 0 ? return scaledSize != 0 ?
(originalSize * RCL_UNITS_PER_SQUARE + RCL_UNITS_PER_SQUARE / 2) / (originalSize * RCL_UNITS_PER_SQUARE + RCL_UNITS_PER_SQUARE / 2) /
// ^ take the middle // ^ take the middle
((RCL_VERTICAL_FOV * 2 * scaledSize) / RCL_UNITS_PER_SQUARE) ((RCL_VERTICAL_FOV_TAN * 2 * scaledSize) / RCL_UNITS_PER_SQUARE)
: RCL_INFINITY; : RCL_INFINITY;
} }