From 463e88583d6b19400718a3493ee2f44b10775604 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 25 Jun 2016 02:52:58 +0100 Subject: [PATCH] prepare new object classes with EntranceObject --- openrct2.vcxproj | 8 ++++ src/object/EntranceObject.cpp | 29 +++++++++++++ src/object/EntranceObject.h | 38 ++++++++++++++++ src/object/ImageTable.cpp | 22 ++++++++++ src/object/ImageTable.h | 27 ++++++++++++ src/object/Object.cpp | 27 ++++++++++++ src/object/Object.h | 49 +++++++++++++++++++++ src/object/StringTable.cpp | 81 +++++++++++++++++++++++++++++++++++ src/object/StringTable.h | 41 ++++++++++++++++++ 9 files changed, 322 insertions(+) create mode 100644 src/object/EntranceObject.cpp create mode 100644 src/object/EntranceObject.h create mode 100644 src/object/ImageTable.cpp create mode 100644 src/object/ImageTable.h create mode 100644 src/object/Object.cpp create mode 100644 src/object/Object.h create mode 100644 src/object/StringTable.cpp create mode 100644 src/object/StringTable.h diff --git a/openrct2.vcxproj b/openrct2.vcxproj index aa51bb272c..9fec386430 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -117,7 +117,11 @@ + + + + @@ -418,7 +422,11 @@ + + + + diff --git a/src/object/EntranceObject.cpp b/src/object/EntranceObject.cpp new file mode 100644 index 0000000000..8a95e905d3 --- /dev/null +++ b/src/object/EntranceObject.cpp @@ -0,0 +1,29 @@ +#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 "../core/IStream.hpp" +#include "EntranceObject.h" + +void EntranceObject::Load(IStream * stream) +{ + _legacyType.string_idx = stream->ReadValue(); + _legacyType.image_id = stream->ReadValue(); + _legacyType.scrolling_mode = stream->ReadValue(); + _legacyType.text_height = stream->ReadValue(); + + LoadStringTable(stream, 0); + LoadImageTable(stream); +} diff --git a/src/object/EntranceObject.h b/src/object/EntranceObject.h new file mode 100644 index 0000000000..608cbe788a --- /dev/null +++ b/src/object/EntranceObject.h @@ -0,0 +1,38 @@ +#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 + +#pragma once + +#include "Object.h" + +extern "C" +{ + #include "../world/entrance.h" +} + +class EntranceObject : public Object +{ +private: + rct_object_entry _objectEntry; + rct_entrance_type _legacyType; + +public: + const rct_object_entry * GetObjectEntry() override { return &_objectEntry; } + void * GetLegacyData() override { return &_legacyType; } + +protected: + void Load(IStream * stream) override; +}; diff --git a/src/object/ImageTable.cpp b/src/object/ImageTable.cpp new file mode 100644 index 0000000000..9a20b42abc --- /dev/null +++ b/src/object/ImageTable.cpp @@ -0,0 +1,22 @@ +#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 "ImageTable.h" + +void ImageTable::Read(IStream * stream) +{ + // TODO +} diff --git a/src/object/ImageTable.h b/src/object/ImageTable.h new file mode 100644 index 0000000000..30cf7ae5d6 --- /dev/null +++ b/src/object/ImageTable.h @@ -0,0 +1,27 @@ +#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 + +#pragma once + +#include "../common.h" + +interface IStream; + +class ImageTable +{ +public: + void Read(IStream * stream); +}; \ No newline at end of file diff --git a/src/object/Object.cpp b/src/object/Object.cpp new file mode 100644 index 0000000000..e758e2e1c1 --- /dev/null +++ b/src/object/Object.cpp @@ -0,0 +1,27 @@ +#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 "Object.h" + +void Object::LoadStringTable(IStream * stream, uint8 id) +{ + _stringTable.Read(stream, id); +} + +void Object::LoadImageTable(IStream * stream) +{ + _imageTable.Read(stream); +} diff --git a/src/object/Object.h b/src/object/Object.h new file mode 100644 index 0000000000..00c85cf5f9 --- /dev/null +++ b/src/object/Object.h @@ -0,0 +1,49 @@ +#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 + +#pragma once + +#include "../common.h" +#include "ImageTable.h" +#include "StringTable.h" + +extern "C" +{ + #include "../object.h" +} + +interface IStream; + +class Object +{ +private: + StringTable _stringTable; + ImageTable _imageTable; + +public: + virtual ~Object() { } + + // Legacy data structures + virtual const rct_object_entry * GetObjectEntry() abstract; + virtual void * GetLegacyData() abstract; + +protected: + virtual void Load(IStream * stream) abstract; + virtual void Unload() abstract; + + void LoadStringTable(IStream * stream, uint8 id); + void LoadImageTable(IStream * stream); +}; diff --git a/src/object/StringTable.cpp b/src/object/StringTable.cpp new file mode 100644 index 0000000000..578dc28bc4 --- /dev/null +++ b/src/object/StringTable.cpp @@ -0,0 +1,81 @@ +#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 +#include "../core/IStream.hpp" +#include "../core/String.hpp" +#include "../localisation/LanguagePack.h" +#include "StringTable.h" + +constexpr uint8 RCT2_LANGUAGE_ID_ENGLISH_UK = 0; +constexpr uint8 RCT2_LANGUAGE_ID_BLANK = 254; +constexpr uint8 RCT2_LANGUAGE_ID_END = 255; + +bool StringIsBlank(utf8 * str) +{ + for (utf8 * ch = str; *ch != '\0'; ch++) + { + if (!isblank(*ch)) + { + return false; + } + } + return true; +} + +void StringTable::Read(IStream * stream, uint8 id) +{ + uint8 languageId; + while ((languageId = stream->ReadValue()) != RCT2_LANGUAGE_ID_END) + { + StringTableEntry entry; + entry.Id = id; + entry.LanguageId = languageId; + entry.Text = stream->ReadString(); + + if (StringIsBlank(entry.Text)) + { + entry.LanguageId = RCT2_LANGUAGE_ID_BLANK; + } + + _strings.push_back(entry); + } + Sort(); +} + +void StringTable::Sort() +{ + std::sort(_strings.begin(), _strings.end(), [](const StringTableEntry &a, const StringTableEntry &b) -> int + { + if (a.Id == b.Id) + { + if (a.LanguageId == b.LanguageId) + { + return _strcmpi(a.Text, b.Text); + } + if (a.LanguageId == LanguagesDescriptors[gCurrentLanguage].rct2_original_id) + { + return -1; + } + if (a.LanguageId == RCT2_LANGUAGE_ID_ENGLISH_UK) + { + return -1; + } + return 1; + } + return a.Id - b.Id; + }); +} diff --git a/src/object/StringTable.h b/src/object/StringTable.h new file mode 100644 index 0000000000..4b14755d8a --- /dev/null +++ b/src/object/StringTable.h @@ -0,0 +1,41 @@ +#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 + +#pragma once + +#include +#include "../common.h" + +interface IStream; + +struct StringTableEntry +{ + uint8 Id; + uint8 LanguageId; + utf8 * Text; +}; + +class StringTable +{ +private: + std::vector _strings; + +public: + void Read(IStream * stream, uint8 id); + +private: + void Sort(); +}; \ No newline at end of file