Refactor invalidation logic to be generic to the callee

This commit is contained in:
Matt 2020-12-31 18:43:48 +02:00
parent 5ae54eb9f9
commit efa1db826e
No known key found for this signature in database
GPG Key ID: 6D4C24A61C93E208
17 changed files with 79 additions and 78 deletions

View File

@ -1601,7 +1601,7 @@ static int32_t cc_mp_desync(InteractiveConsole& console, const arguments_t& argv
if (peeps.size() > 1)
peep = peeps[util_rand() % peeps.size() - 1];
peep->TshirtColour = util_rand() & 0xFF;
peep->Invalidate0();
peep->Invalidate();
}
break;
}

View File

@ -331,11 +331,6 @@ Staff* Peep::AsStaff()
return AssignedPeepType == PeepType::Staff ? static_cast<Staff*>(this) : nullptr;
}
void Peep::Invalidate()
{
Invalidate2();
}
void Peep::MoveTo(const CoordsXYZ& newLocation)
{
Invalidate(); // Invalidate current position.

View File

@ -735,7 +735,6 @@ public: // Peep
std::optional<CoordsXY> UpdateAction();
void SetState(PeepState new_state);
void Remove();
void Invalidate();
void UpdateCurrentActionSpriteType();
void SwitchToSpecialSprite(uint8_t special_sprite_id);
void StateReset();

View File

@ -1421,7 +1421,7 @@ private:
dst->sprite_height_positive = spriteBounds->sprite_height_positive;
dst->MoveTo({ src->x, src->y, src->z });
dst->Invalidate2();
dst->Invalidate();
dst->sprite_direction = src->sprite_direction;
@ -1663,7 +1663,7 @@ private:
litter->sprite_height_negative = srcLitter->sprite_height_negative;
litter->MoveTo({ srcLitter->x, srcLitter->y, srcLitter->z });
litter->Invalidate2();
litter->Invalidate();
}
}
}
@ -1722,7 +1722,7 @@ private:
}
dst->MoveTo({ src->x, src->y, src->z });
dst->Invalidate2();
dst->Invalidate();
}
}
}

View File

@ -832,11 +832,6 @@ Vehicle* try_get_vehicle(uint16_t spriteIndex)
return TryGetEntity<Vehicle>(spriteIndex);
}
void Vehicle::Invalidate()
{
Invalidate2();
}
namespace
{
template<typename T> class TrainIterator;

View File

@ -318,7 +318,6 @@ struct Vehicle : SpriteBase
Vehicle* GetHead();
const Vehicle* GetHead() const;
Vehicle* GetCar(size_t carIndex) const;
void Invalidate();
void SetState(Vehicle::Status vehicleStatus, uint8_t subState = 0);
bool IsGhost() const;
void UpdateSoundParams(std::vector<OpenRCT2::Audio::VehicleSoundParams>& vehicleSoundParamsList) const;

View File

@ -104,9 +104,9 @@ namespace OpenRCT2::Scripting
auto entity = GetEntity();
if (entity != nullptr)
{
entity->Invalidate2();
entity->Invalidate();
entity->MoveTo({ value, entity->y, entity->z });
entity->Invalidate2();
entity->Invalidate();
}
}
@ -122,9 +122,9 @@ namespace OpenRCT2::Scripting
auto entity = GetEntity();
if (entity != nullptr)
{
entity->Invalidate2();
entity->Invalidate();
entity->MoveTo({ entity->x, value, entity->z });
entity->Invalidate2();
entity->Invalidate();
}
}
@ -140,9 +140,9 @@ namespace OpenRCT2::Scripting
auto entity = GetEntity();
if (entity != nullptr)
{
entity->Invalidate2();
entity->Invalidate();
entity->MoveTo({ entity->x, entity->y, value });
entity->Invalidate2();
entity->Invalidate();
}
}
@ -152,7 +152,7 @@ namespace OpenRCT2::Scripting
auto entity = GetEntity();
if (entity != nullptr)
{
entity->Invalidate2();
entity->Invalidate();
switch (entity->sprite_identifier)
{
case SpriteIdentifier::Vehicle:

View File

@ -21,7 +21,7 @@ template<> bool SpriteBase::Is<Balloon>() const
void Balloon::Update()
{
Invalidate2();
Invalidate();
if (popped == 1)
{
frame++;

View File

@ -71,11 +71,6 @@ template<> bool SpriteBase::Is<Duck>() const
return sprite_identifier == SpriteIdentifier::Misc && static_cast<MiscEntityType>(type) == MiscEntityType::Duck;
}
void Duck::Invalidate()
{
Invalidate1();
}
bool Duck::IsFlying()
{
return this->state == DuckState::FlyAway || this->state == DuckState::FlyToWater;

View File

@ -403,7 +403,7 @@ void footpath_remove_litter(const CoordsXYZ& footpathPos)
int32_t distanceZ = abs(litter->z - footpathPos.z);
if (distanceZ <= 32)
{
litter->Invalidate0();
litter->Invalidate();
sprite_remove(litter);
}
}

View File

@ -159,7 +159,7 @@ void JumpingFountain::Update()
return;
}
Invalidate0();
Invalidate();
frame++;
switch (static_cast<MiscEntityType>(type))

View File

@ -205,7 +205,7 @@ static bool map_animation_invalidate_small_scenery(const CoordsXYZ& loc)
peep->ActionFrame = 0;
peep->ActionSpriteImageOffset = 0;
peep->UpdateCurrentActionSpriteType();
peep->Invalidate1();
peep->Invalidate();
break;
}
}

