1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

refactor: changed ObjectType enum to strong enum

code does not compile yet
This commit is contained in:
Łukasz Pękalski
2020-11-09 11:53:29 +01:00
parent 6e5105ab3b
commit 832fd69822
26 changed files with 209 additions and 104 deletions

View File

@@ -30,8 +30,8 @@
bool _maxObjectsWasHit;
std::vector<uint8_t> _objectSelectionFlags;
int32_t _numSelectedObjectsForType[ObjectType::Count];
static int32_t _numAvailableObjectsForType[ObjectType::Count];
int32_t _numSelectedObjectsForType[EnumValue(ObjectType::Count)];
static int32_t _numAvailableObjectsForType[EnumValue(ObjectType::Count)];
static void setup_in_use_selection_flags();
static void setup_track_designer_objects();
@@ -50,7 +50,7 @@ static void setup_track_manager_objects()
{
uint8_t* selectionFlags = &_objectSelectionFlags[i];
const ObjectRepositoryItem* item = &items[i];
uint8_t object_type = item->ObjectEntry.GetType();
ObjectType object_type = item->ObjectEntry.GetType();
if (object_type == ObjectType::Ride)
{
*selectionFlags |= OBJECT_SELECTION_FLAG_6;
@@ -79,7 +79,7 @@ static void setup_track_designer_objects()
{
uint8_t* selectionFlags = &_objectSelectionFlags[i];
const ObjectRepositoryItem* item = &items[i];
uint8_t objectType = item->ObjectEntry.GetType();
ObjectType objectType = item->ObjectEntry.GetType();
if (objectType == ObjectType::Ride)
{
*selectionFlags |= OBJECT_SELECTION_FLAG_6;
@@ -107,16 +107,16 @@ void setup_in_use_selection_flags()
{
auto& objectMgr = OpenRCT2::GetContext()->GetObjectManager();
for (uint8_t objectType = 0; objectType < ObjectType::Count; objectType++)
for (uint8_t objectType = 0; objectType < EnumValue(ObjectType::Count); objectType++)
{
for (int32_t i = 0; i < object_entry_group_counts[objectType]; i++)
{
Editor::ClearSelectedObject(objectType, i, OBJECT_SELECTION_FLAG_ALL);
Editor::ClearSelectedObject(static_cast<ObjectType>(objectType), i, OBJECT_SELECTION_FLAG_ALL);
auto loadedObj = objectMgr.GetLoadedObject(objectType, i);
auto loadedObj = objectMgr.GetLoadedObject(static_cast<ObjectType>(objectType), i);
if (loadedObj != nullptr)
{
Editor::SetSelectedObject(objectType, i, OBJECT_SELECTION_FLAG_2);
Editor::SetSelectedObject(static_cast<ObjectType>(objectType), i, OBJECT_SELECTION_FLAG_2);
}
}
}
@@ -135,7 +135,7 @@ void setup_in_use_selection_flags()
break;
case TILE_ELEMENT_TYPE_PATH:
type = iter.element->AsPath()->GetSurfaceEntryIndex();
assert(type < object_entry_group_counts[ObjectType::Paths]);
assert(type < object_entry_group_counts[EnumValue(ObjectType::Paths)]);
Editor::SetSelectedObject(ObjectType::Paths, type, OBJECT_SELECTION_FLAG_SELECTED);
if (iter.element->AsPath()->HasAddition())
@@ -146,7 +146,7 @@ void setup_in_use_selection_flags()
break;
case TILE_ELEMENT_TYPE_SMALL_SCENERY:
type = iter.element->AsSmallScenery()->GetEntryIndex();
assert(type < object_entry_group_counts[ObjectType::SmallScenery]);
assert(type < object_entry_group_counts[EnumValue(ObjectType::SmallScenery)]);
Editor::SetSelectedObject(ObjectType::SmallScenery, type, OBJECT_SELECTION_FLAG_SELECTED);
break;
case TILE_ELEMENT_TYPE_ENTRANCE:
@@ -159,17 +159,17 @@ void setup_in_use_selection_flags()
Editor::SetSelectedObject(ObjectType::ParkEntrance, 0, OBJECT_SELECTION_FLAG_SELECTED);
type = iter.element->AsEntrance()->GetPathType();
assert(type < object_entry_group_counts[ObjectType::Paths]);
assert(type < object_entry_group_counts[EnumValue(ObjectType::Paths)]);
Editor::SetSelectedObject(ObjectType::Paths, type, OBJECT_SELECTION_FLAG_SELECTED);
break;
case TILE_ELEMENT_TYPE_WALL:
type = iter.element->AsWall()->GetEntryIndex();
assert(type < object_entry_group_counts[ObjectType::Walls]);
assert(type < object_entry_group_counts[EnumValue(ObjectType::Walls)]);
Editor::SetSelectedObject(ObjectType::Walls, type, OBJECT_SELECTION_FLAG_SELECTED);
break;
case TILE_ELEMENT_TYPE_LARGE_SCENERY:
type = iter.element->AsLargeScenery()->GetEntryIndex();
assert(type < object_entry_group_counts[ObjectType::LargeScenery]);
assert(type < object_entry_group_counts[EnumValue(ObjectType::LargeScenery)]);
Editor::SetSelectedObject(ObjectType::LargeScenery, type, OBJECT_SELECTION_FLAG_SELECTED);
break;
case TILE_ELEMENT_TYPE_BANNER:
@@ -178,7 +178,7 @@ void setup_in_use_selection_flags()
if (banner != nullptr)
{
type = banner->type;
assert(type < object_entry_group_counts[ObjectType::Banners]);
assert(type < object_entry_group_counts[EnumValue(ObjectType::Banners)]);
Editor::SetSelectedObject(ObjectType::Banners, type, OBJECT_SELECTION_FLAG_SELECTED);
}
break;
@@ -204,7 +204,7 @@ void setup_in_use_selection_flags()
const ObjectRepositoryItem* item = &items[i];
*selectionFlags &= ~OBJECT_SELECTION_FLAG_IN_USE;
uint8_t entryType;
ObjectType entryType;
ObjectEntryIndex entryIndex;
if (find_object_in_entry_group(&item->ObjectEntry, &entryType, &entryIndex))
{
@@ -230,7 +230,7 @@ void sub_6AB211()
int32_t numObjects = static_cast<int32_t>(object_repository_get_items_count());
_objectSelectionFlags = std::vector<uint8_t>(numObjects);
for (uint8_t objectType = 0; objectType < ObjectType::Count; objectType++)
for (uint8_t objectType = 0; objectType < EnumValue(ObjectType::Count); objectType++)
{
_numSelectedObjectsForType[objectType] = 0;
_numAvailableObjectsForType[objectType] = 0;
@@ -239,7 +239,7 @@ void sub_6AB211()
const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++)
{
uint8_t objectType = items[i].ObjectEntry.GetType();
ObjectType objectType = items[i].ObjectEntry.GetType();
_numAvailableObjectsForType[objectType]++;
}
@@ -284,7 +284,7 @@ void editor_object_flags_free()
*/
static void remove_selected_objects_from_research(const rct_object_entry* installedObject)
{
uint8_t entry_type;
ObjectType entry_type;
ObjectEntryIndex entry_index;
if (!find_object_in_entry_group(installedObject, &entry_type, &entry_index))
return;
@@ -450,7 +450,7 @@ bool window_editor_object_selection_select_object(uint8_t isMasterObject, int32_
return false;
}
uint8_t objectType = item->ObjectEntry.GetType();
ObjectType objectType = item->ObjectEntry.GetType();
if (objectType == ObjectType::SceneryGroup && (flags & INPUT_FLAG_EDITOR_OBJECT_SELECT_OBJECTS_IN_SCENERY_GROUP))
{
for (const auto& sgEntry : item->SceneryGroupInfo.Entries)
@@ -459,7 +459,7 @@ bool window_editor_object_selection_select_object(uint8_t isMasterObject, int32_
}
}
_numSelectedObjectsForType[objectType]--;
_numSelectedObjectsForType[EnumValue(objectType)]--;
*selectionFlags &= ~OBJECT_SELECTION_FLAG_SELECTED;
return true;
}
@@ -477,8 +477,8 @@ bool window_editor_object_selection_select_object(uint8_t isMasterObject, int32_
return true;
}
uint8_t objectType = item->ObjectEntry.GetType();
uint16_t maxObjects = object_entry_group_counts[objectType];
ObjectType objectType = item->ObjectEntry.GetType();
uint16_t maxObjects = object_entry_group_counts[EnumValue(objectType)];
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
{
maxObjects = 4;
@@ -517,7 +517,7 @@ bool window_editor_object_selection_select_object(uint8_t isMasterObject, int32_
return false;
}
_numSelectedObjectsForType[objectType]++;
_numSelectedObjectsForType[EnumValue(objectType)]++;
*selectionFlags |= OBJECT_SELECTION_FLAG_SELECTED;
return true;
@@ -537,14 +537,14 @@ bool window_editor_object_selection_select_object(uint8_t isMasterObject, int32_
return window_editor_object_selection_select_object(isMasterObject, flags, item);
}
bool editor_check_object_group_at_least_one_selected(int32_t checkObjectType)
bool editor_check_object_group_at_least_one_selected(ObjectType checkObjectType)
{
int32_t numObjects = static_cast<int32_t>(object_repository_get_items_count());
const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++)
{
uint8_t objectType = items[i].ObjectEntry.GetType();
ObjectType objectType = items[i].ObjectEntry.GetType();
if (checkObjectType == objectType && (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED))
{
return true;
@@ -570,7 +570,7 @@ int32_t editor_remove_unused_objects()
&& !(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED))
{
const ObjectRepositoryItem* item = &items[i];
uint8_t objectType = item->ObjectEntry.GetType();
ObjectType objectType = item->ObjectEntry.GetType();
if (objectType >= ObjectType::SceneryGroup)
{