Add getter and setter for location in SpriteBase

This commit is contained in:
Matt 2021-02-10 19:23:45 +02:00
parent a2ebec8676
commit ed4d8b4552
No known key found for this signature in database
GPG Key ID: 6D4C24A61C93E208
2 changed files with 29 additions and 11 deletions

View File

@ -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<int16_t>(newLocation.x);
y = static_cast<int16_t>(newLocation.y);
z = static_cast<int16_t>(newLocation.z);
}
void sprite_set_coordinates(const CoordsXYZ& spritePos, SpriteBase* sprite)
{
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), spritePos);

View File

@ -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<typename T> bool Is() const;
template<typename T> T* As()