View File

@ -99,7 +99,7 @@ void MoneyEffect::Create(money32 value, const CoordsXYZ& loc)
*/
void MoneyEffect::Update()
{
Invalidate2();
Invalidate();
Wiggle++;
if (Wiggle >= 22)
{

View File

@ -60,7 +60,7 @@ void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ
*/
void VehicleCrashParticle::Update()
{
Invalidate0();
Invalidate();
time_to_live--;
if (time_to_live == 0)
{
@ -107,7 +107,7 @@ void VehicleCrashParticle::Update()
newLoc.z = landZ;
}
MoveTo(newLoc);
Invalidate0();
Invalidate();
frame += 85;
if (frame >= 3072)
@ -141,7 +141,7 @@ void crash_splash_create(const CoordsXYZ& splashPos)
*/
void CrashSplashParticle::Update()
{
Invalidate2();
Invalidate();
frame += 85;
if (frame >= 7168)
{

View File

@ -1,4 +1,4 @@
/*****************************************************************************
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
@ -133,31 +133,47 @@ static void invalidate_sprite_max_zoom(SpriteBase* sprite, int32_t maxZoom)
}
}
/**
* Invalidate the sprite if at closest zoom.
* rct2: 0x006EC60B
*/
void SpriteBase::Invalidate0()
void SpriteBase::Invalidate()
{
invalidate_sprite_max_zoom(this, 0);
}
/**
* Invalidate sprite if at closest zoom or next zoom up from closest.
* rct2: 0x006EC53F
*/
void SpriteBase::Invalidate1()
{
invalidate_sprite_max_zoom(this, 1);
}
/**
* Invalidate sprite if not at furthest zoom.
* rct2: 0x006EC473
*/
void SpriteBase::Invalidate2()
{
invalidate_sprite_max_zoom(this, 2);
int32_t maxZoom = 0;
switch (sprite_identifier)
{
case SpriteIdentifier::Vehicle:
maxZoom = 2;
break;
case SpriteIdentifier::Peep:
maxZoom = 0;
break;
case SpriteIdentifier::Misc:
switch (static_cast<MiscEntityType>(type))
{
case MiscEntityType::CrashedVehicleParticle:
case MiscEntityType::JumpingFountainWater:
case MiscEntityType::JumpingFountainSnow:
maxZoom = 0;
break;
case MiscEntityType::Duck:
maxZoom = 1;
break;
case MiscEntityType::SteamParticle:
case MiscEntityType::MoneyEffect:
case MiscEntityType::ExplosionCloud:
case MiscEntityType::CrashSplash:
case MiscEntityType::ExplosionFlare:
case MiscEntityType::Balloon:
maxZoom = 2;
break;
default:
break;
}
break;
case SpriteIdentifier::Litter:
maxZoom = 0;
break;
default:
break;
}
invalidate_sprite_max_zoom(this, maxZoom);
}
/**
@ -301,8 +317,8 @@ rct_sprite_checksum sprite_checksum()
copy.peep.Name = {};
// We set this to 0 because as soon the client selects a guest the window will remove the
// invalidation flags causing the sprite checksum to be different than on server, the flag does not affect
// game state.
// invalidation flags causing the sprite checksum to be different than on server, the flag does not
// affect game state.
copy.peep.WindowInvalidateFlags = 0;
}
@ -498,8 +514,8 @@ static void move_sprite_to_list(SpriteBase* sprite, EntityListId newListIndex)
sprite->next = gSpriteListHead[static_cast<uint8_t>(
newListIndex)]; // This sprite's next sprite is the old head, since we're the new head
gSpriteListHead[static_cast<uint8_t>(newListIndex)] = sprite->sprite_index; // Store this sprite's index as head of its new
// list
gSpriteListHead[static_cast<uint8_t>(newListIndex)] = sprite->sprite_index; // Store this sprite's index as head of its
// new list
if (sprite->next != SPRITE_INDEX_NULL)
{
@ -527,9 +543,8 @@ static void move_sprite_to_list(SpriteBase* sprite, EntityListId newListIndex)
*/
void SteamParticle::Update()
{
Invalidate2();
// Move up 1 z every 3 ticks (Starts after 4 ticks)
Invalidate();
time_to_move++;
if (time_to_move >= 4)
{
@ -568,7 +583,7 @@ void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos)
*/
void ExplosionCloud::Update()
{
Invalidate2();
Invalidate();
frame += 128;
if (frame >= (36 * 128))
{
@ -601,7 +616,7 @@ void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos)
*/
void ExplosionFlare::Update()
{
Invalidate2();
Invalidate();
frame += 64;
if (frame >= (124 * 64))
{
@ -725,6 +740,12 @@ static void SpriteSpatialMove(SpriteBase* sprite, const CoordsXY& newLoc)
*/
void SpriteBase::MoveTo(const CoordsXYZ& newLocation)
{
if (x != LOCATION_NULL)
{
// Invalidate old position.
Invalidate();
}
auto loc = newLocation;
if (!map_is_location_valid(loc))
{
@ -743,6 +764,7 @@ void SpriteBase::MoveTo(const CoordsXYZ& newLocation)
else
{
sprite_set_coordinates(loc, this);
Invalidate(); // Invalidate new position.
}
}
@ -833,7 +855,7 @@ void litter_create(const CoordsXYZD& litterPos, int32_t type)
if (newestLitter != nullptr)
{
newestLitter->Invalidate0();
newestLitter->Invalidate();
sprite_remove(newestLitter);
}
}
@ -849,7 +871,6 @@ void litter_create(const CoordsXYZD& litterPos, int32_t type)
litter->sprite_identifier = SpriteIdentifier::Litter;
litter->type = type;
litter->MoveTo(offsetLitterPos);
litter->Invalidate0();
litter->creationTick = gScenarioTicks;
}
@ -865,7 +886,7 @@ void litter_remove_at(const CoordsXYZ& litterPos)
{
if (abs(litter->x - litterPos.x) <= 8 && abs(litter->y - litterPos.y) <= 8)
{
litter->Invalidate0();
litter->Invalidate();
sprite_remove(litter);
}
}
@ -966,7 +987,7 @@ void sprite_position_tween_all(float alpha)
static_cast<int32_t>(std::round(posB.y * alpha + posA.y * inv)),
static_cast<int32_t>(std::round(posB.z * alpha + posA.z * inv)) },
sprite);
sprite->Invalidate2();
sprite->Invalidate();
}
}
}
@ -981,7 +1002,7 @@ void sprite_position_tween_restore()
auto* sprite = GetEntity(i);
if (sprite != nullptr && sprite_should_tween(sprite))
{
sprite->Invalidate2();
sprite->Invalidate();
auto pos = _spritelocations2[i];
sprite_set_coordinates(pos, sprite);

View File

@ -71,7 +71,6 @@ struct Duck : SpriteGeneric
void Update();
uint32_t GetFrameImage(int32_t direction) const;
void Invalidate();
bool IsFlying();
void Remove();

View File

@ -35,9 +35,7 @@ struct SpriteBase
uint8_t sprite_direction;
void MoveTo(const CoordsXYZ& newLocation);
void Invalidate0();
void Invalidate1();
void Invalidate2();
void Invalidate();
template<typename T> bool Is() const;
template<typename T> T* As()
{