From ee981e62e1af78ad74cd2616074bc5d88ba3eafe Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 29 May 2021 08:18:23 +0100 Subject: [PATCH] Move CreateEntity funcs to Entity header. Remove dead enum --- src/openrct2/world/Entity.h | 14 ++++++++++++++ src/openrct2/world/MoneyEffect.cpp | 1 + src/openrct2/world/Sprite.cpp | 10 +++++----- src/openrct2/world/Sprite.h | 20 -------------------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/openrct2/world/Entity.h b/src/openrct2/world/Entity.h index 2259d47bcd..e2e6fd7cd4 100644 --- a/src/openrct2/world/Entity.h +++ b/src/openrct2/world/Entity.h @@ -27,3 +27,17 @@ template T* TryGetEntity(size_t sprite_idx) auto spr = try_get_sprite(sprite_idx); return spr != nullptr ? spr->As() : nullptr; } + +SpriteBase* CreateEntity(EntityType type); +template T* CreateEntity() +{ + return static_cast(CreateEntity(T::cEntityType)); +} + +// Use only with imports that must happen at a specified index +SpriteBase* CreateEntityAt(const uint16_t index, const EntityType type); +// Use only with imports that must happen at a specified index +template T* CreateEntityAt(const uint16_t index) +{ + return static_cast(CreateEntityAt(index, T::cEntityType)); +} diff --git a/src/openrct2/world/MoneyEffect.cpp b/src/openrct2/world/MoneyEffect.cpp index 6d85aa32e2..4ff854a571 100644 --- a/src/openrct2/world/MoneyEffect.cpp +++ b/src/openrct2/world/MoneyEffect.cpp @@ -14,6 +14,7 @@ #include "../interface/Window.h" #include "../localisation/Localisation.h" #include "../network/network.h" +#include "Entity.h" #include "Map.h" #include "Sprite.h" diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 94e02ff18c..54fb0d5db8 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -394,7 +394,7 @@ static void PrepareNewEntity(SpriteBase* base, const EntityType type) SpriteSpatialInsert(base, { LOCATION_NULL, 0 }); } -rct_sprite* create_sprite(EntityType type) +SpriteBase* CreateEntity(EntityType type) { if (_freeIdList.size() == 0) { @@ -414,16 +414,16 @@ rct_sprite* create_sprite(EntityType type) } } - auto* sprite = GetEntity(_freeIdList.back()); - if (sprite == nullptr) + auto* entity = GetEntity(_freeIdList.back()); + if (entity == nullptr) { return nullptr; } _freeIdList.pop_back(); - PrepareNewEntity(sprite, type); + PrepareNewEntity(entity, type); - return reinterpret_cast(sprite); + return entity; } SpriteBase* CreateEntityAt(const uint16_t index, const EntityType type) diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index d2879ba0ac..a8c6c5c969 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -36,26 +36,6 @@ struct rct_sprite_checksum #pragma pack(pop) -enum -{ - SPRITE_FLAGS_IS_CRASHED_VEHICLE_SPRITE = 1 << 7, - SPRITE_FLAGS_PEEP_VISIBLE = 1 << 8, // Peep is eligible to show in summarized guest list window (is inside park?) - SPRITE_FLAGS_PEEP_FLASHING = 1 << 9, // Deprecated: Use sprite_set_flashing/sprite_get_flashing instead. -}; - -rct_sprite* create_sprite(EntityType type); -template T* CreateEntity() -{ - return reinterpret_cast(create_sprite(T::cEntityType)); -} - -// Use only with imports that must happen at a specified index -SpriteBase* CreateEntityAt(const uint16_t index, const EntityType type); -// Use only with imports that must happen at a specified index -template T* CreateEntityAt(const uint16_t index) -{ - return static_cast(CreateEntityAt(index, T::cEntityType)); -} void reset_sprite_list(); void reset_sprite_spatial_index(); void sprite_clear_all_unused();