mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Split off EntityTweener into seperate file
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
#include "ui/UiContext.h"
|
#include "ui/UiContext.h"
|
||||||
#include "ui/WindowManager.h"
|
#include "ui/WindowManager.h"
|
||||||
#include "util/Util.h"
|
#include "util/Util.h"
|
||||||
|
#include "world/EntityTweener.h"
|
||||||
#include "world/Park.h"
|
#include "world/Park.h"
|
||||||
#include "world/Sprite.h"
|
#include "world/Sprite.h"
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "object/ObjectManager.h"
|
#include "object/ObjectManager.h"
|
||||||
#include "object/ObjectRepository.h"
|
#include "object/ObjectRepository.h"
|
||||||
#include "rct2/S6Exporter.h"
|
#include "rct2/S6Exporter.h"
|
||||||
|
#include "world/EntityTweener.h"
|
||||||
#include "world/Park.h"
|
#include "world/Park.h"
|
||||||
#include "world/Sprite.h"
|
#include "world/Sprite.h"
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
|
|||||||
@@ -443,6 +443,7 @@
|
|||||||
<ClInclude Include="world\Duck.h" />
|
<ClInclude Include="world\Duck.h" />
|
||||||
<ClInclude Include="world\Entity.h" />
|
<ClInclude Include="world\Entity.h" />
|
||||||
<ClInclude Include="world\EntityList.h" />
|
<ClInclude Include="world\EntityList.h" />
|
||||||
|
<ClInclude Include="world\EntityTweener.h" />
|
||||||
<ClInclude Include="world\Entrance.h" />
|
<ClInclude Include="world\Entrance.h" />
|
||||||
<ClInclude Include="world\Footpath.h" />
|
<ClInclude Include="world\Footpath.h" />
|
||||||
<ClInclude Include="world\Fountain.h" />
|
<ClInclude Include="world\Fountain.h" />
|
||||||
@@ -865,6 +866,7 @@
|
|||||||
<ClCompile Include="world\Climate.cpp" />
|
<ClCompile Include="world\Climate.cpp" />
|
||||||
<ClCompile Include="world\Duck.cpp" />
|
<ClCompile Include="world\Duck.cpp" />
|
||||||
<ClCompile Include="world\Entity.cpp" />
|
<ClCompile Include="world\Entity.cpp" />
|
||||||
|
<ClCompile Include="world\EntityTweener.cpp" />
|
||||||
<ClCompile Include="world\Entrance.cpp" />
|
<ClCompile Include="world\Entrance.cpp" />
|
||||||
<ClCompile Include="world\Footpath.cpp" />
|
<ClCompile Include="world\Footpath.cpp" />
|
||||||
<ClCompile Include="world\Fountain.cpp" />
|
<ClCompile Include="world\Fountain.cpp" />
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "../ui/WindowManager.h"
|
#include "../ui/WindowManager.h"
|
||||||
#include "../util/SawyerCoding.h"
|
#include "../util/SawyerCoding.h"
|
||||||
#include "../world/EntityList.h"
|
#include "../world/EntityList.h"
|
||||||
|
#include "../world/EntityTweener.h"
|
||||||
#include "../world/Location.hpp"
|
#include "../world/Location.hpp"
|
||||||
#include "../world/Sprite.h"
|
#include "../world/Sprite.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "../windows/Intent.h"
|
#include "../windows/Intent.h"
|
||||||
#include "../world/Balloon.h"
|
#include "../world/Balloon.h"
|
||||||
#include "../world/Climate.h"
|
#include "../world/Climate.h"
|
||||||
|
#include "../world/EntityTweener.h"
|
||||||
#include "../world/Entrance.h"
|
#include "../world/Entrance.h"
|
||||||
#include "../world/Footpath.h"
|
#include "../world/Footpath.h"
|
||||||
#include "../world/LargeScenery.h"
|
#include "../world/LargeScenery.h"
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
#include "../world/Climate.h"
|
#include "../world/Climate.h"
|
||||||
#include "../world/Duck.h"
|
#include "../world/Duck.h"
|
||||||
#include "../world/EntityList.h"
|
#include "../world/EntityList.h"
|
||||||
|
#include "../world/EntityTweener.h"
|
||||||
#include "../world/Entrance.h"
|
#include "../world/Entrance.h"
|
||||||
#include "../world/Fountain.h"
|
#include "../world/Fountain.h"
|
||||||
#include "../world/Litter.h"
|
#include "../world/Litter.h"
|
||||||
|
|||||||
120
src/openrct2/world/EntityTweener.cpp
Normal file
120
src/openrct2/world/EntityTweener.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
|
*
|
||||||
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "EntityTweener.h"
|
||||||
|
|
||||||
|
#include "../peep/Peep.h"
|
||||||
|
#include "../ride/Vehicle.h"
|
||||||
|
#include "EntityList.h"
|
||||||
|
#include "Sprite.h"
|
||||||
|
|
||||||
|
void EntityTweener::PopulateEntities()
|
||||||
|
{
|
||||||
|
for (auto ent : EntityList<Guest>())
|
||||||
|
{
|
||||||
|
Entities.push_back(ent);
|
||||||
|
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
||||||
|
}
|
||||||
|
for (auto ent : EntityList<Staff>())
|
||||||
|
{
|
||||||
|
Entities.push_back(ent);
|
||||||
|
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
||||||
|
}
|
||||||
|
for (auto ent : EntityList<Vehicle>())
|
||||||
|
{
|
||||||
|
Entities.push_back(ent);
|
||||||
|
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTweener::PreTick()
|
||||||
|
{
|
||||||
|
Restore();
|
||||||
|
Reset();
|
||||||
|
PopulateEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTweener::PostTick()
|
||||||
|
{
|
||||||
|
for (auto* ent : Entities)
|
||||||
|
{
|
||||||
|
if (ent == nullptr)
|
||||||
|
{
|
||||||
|
// Sprite was removed, add a dummy position to keep the index aligned.
|
||||||
|
PostPos.emplace_back(0, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PostPos.emplace_back(ent->x, ent->y, ent->z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTweener::RemoveEntity(SpriteBase* entity)
|
||||||
|
{
|
||||||
|
if (!entity->Is<Peep>() && !entity->Is<Vehicle>())
|
||||||
|
{
|
||||||
|
// Only peeps and vehicles are tweened, bail if type is incorrect.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = std::find(Entities.begin(), Entities.end(), entity);
|
||||||
|
if (it != Entities.end())
|
||||||
|
*it = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTweener::Tween(float alpha)
|
||||||
|
{
|
||||||
|
const float inv = (1.0f - alpha);
|
||||||
|
for (size_t i = 0; i < Entities.size(); ++i)
|
||||||
|
{
|
||||||
|
auto* ent = Entities[i];
|
||||||
|
if (ent == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto& posA = PrePos[i];
|
||||||
|
auto& posB = PostPos[i];
|
||||||
|
|
||||||
|
if (posA == posB)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sprite_set_coordinates(
|
||||||
|
{ static_cast<int32_t>(std::round(posB.x * alpha + posA.x * inv)),
|
||||||
|
static_cast<int32_t>(std::round(posB.y * alpha + posA.y * inv)),
|
||||||
|
static_cast<int32_t>(std::round(posB.z * alpha + posA.z * inv)) },
|
||||||
|
ent);
|
||||||
|
ent->Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTweener::Restore()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < Entities.size(); ++i)
|
||||||
|
{
|
||||||
|
auto* ent = Entities[i];
|
||||||
|
if (ent == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sprite_set_coordinates(PostPos[i], ent);
|
||||||
|
ent->Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTweener::Reset()
|
||||||
|
{
|
||||||
|
Entities.clear();
|
||||||
|
PrePos.clear();
|
||||||
|
PostPos.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
static EntityTweener tweener;
|
||||||
|
|
||||||
|
EntityTweener& EntityTweener::Get()
|
||||||
|
{
|
||||||
|
return tweener;
|
||||||
|
}
|
||||||
31
src/openrct2/world/EntityTweener.h
Normal file
31
src/openrct2/world/EntityTweener.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Copyright (c) 2014-2021 OpenRCT2 developers
|
||||||
|
*
|
||||||
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "SpriteBase.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class EntityTweener
|
||||||
|
{
|
||||||
|
std::vector<SpriteBase*> Entities;
|
||||||
|
std::vector<CoordsXYZ> PrePos;
|
||||||
|
std::vector<CoordsXYZ> PostPos;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void PopulateEntities();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static EntityTweener& Get();
|
||||||
|
|
||||||
|
void PreTick();
|
||||||
|
void PostTick();
|
||||||
|
void RemoveEntity(SpriteBase* entity);
|
||||||
|
void Tween(float alpha);
|
||||||
|
void Restore();
|
||||||
|
void Reset();
|
||||||
|
};
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "../scenario/Scenario.h"
|
#include "../scenario/Scenario.h"
|
||||||
#include "Balloon.h"
|
#include "Balloon.h"
|
||||||
#include "Duck.h"
|
#include "Duck.h"
|
||||||
|
#include "EntityTweener.h"
|
||||||
#include "Fountain.h"
|
#include "Fountain.h"
|
||||||
#include "MoneyEffect.h"
|
#include "MoneyEffect.h"
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
@@ -808,112 +809,6 @@ uint16_t remove_floating_sprites()
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTweener::PopulateEntities()
|
|
||||||
{
|
|
||||||
for (auto ent : EntityList<Guest>())
|
|
||||||
{
|
|
||||||
Entities.push_back(ent);
|
|
||||||
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
|
||||||
}
|
|
||||||
for (auto ent : EntityList<Staff>())
|
|
||||||
{
|
|
||||||
Entities.push_back(ent);
|
|
||||||
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
|
||||||
}
|
|
||||||
for (auto ent : EntityList<Vehicle>())
|
|
||||||
{
|
|
||||||
Entities.push_back(ent);
|
|
||||||
PrePos.emplace_back(ent->x, ent->y, ent->z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityTweener::PreTick()
|
|
||||||
{
|
|
||||||
Restore();
|
|
||||||
Reset();
|
|
||||||
PopulateEntities();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityTweener::PostTick()
|
|
||||||
{
|
|
||||||
for (auto* ent : Entities)
|
|
||||||
{
|
|
||||||
if (ent == nullptr)
|
|
||||||
{
|
|
||||||
// Sprite was removed, add a dummy position to keep the index aligned.
|
|
||||||
PostPos.emplace_back(0, 0, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PostPos.emplace_back(ent->x, ent->y, ent->z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityTweener::RemoveEntity(SpriteBase* entity)
|
|
||||||
{
|
|
||||||
if (!entity->Is<Peep>() && !entity->Is<Vehicle>())
|
|
||||||
{
|
|
||||||
// Only peeps and vehicles are tweened, bail if type is incorrect.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto it = std::find(Entities.begin(), Entities.end(), entity);
|
|
||||||
if (it != Entities.end())
|
|
||||||
*it = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityTweener::Tween(float alpha)
|
|
||||||
{
|
|
||||||
const float inv = (1.0f - alpha);
|
|
||||||
for (size_t i = 0; i < Entities.size(); ++i)
|
|
||||||
{
|
|
||||||
auto* ent = Entities[i];
|
|
||||||
if (ent == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto& posA = PrePos[i];
|
|
||||||
auto& posB = PostPos[i];
|
|
||||||
|
|
||||||
if (posA == posB)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
sprite_set_coordinates(
|
|
||||||
{ static_cast<int32_t>(std::round(posB.x * alpha + posA.x * inv)),
|
|
||||||
static_cast<int32_t>(std::round(posB.y * alpha + posA.y * inv)),
|
|
||||||
static_cast<int32_t>(std::round(posB.z * alpha + posA.z * inv)) },
|
|
||||||
ent);
|
|
||||||
ent->Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityTweener::Restore()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < Entities.size(); ++i)
|
|
||||||
{
|
|
||||||
auto* ent = Entities[i];
|
|
||||||
if (ent == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
sprite_set_coordinates(PostPos[i], ent);
|
|
||||||
ent->Invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityTweener::Reset()
|
|
||||||
{
|
|
||||||
Entities.clear();
|
|
||||||
PrePos.clear();
|
|
||||||
PostPos.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
static EntityTweener tweener;
|
|
||||||
|
|
||||||
EntityTweener& EntityTweener::Get()
|
|
||||||
{
|
|
||||||
return tweener;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sprite_set_flashing(SpriteBase* sprite, bool flashing)
|
void sprite_set_flashing(SpriteBase* sprite, bool flashing)
|
||||||
{
|
{
|
||||||
assert(sprite->sprite_index < MAX_ENTITIES);
|
assert(sprite->sprite_index < MAX_ENTITIES);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include "SpriteBase.h"
|
#include "SpriteBase.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class DataSerialiser;
|
class DataSerialiser;
|
||||||
|
|
||||||
@@ -97,24 +96,4 @@ rct_sprite_checksum sprite_checksum();
|
|||||||
void sprite_set_flashing(SpriteBase* sprite, bool flashing);
|
void sprite_set_flashing(SpriteBase* sprite, bool flashing);
|
||||||
bool sprite_get_flashing(SpriteBase* sprite);
|
bool sprite_get_flashing(SpriteBase* sprite);
|
||||||
|
|
||||||
class EntityTweener
|
|
||||||
{
|
|
||||||
std::vector<SpriteBase*> Entities;
|
|
||||||
std::vector<CoordsXYZ> PrePos;
|
|
||||||
std::vector<CoordsXYZ> PostPos;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void PopulateEntities();
|
|
||||||
|
|
||||||
public:
|
|
||||||
static EntityTweener& Get();
|
|
||||||
|
|
||||||
void PreTick();
|
|
||||||
void PostTick();
|
|
||||||
void RemoveEntity(SpriteBase* entity);
|
|
||||||
void Tween(float alpha);
|
|
||||||
void Restore();
|
|
||||||
void Reset();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <openrct2/peep/Peep.h>
|
#include <openrct2/peep/Peep.h>
|
||||||
#include <openrct2/platform/platform.h>
|
#include <openrct2/platform/platform.h>
|
||||||
#include <openrct2/ride/Ride.h>
|
#include <openrct2/ride/Ride.h>
|
||||||
|
#include <openrct2/world/EntityTweener.h>
|
||||||
#include <openrct2/world/MapAnimation.h>
|
#include <openrct2/world/MapAnimation.h>
|
||||||
#include <openrct2/world/Park.h>
|
#include <openrct2/world/Park.h>
|
||||||
#include <openrct2/world/Scenery.h>
|
#include <openrct2/world/Scenery.h>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <openrct2/ride/Vehicle.h>
|
#include <openrct2/ride/Vehicle.h>
|
||||||
#include <openrct2/world/Balloon.h>
|
#include <openrct2/world/Balloon.h>
|
||||||
#include <openrct2/world/Duck.h>
|
#include <openrct2/world/Duck.h>
|
||||||
|
#include <openrct2/world/EntityTweener.h>
|
||||||
#include <openrct2/world/Fountain.h>
|
#include <openrct2/world/Fountain.h>
|
||||||
#include <openrct2/world/MoneyEffect.h>
|
#include <openrct2/world/MoneyEffect.h>
|
||||||
#include <openrct2/world/Park.h>
|
#include <openrct2/world/Park.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user