mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-27 08:45:00 +01:00
Replace sprite_left,t,r,b with SpriteRect (#15408)
* Replace sprite_left,t,r,b with SpriteRect This is required for the NSF. I had to add a silly constructor to rct_sprite for now. Will eventually be removed one day... * Fix compilation and memory leak * Add some UB to prevent some other UB * Make review change
This commit is contained in:
@@ -163,7 +163,7 @@ const std::vector<uint16_t>& GetEntityTileList(const CoordsXY& spritePos)
|
||||
|
||||
void EntityBase::Invalidate()
|
||||
{
|
||||
if (sprite_left == LOCATION_NULL)
|
||||
if (x == LOCATION_NULL)
|
||||
return;
|
||||
|
||||
int32_t maxZoom = 0;
|
||||
@@ -196,7 +196,7 @@ void EntityBase::Invalidate()
|
||||
break;
|
||||
}
|
||||
|
||||
viewports_invalidate(sprite_left, sprite_top, sprite_right, sprite_bottom, maxZoom);
|
||||
viewports_invalidate(SpriteRect.GetLeft(), SpriteRect.GetTop(), SpriteRect.GetRight(), SpriteRect.GetBottom(), maxZoom);
|
||||
}
|
||||
|
||||
static void ResetEntityLists()
|
||||
@@ -228,7 +228,19 @@ const std::list<uint16_t>& GetEntityList(const EntityType id)
|
||||
void reset_sprite_list()
|
||||
{
|
||||
gSavedAge = 0;
|
||||
std::memset(static_cast<void*>(_spriteList), 0, sizeof(_spriteList));
|
||||
|
||||
// Free all associated Entity pointers prior to zeroing memory
|
||||
for (int32_t i = 0; i < MAX_ENTITIES; ++i)
|
||||
{
|
||||
auto* spr = GetEntity(i);
|
||||
if (spr == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
FreeEntity(*spr);
|
||||
}
|
||||
|
||||
std::fill(std::begin(_spriteList), std::end(_spriteList), rct_sprite());
|
||||
OpenRCT2::RideUse::GetHistory().Clear();
|
||||
OpenRCT2::RideUse::GetTypeHistory().Clear();
|
||||
for (int32_t i = 0; i < MAX_ENTITIES; ++i)
|
||||
@@ -238,7 +250,6 @@ void reset_sprite_list()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
FreeEntity(*spr);
|
||||
spr->Type = EntityType::Null;
|
||||
spr->sprite_index = i;
|
||||
|
||||
@@ -313,7 +324,8 @@ static void sprite_reset(EntityBase* sprite)
|
||||
uint16_t sprite_index = sprite->sprite_index;
|
||||
_spriteFlashingList[sprite_index] = false;
|
||||
|
||||
std::memset(sprite, 0, sizeof(rct_sprite));
|
||||
rct_sprite* spr = reinterpret_cast<rct_sprite*>(sprite);
|
||||
*spr = rct_sprite();
|
||||
|
||||
sprite->sprite_index = sprite_index;
|
||||
sprite->Type = EntityType::Null;
|
||||
@@ -370,7 +382,7 @@ static void PrepareNewEntity(EntityBase* base, const EntityType type)
|
||||
base->sprite_width = 0x10;
|
||||
base->sprite_height_negative = 0x14;
|
||||
base->sprite_height_positive = 0x8;
|
||||
base->sprite_left = LOCATION_NULL;
|
||||
base->SpriteRect = {};
|
||||
|
||||
SpriteSpatialInsert(base, { LOCATION_NULL, 0 });
|
||||
}
|
||||
@@ -505,7 +517,6 @@ void EntityBase::MoveTo(const CoordsXYZ& newLocation)
|
||||
|
||||
if (loc.x == LOCATION_NULL)
|
||||
{
|
||||
sprite_left = LOCATION_NULL;
|
||||
x = loc.x;
|
||||
y = loc.y;
|
||||
z = loc.z;
|
||||
@@ -533,10 +544,9 @@ void sprite_set_coordinates(const CoordsXYZ& spritePos, EntityBase* sprite)
|
||||
{
|
||||
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), spritePos);
|
||||
|
||||
sprite->sprite_left = screenCoords.x - sprite->sprite_width;
|
||||
sprite->sprite_right = screenCoords.x + sprite->sprite_width;
|
||||
sprite->sprite_top = screenCoords.y - sprite->sprite_height_negative;
|
||||
sprite->sprite_bottom = screenCoords.y + sprite->sprite_height_positive;
|
||||
sprite->SpriteRect = ScreenRect(
|
||||
screenCoords - ScreenCoordsXY{ sprite->sprite_width, sprite->sprite_height_negative },
|
||||
screenCoords + ScreenCoordsXY{ sprite->sprite_width, sprite->sprite_height_positive });
|
||||
sprite->x = spritePos.x;
|
||||
sprite->y = spritePos.y;
|
||||
sprite->z = spritePos.z;
|
||||
|
||||
Reference in New Issue
Block a user