From ab38828e03d7fadba1ccda4ddec40ffb021718e3 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 6 Jan 2016 20:41:21 +0000 Subject: [PATCH] integrate object list variables: - gInstalledObjectsCount - gInstalledObjects - gNumInstalledRCT2Objects - gNumInstalledCustomObjects - gLastLoadedObjectChunkData --- src/editor.c | 4 +- src/interface/console.c | 6 +- src/object.c | 15 +-- src/object.h | 7 ++ src/object_list.c | 149 ++++++++++++-------------- src/windows/editor_object_selection.c | 56 +++++----- src/windows/options.c | 2 +- 7 files changed, 118 insertions(+), 121 deletions(-) diff --git a/src/editor.c b/src/editor.c index a9fc456a8d..e6a303b308 100644 --- a/src/editor.c +++ b/src/editor.c @@ -567,8 +567,8 @@ static void editor_finalise_main_view() static bool editor_check_object_group_at_least_one_selected(int objectType) { - uint32 numObjects = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); - rct_object_entry *entry = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + uint32 numObjects = gInstalledObjectsCount; + rct_object_entry *entry = gInstalledObjects; uint8 *objectFlag = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); for (uint32 i = 0; i < numObjects; i++) { if ((entry->flags & 0x0F) == objectType && (*objectFlag & 1)) { diff --git a/src/interface/console.c b/src/interface/console.c index 6ca8916546..813b0067a3 100644 --- a/src/interface/console.c +++ b/src/interface/console.c @@ -724,12 +724,12 @@ static int cc_twitch(const utf8 **argv, int argc) static void editor_load_selected_objects_console() { uint8 *selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry *installed_entry = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry *installed_entry = gInstalledObjects; - if (RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32) == 0) + if (gInstalledObjectsCount == 0) return; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i != 0; i--, selection_flags++) { + for (int i = gInstalledObjectsCount; i != 0; i--, selection_flags++) { if (*selection_flags & 1) { uint8 entry_index, entry_type; if (!find_object_in_entry_group(installed_entry, &entry_type, &entry_index)){ diff --git a/src/object.c b/src/object.c index ee641dd7e9..57bf1f2882 100644 --- a/src/object.c +++ b/src/object.c @@ -139,10 +139,11 @@ int object_load_file(int groupIndex, const rct_object_entry *entry, int* chunkSi memcpy(extended_entry, &openedEntry, sizeof(rct_object_entry)); extended_entry->chunk_size = *chunkSize; - RCT2_GLOBAL(RCT2_ADDRESS_CURR_OBJECT_CHUNK_POINTER, uint8*) = chunk; + gLastLoadedObjectChunkData = chunk; - if (RCT2_GLOBAL(0x9ADAFD, uint8) != 0) + if (RCT2_GLOBAL(0x9ADAFD, uint8) != 0) { object_paint(objectType, 0, groupIndex, objectType, 0, (int)chunk, 0, 0); + } return 1; } @@ -159,7 +160,7 @@ int object_load(int groupIndex, rct_object_entry *entry, int* chunkSize) RCT2_GLOBAL(0xF42B64, uint32) = groupIndex; - if (RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32) == 0) { + if (gInstalledObjectsCount == 0) { RCT2_GLOBAL(0xF42BD9, uint8) = 0; log_error("Object Load failed due to no items installed check."); return 1; @@ -277,9 +278,9 @@ int object_load_packed(SDL_RWops* rw) extended_entry->chunk_size = chunkSize; // Ensure the entry does not already exist. - rct_object_entry *installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); - if (RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32)){ - for (uint32 i = 0; i < RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); ++i){ + rct_object_entry *installedObject = gInstalledObjects; + if (gInstalledObjectsCount){ + for (uint32 i = 0; i < gInstalledObjectsCount; ++i){ if (object_entry_compare(&entry, installedObject)){ object_unload_all(); return 0; @@ -1521,7 +1522,7 @@ int object_paint(int type, int eax, int ebx, int ecx, int edx, int esi, int edi, */ int object_get_scenario_text(rct_object_entry *entry) { - rct_object_entry *installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry *installedObject = gInstalledObjects; installedObject = object_list_find(entry); diff --git a/src/object.h b/src/object.h index dfbfc30901..050f84d529 100644 --- a/src/object.h +++ b/src/object.h @@ -93,6 +93,13 @@ typedef struct { extern rct_object_entry_group object_entry_groups[]; extern char gTempObjectLoadName[9]; +extern uint32 gInstalledObjectsCount; +extern rct_object_entry *gInstalledObjects; +extern uint32 gNumInstalledRCT2Objects; +extern uint32 gNumInstalledCustomObjects; + +extern void *gLastLoadedObjectChunkData; + int object_load_entry(const utf8 *path, rct_object_entry *outEntry); void object_list_load(); void set_load_objects_fail_reason(); diff --git a/src/object_list.c b/src/object_list.c index ff069af021..8481c04131 100644 --- a/src/object_list.c +++ b/src/object_list.c @@ -98,6 +98,13 @@ static void load_object_filter(rct_object_entry* entry, uint8* chunk, rct_object static rct_object_filters *_installedObjectFilters = NULL; +uint32 gInstalledObjectsCount; +rct_object_entry *gInstalledObjects; +uint32 gNumInstalledRCT2Objects; +uint32 gNumInstalledCustomObjects; + +void *gLastLoadedObjectChunkData; + static void get_plugin_path(utf8 *outPath) { platform_get_user_directory(outPath, NULL); @@ -112,8 +119,8 @@ static void object_list_sort() char *objectName, *lowestString; uint8 *copied; - objectBuffer = &RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); - numObjects = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, sint32); + objectBuffer = &gInstalledObjects; + numObjects = gInstalledObjectsCount; copied = calloc(numObjects, sizeof(uint8)); // Get buffer size @@ -155,7 +162,7 @@ static void object_list_sort() } // Replace old buffer - rct2_free(*objectBuffer); + free(*objectBuffer); *objectBuffer = newBuffer; if (_installedObjectFilters) { free(_installedObjectFilters); @@ -165,27 +172,29 @@ static void object_list_sort() free(copied); } +static uint32 object_list_count_custom_objects() +{ + uint32 numCustomObjects = 0; + rct_object_entry *object = gInstalledObjects; + for (uint32 i = 0; i < gInstalledObjectsCount; i++) { + if ((object->flags & 0xF0) == 0) { + numCustomObjects++; + } + object = object_get_next(object); + } + + gNumInstalledCustomObjects = numCustomObjects; + return numCustomObjects; +} + /** * * rct2: 0x006A93CD */ static void object_list_examine() { - int i; - rct_object_entry *object; - - RCT2_GLOBAL(RCT2_ADDRESS_CUSTOM_OBJECTS_INSTALLED, uint8) = 0; - - object = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); - for (i = 0; i < RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, sint32); i++) { - if (!(object->flags & 0xF0)) - RCT2_GLOBAL(RCT2_ADDRESS_CUSTOM_OBJECTS_INSTALLED, uint8) |= 1; - - object = object_get_next(object); - } + object_list_count_custom_objects(); object_list_sort(); - - // Create a search index object_list_create_hash_table(); } @@ -256,27 +265,17 @@ void object_list_load() totalFiles = (totalFiles & ~0xFF) | 1; totalFiles = rol32(totalFiles, 24); - if (object_list_cache_load(totalFiles, totalFileSize, fileDateModifiedChecksum)) + if (object_list_cache_load(totalFiles, totalFileSize, fileDateModifiedChecksum)) { return; - - // Reload object list - - // RCT2_ADDRESS_CONFIG_FIRST_TIME_LOAD_OBJECTS used to control if this was the first time loading objects - // and display the starting RCT2 for the first time message. - //if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FIRST_TIME_LOAD_OBJECTS, uint8) != 0) - // RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FIRST_TIME_LOAD_OBJECTS, uint8) = 0; - - reset_loaded_objects(); - - // Dispose installed object list - if (RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, sint32) != -1) { - rct2_free(RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*)); - RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, sint32) = -1; } - RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*) = rct2_malloc(4096); - if (RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, int) == -1){ + // Dispose installed object list + reset_loaded_objects(); + SafeFree(gInstalledObjects); + + gInstalledObjectsCount = 0; + gInstalledObjects = (rct_object_entry*)malloc(4096); + if (gInstalledObjects == NULL) { log_error("Failed to allocate memory for object list"); rct2_exit_reason(835, 3162); return; @@ -284,9 +283,8 @@ void object_list_load() uint32 fileCount = 0; uint32 objectCount = 0; - uint32 current_item_offset = 0; - uint32 next_offset = 0; - RCT2_GLOBAL(RCT2_ADDRESS_ORIGINAL_RCT2_OBJECT_COUNT, uint32) = 0; + size_t currentEntryOffset = 0; + gNumInstalledRCT2Objects = 0; log_verbose("building cache of available objects..."); @@ -297,15 +295,14 @@ void object_list_load() enumFileHandle = platform_enumerate_files_begin(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char)); if (enumFileHandle != INVALID_HANDLE) { - uint32 installed_buffer_size = 0x1000; - + size_t installedObjectsCapacity = 4096; while (platform_enumerate_files_next(enumFileHandle, &enumFileInfo)) { fileCount++; - if ((installed_buffer_size - current_item_offset) <= 2842){ - installed_buffer_size += 0x1000; - RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*) = rct2_realloc(RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*), installed_buffer_size); - if (RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, int) == -1){ + if ((installedObjectsCapacity - currentEntryOffset) <= 2842){ + installedObjectsCapacity += 4096; + gInstalledObjects = (rct_object_entry*)realloc(gInstalledObjects, installedObjectsCapacity); + if (gInstalledObjects == NULL) { log_error("Failed to allocate memory for object list"); rct2_exit_reason(835, 3162); return; @@ -316,23 +313,17 @@ void object_list_load() substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), enumFileInfo.path); rct_object_entry entry; - if (!object_load_entry(path, &entry)) - continue; - - if (_installedObjectFilters) + if (object_load_entry(path, &entry)) { _installedObjectFilters = realloc(_installedObjectFilters, sizeof(rct_object_filters) * (objectCount + 1)); - else - _installedObjectFilters = malloc(sizeof(rct_object_filters) * (objectCount + 1)); - rct_object_entry* installed_entry = (rct_object_entry*)(RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, uint8*) + current_item_offset); - rct_object_filters filter; - - next_offset = install_object_entry(&entry, installed_entry, enumFileInfo.path, &filter); - if (next_offset) { - current_item_offset += next_offset; - - _installedObjectFilters[objectCount] = filter; - objectCount++; + rct_object_entry *installedEntry = (rct_object_entry*)((size_t)gInstalledObjects + currentEntryOffset); + rct_object_filters filter; + size_t newEntrySize = install_object_entry(&entry, installedEntry, enumFileInfo.path, &filter); + if (newEntrySize != 0) { + _installedObjectFilters[objectCount] = filter; + objectCount++; + currentEntryOffset += newEntrySize; + } } } platform_enumerate_files_end(enumFileHandle); @@ -340,7 +331,7 @@ void object_list_load() reset_loaded_objects(); - object_list_cache_save(fileCount, totalFileSize, fileDateModifiedChecksum, current_item_offset); + object_list_cache_save(fileCount, totalFileSize, fileDateModifiedChecksum, currentEntryOffset); // Reload track list ride_list_item ride_list; @@ -375,15 +366,12 @@ static int object_list_cache_load(int totalFiles, uint64 totalFileSize, int file pluginHeader.date_modified_checksum == fileDateModifiedChecksum ) { // Dispose installed object list - if (RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, sint32) != -1) { - rct2_free(RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*)); - RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, sint32) = -1; - } + SafeFree(gInstalledObjects); // Read installed object list - RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*) = rct2_malloc(pluginHeader.object_list_size); - if (SDL_RWread(file, RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, void*), pluginHeader.object_list_size, 1) == 1) { - RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32) = pluginHeader.object_list_no_items; + gInstalledObjects = (rct_object_entry*)malloc(pluginHeader.object_list_size); + if (SDL_RWread(file, gInstalledObjects, pluginHeader.object_list_size, 1) == 1) { + gInstalledObjectsCount = pluginHeader.object_list_no_items; if (pluginHeader.object_list_no_items != (pluginHeader.total_files & 0xFFFFFF)) log_error("Potential mismatch in file numbers. Possible corrupt file. Consider deleting plugin.dat."); @@ -441,7 +429,7 @@ static int object_list_cache_save(int fileCount, uint64 totalFileSize, int fileD pluginHeader.total_file_size = (uint32)totalFileSize; pluginHeader.date_modified_checksum = fileDateModifiedChecksum; pluginHeader.object_list_size = currentItemOffset; - pluginHeader.object_list_no_items = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); + pluginHeader.object_list_no_items = gInstalledObjectsCount; get_plugin_path(path); file = SDL_RWFromFile(path,"wb"); @@ -451,9 +439,9 @@ static int object_list_cache_save(int fileCount, uint64 totalFileSize, int fileD } SDL_RWwrite(file, &pluginHeader, sizeof(rct_plugin_header), 1); - SDL_RWwrite(file, RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, uint8*), pluginHeader.object_list_size, 1); + SDL_RWwrite(file, gInstalledObjects, pluginHeader.object_list_size, 1); SDL_RWwrite(file, &filterVersion, sizeof(filterVersion), 1); - SDL_RWwrite(file, _installedObjectFilters, sizeof(rct_object_filters) * RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32), 1); + SDL_RWwrite(file, _installedObjectFilters, sizeof(rct_object_filters) * gInstalledObjectsCount, 1); SDL_RWclose(file); return 1; } @@ -468,7 +456,8 @@ int check_object_entry(rct_object_entry *entry) * * rct2: 0x006AB344 */ -void object_create_identifier_name(char* string_buffer, const rct_object_entry* object){ +void object_create_identifier_name(char* string_buffer, const rct_object_entry* object) +{ for (uint8 i = 0; i < 8; ++i){ if (object->name[i] != ' '){ *string_buffer++ = object->name[i]; @@ -617,7 +606,7 @@ uint32 object_get_hash_code(rct_object_entry *object) void object_list_create_hash_table() { rct_object_entry *installedObject; - int numInstalledObjects = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, sint32); + int numInstalledObjects = gInstalledObjectsCount; if (_installedObjectHashTable != NULL) free(_installedObjectHashTable); @@ -626,7 +615,7 @@ void object_list_create_hash_table() _installedObjectHashTable = calloc(_installedObjectHashTableSize, sizeof(rct_object_entry*)); _installedObjectHashTableCollisions = 0; - installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + installedObject = gInstalledObjects; for (int i = 0; i < numInstalledObjects; i++) { uint32 hash = object_get_hash_code(installedObject); uint32 index = hash % _installedObjectHashTableSize; @@ -740,7 +729,7 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) = 0xF26E; - RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32)++; + gInstalledObjectsCount++; // This is a variable used by object_load to decide if it should // use object_paint on the entry. @@ -755,7 +744,7 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in log_error("Object Load File failed. Potentially corrupt file: %.8s", entry->name); RCT2_GLOBAL(0x009ADAF4, sint32) = -1; RCT2_GLOBAL(0x009ADAFD, uint8) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32)--; + gInstalledObjectsCount--; return 0; } @@ -766,11 +755,11 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in RCT2_GLOBAL(0x009ADAFD, uint8) = 0; if ((entry->flags & 0xF0) == 0x80) { - RCT2_GLOBAL(RCT2_ADDRESS_ORIGINAL_RCT2_OBJECT_COUNT, uint32)++; - if (RCT2_GLOBAL(RCT2_ADDRESS_ORIGINAL_RCT2_OBJECT_COUNT, uint32) > 772){ + gNumInstalledRCT2Objects++; + if (gNumInstalledRCT2Objects > 772){ log_error("Incorrect number of vanilla RCT2 objects."); - RCT2_GLOBAL(RCT2_ADDRESS_ORIGINAL_RCT2_OBJECT_COUNT, uint32)--; - RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32)--; + gNumInstalledRCT2Objects--; + gInstalledObjectsCount--; object_unload(entry); return 0; } @@ -778,7 +767,7 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in *((sint32*)installed_entry_pointer) = chunk_size; installed_entry_pointer += 4; - uint8* chunk = RCT2_GLOBAL(RCT2_ADDRESS_CURR_OBJECT_CHUNK_POINTER, uint8*); // Loaded in object_load + uint8* chunk = (uint8*)gLastLoadedObjectChunkData; // Loaded in object_load load_object_filter(entry, chunk, filter); diff --git a/src/windows/editor_object_selection.c b/src/windows/editor_object_selection.c index 63ed78a400..c560ca0e62 100644 --- a/src/windows/editor_object_selection.c +++ b/src/windows/editor_object_selection.c @@ -321,14 +321,14 @@ static int visible_list_sort_ride_type(const void *rawA, const void *rawB) static void visible_list_refresh(rct_window *w) { - int numObjects = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, sint32); + int numObjects = gInstalledObjectsCount; visible_list_dispose(); _listItems = malloc(numObjects * sizeof(list_item)); _numListItems = 0; list_item *currentListItem = &_listItems[0]; - rct_object_entry *entry = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry *entry = gInstalledObjects; uint8 *itemFlags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); for (int i = 0; i < numObjects; i++) { rct_object_filters *filter = get_object_filter(i); @@ -436,10 +436,10 @@ void window_editor_object_selection_open() static void setup_track_manager_objects(){ uint8 ride_list[128] = { 0 }; uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; uint16 num_objects = 0; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ uint8 object_type = installedObject->flags & 0xF; if (object_type == OBJECT_TYPE_RIDE){ *selection_flags |= OBJECT_SELECTION_FLAG_6; @@ -503,10 +503,10 @@ static void setup_track_manager_objects(){ */ static void setup_track_designer_objects(){ uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; uint16 num_objects = 0; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ uint8 object_type = installedObject->flags & 0xF; if (object_type == OBJECT_TYPE_RIDE){ *selection_flags |= OBJECT_SELECTION_FLAG_6; @@ -640,9 +640,9 @@ static void setup_in_use_selection_flags(){ } uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ *selection_flags &= ~OBJECT_SELECTION_FLAG_IN_USE; uint8 entry_type, entry_index; @@ -666,7 +666,7 @@ static void setup_in_use_selection_flags(){ * rct2: 0x006AB211 */ static int sub_6AB211(){ - uint32 total_objects = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); + uint32 total_objects = gInstalledObjectsCount; RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*) = rct2_malloc(total_objects); @@ -681,9 +681,9 @@ static int sub_6AB211(){ RCT2_ADDRESS(0x00F433E1, uint16)[object_type] = 0; } - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ uint8 object_type = installedObject->flags & 0xF; RCT2_ADDRESS(0x00F433E1, uint16)[object_type]++; @@ -752,9 +752,9 @@ void remove_selected_objects_from_research(rct_object_entry* installedObject){ */ void unload_unselected_objects(){ uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ if (!(*selection_flags & OBJECT_SELECTION_FLAG_SELECTED)){ remove_selected_objects_from_research(installedObject); object_unload(installedObject); @@ -1577,9 +1577,9 @@ void reset_selected_object_count_and_size(){ uint32 total_object_size = 0; uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ uint8 object_type = installedObject->flags & 0xF; if (*selection_flags & OBJECT_SELECTION_FLAG_SELECTED){ @@ -1613,9 +1613,9 @@ void reset_selected_object_count_and_size(){ */ void set_required_object_flags(rct_object_entry* required_object){ uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ if (object_entry_compare(required_object, installedObject)){ *selection_flags |= OBJECT_SELECTION_FLAG_REQUIRED; @@ -1656,15 +1656,15 @@ void set_required_object_flags(rct_object_entry* required_object){ */ void reset_required_object_flags(){ uint8* selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ *selection_flags &= ~OBJECT_SELECTION_FLAG_REQUIRED; selection_flags++; } selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ if (*selection_flags & OBJECT_SELECTION_FLAG_SELECTED){ uint8* pos = (uint8*)installedObject; // Skip sizeof(rct_object_entry) @@ -1734,10 +1734,10 @@ static int window_editor_object_selection_select_object(uint8 bh, int flags, rct selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); // There was previously a check to make sure the object list had an item - rct_object_entry* installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry* installedObject = gInstalledObjects; uint8 not_found = 1; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i){ + for (int i = gInstalledObjectsCount; i > 0; --i){ if (object_entry_compare(entry, installedObject)){ not_found = 0; break; @@ -1971,12 +1971,12 @@ static void window_editor_object_selection_manage_tracks() static void editor_load_selected_objects() { uint8 *selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*); - rct_object_entry *installed_entry = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry *installed_entry = gInstalledObjects; - if (RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32) == 0) + if (gInstalledObjectsCount == 0) return; - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i != 0; i--, selection_flags++) { + for (int i = gInstalledObjectsCount; i != 0; i--, selection_flags++) { if (*selection_flags & OBJECT_SELECTION_FLAG_SELECTED) { uint8 entry_index, entry_type; if (!find_object_in_entry_group(installed_entry, &entry_type, &entry_index)){ @@ -2100,14 +2100,14 @@ static bool filter_chunks(rct_object_entry *entry, rct_object_filters *filter) static void filter_update_counts() { if (!_FILTER_ALL || strlen(_filter_string) > 0) { - rct_object_entry *installed_entry = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*); + rct_object_entry *installed_entry = gInstalledObjects; rct_object_filters *filter; uint8 type; for (int i = 0; i < 11; i++) { _filter_object_counts[i] = 0; } - for (int i = RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32); i > 0; --i) { - filter = get_object_filter(RCT2_GLOBAL(RCT2_ADDRESS_OBJECT_LIST_NO_ITEMS, uint32) - i); + for (int i = gInstalledObjectsCount; i > 0; --i) { + filter = get_object_filter(gInstalledObjectsCount - i); type = installed_entry->flags & 0xF; if (filter_source(installed_entry) && filter_string(installed_entry, filter) && filter_chunks(installed_entry, filter)) { _filter_object_counts[type]++; diff --git a/src/windows/options.c b/src/windows/options.c index 40b19f12c1..b8b3fadfb2 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -1390,7 +1390,7 @@ static void window_options_invalidate(rct_window *w) w->disabled_widgets |= (1ULL << WIDX_REAL_NAME_CHECKBOX); // save plugin data checkbox: visible or not - if (RCT2_GLOBAL(RCT2_ADDRESS_CUSTOM_OBJECTS_INSTALLED, uint8) == 1) + if (gNumInstalledCustomObjects == 0) window_options_misc_widgets[WIDX_SAVE_PLUGIN_DATA_CHECKBOX].type = WWT_EMPTY; else window_options_misc_widgets[WIDX_SAVE_PLUGIN_DATA_CHECKBOX].type = WWT_CHECKBOX;