From 4a52c948168d38853a4dc9462f6ff46154eda105 Mon Sep 17 00:00:00 2001 From: Sour Date: Tue, 19 Jun 2018 22:17:00 -0400 Subject: [PATCH] HD Packs: Added option to display custom backgrounds behind bg priority sprites (instead of over them) --- Core/HdData.h | 1 + Core/HdNesPack.cpp | 40 +++++++++++++++++++++-------------- Core/HdNesPack.h | 2 +- Core/HdPackLoader.cpp | 6 +++++- GUI.NET/Config/VideoInfo.cs | 2 +- GUI.NET/Forms/frmMain.Help.cs | 3 +++ 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/Core/HdData.h b/Core/HdData.h index 48e915c6..917d84d6 100644 --- a/Core/HdData.h +++ b/Core/HdData.h @@ -314,6 +314,7 @@ struct HdBackgroundInfo vector Conditions; float HorizontalScrollRatio; float VerticalScrollRatio; + bool BehindBgPrioritySprites; uint32_t* data() { diff --git a/Core/HdNesPack.cpp b/Core/HdNesPack.cpp index 05e0e098..b5ec8d3a 100644 --- a/Core/HdNesPack.cpp +++ b/Core/HdNesPack.cpp @@ -289,6 +289,28 @@ void HdNesPack::GetPixels(uint32_t x, uint32_t y, HdPpuPixelInfo &pixelInfo, uin DrawColor(_palette[pixelInfo.Tile.PpuBackgroundColor], outputBuffer, hdData->Scale, screenWidth); + bool hasCustomBackground = false; + bool hasNonBackgroundSurrounding = false; + bool backgroundBehindBgSprites = false; + if(_backgroundIndex >= 0) { + HdBackgroundInfo &bgInfo = hdData->Backgrounds[_backgroundIndex]; + + //Enable custom background if the current pixel fits within the background's boundaries + hasCustomBackground = + (int32_t)x >= -_bgScrollX && + (int32_t)y >= -_bgScrollY && + (y + _bgScrollY + 1) * hdData->Scale <= bgInfo.Data->Height && + (x + _bgScrollX + 1) * hdData->Scale <= bgInfo.Data->Width; + + if(hasCustomBackground) { + hasNonBackgroundSurrounding = _contoursEnabled && IsNextToSprite(x, y); + if(bgInfo.BehindBgPrioritySprites) { + DrawCustomBackground(outputBuffer, x + _bgScrollX, y + _bgScrollY, hdData->Scale, screenWidth); + backgroundBehindBgSprites = true; + } + } + } + if(hasSprite) { for(int k = pixelInfo.SpriteCount - 1; k >= 0; k--) { if(pixelInfo.Sprite[k].BackgroundPriority) { @@ -306,22 +328,8 @@ void HdNesPack::GetPixels(uint32_t x, uint32_t y, HdPpuPixelInfo &pixelInfo, uin } } - bool hasCustomBackground = false; - bool hasNonBackgroundSurrounding = false; - if(_backgroundIndex >= 0) { - HdBackgroundInfo &bgInfo = hdData->Backgrounds[_backgroundIndex]; - - //Enable custom background if the current pixel fits within the background's boundaries - hasCustomBackground = - (int32_t)x >= -_bgScrollX && - (int32_t)y >= -_bgScrollY && - (y + _bgScrollY + 1) * hdData->Scale <= bgInfo.Data->Height && - (x + _bgScrollX + 1) * hdData->Scale <= bgInfo.Data->Width; - - if(hasCustomBackground) { - hasNonBackgroundSurrounding = _contoursEnabled && IsNextToSprite(x, y); - DrawCustomBackground(outputBuffer, x + _bgScrollX, y + _bgScrollY, hdData->Scale, screenWidth); - } + if (hasCustomBackground && !backgroundBehindBgSprites) { + DrawCustomBackground(outputBuffer, x + _bgScrollX, y + _bgScrollY, hdData->Scale, screenWidth); } if(hdPackTileInfo) { diff --git a/Core/HdNesPack.h b/Core/HdNesPack.h index b43bf8a4..8253996d 100644 --- a/Core/HdNesPack.h +++ b/Core/HdNesPack.h @@ -33,7 +33,7 @@ private: __forceinline void ProcessGrayscaleAndEmphasis(HdPpuPixelInfo &pixelInfo, uint32_t* outputBuffer, uint32_t hdScreenWidth); public: - static const uint32_t CurrentVersion = 101; + static const uint32_t CurrentVersion = 102; HdNesPack(); ~HdNesPack(); diff --git a/Core/HdPackLoader.cpp b/Core/HdPackLoader.cpp index 447eddaa..ca3d2b72 100644 --- a/Core/HdPackLoader.cpp +++ b/Core/HdPackLoader.cpp @@ -213,7 +213,6 @@ bool HdPackLoader::ProcessImgTag(string src) bitmapInfo.PixelData.resize(pixelData.size() / 4); memcpy(bitmapInfo.PixelData.data(), pixelData.data(), bitmapInfo.PixelData.size() * sizeof(bitmapInfo.PixelData[0])); - _hdNesBitmaps.push_back(bitmapInfo); return true; } else { @@ -533,6 +532,7 @@ void HdPackLoader::ProcessBackgroundTag(vector &tokens, vector &tokens, vector 3) { backgroundInfo.VerticalScrollRatio = std::stof(tokens[3]); } + if(tokens.size() > 4) { + checkConstraint(_data->Version >= 102, "[HDPack] This feature requires version 102+ of HD Packs"); + backgroundInfo.BehindBgPrioritySprites = tokens[4] == "Y"; + } } _data->Backgrounds.push_back(backgroundInfo); diff --git a/GUI.NET/Config/VideoInfo.cs b/GUI.NET/Config/VideoInfo.cs index d7a008a2..a5daadd4 100644 --- a/GUI.NET/Config/VideoInfo.cs +++ b/GUI.NET/Config/VideoInfo.cs @@ -23,7 +23,7 @@ namespace Mesen.GUI.Config public ScreenRotation ScreenRotation = ScreenRotation.None; [MinMax(0.1, 5.0)] public double CustomAspectRatio = 1.0; public bool VerticalSync = false; - public bool UseHdPacks = false; + public bool UseHdPacks = true; public bool IntegerFpsMode = false; public string PaletteData; diff --git a/GUI.NET/Forms/frmMain.Help.cs b/GUI.NET/Forms/frmMain.Help.cs index 368a08e6..277cb268 100644 --- a/GUI.NET/Forms/frmMain.Help.cs +++ b/GUI.NET/Forms/frmMain.Help.cs @@ -95,6 +95,9 @@ namespace Mesen.GUI.Forms if(ConfigManager.Config.AudioInfo.AudioLatency < 60) { ConfigManager.Config.AudioInfo.AudioLatency = 60; } + + //No reason to keep this disabled by default - enabling it by default makes it easier for new users to install/use HD packs + ConfigManager.Config.VideoInfo.UseHdPacks = true; } ConfigManager.Config.MesenVersion = InteropEmu.GetMesenVersion();