From ed4d8b45526925fbadb0c3a7ca6463864863c76a Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 10 Feb 2021 19:23:45 +0200 Subject: [PATCH] Add getter and setter for location in SpriteBase --- src/openrct2/world/Sprite.cpp | 23 ++++++++++++----------- src/openrct2/world/SpriteBase.h | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index fb8d900413..add25cadfa 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -644,17 +644,6 @@ static void SpriteSpatialMove(SpriteBase* sprite, const CoordsXY& newLoc) SpriteSpatialInsert(sprite, newLoc); } -/** - * Moves a sprite to a new location, invalidates the current position if valid - * and also the new position. - * - * rct2: 0x0069E9D3 - * - * @param x (ax) - * @param y (cx) - * @param z (dx) - * @param sprite (esi) - */ void SpriteBase::MoveTo(const CoordsXYZ& newLocation) { if (x != LOCATION_NULL) @@ -685,6 +674,18 @@ void SpriteBase::MoveTo(const CoordsXYZ& newLocation) } } +CoordsXYZ SpriteBase::GetLocation() const +{ + return { x, y, z }; +} + +void SpriteBase::SetLocation(const CoordsXYZ& newLocation) +{ + x = static_cast(newLocation.x); + y = static_cast(newLocation.y); + z = static_cast(newLocation.z); +} + void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite) { auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), spritePos); diff --git a/src/openrct2/world/SpriteBase.h b/src/openrct2/world/SpriteBase.h index 419de2effa..25d792b819 100644 --- a/src/openrct2/world/SpriteBase.h +++ b/src/openrct2/world/SpriteBase.h @@ -30,7 +30,24 @@ struct SpriteBase uint8_t sprite_direction; + /** + * Moves a sprite to a new location, invalidates the current position if valid + * and also the new position. + * + * rct2: 0x0069E9D3 + */ void MoveTo(const CoordsXYZ& newLocation); + + /** + * Sets the entity location without screen invalidation. + */ + void SetLocation(const CoordsXYZ& newLocation); + + /** + * Gets the entity current location. + */ + CoordsXYZ GetLocation() const; + void Invalidate(); template bool Is() const; template T* As()