Skip to content

Commit baf292c

Browse files
committed
optimize shield bar drawing
1 parent 5a0f504 commit baf292c

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/New/Entity/ShieldClass.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -879,19 +879,21 @@ void ShieldClass::DrawShieldBar_Building(const int length, RectangleStruct* pBou
879879
if (this->HP <= 0 && this->Type->Pips_HideIfNoStrength)
880880
return;
881881

882-
Point2D position = { 0, 0 };
882+
Point2D selectBracketPosition = TechnoExt::GetBuildingSelectBracketPosition(this->Techno, BuildingSelectBracketPosition::Top);
883+
selectBracketPosition.X -= 6;
884+
selectBracketPosition.Y -= 3;
883885
const int totalLength = DrawShieldBar_PipAmount(length);
884-
int frame = this->DrawShieldBar_Pip(true);
886+
const int frame = this->DrawShieldBar_Pip(true);
885887

886888
if (totalLength > 0)
887889
{
888890
for (int frameIdx = totalLength, deltaX = 0, deltaY = 0;
889891
frameIdx;
890892
frameIdx--, deltaX += 4, deltaY -= 2)
891893
{
892-
position = TechnoExt::GetBuildingSelectBracketPosition(Techno, BuildingSelectBracketPosition::Top);
893-
position.X -= deltaX + 6;
894-
position.Y -= deltaY + 3;
894+
Point2D position = selectBracketPosition;
895+
position.X -= deltaX;
896+
position.Y -= deltaY;
895897

896898
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP,
897899
frame, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
@@ -900,15 +902,15 @@ void ShieldClass::DrawShieldBar_Building(const int length, RectangleStruct* pBou
900902

901903
if (totalLength < length)
902904
{
905+
const int emptyFrame = this->Type->Pips_Building_Empty.Get(RulesExt::Global()->Pips_Shield_Building_Empty.Get(0));
906+
903907
for (int frameIdx = length - totalLength, deltaX = 4 * totalLength, deltaY = -2 * totalLength;
904908
frameIdx;
905909
frameIdx--, deltaX += 4, deltaY -= 2)
906910
{
907-
position = TechnoExt::GetBuildingSelectBracketPosition(Techno, BuildingSelectBracketPosition::Top);
908-
position.X -= deltaX + 6;
909-
position.Y -= deltaY + 3;
910-
911-
const int emptyFrame = this->Type->Pips_Building_Empty.Get(RulesExt::Global()->Pips_Shield_Building_Empty.Get(0));
911+
Point2D position = selectBracketPosition;
912+
position.X -= deltaX;
913+
position.Y -= deltaY;
912914

913915
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP,
914916
emptyFrame, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
@@ -921,24 +923,27 @@ void ShieldClass::DrawShieldBar_Other(const int length, RectangleStruct* pBound)
921923
if (this->HP <= 0 && this->Type->Pips_HideIfNoStrength)
922924
return;
923925

924-
auto position = TechnoExt::GetFootSelectBracketPosition(Techno, Anchor(HorizontalPosition::Left, VerticalPosition::Top));
926+
auto position = TechnoExt::GetFootSelectBracketPosition(this->Techno, Anchor(HorizontalPosition::Left, VerticalPosition::Top));
925927
const auto pipBoard = this->Type->Pips_Background.Get(RulesExt::Global()->Pips_Shield_Background.Get(FileSystem::PIPBRD_SHP));
926-
int frame;
928+
int frame = pipBoard->Frames > 2 ? 2 : 0;
927929

928930
position.X -= 1;
929931
position.Y += this->Techno->GetTechnoType()->PixelSelectionBracketDelta + this->Type->BracketDelta - 3;
930932

931-
if (length == 8)
932-
frame = pipBoard->Frames > 2 ? 3 : 1;
933-
else
934-
frame = pipBoard->Frames > 2 ? 2 : 0;
935-
936933
if (this->Techno->IsSelected)
937934
{
938-
position.X += length + 1 + (length == 8 ? length + 1 : 0);
935+
int offset = length + 1;
936+
937+
if (length == 8)
938+
{
939+
frame += 1;
940+
offset += length + 1;
941+
}
942+
943+
position.X += offset;
939944
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, pipBoard,
940945
frame, &position, pBound, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
941-
position.X -= length + 1 + (length == 8 ? length + 1 : 0);
946+
position.X -= offset;
942947
}
943948

944949
frame = this->DrawShieldBar_Pip(false);
@@ -957,14 +962,9 @@ int ShieldClass::DrawShieldBar_Pip(const bool isBuilding) const
957962
{
958963
const int strength = this->Type->Strength.Get();
959964
const auto pipsShield = isBuilding ? this->Type->Pips_Building.Get() : this->Type->Pips.Get();
960-
const auto pipsGlobal = isBuilding ? RulesExt::Global()->Pips_Shield_Building.Get() : RulesExt::Global()->Pips_Shield.Get();
961965

962-
CoordStruct shieldPip;
963-
964-
if (pipsShield.X != -1)
965-
shieldPip = pipsShield;
966-
else
967-
shieldPip = pipsGlobal;
966+
const auto shieldPip = pipsShield.X != -1 ? pipsShield :
967+
(isBuilding ? RulesExt::Global()->Pips_Shield_Building.Get() : RulesExt::Global()->Pips_Shield.Get());
968968

969969
if (this->HP > this->Type->GetConditionYellow() * strength && shieldPip.X != -1)
970970
return shieldPip.X;

0 commit comments

Comments
 (0)