Move kObjectEntryGroupCounts to ObjectList.cpp

This commit is contained in:
Aaron van Geffen 2024-03-27 20:13:10 +01:00
parent d645906003
commit e898e9211d
15 changed files with 48 additions and 33 deletions

View File

@ -19,6 +19,7 @@
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Research.h>
#include <openrct2/object/DefaultObjects.h>
#include <openrct2/object/ObjectList.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/object/ObjectRepository.h>
#include <openrct2/ride/RideData.h>
@ -84,8 +85,8 @@ static Widget _inventionListDragWidgets[] = {
// Reset all objects to not required
for (auto objectType : getTransientObjectTypes())
{
auto maxObjects = object_entry_group_counts[EnumValue(objectType)];
for (int32_t i = 0; i < maxObjects; i++)
auto maxObjects = getObjectEntryGroupCount(objectType);
for (auto i = 0u; i < maxObjects; i++)
{
Editor::ClearSelectedObject(objectType, i, ObjectSelectionFlags::AllFlags);
}

View File

@ -1048,8 +1048,8 @@ static std::vector<Widget> _window_editor_object_selection_widgets = {
{
auto screenPos = windowPos + ScreenCoordsXY{ 3, height - 13 };
int32_t numSelected = _numSelectedObjectsForType[EnumValue(GetSelectedObjectType())];
int32_t totalSelectable = object_entry_group_counts[EnumValue(GetSelectedObjectType())];
auto numSelected = _numSelectedObjectsForType[EnumValue(GetSelectedObjectType())];
auto totalSelectable = getObjectEntryGroupCount(GetSelectedObjectType());
auto ft = Formatter();
ft.Add<uint16_t>(numSelected);

View File

@ -808,7 +808,7 @@ namespace OpenRCT2
{
for (auto objectType : ObjectTypes)
{
auto maxObjectsOfType = static_cast<ObjectEntryIndex>(object_entry_group_counts[EnumValue(objectType)]);
auto maxObjectsOfType = static_cast<ObjectEntryIndex>(getObjectEntryGroupCount(objectType));
for (ObjectEntryIndex i = 0; i < maxObjectsOfType; i++)
{
auto obj = _objectManager->GetLoadedObject(objectType, i);

View File

@ -562,7 +562,7 @@ namespace Editor
{
if (index != OBJECT_ENTRY_INDEX_NULL)
{
assert(static_cast<int32_t>(objectType) < object_entry_group_counts[EnumValue(ObjectType::Paths)]);
assert(index < getObjectEntryGroupCount(ObjectType::Paths));
auto& list = _editorSelectedObjectFlags[EnumValue(objectType)];
if (list.size() <= index)
{

View File

@ -36,7 +36,7 @@
std::optional<StringId> _gSceneryGroupPartialSelectError;
std::vector<uint8_t> _objectSelectionFlags;
int32_t _numSelectedObjectsForType[EnumValue(ObjectType::Count)];
uint32_t _numSelectedObjectsForType[EnumValue(ObjectType::Count)];
static int32_t _numAvailableObjectsForType[EnumValue(ObjectType::Count)];
static void SetupInUseSelectionFlags();
@ -127,7 +127,7 @@ void SetupInUseSelectionFlags()
for (auto objectType : getTransientObjectTypes())
{
for (int32_t i = 0; i < object_entry_group_counts[EnumValue(objectType)]; i++)
for (auto i = 0u; i < getObjectEntryGroupCount(objectType); i++)
{
Editor::ClearSelectedObject(static_cast<ObjectType>(objectType), i, ObjectSelectionFlags::AllFlags);
@ -580,7 +580,7 @@ ResultWithMessage WindowEditorObjectSelectionSelectObject(
}
ObjectType objectType = item->Type;
uint16_t maxObjects = object_entry_group_counts[EnumValue(objectType)];
auto maxObjects = getObjectEntryGroupCount(objectType);
if (maxObjects <= _numSelectedObjectsForType[EnumValue(objectType)])
{

View File

@ -27,7 +27,7 @@ enum EDITOR_INPUT_FLAGS
extern std::optional<StringId> _gSceneryGroupPartialSelectError;
extern std::vector<uint8_t> _objectSelectionFlags;
extern int32_t _numSelectedObjectsForType[EnumValue(ObjectType::Count)];
extern uint32_t _numSelectedObjectsForType[EnumValue(ObjectType::Count)];
bool EditorCheckObjectGroupAtLeastOneSelected(ObjectType checkObjectType);
bool EditorCheckObjectGroupAtLeastOneSurfaceSelected(bool queue);

View File

@ -1313,8 +1313,8 @@ static int32_t ConsoleCommandCountObjects(InteractiveConsole& console, [[maybe_u
{
for (auto objectType : ObjectTypes)
{
int32_t entryGroupIndex = 0;
for (; entryGroupIndex < object_entry_group_counts[EnumValue(objectType)]; entryGroupIndex++)
uint32_t entryGroupIndex = 0;
for (; entryGroupIndex < getObjectEntryGroupCount(objectType); entryGroupIndex++)
{
if (ObjectEntryGetObject(objectType, entryGroupIndex) == nullptr)
{
@ -1322,8 +1322,7 @@ static int32_t ConsoleCommandCountObjects(InteractiveConsole& console, [[maybe_u
}
}
console.WriteFormatLine(
"%s: %d/%d", _objectTypeNames[EnumValue(objectType)], entryGroupIndex,
object_entry_group_counts[EnumValue(objectType)]);
"%s: %d/%d", _objectTypeNames[EnumValue(objectType)], entryGroupIndex, getObjectEntryGroupCount(objectType));
}
return 0;

View File

@ -342,8 +342,6 @@ public:
# pragma GCC diagnostic pop
#endif
extern int32_t object_entry_group_counts[];
int32_t ObjectCalculateChecksum(const RCTObjectEntry* entry, const void* data, size_t dataLength);
void ObjectCreateIdentifierName(char* string_buffer, size_t size, const RCTObjectEntry* object);

View File

@ -14,6 +14,7 @@
#include "../object/Object.h"
#include "../util/SawyerCoding.h"
#include "../util/Util.h"
#include "ObjectLimits.h"
#include "ObjectManager.h"
#include "ObjectRepository.h"
@ -21,8 +22,8 @@
#include <array>
#include <cstring>
// 98DA00
int32_t object_entry_group_counts[] = {
// 0x0098DA00
static constexpr std::array<int32_t, EnumValue(ObjectType::Count)> kObjectEntryGroupCounts = {
MAX_RIDE_OBJECTS, // rides
MAX_SMALL_SCENERY_OBJECTS, // small scenery
MAX_LARGE_SCENERY_OBJECTS, // large scenery
@ -42,7 +43,20 @@ int32_t object_entry_group_counts[] = {
MAX_FOOTPATH_RAILINGS_OBJECTS,
MAX_AUDIO_OBJECTS,
};
static_assert(std::size(object_entry_group_counts) == EnumValue(ObjectType::Count));
static_assert(std::size(kObjectEntryGroupCounts) == EnumValue(ObjectType::Count));
size_t getObjectEntryGroupCount(ObjectType objectType)
{
return kObjectEntryGroupCounts[EnumValue(objectType)];
}
size_t getObjectTypeLimit(ObjectType type)
{
auto index = EnumValue(type);
if (index >= EnumValue(ObjectType::Count))
return 0;
return static_cast<size_t>(kObjectEntryGroupCounts[index]);
}
ObjectList::const_iterator::const_iterator(const ObjectList* parent, bool end)
{
@ -186,7 +200,7 @@ void ObjectCreateIdentifierName(char* string_buffer, size_t size, const RCTObjec
void ObjectGetTypeEntryIndex(size_t index, ObjectType* outObjectType, ObjectEntryIndex* outEntryIndex)
{
uint8_t objectType = EnumValue(ObjectType::Ride);
for (size_t groupCount : object_entry_group_counts)
for (size_t groupCount : kObjectEntryGroupCounts)
{
if (index >= groupCount)
{

View File

@ -10,7 +10,6 @@
#pragma once
#include "Object.h"
#include "ObjectLimits.h"
#include <vector>
@ -51,3 +50,6 @@ public:
};
void ObjectGetTypeEntryIndex(size_t index, ObjectType* outObjectType, ObjectEntryIndex* outEntryIndex);
size_t getObjectEntryGroupCount(ObjectType objectType);
size_t getObjectTypeLimit(ObjectType type);

View File

@ -21,6 +21,7 @@
#include "BannerSceneryEntry.h"
#include "LargeSceneryObject.h"
#include "Object.h"
#include "ObjectLimits.h"
#include "ObjectList.h"
#include "ObjectRepository.h"
#include "PathAdditionObject.h"
@ -79,7 +80,7 @@ public:
return nullptr;
}
if (index >= static_cast<size_t>(object_entry_group_counts[EnumValue(objectType)]))
if (index >= static_cast<size_t>(getObjectEntryGroupCount(objectType)))
{
#ifdef DEBUG
if (index != OBJECT_ENTRY_INDEX_NULL)
@ -144,7 +145,7 @@ public:
ObjectList objectList;
for (auto objectType : ObjectTypes)
{
auto maxObjectsOfType = static_cast<ObjectEntryIndex>(object_entry_group_counts[EnumValue(objectType)]);
auto maxObjectsOfType = static_cast<ObjectEntryIndex>(getObjectEntryGroupCount(objectType));
for (ObjectEntryIndex i = 0; i < maxObjectsOfType; i++)
{
auto obj = GetLoadedObject(objectType, i);
@ -384,7 +385,7 @@ private:
return static_cast<ObjectEntryIndex>(std::distance(list.begin(), it));
}
auto maxSize = object_entry_group_counts[EnumValue(objectType)];
auto maxSize = getObjectEntryGroupCount(objectType);
if (list.size() < static_cast<size_t>(maxSize))
{
list.emplace_back();
@ -524,7 +525,7 @@ private:
for (auto objectType : ObjectTypes)
{
auto& descriptors = objectList.GetList(objectType);
auto maxSize = static_cast<size_t>(object_entry_group_counts[EnumValue(objectType)]);
auto maxSize = static_cast<size_t>(getObjectEntryGroupCount(objectType));
auto listSize = static_cast<ObjectEntryIndex>(std::min(descriptors.size(), maxSize));
for (ObjectEntryIndex i = 0; i < listSize; i++)
{
@ -724,7 +725,7 @@ private:
}
// Build object lists
const auto maxRideObjects = static_cast<size_t>(object_entry_group_counts[EnumValue(ObjectType::Ride)]);
const auto maxRideObjects = static_cast<size_t>(getObjectEntryGroupCount(ObjectType::Ride));
for (size_t i = 0; i < maxRideObjects; i++)
{
auto* rideObject = static_cast<RideObject*>(GetLoadedObject(ObjectType::Ride, i));

View File

@ -570,7 +570,7 @@ namespace RCT1
RCT12::EntryList* entries = GetEntryList(objectType);
// Check if there are spare entries available
size_t maxEntries = static_cast<size_t>(object_entry_group_counts[EnumValue(objectType)]);
size_t maxEntries = static_cast<size_t>(getObjectEntryGroupCount(objectType));
if (entries != nullptr && entries->GetCount() < maxEntries)
{
entries->GetOrAddEntry(objectName);

View File

@ -257,7 +257,7 @@ const RideObjectEntry* GetRideEntryByIndex(ObjectEntryIndex index)
std::string_view GetRideEntryName(ObjectEntryIndex index)
{
if (index >= object_entry_group_counts[EnumValue(ObjectType::Ride)])
if (index >= getObjectEntryGroupCount(ObjectType::Ride))
{
LOG_ERROR("invalid index %d for ride type", index);
return {};

View File

@ -106,7 +106,7 @@ DukValue ScObjectManager::load(const DukValue& p1, const DukValue& p2)
throw DukException() << "Expected number for 'index'.";
auto index = static_cast<size_t>(p2.as_int());
auto limit = GetObjectTypeLimit(installedObject->Type);
auto limit = getObjectTypeLimit(installedObject->Type);
if (index < limit)
{
auto loadedObject = objectManager.GetLoadedObject(installedObject->Type, index);
@ -214,8 +214,8 @@ std::vector<DukValue> ScObjectManager::getAllObjects(const std::string& typez) c
auto type = ScObject::StringToObjectType(typez);
if (type)
{
auto count = object_entry_group_counts[EnumValue(*type)];
for (int32_t i = 0; i < count; i++)
auto count = getObjectEntryGroupCount(*type);
for (auto i = 0u; i < count; i++)
{
auto obj = objManager.GetLoadedObject(*type, i);
if (obj != nullptr)

View File

@ -18,8 +18,8 @@
#include "../core/String.hpp"
#include "../localisation/Localisation.h"
#include "../localisation/StringIds.h"
#include "../object/Object.h"
#include "../object/ObjectEntryManager.h"
#include "../object/ObjectList.h"
#include "../object/ObjectManager.h"
#include "../object/SmallSceneryEntry.h"
#include "../object/TerrainEdgeObject.h"
@ -311,7 +311,7 @@ static void MapGenPlaceTrees()
std::vector<int32_t> desertTreeIds;
std::vector<int32_t> snowTreeIds;
for (int32_t i = 0; i < object_entry_group_counts[EnumValue(ObjectType::SmallScenery)]; i++)
for (auto i = 0u; i < getObjectEntryGroupCount(ObjectType::SmallScenery); i++)
{
auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry<SmallSceneryEntry>(i);
auto entry = ObjectEntryGetObject(ObjectType::SmallScenery, i);