mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Merge pull request #15400 from Gymnasiast/refactor/free-entity-from-nsf
Small cherry-picks from NSF
This commit is contained in:
@@ -60,9 +60,25 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
static std::string_view ObjectTypeToString(uint8_t type)
|
||||
{
|
||||
static const char* Types[] = { "ride", "small_scenery", "large_scenery", "wall", "banner",
|
||||
"footpath", "footpath_addition", "scenery_group", "park_entrance", "water",
|
||||
"stex", "terrain_surface", "terrain_edge", "station", "music" };
|
||||
static constexpr std::string_view Types[] = {
|
||||
"ride",
|
||||
"small_scenery",
|
||||
"large_scenery",
|
||||
"wall",
|
||||
"banner",
|
||||
"footpath",
|
||||
"footpath_addition",
|
||||
"scenery_group",
|
||||
"park_entrance",
|
||||
"water",
|
||||
"stex",
|
||||
"terrain_surface",
|
||||
"terrain_edge",
|
||||
"station",
|
||||
"music",
|
||||
"footpath_surface",
|
||||
"footpath_railings",
|
||||
};
|
||||
if (type >= std::size(Types))
|
||||
return "unknown";
|
||||
return Types[type];
|
||||
|
||||
@@ -252,13 +252,13 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ScRide::stationStyle_get() const
|
||||
ObjectEntryIndex ScRide::stationStyle_get() const
|
||||
{
|
||||
auto ride = GetRide();
|
||||
return ride != nullptr ? ride->entrance_style : 0;
|
||||
}
|
||||
|
||||
void ScRide::stationStyle_set(uint8_t value)
|
||||
void ScRide::stationStyle_set(ObjectEntryIndex value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto ride = GetRide();
|
||||
@@ -268,13 +268,13 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ScRide::music_get() const
|
||||
ObjectEntryIndex ScRide::music_get() const
|
||||
{
|
||||
auto ride = GetRide();
|
||||
return ride != nullptr ? ride->music : 0;
|
||||
}
|
||||
|
||||
void ScRide::music_set(uint8_t value)
|
||||
void ScRide::music_set(ObjectEntryIndex value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto ride = GetRide();
|
||||
|
||||
@@ -109,13 +109,13 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
void colourSchemes_set(const std::vector<DukValue>& value);
|
||||
|
||||
uint8_t stationStyle_get() const;
|
||||
ObjectEntryIndex stationStyle_get() const;
|
||||
|
||||
void stationStyle_set(uint8_t value);
|
||||
void stationStyle_set(ObjectEntryIndex value);
|
||||
|
||||
uint8_t music_get() const;
|
||||
ObjectEntryIndex music_get() const;
|
||||
|
||||
void music_set(uint8_t value);
|
||||
void music_set(ObjectEntryIndex value);
|
||||
|
||||
std::vector<std::shared_ptr<ScRideStation>> stations_get() const;
|
||||
|
||||
|
||||
@@ -566,7 +566,7 @@ constexpr int32_t MAX_ZLIB_REALLOC = 4 * 1024 * 1024;
|
||||
* @return Returns a pointer to memory holding decompressed data or NULL on failure.
|
||||
* @note It is caller's responsibility to free() the returned pointer once done with it.
|
||||
*/
|
||||
uint8_t* util_zlib_inflate(uint8_t* data, size_t data_in_size, size_t* data_out_size)
|
||||
uint8_t* util_zlib_inflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size)
|
||||
{
|
||||
int32_t ret = Z_OK;
|
||||
uLongf out_size = static_cast<uLong>(*data_out_size);
|
||||
|
||||
@@ -56,7 +56,7 @@ bool str_is_null_or_empty(const char* str);
|
||||
uint32_t util_rand();
|
||||
|
||||
std::optional<std::vector<uint8_t>> util_zlib_deflate(const uint8_t* data, size_t data_in_size);
|
||||
uint8_t* util_zlib_inflate(uint8_t* data, size_t data_in_size, size_t* data_out_size);
|
||||
uint8_t* util_zlib_inflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size);
|
||||
bool util_gzip_compress(FILE* source, FILE* dest);
|
||||
|
||||
int8_t add_clamp_int8_t(int8_t value, int8_t value_to_add);
|
||||
|
||||
@@ -44,7 +44,7 @@ constexpr const uint32_t SPATIAL_INDEX_LOCATION_NULL = SPATIAL_INDEX_SIZE - 1;
|
||||
|
||||
static std::array<std::vector<uint16_t>, SPATIAL_INDEX_SIZE> gSpriteSpatialIndex;
|
||||
|
||||
static void FreeEntity(EntityBase* entity);
|
||||
static void FreeEntity(EntityBase& entity);
|
||||
|
||||
constexpr size_t GetSpatialIndexOffset(int32_t x, int32_t y)
|
||||
{
|
||||
@@ -238,7 +238,7 @@ void reset_sprite_list()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
FreeEntity(spr);
|
||||
FreeEntity(*spr);
|
||||
spr->Type = EntityType::Null;
|
||||
spr->sprite_index = i;
|
||||
|
||||
@@ -545,10 +545,10 @@ void sprite_set_coordinates(const CoordsXYZ& spritePos, EntityBase* sprite)
|
||||
/**
|
||||
* Frees any dynamically attached memory to the entity, such as peep name.
|
||||
*/
|
||||
static void FreeEntity(EntityBase* entity)
|
||||
static void FreeEntity(EntityBase& entity)
|
||||
{
|
||||
auto* guest = entity->As<Guest>();
|
||||
auto* staff = entity->As<Staff>();
|
||||
auto* guest = entity.As<Guest>();
|
||||
auto* staff = entity.As<Staff>();
|
||||
if (staff != nullptr)
|
||||
{
|
||||
staff->SetName({});
|
||||
@@ -567,7 +567,7 @@ static void FreeEntity(EntityBase* entity)
|
||||
*/
|
||||
void sprite_remove(EntityBase* sprite)
|
||||
{
|
||||
FreeEntity(sprite);
|
||||
FreeEntity(*sprite);
|
||||
|
||||
EntityTweener::Get().RemoveEntity(sprite);
|
||||
RemoveFromEntityList(sprite); // remove from existing list
|
||||
|
||||
Reference in New Issue
Block a user