From 357163c60d381ee444e452d87dc3d973e2277e76 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Mar 2021 14:45:29 +0100 Subject: [PATCH] - Backend update from Raze. --- src/common/audio/sound/s_soundinternal.h | 5 + src/common/console/c_console.cpp | 4 +- src/common/engine/namedef.h | 1 + src/common/engine/printf.h | 1 + src/common/models/models_md3.cpp | 17 ++-- src/common/models/models_obj.cpp | 4 +- src/common/models/models_ue1.cpp | 4 +- src/common/models/models_voxel.cpp | 3 + src/common/statusbar/base_sbar.cpp | 101 ++++++++++++++++++++- src/common/statusbar/base_sbar.h | 6 +- src/common/textures/formats/pngtexture.cpp | 5 - src/common/utility/findfile.cpp | 2 +- src/maploader/udmf.cpp | 8 ++ 13 files changed, 137 insertions(+), 24 deletions(-) diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index cbdeae464..df6943c5d 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -254,6 +254,11 @@ public: virtual void StopChannel(FSoundChan* chan); sfxinfo_t* LoadSound(sfxinfo_t* sfx); + const sfxinfo_t* GetSfx(unsigned snd) + { + if (snd >= S_sfx.Size()) return nullptr; + return &S_sfx[snd]; + } // Initializes sound stuff, including volume // Sets channels, SFX and music volume, diff --git a/src/common/console/c_console.cpp b/src/common/console/c_console.cpp index 365d92889..48c7b86de 100644 --- a/src/common/console/c_console.cpp +++ b/src/common/console/c_console.cpp @@ -70,6 +70,8 @@ #define RIGHTMARGIN 8 #define BOTTOMARGIN 12 +extern bool AppActive; + CUSTOM_CVAR(Int, con_buffersize, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { // ensure a minimum size @@ -1039,7 +1041,7 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer) // Close console and clear command line. But if we're in the // fullscreen console mode, there's nothing to fall back on // if it's closed, so open the main menu instead. - if (gamestate == GS_STARTUP) + if (gamestate == GS_STARTUP || !AppActive) { return false; } diff --git a/src/common/engine/namedef.h b/src/common/engine/namedef.h index 8be149bea..cf8b8da62 100644 --- a/src/common/engine/namedef.h +++ b/src/common/engine/namedef.h @@ -525,6 +525,7 @@ xx(ZDoom) xx(ZDoomTranslated) xx(Vavoom) xx(GZDoom) +xx(Eternity) xx(Xpanningfloor) xx(Ypanningfloor) diff --git a/src/common/engine/printf.h b/src/common/engine/printf.h index 35efdd5fd..3c6164f76 100644 --- a/src/common/engine/printf.h +++ b/src/common/engine/printf.h @@ -86,6 +86,7 @@ int Printf (int printlevel, const char *format, ...) ATTRIBUTE((format(printf,2, int Printf (const char *format, ...) ATTRIBUTE((format(printf,1,2))); int DPrintf (int level, const char *format, ...) ATTRIBUTE((format(printf,2,3))); +void I_DebugPrint(const char* cp); void debugprintf(const char* f, ...); // Prints to the debugger's log. // flag to silence non-error output diff --git a/src/common/models/models_md3.cpp b/src/common/models/models_md3.cpp index 15224e4fe..ba17eb83a 100644 --- a/src/common/models/models_md3.cpp +++ b/src/common/models/models_md3.cpp @@ -306,7 +306,7 @@ void FMD3Model::AddSkins(uint8_t *hitlist) { for (unsigned i = 0; i < Surfaces.Size(); i++) { - if (curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) + if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) { hitlist[curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].GetIndex()] |= FTextureManager::HIT_Flat; } @@ -357,13 +357,16 @@ void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f FGameTexture *surfaceSkin = skin; if (!surfaceSkin) { - if (curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) + if (curSpriteMDLFrame) { - surfaceSkin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true); - } - else if (surf->numSkins > 0 && surf->Skins[0].isValid()) - { - surfaceSkin = TexMan.GetGameTexture(surf->Skins[0], true); + if (curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) + { + surfaceSkin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true); + } + else if (surf->numSkins > 0 && surf->Skins[0].isValid()) + { + surfaceSkin = TexMan.GetGameTexture(surf->Skins[0], true); + } } if (!surfaceSkin) diff --git a/src/common/models/models_obj.cpp b/src/common/models/models_obj.cpp index 264ffd6ac..cd0e99536 100644 --- a/src/common/models/models_obj.cpp +++ b/src/common/models/models_obj.cpp @@ -636,7 +636,7 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f OBJSurface *surf = &surfaces[i]; FGameTexture *userSkin = skin; - if (!userSkin) + if (!userSkin && curSpriteMDLFrame) { if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) { @@ -669,7 +669,7 @@ void FOBJModel::AddSkins(uint8_t* hitlist) { for (size_t i = 0; i < surfaces.Size(); i++) { - if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) + if (curSpriteMDLFrame && i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) { // Precache skins manually reassigned by the user. // On OBJs with lots of skins, such as Doom map OBJs exported from GZDB, diff --git a/src/common/models/models_ue1.cpp b/src/common/models/models_ue1.cpp index 3066b7759..7210a26f2 100644 --- a/src/common/models/models_ue1.cpp +++ b/src/common/models/models_ue1.cpp @@ -242,7 +242,7 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int f FGameTexture *sskin = skin; if ( !sskin ) { - if ( curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum].isValid() ) + if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum].isValid() ) sskin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum], true); if ( !sskin ) { @@ -303,7 +303,7 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer ) void FUE1Model::AddSkins( uint8_t *hitlist ) { for ( int i=0; isurfaceskinIDs[curMDLIndex][groups[i].texNum].isValid() ) + if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum].isValid() ) hitlist[curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum].GetIndex()] |= FTextureManager::HIT_Flat; } diff --git a/src/common/models/models_voxel.cpp b/src/common/models/models_voxel.cpp index cfac12372..2be0521ad 100644 --- a/src/common/models/models_voxel.cpp +++ b/src/common/models/models_voxel.cpp @@ -37,6 +37,7 @@ #include "texturemanager.h" #include "palettecontainer.h" #include "textures.h" +#include "imagehelpers.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data @@ -99,6 +100,7 @@ TArray FVoxelTexture::CreatePalettedPixels(int conversion) pe.b = (pp[2] << 2) | (pp[2] >> 4); // Alphatexture handling is just for completeness, but rather unlikely to be used ever. Pixels[i] = conversion == luminance ? pe.r : ColorMatcher.Pick(pe); + } } else @@ -108,6 +110,7 @@ TArray FVoxelTexture::CreatePalettedPixels(int conversion) Pixels[i] = (uint8_t)i; } } + ImageHelpers::FlipSquareBlock(Pixels.Data(), Width); return Pixels; } diff --git a/src/common/statusbar/base_sbar.cpp b/src/common/statusbar/base_sbar.cpp index 18cbe778c..b0e917872 100644 --- a/src/common/statusbar/base_sbar.cpp +++ b/src/common/statusbar/base_sbar.cpp @@ -452,16 +452,16 @@ void DStatusBarCore::StatusbarToRealCoords(double& x, double& y, double& w, doub // //============================================================================ -void DStatusBarCore::DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color, int translation, double rotate, ERenderStyle style) +void DStatusBarCore::DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color, int translation, ERenderStyle style, double clipwidth) { if (!texture.isValid()) return; FGameTexture* tex = TexMan.GetGameTexture(texture, !(flags & DI_DONTANIMATE)); - DrawGraphic(tex, x, y, flags, Alpha, boxwidth, boxheight, scaleX, scaleY, color, translation, rotate, style); + DrawGraphic(tex, x, y, flags, Alpha, boxwidth, boxheight, scaleX, scaleY, color, translation, style); } -void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color, int translation, double rotate, ERenderStyle style) +void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color, int translation, ERenderStyle style, double clipwidth) { double texwidth = tex->GetDisplayWidth() * scaleX; double texheight = tex->GetDisplayHeight() * scaleY; @@ -582,6 +582,10 @@ void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flag DTA_LeftOffset, 0, DTA_DestWidthF, boxwidth, DTA_DestHeightF, boxheight, + DTA_ClipLeft, 0, + DTA_ClipTop, 0, + DTA_ClipBottom, twod->GetHeight(), + DTA_ClipRight, clipwidth < 0? twod->GetWidth() : int(x + boxwidth * clipwidth), DTA_Color, color, DTA_TranslationIndex, translation? translation : (flags & DI_TRANSLATABLE) ? GetTranslation() : 0, DTA_ColorOverlay, (flags & DI_DIM) ? MAKEARGB(170, 0, 0, 0) : 0, @@ -590,7 +594,96 @@ void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flag DTA_FillColor, (flags & DI_ALPHAMAPPED) ? 0 : -1, DTA_FlipX, !!(flags & DI_MIRROR), DTA_FlipY, !!(flags& DI_MIRRORY), - DTA_Rotate, rotate, + DTA_LegacyRenderStyle, style, + TAG_DONE); +} + + +//============================================================================ +// +// draw stuff +// +//============================================================================ + +void DStatusBarCore::DrawRotated(FTextureID texture, double x, double y, double angle, int flags, double Alpha, double scaleX, double scaleY, PalEntry color, int translation, ERenderStyle style) +{ + if (!texture.isValid()) + return; + + FGameTexture* tex = TexMan.GetGameTexture(texture, !(flags & DI_DONTANIMATE)); + DrawRotated(tex, x, y, angle, flags, Alpha, scaleX, scaleY, color, translation, style); +} + +void DStatusBarCore::DrawRotated(FGameTexture* tex, double x, double y, int flags, double angle, double Alpha, double scaleX, double scaleY, PalEntry color, int translation, ERenderStyle style) +{ + double texwidth = tex->GetDisplayWidth() * scaleX; + double texheight = tex->GetDisplayHeight() * scaleY; + double texleftoffs = tex->GetDisplayLeftOffset() * scaleY; + double textopoffs = tex->GetDisplayTopOffset() * scaleY; + + // resolve auto-alignment before making any adjustments to the position values. + if (!(flags & DI_SCREEN_MANUAL_ALIGN)) + { + if (x < 0) flags |= DI_SCREEN_RIGHT; + else flags |= DI_SCREEN_LEFT; + if (y < 0) flags |= DI_SCREEN_BOTTOM; + else flags |= DI_SCREEN_TOP; + } + + Alpha *= this->Alpha; + if (Alpha <= 0) return; + x += drawOffset.X; + y += drawOffset.Y; + DVector2 Scale = GetHUDScale(); + + scaleX = 1 / scaleX; + scaleY = 1 / scaleY; + + if (!fullscreenOffsets) + { + StatusbarToRealCoords(x, y, texwidth, texheight); + } + else + { + double orgx, orgy; + + switch (flags & DI_SCREEN_HMASK) + { + default: orgx = 0; break; + case DI_SCREEN_HCENTER: orgx = twod->GetWidth() / 2; break; + case DI_SCREEN_RIGHT: orgx = twod->GetWidth(); break; + } + + switch (flags & DI_SCREEN_VMASK) + { + default: orgy = 0; break; + case DI_SCREEN_VCENTER: orgy = twod->GetHeight() / 2; break; + case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break; + } + + // move stuff in the top right corner a bit down if the fps counter is on. + if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10; + + x *= Scale.X; + y *= Scale.Y; + scaleX *= Scale.X; + scaleY *= Scale.Y; + x += orgx; + y += orgy; + } + DrawTexture(twod, tex, x, y, + DTA_ScaleX, scaleX, + DTA_ScaleY, scaleY, + DTA_Color, color, + DTA_CenterOffsetRel, !!(flags & DI_ITEM_RELCENTER), + DTA_Rotate, angle, + DTA_TranslationIndex, translation ? translation : (flags & DI_TRANSLATABLE) ? GetTranslation() : 0, + DTA_ColorOverlay, (flags & DI_DIM) ? MAKEARGB(170, 0, 0, 0) : 0, + DTA_Alpha, Alpha, + DTA_AlphaChannel, !!(flags & DI_ALPHAMAPPED), + DTA_FillColor, (flags & DI_ALPHAMAPPED) ? 0 : -1, + DTA_FlipX, !!(flags & DI_MIRROR), + DTA_FlipY, !!(flags & DI_MIRRORY), DTA_LegacyRenderStyle, style, TAG_DONE); } diff --git a/src/common/statusbar/base_sbar.h b/src/common/statusbar/base_sbar.h index 75daeb826..02c66ba26 100644 --- a/src/common/statusbar/base_sbar.h +++ b/src/common/statusbar/base_sbar.h @@ -184,8 +184,10 @@ public: virtual void SetScale(); void ValidateResolution(int& hres, int& vres) const; void StatusbarToRealCoords(double& x, double& y, double& w, double& h) const; - void DrawGraphic(FGameTexture* texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, double rotate = 0, ERenderStyle style = STYLE_Translucent); - void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, double rotate = 0, ERenderStyle style = STYLE_Translucent); + void DrawGraphic(FGameTexture* texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, ERenderStyle style = STYLE_Translucent, double clipwidth = -1.0); + void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, ERenderStyle style = STYLE_Translucent, double clipwidth = -1.0); + void DrawRotated(FTextureID texture, double x, double y, double angle, int flags, double Alpha, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, ERenderStyle style = STYLE_Translucent); + void DrawRotated(FGameTexture* tex, double x, double y, int flags, double angle, double Alpha, double scaleX, double scaleY, PalEntry color = 0xffffffff, int translation = 0, ERenderStyle style = STYLE_Translucent); void DrawString(FFont* font, const FString& cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY, double scaleX, double scaleY, int pt); void TransformRect(double& x, double& y, double& w, double& h, int flags = 0); void Fill(PalEntry color, double x, double y, double w, double h, int flags = 0); diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index 03997f8e5..37254b32a 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -115,11 +115,6 @@ FImageSource *PNGImage_TryCreate(FileReader & data, int lumpnum) uint8_t filter = data.ReadUInt8(); uint8_t interlace = data.ReadUInt8(); - // NOTICE: GZDoom is the ONLY program in the typical development stack (GIMP, Slade, UDB) which does not support these formats - // As such, the average developer will have no other way to figure out what's going wrong without these: these CANNOT be allowed to fail silently. - // As things like PNG-compression and 64-bit color become more common in royalty-free PBR materials, support should be an eventual target. - // Even then, these warnings should remain to prevent this from being an issue the next time things change. - if (compression != 0 || filter != 0 || interlace > 1) { Printf(TEXTCOLOR_YELLOW"WARNING: failed to load PNG %s: the compression, filter, or interlace is not supported!\n", fileSystem.GetFileFullName(lumpnum)); diff --git a/src/common/utility/findfile.cpp b/src/common/utility/findfile.cpp index ac0ca8fdf..6006a34a1 100644 --- a/src/common/utility/findfile.cpp +++ b/src/common/utility/findfile.cpp @@ -208,10 +208,10 @@ bool D_AddFile(TArray& wadfiles, const char* file, bool check, int posi // Confirm file exists in filesystem. struct stat info; bool found = stat(file, &info) == 0; + FString fullpath = file; if (!found) { // File not found, so split file into path and filename so we can enumerate the path for the file. - FString fullpath = file; auto lastindex = fullpath.LastIndexOf("/"); FString basepath = fullpath.Left(lastindex); FString filename = fullpath.Right(fullpath.Len() - lastindex - 1); diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index 621ad1b28..0b5e5f642 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -761,6 +761,10 @@ public: ReadUserKey(ukey); loader->MapThingsUserData.Push(ukey); } + else + { + DPrintf(DMSG_WARNING, "Unknown UDMF thing key %s\n", key.GetChars()); + } break; } } @@ -1111,6 +1115,7 @@ public: break; default: + DPrintf(DMSG_WARNING, "Unknown UDMF linedef key %s\n", key.GetChars()); break; } @@ -1425,6 +1430,7 @@ public: break; default: + DPrintf(DMSG_WARNING, "Unknown UDMF sidedef key %s\n", key.GetChars()); break; } @@ -1929,6 +1935,7 @@ public: break; default: + DPrintf(DMSG_WARNING, "Unknown UDMF sector key %s\n", key.GetChars()); break; } if ((namespace_bits & (Zd | Zdt)) && !strnicmp("user_", key.GetChars(), 5)) @@ -2179,6 +2186,7 @@ public: switch(namespc.GetIndex()) { case NAME_ZDoom: + case NAME_Eternity: namespace_bits = Zd; isTranslated = false; break;