From ef1906d452f798b6d2b71fc2e8e9b544a5567038 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Fri, 20 Mar 2020 20:16:38 +0100 Subject: [PATCH] Use constants for max sprites and spatial index (#10983) --- src/openrct2/network/Network.cpp | 4 ++-- src/openrct2/scenario/Scenario.h | 4 ++-- src/openrct2/world/Sprite.cpp | 8 +++----- src/openrct2/world/Sprite.h | 8 +++++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 6050a5a7fa..d2ac4d1f75 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -2726,7 +2726,7 @@ bool Network::LoadMap(IStream* stream) [[maybe_unused]] uint32_t checksum = stream->ReadValue(); // Read other data not in normal save files - stream->Read(gSpriteSpatialIndex, 0x10001 * sizeof(uint16_t)); + stream->Read(gSpriteSpatialIndex, SPATIAL_INDEX_SIZE * sizeof(uint16_t)); gGamePaused = stream->ReadValue(); _guestGenerationProbability = stream->ReadValue(); _suggestedGuestMaximum = stream->ReadValue(); @@ -2775,7 +2775,7 @@ bool Network::SaveMap(IStream* stream, const std::vectorSaveGame(stream); // Write other data not in normal save files - stream->Write(gSpriteSpatialIndex, 0x10001 * sizeof(uint16_t)); + stream->Write(gSpriteSpatialIndex, SPATIAL_INDEX_SIZE * sizeof(uint16_t)); stream->WriteValue(gGamePaused); stream->WriteValue(_guestGenerationProbability); stream->WriteValue(_suggestedGuestMaximum); diff --git a/src/openrct2/scenario/Scenario.h b/src/openrct2/scenario/Scenario.h index 135c2ab276..19e32dfeab 100644 --- a/src/openrct2/scenario/Scenario.h +++ b/src/openrct2/scenario/Scenario.h @@ -112,8 +112,8 @@ struct rct_s6_data // SC6[6] uint32_t next_free_tile_element_pointer_index; RCT2Sprite sprites[RCT2_MAX_SPRITES]; - uint16_t sprite_lists_head[6]; - uint16_t sprite_lists_count[6]; + uint16_t sprite_lists_head[SPRITE_LIST_COUNT]; + uint16_t sprite_lists_count[SPRITE_LIST_COUNT]; rct_string_id park_name; uint8_t pad_013573D6[2]; uint32_t park_name_args; diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index bef7ef98b7..a74cb004f6 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -31,9 +31,7 @@ static rct_sprite _spriteList[MAX_SPRITES]; static bool _spriteFlashingList[MAX_SPRITES]; -#define SPATIAL_INDEX_LOCATION_NULL 0x10000 - -uint16_t gSpriteSpatialIndex[0x10001]; +uint16_t gSpriteSpatialIndex[SPATIAL_INDEX_SIZE]; const rct_string_id litterNames[12] = { STR_LITTER_VOMIT, STR_LITTER_VOMIT, @@ -202,7 +200,7 @@ void reset_sprite_spatial_index() if (spr->generic.sprite_identifier != SPRITE_IDENTIFIER_NULL) { size_t index = GetSpatialIndexOffset(spr->generic.x, spr->generic.y); - uint16_t nextSpriteId = gSpriteSpatialIndex[index]; + uint32_t nextSpriteId = gSpriteSpatialIndex[index]; gSpriteSpatialIndex[index] = spr->generic.sprite_index; spr->generic.next_in_quadrant = nextSpriteId; } @@ -1121,7 +1119,7 @@ int32_t fix_disjoint_sprites() int32_t check_for_spatial_index_cycles(bool fix) { - for (int32_t i = 0; i < SPATIAL_INDEX_LOCATION_NULL; i++) + for (uint32_t i = 0; i < SPATIAL_INDEX_LOCATION_NULL; i++) { rct_sprite* cycle_start = find_sprite_quadrant_cycle(gSpriteSpatialIndex[i]); if (cycle_start != nullptr) diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index d106d1a82f..09a7770000 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -195,9 +195,11 @@ enum rct_sprite* try_get_sprite(size_t spriteIndex); rct_sprite* get_sprite(size_t sprite_idx); -extern uint16_t gSpriteListHead[6]; -extern uint16_t gSpriteListCount[6]; -extern uint16_t gSpriteSpatialIndex[0x10001]; +extern uint16_t gSpriteListHead[SPRITE_LIST_COUNT]; +extern uint16_t gSpriteListCount[SPRITE_LIST_COUNT]; +constexpr const uint32_t SPATIAL_INDEX_SIZE = (MAXIMUM_MAP_SIZE_TECHNICAL * MAXIMUM_MAP_SIZE_TECHNICAL) + 1; +constexpr const uint32_t SPATIAL_INDEX_LOCATION_NULL = SPATIAL_INDEX_SIZE - 1; +extern uint16_t gSpriteSpatialIndex[SPATIAL_INDEX_SIZE]; extern const rct_string_id litterNames[12];