From f749a673148c6aec202cd99311782db6b787c557 Mon Sep 17 00:00:00 2001 From: Michael Chaban Date: Sat, 1 Aug 2020 23:05:34 +0300 Subject: [PATCH] Fixed a bug where pickup sprites were cropped by the floor if Z-Buffer is enabled. --- 3dsystem/scalespr.cpp | 16 ++++++++++++++++ CHANGELOG.md | 1 + game/draw.cpp | 3 ++- global/types.h | 1 + specific/registry.h | 1 + specific/smain.cpp | 2 ++ 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/3dsystem/scalespr.cpp b/3dsystem/scalespr.cpp index d03e594..c0a26eb 100644 --- a/3dsystem/scalespr.cpp +++ b/3dsystem/scalespr.cpp @@ -28,6 +28,10 @@ extern int CalculateFogShade(int depth); #endif // FEATURE_VIEW_IMPROVED +#ifdef FEATURE_VIDEOFX_IMPROVED +DWORD PickupItemMode = 1; +#endif // FEATURE_VIDEOFX_IMPROVED + void __cdecl S_DrawSprite(DWORD flags, int x, int y, int z, __int16 spriteIdx, __int16 shade, __int16 scale) { int xv, yv, zv, zp, depth; int x1, y1, x2, y2; @@ -70,6 +74,18 @@ void __cdecl S_DrawSprite(DWORD flags, int x, int y, int z, __int16 spriteIdx, _ x2 = PhdSpriteInfo[spriteIdx].x2; y2 = PhdSpriteInfo[spriteIdx].y2; +#ifdef FEATURE_VIDEOFX_IMPROVED + if( PickupItemMode == 1 && CHK_ALL(flags, SPR_ITEM|SPR_ABS) ) { + if( y1 < y2 ) { + y1 -= y2; + y2 = 0; + } else { + y2 -= y1; + y1 = 0; + } + } +#endif // FEATURE_VIDEOFX_IMPROVED + if( CHK_ANY(flags, SPR_SCALE) ) { // scaling required x1 = (x1 * scale) << (W2V_SHIFT - 8); y1 = (y1 * scale) << (W2V_SHIFT - 8); diff --git a/CHANGELOG.md b/CHANGELOG.md index 93af0a5..e6c9b20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a rare game crash occurring when you explode an enemy with a grenade launcher. - Fixed incorrect sorting of 3D polygons if Z-Buffer is turned off or the software renderer is used. - Fixed a bug due to which the skybox was not drawn in some rooms. +- Fixed a bug where pickup sprites were cropped by the floor if Z-Buffer is enabled. Some pickup items are slightly raised (optional fix). ### TR2Main bugfixes - Background capture is optimized even more, now it is 3-4 times faster than v0.8.2. No lags anymore (broken since v0.8.0). diff --git a/game/draw.cpp b/game/draw.cpp index b92f164..4679dbb 100644 --- a/game/draw.cpp +++ b/game/draw.cpp @@ -498,7 +498,8 @@ void __cdecl DrawSpriteItem(ITEM_INFO *item) { obj = &Objects[item->objectID]; - S_DrawSprite(SPR_ABS | SPR_SHADE | (obj->semi_transparent ? SPR_SEMITRANS : 0), + // NOTE: SPR_ITEM is not presented in the original game + S_DrawSprite(SPR_ITEM | SPR_ABS | SPR_SHADE | (obj->semi_transparent ? SPR_SEMITRANS : 0), item->pos.x, item->pos.y, item->pos.z, obj->meshIndex - item->frameNumber, LsAdder + 0x1000, 0); diff --git a/global/types.h b/global/types.h index 3b076b6..27f0bbd 100644 --- a/global/types.h +++ b/global/types.h @@ -223,6 +223,7 @@ typedef struct { #define SPR_BLEND_SUB (0x40000000) #define SPR_BLEND_QRT (SPR_BLEND_ADD|SPR_BLEND_SUB) #define SPR_BLEND (SPR_BLEND_QRT) +#define SPR_ITEM (0x80000000) // Item flags #define IFL_INVISIBLE (0x0100) diff --git a/specific/registry.h b/specific/registry.h index 6e2b7a6..2ca98cf 100644 --- a/specific/registry.h +++ b/specific/registry.h @@ -60,6 +60,7 @@ #define REG_ALPHABLEND_MODE "AlphaBlendMode" #define REG_INVTEXTBOX_MODE "InvTextBoxMode" #define REG_HEALTHBAR_MODE "HealthBarMode" +#define REG_PICKUPITEM_MODE "PickupItemMode" #define REG_SCREENSHOT_FORMAT "ScreenshotFormat" // BOOL value names diff --git a/specific/smain.cpp b/specific/smain.cpp index a7a97f5..c369be4 100644 --- a/specific/smain.cpp +++ b/specific/smain.cpp @@ -68,6 +68,7 @@ extern DWORD ShadowMode; extern DWORD AlphaBlendMode; extern DWORD ReflectionMode; extern DWORD ReflectionBlur; +extern DWORD PickupItemMode; extern bool CustomWaterColorEnabled; #endif // FEATURE_VIDEOFX_IMPROVED @@ -551,6 +552,7 @@ void __cdecl S_LoadSettings() { GetRegistryDwordValue(REG_ALPHABLEND_MODE, &AlphaBlendMode, 0); GetRegistryDwordValue(REG_REFLECTION_MODE, &ReflectionMode, 0); GetRegistryDwordValue(REG_REFLECTION_BLUR, &ReflectionBlur, 2); + GetRegistryDwordValue(REG_PICKUPITEM_MODE, &PickupItemMode, 1); GetRegistryBoolValue(REG_CUSTOM_WATER_COLOR, &CustomWaterColorEnabled, false); CLAMPG(AlphaBlendMode, 2); CLAMPG(ReflectionMode, 2);