From 4efc0e3b82d499a03b26ff1d23e6ba4be89f4d2c Mon Sep 17 00:00:00 2001 From: 12pm <30786226+12pm@users.noreply.github.com> Date: Wed, 3 Apr 2019 01:05:38 +0200 Subject: [PATCH] Make world offset calculation more accurate Noticed that after some time groups with a parallax different than 100 were incorrectly rendered in the editor --- src/game/client/components/hud.cpp | 24 +++++++++++------------ src/game/client/components/maplayers.cpp | 2 +- src/game/client/components/nameplates.cpp | 2 +- src/game/client/render.cpp | 8 ++++---- src/game/editor/editor.cpp | 9 ++++----- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 1c553c2aa..713f2bd6c 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -91,7 +91,7 @@ void CHud::OnInit() RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[i].m_pSpriteCursor); RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 64.f); } - + // the flags RenderTools()->SelectSprite(SPRITE_FLAG_RED); RenderTools()->QuadContainerAddSprite(m_HudQuadContainerIndex, 0.f, 0.f, 8.f, 16.f); @@ -196,8 +196,8 @@ void CHud::RenderScoreHud() bool RecreateTeamScore[2] = { str_comp(aScoreTeam[0], m_aScoreInfo[0].m_aScoreText) != 0, str_comp(aScoreTeam[1], m_aScoreInfo[1].m_aScoreText) != 0 }; - int FlagCarrier[2] = { - m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierRed, + int FlagCarrier[2] = { + m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierRed, m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierBlue }; @@ -220,7 +220,7 @@ void CHud::RenderScoreHud() { // draw box if(RecreateRect) - { + { if(m_aScoreInfo[t].m_RoundRectQuadContainerIndex != -1) Graphics()->DeleteQuadContainer(m_aScoreInfo[t].m_RoundRectQuadContainerIndex); @@ -277,8 +277,8 @@ void CHud::RenderScoreHud() if(m_aScoreInfo[t].m_OptionalNameTextContainerIndex != -1) TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_OptionalNameTextContainerIndex); - float w = TextRender()->TextWidth(0, 8.0f, pName, -1); - + float w = TextRender()->TextWidth(0, 8.0f, pName, -1); + CTextCursor Cursor; TextRender()->SetCursor(&Cursor, min(Whole - w - 1.0f, Whole - ScoreWidthMax - ImageSize - 2 * Split), StartY + (t + 1)*20.0f - 2.0f, 8.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; @@ -435,7 +435,7 @@ void CHud::RenderScoreHud() int ID = apPlayerInfo[t]->m_ClientID; if(ID >= 0 && ID < MAX_CLIENTS) { - const char *pName = m_pClient->m_aClients[ID].m_aName; + const char *pName = m_pClient->m_aClients[ID].m_aName; if(RecreateRect) { mem_copy(m_aScoreInfo[t].m_aPlayerNameText, pName, sizeof(m_aScoreInfo[t].m_aPlayerNameText)); @@ -479,7 +479,7 @@ void CHud::RenderScoreHud() if(m_aScoreInfo[t].m_TextRankContainerIndex != -1) TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextRankContainerIndex); - + CTextCursor Cursor; TextRender()->SetCursor(&Cursor, Whole - ScoreWidthMax - ImageSize - Split - PosSize, StartY + t * 20 + (18.f - 10.f) / 2.f, 10.0f, TEXTFLAG_RENDER); Cursor.m_LineWidth = -1; @@ -521,7 +521,7 @@ void CHud::RenderWarmupTimer() void CHud::MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup) { float Points[4]; - RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX/100.0f, pGroup->m_ParallaxY/100.0f, + RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX, pGroup->m_ParallaxY, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points); Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]); } @@ -705,7 +705,7 @@ void CHud::RenderCursor() MapscreenToGroup(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y, Layers()->GameGroup()); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id); - + // render cursor int QuadOffset = NUM_WEAPONS * 10 + 40 + (m_pClient->m_Snap.m_pLocalCharacter->m_Weapon%NUM_WEAPONS); Graphics()->SetColor(1.f, 1.f, 1.f, 1.f); @@ -759,13 +759,13 @@ void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter) // render gui stuff Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id); - + int QuadOffset = pCharacter->m_Weapon%NUM_WEAPONS * 10; Graphics()->RenderQuadContainer(m_HudQuadContainerIndex, QuadOffset, min(pCharacter->m_AmmoCount, 10)); QuadOffset = NUM_WEAPONS * 10; Graphics()->RenderQuadContainer(m_HudQuadContainerIndex, QuadOffset, min(pCharacter->m_Health, 10)); - + QuadOffset += 10 + min(pCharacter->m_Health, 10); if(min(pCharacter->m_Health, 10) < 10) Graphics()->RenderQuadContainer(m_HudQuadContainerIndex, QuadOffset, 10 - min(pCharacter->m_Health, 10)); diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 214bf7817..f9924951d 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -49,7 +49,7 @@ void CMapLayers::EnvelopeUpdate() void CMapLayers::MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom) { float Points[4]; - RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX/100.0f, pGroup->m_ParallaxY/100.0f, + RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX, pGroup->m_ParallaxY, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), Zoom, Points); Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]); } diff --git a/src/game/client/components/nameplates.cpp b/src/game/client/components/nameplates.cpp index 2a06dc2f9..eb1dafbb6 100644 --- a/src/game/client/components/nameplates.cpp +++ b/src/game/client/components/nameplates.cpp @@ -17,7 +17,7 @@ void CNamePlates::MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup) { float Points[4]; - RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX / 100.0f, pGroup->m_ParallaxY / 100.0f, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points); + RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX, pGroup->m_ParallaxY, pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points); Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]); } diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp index f562b9fcc..5294c0494 100644 --- a/src/game/client/render.cpp +++ b/src/game/client/render.cpp @@ -146,7 +146,7 @@ void CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float Size, bo void CRenderTools::QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height) { IGraphics::CQuadItem QuadItem(X, Y, Width, Height); - Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1); + Graphics()->QuadContainerAddQuads(QuadContainerIndex, &QuadItem, 1); } void CRenderTools::DrawRoundRectExt(float x, float y, float w, float h, float r, int Corners) @@ -334,7 +334,7 @@ void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote //Graphics()->TextureSet(data->images[IMAGE_CHAR_DEFAULT].id); Graphics()->TextureSet(pInfo->m_Texture); - + // first pass we draw the outline // second pass we draw the filling for(int p = 0; p < 2; p++) @@ -453,8 +453,8 @@ void CRenderTools::MapscreenToWorld(float CenterX, float CenterY, float Parallax { float Width, Height; CalcScreenParams(1150*1000, 1500, 1050, Aspect, &Width, &Height); - CenterX *= ParallaxX; - CenterY *= ParallaxY; + CenterX *= ParallaxX/100.0f; + CenterY *= ParallaxY/100.0f; Width *= Zoom; Height *= Zoom; pPoints[0] = OffsetX+CenterX-Width/2; diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index fa39b7acd..bb0adc08d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -170,8 +170,7 @@ void CLayerGroup::Mapping(float *pPoints) { m_pMap->m_pEditor->RenderTools()->MapscreenToWorld( m_pMap->m_pEditor->m_WorldOffsetX, m_pMap->m_pEditor->m_WorldOffsetY, - m_ParallaxX/100.0f, m_ParallaxY/100.0f, - m_OffsetX, m_OffsetY, + m_ParallaxX, m_ParallaxY, m_OffsetX, m_OffsetY, m_pMap->m_pEditor->Graphics()->ScreenAspect(), m_pMap->m_pEditor->m_WorldZoom, pPoints); pPoints[0] += m_pMap->m_pEditor->m_EditorOffsetX; @@ -2874,7 +2873,7 @@ void CEditor::DoMapEditor(CUIRect View) RenderTools()->MapscreenToWorld( m_WorldOffsetX, m_WorldOffsetY, - 1.0f, 1.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints); + 100.0f, 100.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints); if(i == 0) { @@ -2916,7 +2915,7 @@ void CEditor::DoMapEditor(CUIRect View) RenderTools()->MapscreenToWorld( m_WorldOffsetX, m_WorldOffsetY, - 1.0f, 1.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints); + 100.0f, 100.0f, 0.0f, 0.0f, Aspect, 1.0f, aPoints); CUIRect r; r.x = aPoints[0]; @@ -5870,7 +5869,7 @@ void CEditor::ZoomMouseTarget(float ZoomFactor) float aPoints[4]; RenderTools()->MapscreenToWorld( m_WorldOffsetX, m_WorldOffsetY, - 1.0f, 1.0f, 0.0f, 0.0f, Graphics()->ScreenAspect(), m_WorldZoom, aPoints); + 100.0f, 100.0f, 0.0f, 0.0f, Graphics()->ScreenAspect(), m_WorldZoom, aPoints); float WorldWidth = aPoints[2]-aPoints[0]; float WorldHeight = aPoints[3]-aPoints[1];