Add z-buffer mod

This commit is contained in:
Miloslav Ciz 2023-01-03 20:49:27 +01:00
parent d6b1455cc9
commit b9dd67a091
2 changed files with 80 additions and 0 deletions

View File

@ -10,6 +10,8 @@ everywhere, made for the benefit of all living beings*
![](media/3screens.png)
**NOTE: for a more consoomerist experience there are now mods in the mod directory with which you may rice the game.**
This game got some attention on 4chan: [1](https://archive.li/Yzcwt), [2](https://archive.li/xY4ia), [3](https://archive.li/tFWrL).
- [why this game is special](#why-this-game-is-special)

78
mods/full_zbuffer.diff Normal file
View File

@ -0,0 +1,78 @@
This mod adds full z-buffer that mostly fixes the incorrect sprite visibility,
however RAM consumption increases quite a bit. Note that visiblity inaccuracies
may still occur as e.g. floor depth is not accurate and isn't used, but the game
generally looks much better. By drummyfish, released under CC0 1.0, public
domain.
diff --git a/constants.h b/constants.h
index 956baa0..da72f24 100644
--- a/constants.h
+++ b/constants.h
@@ -352,7 +352,7 @@
#define SFG_FONT_SIZE_BIG 1
#endif
-#define SFG_Z_BUFFER_SIZE SFG_GAME_RESOLUTION_X
+#define SFG_Z_BUFFER_SIZE (SFG_GAME_RESOLUTION_X * SFG_GAME_RESOLUTION_Y)
/**
Step in which walls get higher, in raycastlib units.
diff --git a/game.h b/game.h
index 24285cb..f8ef257 100755
--- a/game.h
+++ b/game.h
@@ -951,6 +951,14 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
:
SFG_TRANSPARENT_COLOR;
+ uint8_t *zValue = SFG_game.zBuffer +
+ pixel->position.y * SFG_GAME_RESOLUTION_X + pixel->position.x;
+
+ uint8_t zDistance = SFG_RCLUnitToZBuffer(pixel->depth);
+
+ if (*zValue >= zDistance)
+ *zValue = zDistance;
+
shadow = pixel->hit.direction >> 1;
}
else // floor/ceiling
@@ -1216,29 +1224,25 @@ void SFG_drawScaledSprite(
for (int16_t x = x0, u = u0; x <= x1; ++x, ++u)
{
- if (SFG_game.zBuffer[x] >= zDistance)
+ for (int16_t y = y0, v = v0; y <= y1; ++y, ++v)
{
- int8_t columnTransparent = 1;
+ uint8_t color =
+ SFG_getTexel(image,SFG_game.spriteSamplingPoints[u],
+ SFG_game.spriteSamplingPoints[v]);
- for (int16_t y = y0, v = v0; y <= y1; ++y, ++v)
+ if (color != SFG_TRANSPARENT_COLOR)
{
- uint8_t color =
- SFG_getTexel(image,SFG_game.spriteSamplingPoints[u],
- SFG_game.spriteSamplingPoints[v]);
-
- if (color != SFG_TRANSPARENT_COLOR)
- {
#if SFG_DIMINISH_SPRITES
- color = palette_minusValue(color,minusValue);
+ color = palette_minusValue(color,minusValue);
#endif
- columnTransparent = 0;
+ uint8_t *zValue = SFG_game.zBuffer + y * SFG_GAME_RESOLUTION_X + x;
+ if (*zValue >= zDistance)
+ {
SFG_setGamePixel(x,y,color);
+ *zValue = zDistance;
}
}
-
- if (!columnTransparent)
- SFG_game.zBuffer[x] = zDistance;
}
}
}