mirror of https://github.com/OpenRCT2/OpenRCT2.git
do more cleanup of old object code
This commit is contained in:
parent
faf1f08b7f
commit
7124143b89
|
@ -118,7 +118,6 @@
|
|||
<ClCompile Include="src\network\NetworkUser.cpp" />
|
||||
<ClCompile Include="src\network\TcpSocket.cpp" />
|
||||
<ClCompile Include="src\network\twitch.cpp" />
|
||||
<ClCompile Include="src\object.c" />
|
||||
<ClCompile Include="src\object\BannerObject.cpp" />
|
||||
<ClCompile Include="src\object\EntranceObject.cpp" />
|
||||
<ClCompile Include="src\object\FootpathItemObject.cpp" />
|
||||
|
@ -605,4 +604,4 @@
|
|||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
</Project>
|
||||
</Project>
|
|
@ -322,129 +322,6 @@ static bool rct2_language_is_multibyte_charset(int languageId)
|
|||
}
|
||||
}
|
||||
|
||||
/* rct2: 0x006A9E24*/
|
||||
rct_string_id object_get_localised_text(uint8_t** pStringTable/*ebp*/, int type/*ecx*/, int index/*ebx*/, int tableindex/*edx*/)
|
||||
{
|
||||
uint8 languageId, chosenLanguageId;
|
||||
char *pString = nullptr;
|
||||
int result = 0;
|
||||
bool isBlank;
|
||||
|
||||
while ((languageId = *(*pStringTable)++) != RCT2_LANGUAGE_ID_END) {
|
||||
isBlank = true;
|
||||
|
||||
// Strings that are just ' ' are set as invalid langauges.
|
||||
// But if there is no real string then it will set the string as
|
||||
// the blank string
|
||||
for (char *ch = (char*)(*pStringTable); *ch != 0; ch++) {
|
||||
if (!isblank(*ch)) {
|
||||
isBlank = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlank) languageId = 0xFE;
|
||||
|
||||
// This is the ideal situation. Language found
|
||||
if (languageId == LanguagesDescriptors[gCurrentLanguage].rct2_original_id) {
|
||||
chosenLanguageId = languageId;
|
||||
pString = (char*)(*pStringTable);
|
||||
result |= 1;
|
||||
}
|
||||
|
||||
// Just in case always load english into pString
|
||||
if (languageId == RCT2_LANGUAGE_ID_ENGLISH_UK && !(result & 1)) {
|
||||
chosenLanguageId = languageId;
|
||||
pString = (char*)(*pStringTable);
|
||||
result |= 2;
|
||||
}
|
||||
|
||||
// Failing that fall back to whatever is first string
|
||||
if (!(result & 7)) {
|
||||
chosenLanguageId = languageId;
|
||||
pString = (char*)(*pStringTable);
|
||||
if (!isBlank) result |= 4;
|
||||
}
|
||||
|
||||
// Skip over the actual string entry to get to the next entry
|
||||
while (*(*pStringTable)++ != 0);
|
||||
}
|
||||
// Fall back in case language does not get set.
|
||||
if (pString == NULL)
|
||||
{
|
||||
pString = (char*)(*pStringTable);
|
||||
}
|
||||
|
||||
char name[9];
|
||||
if (RCT2_GLOBAL(0x009ADAFC, uint8) == 0) {
|
||||
memcpy(name, object_entry_groups[type].entries[index].name, 8);
|
||||
} else {
|
||||
memcpy(name, gTempObjectLoadName, 8);
|
||||
}
|
||||
name[8] = 0;
|
||||
|
||||
rct_string_id stringId = _languageCurrent->GetObjectOverrideStringId(name, tableindex);
|
||||
if (stringId != STR_NONE) {
|
||||
return stringId;
|
||||
}
|
||||
|
||||
// If not scenario text
|
||||
if (RCT2_GLOBAL(0x009ADAFC, uint8) == 0) {
|
||||
int stringid = NONSTEX_BASE_STRING_ID;
|
||||
for (int i = 0; i < type; i++) {
|
||||
int nrobjects = object_entry_group_counts[i];
|
||||
int nrstringtables = ObjectTypeStringTableCount[i];
|
||||
stringid += nrobjects * nrstringtables;
|
||||
}
|
||||
stringid += index * ObjectTypeStringTableCount[type];
|
||||
// Used by the object list to allocate name in plugin.dat
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CURR_OBJECT_BASE_STRING_ID, uint32) = stringid;
|
||||
stringid += tableindex;
|
||||
|
||||
// cache UTF-8 string
|
||||
int cacheStringOffset = stringid - STEX_BASE_STRING_ID;
|
||||
utf8 **cacheString = &_cachedObjectStrings[cacheStringOffset];
|
||||
if (*cacheString != nullptr) {
|
||||
free(*cacheString);
|
||||
}
|
||||
if (rct2_language_is_multibyte_charset(chosenLanguageId)) {
|
||||
*cacheString = convert_multibyte_charset(pString, chosenLanguageId);
|
||||
} else {
|
||||
*cacheString = win1252_to_utf8_alloc(pString);
|
||||
}
|
||||
utf8_trim_string(*cacheString);
|
||||
|
||||
//put pointer in stringtable
|
||||
_languageCurrent->SetString(stringid, *cacheString);
|
||||
// Until all string related functions are finished copy
|
||||
// to old array as well.
|
||||
_languageOriginal[stringid] = *cacheString;
|
||||
return stringid;
|
||||
} else {
|
||||
int stringid = STEX_BASE_STRING_ID + tableindex;
|
||||
|
||||
// cache UTF-8 string
|
||||
int cacheStringOffset = stringid - STEX_BASE_STRING_ID;
|
||||
utf8 **cacheString = &_cachedObjectStrings[cacheStringOffset];
|
||||
if (*cacheString != nullptr) {
|
||||
free(*cacheString);
|
||||
}
|
||||
if (rct2_language_is_multibyte_charset(chosenLanguageId)) {
|
||||
*cacheString = convert_multibyte_charset(pString, chosenLanguageId);
|
||||
} else {
|
||||
*cacheString = win1252_to_utf8_alloc(pString);
|
||||
}
|
||||
utf8_trim_string(*cacheString);
|
||||
|
||||
//put pointer in stringtable
|
||||
_languageCurrent->SetString(stringid, *cacheString);
|
||||
// Until all string related functions are finished copy
|
||||
// to old array as well.
|
||||
_languageOriginal[stringid] = *cacheString;
|
||||
return stringid;
|
||||
}
|
||||
}
|
||||
|
||||
bool language_get_localised_scenario_strings(const utf8 *scenarioFilename, rct_string_id *outStringIds)
|
||||
{
|
||||
outStringIds[0] = _languageCurrent->GetScenarioOverrideStringId(scenarioFilename, 0);
|
||||
|
|
|
@ -69,8 +69,6 @@ const char *language_get_string(rct_string_id id);
|
|||
bool language_open(int id);
|
||||
void language_close_all();
|
||||
|
||||
rct_string_id object_get_localised_text(uint8_t** pStringTable/*ebp*/, int type/*ecx*/, int index/*ebx*/, int tableindex/*edx*/);
|
||||
|
||||
uint32 utf8_get_next(const utf8 *char_ptr, const utf8 **nextchar_ptr);
|
||||
utf8 *utf8_write_codepoint(utf8 *dst, uint32 codepoint);
|
||||
int utf8_insert_codepoint(utf8 *dst, uint32 codepoint);
|
||||
|
|
92
src/object.c
92
src/object.c
|
@ -1,92 +0,0 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* A full copy of the GNU General Public License can be found in licence.txt
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "addresses.h"
|
||||
#include "config.h"
|
||||
#include "drawing/drawing.h"
|
||||
#include "localisation/localisation.h"
|
||||
#include "object.h"
|
||||
#include "object_list.h"
|
||||
#include "platform/platform.h"
|
||||
#include "rct1.h"
|
||||
#include "ride/ride.h"
|
||||
#include "scenario.h"
|
||||
#include "util/sawyercoding.h"
|
||||
#include "world/entrance.h"
|
||||
#include "world/footpath.h"
|
||||
#include "world/scenery.h"
|
||||
#include "world/water.h"
|
||||
|
||||
char gTempObjectLoadName[9] = { 0 };
|
||||
uint32 gTotalNoImages = 0;
|
||||
|
||||
int object_load_entry(const utf8 *path, rct_object_entry *outEntry)
|
||||
{
|
||||
SDL_RWops *file;
|
||||
|
||||
file = SDL_RWFromFile(path, "rb");
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
|
||||
if (SDL_RWread(file, outEntry, sizeof(rct_object_entry), 1) != 1) {
|
||||
SDL_RWclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_RWclose(file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int object_entry_compare(const rct_object_entry *a, const rct_object_entry *b)
|
||||
{
|
||||
// If an official object don't bother checking checksum
|
||||
if ((a->flags & 0xF0) || (b->flags & 0xF0)) {
|
||||
if ((a->flags & 0x0F) != (b->flags & 0x0F))
|
||||
return 0;
|
||||
int match = memcmp(a->name, b->name, 8);
|
||||
if (match)
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (a->flags != b->flags)
|
||||
return 0;
|
||||
int match = memcmp(a->name, b->name, 8);
|
||||
if (match)
|
||||
return 0;
|
||||
if (a->checksum != b->checksum)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int object_calculate_checksum(const rct_object_entry *entry, const uint8 *data, int dataLength)
|
||||
{
|
||||
const uint8 *entryBytePtr = (uint8*)entry;
|
||||
|
||||
uint32 checksum = 0xF369A75B;
|
||||
checksum ^= entryBytePtr[0];
|
||||
checksum = rol32(checksum, 11);
|
||||
for (int i = 4; i < 12; i++) {
|
||||
checksum ^= entryBytePtr[i];
|
||||
checksum = rol32(checksum, 11);
|
||||
}
|
||||
for (int i = 0; i < dataLength; i++) {
|
||||
checksum ^= data[i];
|
||||
checksum = rol32(checksum, 11);
|
||||
}
|
||||
return (int)checksum;
|
||||
}
|
|
@ -105,11 +105,7 @@ assert_struct_size(rct_object_filters, 3);
|
|||
#pragma pack(pop)
|
||||
|
||||
extern const rct_object_entry_group object_entry_groups[];
|
||||
extern char gTempObjectLoadName[9];
|
||||
|
||||
extern uint32 gTotalNoImages;
|
||||
|
||||
int object_load_entry(const utf8 *path, rct_object_entry *outEntry);
|
||||
void object_list_load();
|
||||
void set_load_objects_fail_reason();
|
||||
bool object_read_and_load_entries(SDL_RWops* rw);
|
||||
|
@ -120,8 +116,8 @@ void object_unload_all();
|
|||
|
||||
int check_object_entry(rct_object_entry *entry);
|
||||
bool object_load_chunk(int groupIndex, const rct_object_entry * entry, int * outGroupIndex);
|
||||
int object_entry_compare(const rct_object_entry *a, const rct_object_entry *b);
|
||||
int object_calculate_checksum(const rct_object_entry *entry, const uint8 *data, int dataLength);
|
||||
bool object_entry_compare(const rct_object_entry *a, const rct_object_entry *b);
|
||||
int object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength);
|
||||
void reset_loaded_objects();
|
||||
int find_object_in_entry_group(const rct_object_entry* entry, uint8* entry_type, uint8* entry_index);
|
||||
void object_create_identifier_name(char* string_buffer, const rct_object_entry* object);
|
||||
|
|
|
@ -640,8 +640,6 @@ extern "C"
|
|||
|
||||
void reset_loaded_objects()
|
||||
{
|
||||
gTotalNoImages = 0xF26E;
|
||||
|
||||
for (int i = 0; i < 721; i++)
|
||||
{
|
||||
Object * object = _loadedObjects[i];
|
||||
|
@ -881,4 +879,61 @@ extern "C"
|
|||
const Object * baseObject = (const Object *)object;
|
||||
baseObject->DrawPreview(dpi);
|
||||
}
|
||||
|
||||
bool object_entry_compare(const rct_object_entry * a, const rct_object_entry * b)
|
||||
{
|
||||
// If an official object don't bother checking checksum
|
||||
if ((a->flags & 0xF0) || (b->flags & 0xF0))
|
||||
{
|
||||
if ((a->flags & 0x0F) != (b->flags & 0x0F))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int match = memcmp(a->name, b->name, 8);
|
||||
if (match)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a->flags != b->flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int match = memcmp(a->name, b->name, 8);
|
||||
if (match)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (a->checksum != b->checksum)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength)
|
||||
{
|
||||
const uint8 *entryBytePtr = (uint8*)entry;
|
||||
|
||||
uint32 checksum = 0xF369A75B;
|
||||
checksum ^= entryBytePtr[0];
|
||||
checksum = rol32(checksum, 11);
|
||||
for (int i = 4; i < 12; i++)
|
||||
{
|
||||
checksum ^= entryBytePtr[i];
|
||||
checksum = rol32(checksum, 11);
|
||||
}
|
||||
|
||||
uint8 * dataBytes = (uint8 *)data;
|
||||
for (size_t i = 0; i < dataLength; i++)
|
||||
{
|
||||
checksum ^= dataBytes[i];
|
||||
checksum = rol32(checksum, 11);
|
||||
}
|
||||
|
||||
return (int)checksum;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -304,35 +304,6 @@ void RideObject::Load()
|
|||
vehicleEntry->peep_loading_positions = _peepLoadingPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
// 0x6DEB71
|
||||
if (RCT2_GLOBAL(0x9ADAFD, uint8) == 0)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
sint16 rideType = _legacyType.ride_type[i];
|
||||
if (rideType != RIDE_TYPE_NULL)
|
||||
{
|
||||
uint8 * typeToRideEntryIndexMap = gTypeToRideEntryIndexMap;
|
||||
while (rideType >= 0)
|
||||
{
|
||||
if (*typeToRideEntryIndexMap++ == 0xFF)
|
||||
{
|
||||
rideType--;
|
||||
}
|
||||
}
|
||||
|
||||
typeToRideEntryIndexMap--;
|
||||
uint8 previous_entry = 0; // TODO set this to entryIndex
|
||||
while (typeToRideEntryIndexMap < gTypeToRideEntryIndexMap + Util::CountOf(gTypeToRideEntryIndexMap))
|
||||
{
|
||||
uint8 backup_entry = *typeToRideEntryIndexMap;
|
||||
*typeToRideEntryIndexMap++ = previous_entry;
|
||||
previous_entry = backup_entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RideObject::Unload()
|
||||
|
|
|
@ -47,11 +47,8 @@ void WaterObject::Load()
|
|||
_legacyType.var_06 = _legacyType.image_id + 1;
|
||||
_legacyType.var_0A = _legacyType.image_id + 4;
|
||||
|
||||
if (RCT2_GLOBAL(0x009ADAFD, uint8) == 0)
|
||||
{
|
||||
load_palette();
|
||||
gfx_invalidate_screen();
|
||||
}
|
||||
load_palette();
|
||||
gfx_invalidate_screen();
|
||||
}
|
||||
|
||||
void WaterObject::Unload()
|
||||
|
|
Loading…
Reference in New Issue