diff --git a/src/openrct2/Editor.h b/src/openrct2/Editor.h index 7ea324888c..0136b86407 100644 --- a/src/openrct2/Editor.h +++ b/src/openrct2/Editor.h @@ -85,6 +85,12 @@ extern "C" void editor_open_windows_for_current_step(); + /** + * Removes all unused objects from the object selection. + * @return The number of removed objects. + */ + sint32 editor_remove_unused_objects(); + void game_command_edit_scenario_options(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); #ifdef __cplusplus } diff --git a/src/openrct2/interface/console.c b/src/openrct2/interface/console.c index 29b2d5c872..da18da0861 100644 --- a/src/openrct2/interface/console.c +++ b/src/openrct2/interface/console.c @@ -19,6 +19,7 @@ #include "../config/Config.h" #include "../Context.h" #include "../drawing/drawing.h" +#include "../Editor.h" #include "../game.h" #include "../input.h" #include "../localisation/localisation.h" @@ -1206,6 +1207,13 @@ static sint32 cc_open(const utf8 **argv, sint32 argc) { return 0; } +static sint32 cc_remove_unused_objects(const utf8 **argv, sint32 argc) +{ + sint32 result = editor_remove_unused_objects(); + console_printf("%d unused object entries have been removed.", result); + return 0; +} + typedef sint32 (*console_command_func)(const utf8 **argv, sint32 argc); typedef struct console_command { @@ -1280,6 +1288,7 @@ console_command console_command_table[] = { { "reset_user_strings", cc_reset_user_strings, "Resets all user-defined strings, to fix incorrectly occurring 'Chosen name in use already' errors.", "reset_user_strings" }, { "rides", cc_rides, "Ride management.", "rides " }, { "staff", cc_staff, "Staff management.", "staff "}, + { "remove_unused_objects", cc_remove_unused_objects, "Removes all the unused objects from the object selection.", "remove_unused_objects" }, }; static sint32 cc_windows(const utf8 **argv, sint32 argc) { diff --git a/src/openrct2/windows/EditorObjectSelection.cpp b/src/openrct2/windows/EditorObjectSelection.cpp index 5cee9ce57b..0ad73565fd 100644 --- a/src/openrct2/windows/EditorObjectSelection.cpp +++ b/src/openrct2/windows/EditorObjectSelection.cpp @@ -1877,3 +1877,44 @@ bool editor_check_object_group_at_least_one_selected(sint32 checkObjectType) } return false; } + +sint32 editor_remove_unused_objects() +{ + bool createSelectionFlags = (_objectSelectionFlags == nullptr); + if (createSelectionFlags && !sub_6AB211()) + { + return 0; + } + + setup_in_use_selection_flags(); + + sint32 numObjects = (sint32)object_repository_get_items_count(); + const ObjectRepositoryItem * items = object_repository_get_items(); + + sint32 numUnselectedObjects = 0; + for (sint32 i = 0; i < numObjects; i++) + { + if (!(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_IN_USE) && !(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED)) + { + const ObjectRepositoryItem * item = &items[i]; + uint8 objectType = item->ObjectEntry.flags & 0xF; + + if (objectType == OBJECT_TYPE_PARK_ENTRANCE || objectType == OBJECT_TYPE_SCENARIO_TEXT || objectType == OBJECT_TYPE_WATER || objectType == OBJECT_TYPE_SCENERY_SETS) + { + continue; + } + + _numSelectedObjectsForType[objectType]--; + _objectSelectionFlags[i] &= ~OBJECT_SELECTION_FLAG_SELECTED; + numUnselectedObjects++; + } + } + unload_unselected_objects(); + + if (createSelectionFlags) + { + editor_object_flags_free(); + } + + return numUnselectedObjects; +}