From 8ee49ab615c88b1d38508ae2217cb1095c958ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 23 Feb 2021 00:28:57 +0100 Subject: [PATCH] Reduce inclusion of world/Sprite.h --- src/openrct2/Context.cpp | 1 + src/openrct2/GameState.cpp | 1 + src/openrct2/ReplayManager.cpp | 1 + src/openrct2/actions/GameAction.cpp | 1 + src/openrct2/interface/Window_internal.h | 2 +- src/openrct2/network/NetworkBase.cpp | 1 + src/openrct2/network/NetworkPlayer.h | 1 - src/openrct2/paint/sprite/Paint.Sprite.h | 4 +- src/openrct2/peep/Peep.h | 2 +- src/openrct2/rct2/S6Exporter.h | 2 + src/openrct2/scenario/Scenario.h | 2 +- src/openrct2/world/Sprite.h | 227 +---------------------- 12 files changed, 15 insertions(+), 230 deletions(-) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 3f1f685e76..130fc95eb9 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -64,6 +64,7 @@ #include "ui/WindowManager.h" #include "util/Util.h" #include "world/Park.h" +#include "world/Sprite.h" #include #include diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 26f981b620..5d891f9e86 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -36,6 +36,7 @@ #include "world/MapAnimation.h" #include "world/Park.h" #include "world/Scenery.h" +#include "world/Sprite.h" #include #include diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index a45efa8a14..81c6746bd8 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -30,6 +30,7 @@ #include "object/ObjectRepository.h" #include "rct2/S6Exporter.h" #include "world/Park.h" +#include "world/Sprite.h" #include "zlib.h" #include diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index de3a3869cf..ccad0e2543 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -25,6 +25,7 @@ #include "../ui/WindowManager.h" #include "../world/Park.h" #include "../world/Scenery.h" +#include "../world/Sprite.h" #include #include diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index ab577334d0..549cd3275b 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -9,7 +9,7 @@ #pragma once -#include "../world/Sprite.h" +#include "../rct12/RCT12.h" #include "Window.h" #include diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index b2dc9918af..7ff908d54e 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -25,6 +25,7 @@ #include "../ui/WindowManager.h" #include "../util/SawyerCoding.h" #include "../world/Location.hpp" +#include "../world/Sprite.h" #include "network.h" #include diff --git a/src/openrct2/network/NetworkPlayer.h b/src/openrct2/network/NetworkPlayer.h index 422fb5b1fd..c589900b56 100644 --- a/src/openrct2/network/NetworkPlayer.h +++ b/src/openrct2/network/NetworkPlayer.h @@ -13,7 +13,6 @@ #include "../common.h" #include "../peep/Peep.h" #include "../world/Map.h" -#include "../world/Sprite.h" #include #include diff --git a/src/openrct2/paint/sprite/Paint.Sprite.h b/src/openrct2/paint/sprite/Paint.Sprite.h index 9638184780..c69b31b8ef 100644 --- a/src/openrct2/paint/sprite/Paint.Sprite.h +++ b/src/openrct2/paint/sprite/Paint.Sprite.h @@ -11,9 +11,11 @@ #define _PAINT_SPRITE_H #include "../../common.h" -#include "../../world/Sprite.h" struct paint_session; +struct Litter; +struct MiscEntity; +struct Peep; void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t y); diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 230ff10318..0feb0e1250 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -593,7 +593,7 @@ struct Peep : SpriteBase uint8_t Toilet; uint8_t Mass; uint8_t TimeToConsume; - IntensityRange Intensity; + IntensityRange Intensity{ 0 }; PeepNauseaTolerance NauseaTolerance; uint8_t WindowInvalidateFlags; money16 PaidOnDrink; diff --git a/src/openrct2/rct2/S6Exporter.h b/src/openrct2/rct2/S6Exporter.h index fc1d2e0155..59ae39c231 100644 --- a/src/openrct2/rct2/S6Exporter.h +++ b/src/openrct2/rct2/S6Exporter.h @@ -23,8 +23,10 @@ namespace OpenRCT2 struct IStream; } +struct Litter; struct ObjectRepositoryItem; struct RCT12SpriteBase; +union rct_sprite; struct SpriteBase; /** diff --git a/src/openrct2/scenario/Scenario.h b/src/openrct2/scenario/Scenario.h index be881c5a52..5174ab3518 100644 --- a/src/openrct2/scenario/Scenario.h +++ b/src/openrct2/scenario/Scenario.h @@ -21,9 +21,9 @@ #include "../ride/RideRatings.h" #include "../world/Banner.h" #include "../world/Climate.h" +#include "../world/EntityList.h" #include "../world/Map.h" #include "../world/MapAnimation.h" -#include "../world/Sprite.h" using random_engine_t = Random::Rct2::Engine; diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 2e872f6cbc..43629fdc5d 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -13,14 +13,10 @@ #include "../common.h" #include "../peep/Peep.h" #include "../ride/Vehicle.h" +#include "EntityList.h" #include "Fountain.h" #include "SpriteBase.h" -#include - -#define SPRITE_INDEX_NULL 0xFFFF -#define MAX_SPRITES 10000 - enum class SpriteIdentifier : uint8_t { Vehicle = 0, @@ -30,17 +26,6 @@ enum class SpriteIdentifier : uint8_t Null = 255 }; -enum class EntityListId : uint8_t -{ - Free, - TrainHead, - Peep, - Misc, - Litter, - Vehicle, - Count, -}; - enum LitterType : uint8_t; struct Litter : SpriteBase @@ -215,7 +200,7 @@ enum LitterType : uint8_t SpriteBase* try_get_sprite(size_t spriteIndex); SpriteBase* get_sprite(size_t sprite_idx); -template T* GetEntity(size_t sprite_idx) +template T* GetEntity(size_t sprite_idx) { auto spr = get_sprite(sprite_idx); return spr != nullptr ? spr->As() : nullptr; @@ -227,9 +212,6 @@ template T* TryGetEntity(size_t sprite_idx) return spr != nullptr ? spr->As() : nullptr; } -uint16_t GetEntityListCount(EntityListId list); -uint16_t GetNumFreeEntities(); - 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; @@ -237,7 +219,6 @@ extern const rct_string_id litterNames[12]; rct_sprite* create_sprite(SpriteIdentifier spriteIdentifier); rct_sprite* create_sprite(SpriteIdentifier spriteIdentifier, EntityListId linkedListIndex); -void RebuildEntityLists(); void reset_sprite_list(); void reset_sprite_spatial_index(); void sprite_clear_all_unused(); @@ -249,7 +230,6 @@ void litter_remove_at(const CoordsXYZ& litterPos); uint16_t remove_floating_sprites(); void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos); void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos); -const std::vector& GetEntityTileList(const CoordsXY& spritePos); /////////////////////////////////////////////////////////////// // Balloon @@ -275,209 +255,6 @@ rct_sprite_checksum sprite_checksum(); void sprite_set_flashing(SpriteBase* sprite, bool flashing); bool sprite_get_flashing(SpriteBase* sprite); -const std::list& GetEntityList(const EntityListId id); - -template class EntityIterator -{ -private: - T* Entity = nullptr; - uint16_t NextEntityId = SPRITE_INDEX_NULL; - -public: - EntityIterator(const uint16_t _EntityId) - : NextEntityId(_EntityId) - { - ++(*this); - } - EntityIterator& operator++() - { - Entity = nullptr; - - while (NextEntityId != SPRITE_INDEX_NULL && Entity == nullptr) - { - auto baseEntity = GetEntity(NextEntityId); - if (!baseEntity) - { - NextEntityId = SPRITE_INDEX_NULL; - continue; - } - NextEntityId = baseEntity->*NextList; - Entity = baseEntity->template As(); - } - return *this; - } - - EntityIterator operator++(int) - { - EntityIterator retval = *this; - ++(*this); - return retval; - } - bool operator==(EntityIterator other) const - { - return Entity == other.Entity; - } - bool operator!=(EntityIterator other) const - { - return !(*this == other); - } - T* operator*() - { - return Entity; - } - // iterator traits - using difference_type = std::ptrdiff_t; - using value_type = T; - using pointer = const T*; - using reference = const T&; - using iterator_category = std::forward_iterator_tag; -}; - -template class EntityTileIterator -{ -private: - std::vector::const_iterator iter; - std::vector::const_iterator end; - T* Entity = nullptr; - -public: - EntityTileIterator(std::vector::const_iterator _iter, std::vector::const_iterator _end) - : iter(_iter) - , end(_end) - { - ++(*this); - } - EntityTileIterator& operator++() - { - Entity = nullptr; - - while (iter != end && Entity == nullptr) - { - Entity = GetEntity(*iter++); - } - return *this; - } - - EntityTileIterator operator++(int) - { - EntityTileIterator retval = *this; - ++(*this); - return *iter; - } - bool operator==(EntityTileIterator other) const - { - return Entity == other.Entity; - } - bool operator!=(EntityTileIterator other) const - { - return !(*this == other); - } - T* operator*() - { - return Entity; - } - // iterator traits - using difference_type = std::ptrdiff_t; - using value_type = T; - using pointer = const T*; - using reference = const T&; - using iterator_category = std::forward_iterator_tag; -}; - -template class EntityTileList -{ -private: - const std::vector& vec; - -public: - EntityTileList(const CoordsXY& loc) - : vec(GetEntityTileList(loc)) - { - } - - EntityTileIterator begin() - { - return EntityTileIterator(std::begin(vec), std::end(vec)); - } - EntityTileIterator end() - { - return EntityTileIterator(std::end(vec), std::end(vec)); - } -}; - -template class EntityListIterator -{ -private: - std::list::const_iterator iter; - std::list::const_iterator end; - T* Entity = nullptr; - -public: - EntityListIterator(std::list::const_iterator _iter, std::list::const_iterator _end) - : iter(_iter) - , end(_end) - { - ++(*this); - } - EntityListIterator& operator++() - { - Entity = nullptr; - - while (iter != end && Entity == nullptr) - { - Entity = GetEntity(*iter++); - } - return *this; - } - - EntityListIterator operator++(int) - { - EntityListIterator retval = *this; - ++(*this); - return *iter; - } - bool operator==(EntityListIterator other) const - { - return Entity == other.Entity; - } - bool operator!=(EntityListIterator other) const - { - return !(*this == other); - } - T* operator*() - { - return Entity; - } - // iterator traits - using difference_type = std::ptrdiff_t; - using value_type = T; - using pointer = const T*; - using reference = const T&; - using iterator_category = std::forward_iterator_tag; -}; - -template class EntityList -{ -private: - using EntityListIterator_t = EntityListIterator; - const std::list& vec; - -public: - EntityList(EntityListId type) - : vec(GetEntityList(type)) - { - } - - EntityListIterator_t begin() - { - return EntityListIterator_t(std::cbegin(vec), std::cend(vec)); - } - EntityListIterator_t end() - { - return EntityListIterator_t(std::cend(vec), std::cend(vec)); - } -}; - class EntityTweener { std::vector Entities;