Move CreateEntity funcs to Entity header. Remove dead enum

This commit is contained in:
duncanspumpkin 2021-05-29 08:18:23 +01:00
parent 63bcb3c3e5
commit ee981e62e1
4 changed files with 20 additions and 25 deletions

View File

@ -27,3 +27,17 @@ template<typename T = SpriteBase> T* TryGetEntity(size_t sprite_idx)
auto spr = try_get_sprite(sprite_idx);
return spr != nullptr ? spr->As<T>() : nullptr;
}
SpriteBase* CreateEntity(EntityType type);
template<typename T> T* CreateEntity()
{
return static_cast<T*>(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<typename T> T* CreateEntityAt(const uint16_t index)
{
return static_cast<T*>(CreateEntityAt(index, T::cEntityType));
}

View File

@ -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"

View File

@ -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<rct_sprite*>(sprite);
return entity;
}
SpriteBase* CreateEntityAt(const uint16_t index, const EntityType type)

View File

@ -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<typename T> T* CreateEntity()
{
return reinterpret_cast<T*>(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<typename T> T* CreateEntityAt(const uint16_t index)
{
return static_cast<T*>(CreateEntityAt(index, T::cEntityType));
}
void reset_sprite_list();
void reset_sprite_spatial_index();
void sprite_clear_all_unused();