From 3f697a25097cd04089c058b791129b43a17d5065 Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Wed, 22 Jul 2020 13:34:21 -0700 Subject: [PATCH] DisplayTacticalCoord will now store the result instead of recalc everytime its needed. --- code/redalert/display.cpp | 7 +++---- code/redalert/tacticalcoord.cpp | 18 +++++++++++++++--- code/redalert/tacticalcoord.h | 7 +++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/code/redalert/display.cpp b/code/redalert/display.cpp index 9809840..2be321d 100644 --- a/code/redalert/display.cpp +++ b/code/redalert/display.cpp @@ -1241,11 +1241,10 @@ bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really) int neighborCellX = weights[crude].x * (distance * 0.4f); int neighbotCellY = weights[crude].y * (distance * 0.4f); DisplayTacticalCoord newCoord = TacticalCoord; - newCoord.x += Pixel_To_Lepton(neighborCellX); - newCoord.y += Pixel_To_Lepton(neighbotCellY); + newCoord.AddPixelXY(neighborCellX, neighbotCellY); - int sx = Lepton_To_Pixel(newCoord.x); - int sy = Lepton_To_Pixel(newCoord.y); + int sx = Lepton_To_Pixel(newCoord.GetX()); + int sy = Lepton_To_Pixel(newCoord.GetY()); CellClass::ConvertCoordsToIsometric(sx, sy); sy += (ScreenWidth / 4); sy += ScreenHeight / 2; diff --git a/code/redalert/tacticalcoord.cpp b/code/redalert/tacticalcoord.cpp index 7bae6c6..420ed9b 100644 --- a/code/redalert/tacticalcoord.cpp +++ b/code/redalert/tacticalcoord.cpp @@ -10,17 +10,29 @@ DisplayTacticalCoord::DisplayTacticalCoord() { DisplayTacticalCoord::DisplayTacticalCoord(COORDINATE coord) { - SetFromCoordinate(coord); + SetFromCoordinate(coord); } COORDINATE DisplayTacticalCoord::GetCoordinate() const { - return XY_Coord(x, y); + return coord; +} + +void DisplayTacticalCoord::SetXY(int x, int y) { + this->x = x; + this->y = y; + this->coord = XY_Coord(x, y); } void DisplayTacticalCoord::SetFromCoordinate(COORDINATE coord) { - //Map.Coord_To_Pixel(coord, x, y); + this->coord = coord; x = Coord_X(coord); y = Coord_Y(coord); +} + +void DisplayTacticalCoord::AddPixelXY(int x, int y) { + int _x = this->x + Pixel_To_Lepton(x); + int _y = this->y + Pixel_To_Lepton(y); + SetXY(_x, _y); } \ No newline at end of file diff --git a/code/redalert/tacticalcoord.h b/code/redalert/tacticalcoord.h index ead50ca..4c9e523 100644 --- a/code/redalert/tacticalcoord.h +++ b/code/redalert/tacticalcoord.h @@ -9,7 +9,14 @@ struct DisplayTacticalCoord { COORDINATE GetCoordinate() const; void SetFromCoordinate(COORDINATE coord); + void SetXY(int x, int y); + int GetX() { return x; } + int GetY() { return y; } + + void AddPixelXY(int x, int y); +private: int x; int y; + COORDINATE coord; }; \ No newline at end of file