Revert "Fix split-screen UI wrong positioning on window resize (#989)"

This reverts commit e2adaa082c.
This commit is contained in:
Spring 2026-03-08 22:55:54 -05:00
parent e2adaa082c
commit 6b09aa8800
6 changed files with 976 additions and 994 deletions

View file

@ -51,10 +51,7 @@ private:
struct GammaCBData
{
float gamma;
float pad;
float uvOffsetX, uvOffsetY;
float uvScaleX, uvScaleY;
float pad2[2];
float pad[3];
};
static const char* g_gammaVSCode;

View file

@ -143,18 +143,14 @@ void UIComponent_Chat::render(S32 width, S32 height, C4JRender::eViewportType vi
F32 scale;
ComputeTileScale(tileWidth, tileHeight, m_movieWidth, m_movieHeight, needsYTile, scale, tileYStart);
// For vertical split, scale down to fit the full SWF height when the
// window is shorter than the movie (same fix as HUD).
if(!needsYTile && m_movieHeight > 0)
{
F32 scaleH = (F32)tileHeight / (F32)m_movieHeight;
if(scaleH < scale)
scale = scaleH;
}
IggyPlayerSetDisplaySize( getMovie(), (S32)(m_movieWidth * scale), (S32)(m_movieHeight * scale) );
S32 contentOffX, contentOffY;
ComputeSplitContentOffset(viewport, m_movieWidth, m_movieHeight, scale, tileWidth, tileHeight, tileYStart, contentOffX, contentOffY);
xPos += contentOffX;
yPos += contentOffY;
ui.setupRenderPosition(xPos, yPos);
IggyPlayerDrawTilesStart ( getMovie() );
m_renderWidth = tileWidth;

View file

@ -247,18 +247,14 @@ void UIComponent_Tooltips::render(S32 width, S32 height, C4JRender::eViewportTyp
F32 scale;
ComputeTileScale(tileWidth, tileHeight, m_movieWidth, m_movieHeight, needsYTile, scale, tileYStart);
// For vertical split, scale down to fit the full SWF height when the
// window is shorter than the movie (same fix as HUD).
if(!needsYTile && m_movieHeight > 0)
{
F32 scaleH = (F32)tileHeight / (F32)m_movieHeight;
if(scaleH < scale)
scale = scaleH;
}
IggyPlayerSetDisplaySize( getMovie(), (S32)(m_movieWidth * scale), (S32)(m_movieHeight * scale) );
S32 contentOffX, contentOffY;
ComputeSplitContentOffset(viewport, m_movieWidth, m_movieHeight, scale, tileWidth, tileHeight, tileYStart, contentOffX, contentOffY);
xPos += contentOffX;
yPos += contentOffY;
ui.setupRenderPosition(xPos, yPos);
IggyPlayerDrawTilesStart ( getMovie() );
m_renderWidth = tileWidth;

File diff suppressed because it is too large Load diff

View file

@ -954,70 +954,91 @@ float GameRenderer::ComputeGammaFromSlider(float slider0to100)
void GameRenderer::CachePlayerGammas()
{
const float slider = app.GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Gamma);
const float gamma = ComputeGammaFromSlider(slider);
for (int j = 0; j < XUSER_MAX_COUNT && j < NUM_LIGHT_TEXTURES; ++j)
m_cachedGammaPerPlayer[j] = gamma;
{
std::shared_ptr<MultiplayerLocalPlayer> player = Minecraft::GetInstance()->localplayers[j];
if (!player)
{
m_cachedGammaPerPlayer[j] = 1.0f;
continue;
}
const float slider = app.GetGameSettings(j, eGameSetting_Gamma); // 0..100
m_cachedGammaPerPlayer[j] = ComputeGammaFromSlider(slider);
}
}
bool GameRenderer::ComputeViewportForPlayer(int j, D3D11_VIEWPORT &outViewport) const
{
// Use the actual backbuffer dimensions so viewports adapt to window resize.
extern int g_rScreenWidth;
extern int g_rScreenHeight;
std::shared_ptr<MultiplayerLocalPlayer> player = Minecraft::GetInstance()->localplayers[j];
if (!player)
int active = 0;
int indexMap[NUM_LIGHT_TEXTURES] = {-1, -1, -1, -1};
for (int i = 0; i < XUSER_MAX_COUNT && i < NUM_LIGHT_TEXTURES; ++i)
{
if (Minecraft::GetInstance()->localplayers[i])
indexMap[active++] = i;
}
if (active <= 1)
{
outViewport.TopLeftX = 0.0f;
outViewport.TopLeftY = 0.0f;
outViewport.Width = static_cast<FLOAT>(g_rScreenWidth);
outViewport.Height = static_cast<FLOAT>(g_rScreenHeight);
outViewport.MinDepth = 0.0f;
outViewport.MaxDepth = 1.0f;
return true;
}
int k = -1;
for (int ord = 0; ord < active; ++ord)
if (indexMap[ord] == j)
{
k = ord;
break;
}
if (k < 0)
return false;
const float w = static_cast<float>(g_rScreenWidth);
const float h = static_cast<float>(g_rScreenHeight);
const float halfW = w * 0.5f;
const float halfH = h * 0.5f;
const float width = static_cast<float>(g_rScreenWidth);
const float height = static_cast<float>(g_rScreenHeight);
outViewport.MinDepth = 0.0f;
outViewport.MaxDepth = 1.0f;
switch (static_cast<C4JRender::eViewportType>(player->m_iScreenSection))
if (active == 2)
{
case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
outViewport.Width = w; outViewport.Height = halfH;
break;
case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
outViewport.TopLeftX = 0; outViewport.TopLeftY = halfH;
outViewport.Width = w; outViewport.Height = halfH;
break;
case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
outViewport.Width = halfW; outViewport.Height = h;
break;
case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
outViewport.TopLeftX = halfW; outViewport.TopLeftY = 0;
outViewport.Width = halfW; outViewport.Height = h;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
outViewport.Width = halfW; outViewport.Height = halfH;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
outViewport.TopLeftX = halfW; outViewport.TopLeftY = 0;
outViewport.Width = halfW; outViewport.Height = halfH;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
outViewport.TopLeftX = 0; outViewport.TopLeftY = halfH;
outViewport.Width = halfW; outViewport.Height = halfH;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
outViewport.TopLeftX = halfW; outViewport.TopLeftY = halfH;
outViewport.Width = halfW; outViewport.Height = halfH;
break;
default:
outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
outViewport.Width = w; outViewport.Height = h;
break;
const float halfH = height * 0.5f;
outViewport.TopLeftX = 0.0f;
outViewport.Width = width;
outViewport.MinDepth = 0.0f;
outViewport.MaxDepth = 1.0f;
if (k == 0)
{
outViewport.TopLeftY = 0.0f;
outViewport.Height = halfH;
}
else
{
outViewport.TopLeftY = halfH;
outViewport.Height = halfH;
}
return true;
}
else
{
const float halfW = width * 0.5f;
const float halfH = height * 0.5f;
const int row = (k >= 2) ? 1 : 0;
const int col = (k % 2);
outViewport.TopLeftX = col ? halfW : 0.0f;
outViewport.TopLeftY = row ? halfH : 0.0f;
outViewport.Width = halfW;
outViewport.Height = halfH;
outViewport.MinDepth = 0.0f;
outViewport.MaxDepth = 1.0f;
return true;
}
return true;
}
uint32_t GameRenderer::BuildPlayerViewports(D3D11_VIEWPORT *outViewports, float *outGammas, UINT maxCount) const

View file

@ -21,17 +21,13 @@ const char* PostProcesser::g_gammaPSCode =
"cbuffer GammaCB : register(b0)\n"
"{\n"
" float gamma;\n"
" float _pad;\n"
" float2 uvOffset;\n"
" float2 uvScale;\n"
" float2 _pad2;\n"
" float3 pad;\n"
"};\n"
"Texture2D sceneTex : register(t0);\n"
"SamplerState sceneSampler : register(s0);\n"
"float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target\n"
"{\n"
" float2 texUV = uvOffset + uv * uvScale;\n"
" float4 color = sceneTex.Sample(sceneSampler, texUV);\n"
" float4 color = sceneTex.Sample(sceneSampler, uv);\n"
"\n"
" color.rgb = max(color.rgb, 0.0);\n"
"\n"
@ -162,7 +158,7 @@ void PostProcesser::Init()
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
GammaCBData initData = {1.0f, 0, 0.0f, 0.0f, 1.0f, 1.0f, {0, 0}};
GammaCBData initData = {1.0f, {0, 0, 0}};
D3D11_SUBRESOURCE_DATA srData;
srData.pSysMem = &initData;
srData.SysMemPitch = 0;
@ -241,10 +237,6 @@ void PostProcesser::Apply() const
{
GammaCBData *cb = static_cast<GammaCBData *>(mapped.pData);
cb->gamma = m_gamma;
cb->uvOffsetX = 0.0f;
cb->uvOffsetY = 0.0f;
cb->uvScaleX = 1.0f;
cb->uvScaleY = 1.0f;
ctx->Unmap(m_pGammaCB, 0);
}
@ -341,6 +333,27 @@ void PostProcesser::ApplyFromCopied() const
ID3D11DeviceContext* ctx = g_pImmediateContext;
D3D11_MAPPED_SUBRESOURCE mapped;
const D3D11_MAP mapType = m_wineMode ? D3D11_MAP_WRITE_NO_OVERWRITE : D3D11_MAP_WRITE_DISCARD;
const HRESULT hr = ctx->Map(m_pGammaCB, 0, mapType, 0, &mapped);
if (SUCCEEDED(hr))
{
const auto cb = static_cast<GammaCBData*>(mapped.pData);
cb->gamma = m_gamma;
ctx->Unmap(m_pGammaCB, 0);
}
ID3D11RenderTargetView* oldRTV = nullptr;
ID3D11DepthStencilView* oldDSV = nullptr;
ctx->OMGetRenderTargets(1, &oldRTV, &oldDSV);
UINT numViewports = 1;
D3D11_VIEWPORT oldViewport = {};
ctx->RSGetViewports(&numViewports, &oldViewport);
ID3D11RenderTargetView* bbRTV = g_pRenderTargetView;
ctx->OMSetRenderTargets(1, &bbRTV, nullptr);
D3D11_VIEWPORT vp;
if (m_useCustomViewport)
{
@ -356,33 +369,6 @@ void PostProcesser::ApplyFromCopied() const
vp.TopLeftY = 0;
}
D3D11_MAPPED_SUBRESOURCE mapped;
const D3D11_MAP mapType = m_wineMode ? D3D11_MAP_WRITE_NO_OVERWRITE : D3D11_MAP_WRITE_DISCARD;
const HRESULT hr = ctx->Map(m_pGammaCB, 0, mapType, 0, &mapped);
if (SUCCEEDED(hr))
{
const auto cb = static_cast<GammaCBData*>(mapped.pData);
cb->gamma = m_gamma;
const float texW = static_cast<float>(m_gammaTexWidth);
const float texH = static_cast<float>(m_gammaTexHeight);
cb->uvOffsetX = vp.TopLeftX / texW;
cb->uvOffsetY = vp.TopLeftY / texH;
cb->uvScaleX = vp.Width / texW;
cb->uvScaleY = vp.Height / texH;
ctx->Unmap(m_pGammaCB, 0);
}
ID3D11RenderTargetView* oldRTV = nullptr;
ID3D11DepthStencilView* oldDSV = nullptr;
ctx->OMGetRenderTargets(1, &oldRTV, &oldDSV);
UINT numViewports = 1;
D3D11_VIEWPORT oldViewport = {};
ctx->RSGetViewports(&numViewports, &oldViewport);
ID3D11RenderTargetView* bbRTV = g_pRenderTargetView;
ctx->OMSetRenderTargets(1, &bbRTV, nullptr);
ctx->RSSetViewports(1, &vp);
ctx->IASetInputLayout(nullptr);