mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Merge pull request #4425 from IntelOrca/refactor/misc
Remove List and refactor S4Importer
This commit is contained in:
@@ -557,7 +557,6 @@
|
||||
D44270EA1CC81B3200D84D28 /* IStream.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = IStream.hpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
D44270EB1CC81B3200D84D28 /* Json.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Json.cpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
D44270EC1CC81B3200D84D28 /* Json.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Json.hpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
D44270ED1CC81B3200D84D28 /* List.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = List.hpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
D44270EE1CC81B3200D84D28 /* Math.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Math.hpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
D44270EF1CC81B3200D84D28 /* Memory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Memory.hpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
D44270F01CC81B3200D84D28 /* Path.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Path.cpp; sourceTree = "<group>"; usesTabs = 0; };
|
||||
@@ -1369,7 +1368,6 @@
|
||||
D44270EA1CC81B3200D84D28 /* IStream.hpp */,
|
||||
D44270EB1CC81B3200D84D28 /* Json.cpp */,
|
||||
D44270EC1CC81B3200D84D28 /* Json.hpp */,
|
||||
D44270ED1CC81B3200D84D28 /* List.hpp */,
|
||||
D44270EE1CC81B3200D84D28 /* Math.hpp */,
|
||||
D44270EF1CC81B3200D84D28 /* Memory.hpp */,
|
||||
D464FEBC1D31A66E00CBABAC /* MemoryStream.cpp */,
|
||||
|
||||
@@ -363,6 +363,7 @@
|
||||
<ClInclude Include="src\cmdline_sprite.h" />
|
||||
<ClInclude Include="src\common.h" />
|
||||
<ClInclude Include="src\config.h" />
|
||||
<ClInclude Include="src\core\Collections.hpp" />
|
||||
<ClInclude Include="src\core\Console.hpp" />
|
||||
<ClInclude Include="src\core\Diagnostics.hpp" />
|
||||
<ClInclude Include="src\core\Exception.hpp" />
|
||||
@@ -371,7 +372,6 @@
|
||||
<ClInclude Include="src\core\Guard.hpp" />
|
||||
<ClInclude Include="src\core\IStream.hpp" />
|
||||
<ClInclude Include="src\core\Json.hpp" />
|
||||
<ClInclude Include="src\core\List.hpp" />
|
||||
<ClInclude Include="src\core\Math.hpp" />
|
||||
<ClInclude Include="src\core\Memory.hpp" />
|
||||
<ClInclude Include="src\core\MemoryStream.h" />
|
||||
|
||||
104
src/core/Collections.hpp
Normal file
104
src/core/Collections.hpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#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 <initializer_list>
|
||||
#include "../common.h"
|
||||
#include "String.hpp"
|
||||
|
||||
namespace Collections
|
||||
{
|
||||
template<typename TCollection, typename TItem>
|
||||
void AddRange(TCollection &collection, std::initializer_list<TItem> initializerList)
|
||||
{
|
||||
collection.insert(collection.end(), initializerList.begin(), initializerList.end());
|
||||
}
|
||||
|
||||
template<typename TCollection, typename TItem, typename TComparer>
|
||||
bool Contains(TCollection &collection, TItem needle, TComparer comparer)
|
||||
{
|
||||
for (TItem item : collection)
|
||||
{
|
||||
if (comparer(item, needle))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename TCollection, typename TItem, typename TComparer>
|
||||
size_t IndexOf(TCollection &collection, TItem needle, TComparer comparer)
|
||||
{
|
||||
size_t index = 0;
|
||||
for (TItem item : collection)
|
||||
{
|
||||
if (comparer(item, needle))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
#pragma region String helpers
|
||||
|
||||
template<typename TCollection>
|
||||
bool Contains(TCollection &collection, const char * item, bool ignoreCase = false)
|
||||
{
|
||||
if (ignoreCase)
|
||||
{
|
||||
return Contains(collection, item,
|
||||
[](const char * a, const char * b)
|
||||
{
|
||||
return String::Equals(a, b, true);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return Contains(collection, item,
|
||||
[](const char * a, const char * b)
|
||||
{
|
||||
return String::Equals(a, b, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TCollection>
|
||||
size_t IndexOf(TCollection &collection, const char * item, bool ignoreCase = false)
|
||||
{
|
||||
if (ignoreCase)
|
||||
{
|
||||
return IndexOf(collection, item,
|
||||
[](const char * a, const char * b)
|
||||
{
|
||||
return String::Equals(a, b, true);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return IndexOf(collection, item,
|
||||
[](const char * a, const char * b)
|
||||
{
|
||||
return String::Equals(a, b, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
}
|
||||
@@ -1,150 +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
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "../common.h"
|
||||
#include "Guard.hpp"
|
||||
#include "Memory.hpp"
|
||||
|
||||
/**
|
||||
* A container that stores elements in contiguous memory. Automatically reallocates memory when required. Equivalent to
|
||||
* std::vector.
|
||||
*/
|
||||
template<typename T>
|
||||
class List : public std::vector<T>
|
||||
{
|
||||
public:
|
||||
typedef typename std::vector<T>::const_reference const_reference;
|
||||
typedef typename std::vector<T>::reference reference;
|
||||
size_t GetCapacity() const { return this->capacity(); }
|
||||
size_t GetCount() const { return this->size(); }
|
||||
const T * GetItems() const { return this->data(); }
|
||||
|
||||
List() : std::vector<T>() { }
|
||||
|
||||
List(std::initializer_list<T> initializerList) : std::vector<T>(initializerList) { }
|
||||
|
||||
List(size_t capacity) : std::vector<T>(capacity) { }
|
||||
|
||||
List(const T * items, size_t count) : std::vector<T>(items, items + count) { }
|
||||
|
||||
void EnsureCapacity(size_t capacity)
|
||||
{
|
||||
this->reserve(capacity);
|
||||
}
|
||||
|
||||
void ShrinkToLength()
|
||||
{
|
||||
this->shrink_to_fit();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void Add(T item)
|
||||
{
|
||||
this->push_back(item);
|
||||
}
|
||||
|
||||
void AddRange(std::initializer_list<T> initializerList)
|
||||
{
|
||||
this->insert(this->end(), initializerList.begin(), initializerList.end());
|
||||
}
|
||||
|
||||
void Insert(T item, size_t index)
|
||||
{
|
||||
Guard::ArgumentInRange(index, (size_t)0, this->size(), GUARD_LINE);
|
||||
this->insert(this->begin() + index, item);
|
||||
}
|
||||
|
||||
bool Remove(T item)
|
||||
{
|
||||
for (size_t i = 0; i < this->size(); i++)
|
||||
{
|
||||
if (*this[i] == item)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RemoveAt(size_t index)
|
||||
{
|
||||
Guard::ArgumentInRange(index, (size_t)0, this->size() - 1, GUARD_LINE);
|
||||
this->erase(this->begin() + index);
|
||||
}
|
||||
|
||||
const T * ToArray() const
|
||||
{
|
||||
return Memory::DuplicateArray(this->data(), this->size());
|
||||
}
|
||||
|
||||
const_reference operator[](size_t index) const
|
||||
{
|
||||
Guard::ArgumentInRange(index, (size_t)0, this->size() - 1, GUARD_LINE);
|
||||
return std::vector<T>::operator[](index);
|
||||
}
|
||||
|
||||
reference operator[](size_t index)
|
||||
{
|
||||
Guard::ArgumentInRange(index, (size_t)0, this->size() - 1, GUARD_LINE);
|
||||
return std::vector<T>::operator[](index);
|
||||
}
|
||||
|
||||
size_t IndexOf(std::function<bool(T)> predicate)
|
||||
{
|
||||
for (size_t i = 0; i < this->size(); i++)
|
||||
{
|
||||
T item = std::vector<T>::operator[](i);
|
||||
if (predicate(item))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
size_t IndexOf(T item, std::function<bool(T, T)> comparer)
|
||||
{
|
||||
for (size_t i = 0; i < this->size(); i++)
|
||||
{
|
||||
T element = std::vector<T>::operator[](i);
|
||||
if (comparer(item, element))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
bool Contains(std::function<bool(T)> predicate)
|
||||
{
|
||||
return IndexOf(predicate) != SIZE_MAX;
|
||||
}
|
||||
|
||||
bool Contains(T item, std::function<bool(T, T)> comparer)
|
||||
{
|
||||
return IndexOf(item, comparer) != SIZE_MAX;
|
||||
}
|
||||
};
|
||||
@@ -14,6 +14,7 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <vector>
|
||||
#include <jansson.h>
|
||||
|
||||
extern "C"
|
||||
@@ -25,7 +26,6 @@ extern "C"
|
||||
}
|
||||
|
||||
#include "../core/Json.hpp"
|
||||
#include "../core/List.hpp"
|
||||
#include "../core/Math.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
@@ -65,9 +65,9 @@ struct UIThemeWindowEntry
|
||||
class UITheme
|
||||
{
|
||||
public:
|
||||
utf8 * Name;
|
||||
List<UIThemeWindowEntry> Entries;
|
||||
uint8 Flags;
|
||||
utf8 * Name;
|
||||
std::vector<UIThemeWindowEntry> Entries;
|
||||
uint8 Flags;
|
||||
|
||||
UITheme(const utf8 * name);
|
||||
UITheme(const UITheme & copy);
|
||||
@@ -323,7 +323,7 @@ void UITheme::SetName(const utf8 * name)
|
||||
|
||||
const UIThemeWindowEntry * UITheme::GetEntry(rct_windowclass windowClass) const
|
||||
{
|
||||
for (size_t i = 0; i < Entries.GetCount(); i++)
|
||||
for (size_t i = 0; i < Entries.size(); i++)
|
||||
{
|
||||
const UIThemeWindowEntry * entry = &Entries[i];
|
||||
if (entry->WindowClass == windowClass)
|
||||
@@ -337,7 +337,7 @@ const UIThemeWindowEntry * UITheme::GetEntry(rct_windowclass windowClass) const
|
||||
void UITheme::SetEntry(const UIThemeWindowEntry * newEntry)
|
||||
{
|
||||
// Try to replace existing entry
|
||||
for (size_t i = 0; i < Entries.GetCount(); i++)
|
||||
for (size_t i = 0; i < Entries.size(); i++)
|
||||
{
|
||||
UIThemeWindowEntry * entry = &Entries[i];
|
||||
if (entry->WindowClass == newEntry->WindowClass)
|
||||
@@ -347,18 +347,18 @@ void UITheme::SetEntry(const UIThemeWindowEntry * newEntry)
|
||||
}
|
||||
}
|
||||
|
||||
Entries.Add(*newEntry);
|
||||
Entries.push_back(*newEntry);
|
||||
}
|
||||
|
||||
void UITheme::RemoveEntry(rct_windowclass windowClass)
|
||||
{
|
||||
// Remove existing entry
|
||||
for (size_t i = 0; i < Entries.GetCount(); i++)
|
||||
for (size_t i = 0; i < Entries.size(); i++)
|
||||
{
|
||||
UIThemeWindowEntry * entry = &Entries[i];
|
||||
if (entry->WindowClass == windowClass)
|
||||
{
|
||||
Entries.RemoveAt(i);
|
||||
Entries.erase(Entries.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -485,7 +485,7 @@ UITheme UITheme::CreatePredefined(const utf8 * name, const UIThemeWindowEntry *
|
||||
numEntries++;
|
||||
}
|
||||
|
||||
theme.Entries = List<UIThemeWindowEntry>(entries, numEntries);
|
||||
theme.Entries = std::vector<UIThemeWindowEntry>(entries, entries + numEntries);
|
||||
return theme;
|
||||
}
|
||||
|
||||
@@ -499,21 +499,21 @@ namespace ThemeManager
|
||||
utf8 Name[96];
|
||||
};
|
||||
|
||||
utf8 * CurrentThemePath;
|
||||
UITheme * CurrentTheme;
|
||||
List<AvailableTheme> AvailableThemes;
|
||||
size_t ActiveAvailableThemeIndex = SIZE_MAX;
|
||||
size_t NumPredefinedThemes = 0;
|
||||
utf8 * CurrentThemePath;
|
||||
UITheme * CurrentTheme;
|
||||
std::vector<AvailableTheme> AvailableThemes;
|
||||
size_t ActiveAvailableThemeIndex = SIZE_MAX;
|
||||
size_t NumPredefinedThemes = 0;
|
||||
|
||||
void GetThemeFileName(utf8 * buffer, size_t bufferSize, const utf8 * name);
|
||||
bool EnsureThemeDirectoryExists();
|
||||
void GetThemePath(utf8 * buffer, size_t bufferSize);
|
||||
|
||||
static void GetAvailableThemes(List<AvailableTheme> * outThemes)
|
||||
static void GetAvailableThemes(std::vector<AvailableTheme> * outThemes)
|
||||
{
|
||||
Guard::ArgumentNotNull(outThemes, GUARD_LINE);
|
||||
|
||||
outThemes->Clear();
|
||||
outThemes->clear();
|
||||
|
||||
NumPredefinedThemes = 0;
|
||||
for (const UITheme * * predefinedTheme = PredefinedThemes; *predefinedTheme != nullptr; predefinedTheme++)
|
||||
@@ -521,7 +521,7 @@ namespace ThemeManager
|
||||
AvailableTheme theme;
|
||||
String::Set(theme.Path, sizeof(theme.Path), String::Empty);
|
||||
String::Set(theme.Name, sizeof(theme.Name), (*predefinedTheme)->Name);
|
||||
outThemes->Add(theme);
|
||||
outThemes->push_back(theme);
|
||||
|
||||
NumPredefinedThemes++;
|
||||
}
|
||||
@@ -540,11 +540,11 @@ namespace ThemeManager
|
||||
Path::GetFileNameWithoutExtension(theme.Name, sizeof(theme.Name), fileInfo.path);
|
||||
GetThemeFileName(theme.Path, sizeof(theme.Path), theme.Name);
|
||||
|
||||
outThemes->Add(theme);
|
||||
outThemes->push_back(theme);
|
||||
|
||||
if (Path::Equals(CurrentThemePath, fileInfo.path))
|
||||
{
|
||||
ActiveAvailableThemeIndex = outThemes->GetCount() - 1;
|
||||
ActiveAvailableThemeIndex = outThemes->size() - 1;
|
||||
}
|
||||
}
|
||||
platform_enumerate_files_end(handle);
|
||||
@@ -590,7 +590,7 @@ namespace ThemeManager
|
||||
|
||||
static bool LoadThemeByName(const utf8 * name)
|
||||
{
|
||||
for (size_t i = 0; i < ThemeManager::AvailableThemes.GetCount(); i++)
|
||||
for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++)
|
||||
{
|
||||
if (String::Equals(name, ThemeManager::AvailableThemes[i].Name))
|
||||
{
|
||||
@@ -660,7 +660,7 @@ extern "C"
|
||||
|
||||
size_t theme_manager_get_num_available_themes()
|
||||
{
|
||||
return ThemeManager::AvailableThemes.GetCount();
|
||||
return ThemeManager::AvailableThemes.size();
|
||||
}
|
||||
|
||||
const utf8 * theme_manager_get_available_theme_path(size_t index)
|
||||
@@ -766,7 +766,7 @@ extern "C"
|
||||
ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath);
|
||||
|
||||
theme_manager_load_available_themes();
|
||||
for (size_t i = 0; i < ThemeManager::AvailableThemes.GetCount(); i++)
|
||||
for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++)
|
||||
{
|
||||
if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path))
|
||||
{
|
||||
@@ -794,7 +794,7 @@ extern "C"
|
||||
ThemeManager::LoadTheme(newPath);
|
||||
|
||||
theme_manager_load_available_themes();
|
||||
for (size_t i = 0; i < ThemeManager::AvailableThemes.GetCount(); i++)
|
||||
for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++)
|
||||
{
|
||||
if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path))
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#error HTTP must be enabled to use the TWITCH functionality.
|
||||
#endif
|
||||
|
||||
#include "../core/List.hpp"
|
||||
#include <vector>
|
||||
#include "../core/Math.hpp"
|
||||
#include "../core/String.hpp"
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Twitch
|
||||
static void ParseMessages();
|
||||
static bool ShouldTrackMember(const AudienceMember * member);
|
||||
static bool ShouldMemberBeGuest(const AudienceMember * member);
|
||||
static void ManageGuestNames(List<AudienceMember> &members);
|
||||
static void ManageGuestNames(std::vector<AudienceMember> &members);
|
||||
static void ParseChatMessage(const char * message);
|
||||
static void DoChatMessageNews(const char * message);
|
||||
|
||||
@@ -328,7 +328,7 @@ namespace Twitch
|
||||
http_json_response *jsonResponse = _twitchJsonResponse;
|
||||
if (json_is_array(jsonResponse->root))
|
||||
{
|
||||
List<AudienceMember> members;
|
||||
std::vector<AudienceMember> members;
|
||||
|
||||
size_t audienceCount = json_array_size(jsonResponse->root);
|
||||
for (size_t i = 0; i < audienceCount; i++)
|
||||
@@ -340,7 +340,7 @@ namespace Twitch
|
||||
member.ShouldTrack = ShouldTrackMember(&member);
|
||||
if (ShouldMemberBeGuest(&member))
|
||||
{
|
||||
members.Add(member);
|
||||
members.push_back(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,7 +405,7 @@ namespace Twitch
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ManageGuestNames(List<AudienceMember> &members)
|
||||
static void ManageGuestNames(std::vector<AudienceMember> &members)
|
||||
{
|
||||
// Check what followers are already in the park
|
||||
uint16 spriteIndex;
|
||||
@@ -462,13 +462,13 @@ namespace Twitch
|
||||
}
|
||||
|
||||
// Rename non-named peeps to followers that aren't currently in the park.
|
||||
if (members.GetCount() > 0)
|
||||
if (members.size() > 0)
|
||||
{
|
||||
size_t memberIndex = SIZE_MAX;
|
||||
FOR_ALL_GUESTS(spriteIndex, peep)
|
||||
{
|
||||
size_t originalMemberIndex = memberIndex;
|
||||
for (size_t i = memberIndex + 1; i < members.GetCount(); i++)
|
||||
for (size_t i = memberIndex + 1; i < members.size(); i++)
|
||||
{
|
||||
if (!members[i].Exists)
|
||||
{
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <vector>
|
||||
#include "../core/Collections.hpp"
|
||||
#include "../core/Console.hpp"
|
||||
#include "../core/Exception.hpp"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../core/List.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../core/Util.hpp"
|
||||
@@ -51,10 +53,38 @@ extern "C"
|
||||
#include "../ride/ride_data.h"
|
||||
}
|
||||
|
||||
static bool ObjectNameComparer(const char * a, const char * b)
|
||||
class EntryList
|
||||
{
|
||||
return String::Equals(a, b, true);
|
||||
}
|
||||
private:
|
||||
std::vector<const char *> _entries;
|
||||
|
||||
public:
|
||||
size_t GetCount() const
|
||||
{
|
||||
return _entries.size();
|
||||
}
|
||||
|
||||
const std::vector<const char *> & GetEntries() const
|
||||
{
|
||||
return _entries;
|
||||
}
|
||||
|
||||
size_t GetOrAddEntry(const char * entryName)
|
||||
{
|
||||
size_t entryIndex = Collections::IndexOf(_entries, entryName, true);
|
||||
if (entryIndex == SIZE_MAX)
|
||||
{
|
||||
entryIndex = _entries.size();
|
||||
_entries.push_back(entryName);
|
||||
}
|
||||
return entryIndex;
|
||||
}
|
||||
|
||||
void AddRange(std::initializer_list<const char *> initializerList)
|
||||
{
|
||||
Collections::AddRange(_entries, initializerList);
|
||||
}
|
||||
};
|
||||
|
||||
class S4Importer : public IS4Importer
|
||||
{
|
||||
@@ -64,13 +94,13 @@ private:
|
||||
uint8 _gameVersion;
|
||||
|
||||
// Lists of dynamic object entries
|
||||
List<const char *> _rideEntries;
|
||||
List<const char *> _smallSceneryEntries;
|
||||
List<const char *> _largeSceneryEntries;
|
||||
List<const char *> _wallEntries;
|
||||
List<const char *> _pathEntries;
|
||||
List<const char *> _pathAdditionEntries;
|
||||
List<const char *> _sceneryGroupEntries;
|
||||
EntryList _rideEntries;
|
||||
EntryList _smallSceneryEntries;
|
||||
EntryList _largeSceneryEntries;
|
||||
EntryList _wallEntries;
|
||||
EntryList _pathEntries;
|
||||
EntryList _pathAdditionEntries;
|
||||
EntryList _sceneryGroupEntries;
|
||||
|
||||
// Lookup tables for converting from RCT1 hard coded types to the new dynamic object entries
|
||||
uint8 _rideTypeToRideEntryMap[96];
|
||||
@@ -335,7 +365,7 @@ private:
|
||||
if (sceneryTheme != 0 &&
|
||||
_sceneryThemeTypeToEntryMap[sceneryTheme] == 255) continue;
|
||||
|
||||
List<const char *> objects = RCT1::GetSceneryObjects(sceneryTheme);
|
||||
std::vector<const char *> objects = RCT1::GetSceneryObjects(sceneryTheme);
|
||||
for (const char * objectName : objects)
|
||||
{
|
||||
rct_object_entry * foundEntry = object_list_find_by_name(objectName);
|
||||
@@ -349,17 +379,13 @@ private:
|
||||
case OBJECT_TYPE_PATHS:
|
||||
case OBJECT_TYPE_PATH_BITS:
|
||||
{
|
||||
List<const char *> * entries = GetEntryList(objectType);
|
||||
EntryList * entries = GetEntryList(objectType);
|
||||
|
||||
// Ran out of available entries
|
||||
if (entries->GetCount() >= (size_t)object_entry_group_counts[objectType])
|
||||
// Check if there are spare entries available
|
||||
size_t maxEntries = (size_t)object_entry_group_counts[objectType];
|
||||
if (entries->GetCount() < maxEntries)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!entries->Contains(objectName, ObjectNameComparer))
|
||||
{
|
||||
entries->Add(objectName);
|
||||
entries->GetOrAddEntry(objectName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -375,13 +401,8 @@ private:
|
||||
if (_rideTypeToRideEntryMap[rideType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetRideTypeObject(rideType);
|
||||
size_t entryIndex = _rideEntries.GetOrAddEntry(entryName);
|
||||
|
||||
size_t entryIndex = _rideEntries.IndexOf(entryName, ObjectNameComparer);
|
||||
if (entryIndex == SIZE_MAX)
|
||||
{
|
||||
entryIndex = _rideEntries.GetCount();
|
||||
_rideEntries.Add(entryName);
|
||||
}
|
||||
_rideTypeToRideEntryMap[rideType] = (uint8)entryIndex;
|
||||
}
|
||||
}
|
||||
@@ -392,13 +413,8 @@ private:
|
||||
if (_vehicleTypeToRideEntryMap[vehicleType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetVehicleObject(vehicleType);
|
||||
size_t entryIndex = _rideEntries.GetOrAddEntry(entryName);
|
||||
|
||||
size_t entryIndex = _rideEntries.IndexOf(entryName, ObjectNameComparer);
|
||||
if (entryIndex == SIZE_MAX)
|
||||
{
|
||||
entryIndex = _rideEntries.GetCount();
|
||||
_rideEntries.Add(entryName);
|
||||
}
|
||||
_vehicleTypeToRideEntryMap[vehicleType] = (uint8)entryIndex;
|
||||
_rideTypeToRideEntryMap[rideType] = (uint8)entryIndex;
|
||||
}
|
||||
@@ -410,8 +426,9 @@ private:
|
||||
if (_smallSceneryTypeToEntryMap[smallSceneryType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetSmallSceneryObject(smallSceneryType);
|
||||
_smallSceneryTypeToEntryMap[smallSceneryType] = (uint8)_smallSceneryEntries.GetCount();
|
||||
_smallSceneryEntries.Add(entryName);
|
||||
size_t entryIndex = _smallSceneryEntries.GetOrAddEntry(entryName);
|
||||
|
||||
_smallSceneryTypeToEntryMap[smallSceneryType] = (uint8)entryIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,8 +438,9 @@ private:
|
||||
if (_largeSceneryTypeToEntryMap[largeSceneryType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetLargeSceneryObject(largeSceneryType);
|
||||
_largeSceneryTypeToEntryMap[largeSceneryType] = (uint8)_largeSceneryEntries.GetCount();
|
||||
_largeSceneryEntries.Add(entryName);
|
||||
size_t entryIndex = _largeSceneryEntries.GetOrAddEntry(entryName);
|
||||
|
||||
_largeSceneryTypeToEntryMap[largeSceneryType] = (uint8)entryIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,8 +450,9 @@ private:
|
||||
if (_wallTypeToEntryMap[wallType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetWallObject(wallType);
|
||||
_wallTypeToEntryMap[wallType] = (uint8)_wallEntries.GetCount();
|
||||
_wallEntries.Add(entryName);
|
||||
size_t entryIndex = _wallEntries.GetOrAddEntry(entryName);
|
||||
|
||||
_wallTypeToEntryMap[wallType] = (uint8)entryIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,17 +462,9 @@ private:
|
||||
if (_pathTypeToEntryMap[pathType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetPathObject(pathType);
|
||||
size_t entryIndex = _pathEntries.GetOrAddEntry(entryName);
|
||||
|
||||
size_t index = _pathEntries.IndexOf(entryName, ObjectNameComparer);
|
||||
if (index != SIZE_MAX)
|
||||
{
|
||||
_pathTypeToEntryMap[pathType] = (uint8)index;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pathTypeToEntryMap[pathType] = (uint8)_pathEntries.GetCount();
|
||||
_pathEntries.Add(entryName);
|
||||
}
|
||||
_pathTypeToEntryMap[pathType] = (uint8)entryIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,8 +478,9 @@ private:
|
||||
if (_pathAdditionTypeToEntryMap[normalisedPathAdditionType] == 255)
|
||||
{
|
||||
const char * entryName = RCT1::GetPathAddtionObject(normalisedPathAdditionType);
|
||||
_pathAdditionTypeToEntryMap[normalisedPathAdditionType] = (uint8)_pathAdditionEntries.GetCount();
|
||||
_pathAdditionEntries.Add(entryName);
|
||||
size_t entryIndex = _pathAdditionEntries.GetOrAddEntry(entryName);
|
||||
|
||||
_pathAdditionTypeToEntryMap[normalisedPathAdditionType] = (uint8)entryIndex;
|
||||
}
|
||||
|
||||
_pathAdditionTypeToEntryMap[pathAdditionType] = _pathAdditionTypeToEntryMap[normalisedPathAdditionType];
|
||||
@@ -486,16 +498,15 @@ private:
|
||||
else
|
||||
{
|
||||
const char * entryName = RCT1::GetSceneryGroupObject(sceneryThemeType);
|
||||
uint8 entryIndex = (uint8)_sceneryGroupEntries.GetCount();
|
||||
if (entryIndex >= 19)
|
||||
if (_sceneryGroupEntries.GetCount() >= 19)
|
||||
{
|
||||
Console::WriteLine("Warning: More than 19 (max scenery groups) in RCT1 park.");
|
||||
Console::WriteLine(" [%s] scenery group not added.", entryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sceneryThemeTypeToEntryMap[sceneryThemeType] = (uint8)_sceneryGroupEntries.GetCount();
|
||||
_sceneryGroupEntries.Add(entryName);
|
||||
size_t entryIndex = _sceneryGroupEntries.GetOrAddEntry(entryName);
|
||||
_sceneryThemeTypeToEntryMap[sceneryThemeType] = (uint8)entryIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -779,7 +790,7 @@ private:
|
||||
LoadObjects(OBJECT_TYPE_PATHS, _pathEntries);
|
||||
LoadObjects(OBJECT_TYPE_PATH_BITS, _pathAdditionEntries);
|
||||
LoadObjects(OBJECT_TYPE_SCENERY_SETS, _sceneryGroupEntries);
|
||||
LoadObjects(OBJECT_TYPE_BANNERS, List<const char *>({
|
||||
LoadObjects(OBJECT_TYPE_BANNERS, std::vector<const char *>({
|
||||
"BN1 ",
|
||||
"BN2 ",
|
||||
"BN3 ",
|
||||
@@ -790,11 +801,16 @@ private:
|
||||
"BN8 ",
|
||||
"BN9 "
|
||||
}));
|
||||
LoadObjects(OBJECT_TYPE_PARK_ENTRANCE, List<const char *>({ "PKENT1 " }));
|
||||
LoadObjects(OBJECT_TYPE_WATER, List<const char *>({ "WTRCYAN " }));
|
||||
LoadObjects(OBJECT_TYPE_PARK_ENTRANCE, std::vector<const char *>({ "PKENT1 " }));
|
||||
LoadObjects(OBJECT_TYPE_WATER, std::vector<const char *>({ "WTRCYAN " }));
|
||||
}
|
||||
|
||||
void LoadObjects(uint8 objectType, List<const char *> entries)
|
||||
void LoadObjects(uint8 objectType, const EntryList &entries)
|
||||
{
|
||||
LoadObjects(objectType, entries.GetEntries());
|
||||
}
|
||||
|
||||
void LoadObjects(uint8 objectType, const std::vector<const char *> &entries)
|
||||
{
|
||||
IObjectManager * objectManager = GetObjectManager();
|
||||
|
||||
@@ -1516,7 +1532,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
List<const char *> * GetEntryList(uint8 objectType)
|
||||
EntryList * GetEntryList(uint8 objectType)
|
||||
{
|
||||
switch (objectType) {
|
||||
case OBJECT_TYPE_RIDE: return &_rideEntries;
|
||||
@@ -1640,7 +1656,7 @@ extern "C"
|
||||
*/
|
||||
int vehicle_preference_compare(uint8 rideType, const char * a, const char * b)
|
||||
{
|
||||
List<const char *> rideEntryOrder = RCT1::GetPreferedRideEntryOrder(rideType);
|
||||
std::vector<const char *> rideEntryOrder = RCT1::GetPreferedRideEntryOrder(rideType);
|
||||
for (const char * object : rideEntryOrder)
|
||||
{
|
||||
if (String::Equals(object, a, true))
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "../core/List.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace RCT1
|
||||
{
|
||||
@@ -42,9 +42,9 @@ namespace RCT1
|
||||
const char * GetPathAddtionObject(uint8 pathAdditionType);
|
||||
const char * GetSceneryGroupObject(uint8 sceneryGroupType);
|
||||
|
||||
const List<const char *> GetSceneryObjects(uint8 sceneryType);
|
||||
const std::vector<const char *> GetSceneryObjects(uint8 sceneryType);
|
||||
|
||||
const List<const char *> GetPreferedRideEntryOrder(uint8 rideType);
|
||||
const std::vector<const char *> GetPreferedRideEntryOrder(uint8 rideType);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#pragma endregion
|
||||
|
||||
#include "../common.h"
|
||||
#include "../core/List.hpp"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../core/Util.hpp"
|
||||
#include "Tables.h"
|
||||
|
||||
@@ -962,9 +962,9 @@ namespace RCT1
|
||||
return map[waterType];
|
||||
}
|
||||
|
||||
const List<const char *> GetPreferedRideEntryOrder(uint8 rideType)
|
||||
const std::vector<const char *> GetPreferedRideEntryOrder(uint8 rideType)
|
||||
{
|
||||
static const List<const char *> preferedRideEntryOrder[] =
|
||||
static const std::vector<const char *> preferedRideEntryOrder[] =
|
||||
{
|
||||
{ "SPDRCR "}, // RIDE_TYPE_SPIRAL_ROLLER_COASTER
|
||||
{ "TOGST "}, // RIDE_TYPE_STAND_UP_ROLLER_COASTER
|
||||
@@ -1061,15 +1061,15 @@ namespace RCT1
|
||||
return preferedRideEntryOrder[rideType];
|
||||
}
|
||||
|
||||
const List<const char *> GetSceneryObjects(uint8 sceneryType)
|
||||
const std::vector<const char *> GetSceneryObjects(uint8 sceneryType)
|
||||
{
|
||||
static const List<const char *> map[] =
|
||||
static const std::vector<const char *> map[] =
|
||||
{
|
||||
// RCT1_SCENERY_THEME_GENERAL (trees, shrubs, garden, walls, fence, path accessories)
|
||||
{ "TIC ", "TLC ", "TMC ", "TMP ", "TITC ", "TGHC ", "TAC ", "TGHC2 ", "TCJ ", "TMBJ ", "TCF ", "TCL ", "TRF ", "TRF2 ", "TEL ", "TAP ", "TSP ", "TMZP ", "TCRP ", "TBP ", "TLP ", "TWP ", "TAS ", "TMG ", "TWW ", "TSB ", "TVL ", "TCY ", "TNS ", "TWN ", "TCE ", "TCO ", "THL ", "TCC ", "TF1 ", "TF2 ", "TCT ", "TH1 ", "TH2 ", "TPM ", "TROPT1 ",
|
||||
"TS0 ", "TS1 ", "TS2 ", "TS3 ", "TS4 ", "TS5 ", "TS6 ", "TEF ", "TAL ", "TSQ ", "THT ", "TCB ", "TDM ", "TSD ", "TORN1 ", "TORN2 ", "TGS ", "TUS ", "TBC ", "TSC ", "TWF ", "TSH0 ", "TSH1 ", "TSH2 ", "TSH3 ", "TSH4 ", "TSH5 ", "TDF ", "TSH ", "THRS ", "TSTD ", "TBR ", "TTF ", "WHG ", "WHGG ", "WCH ", "WCHG ",
|
||||
"TG1 ", "TG2 ", "TG3 ", "TG4 ", "TG5 ", "TG6 ", "TG7 ", "TG8 ", "TG9 ", "TG10 ", "TG11 ", "TG12 ", "TG13 ", "TG14 ", "TG15 ", "TG16 ", "TG17 ", "TG18 ", "TG19 ", "TG20 ", "TG21 ",
|
||||
"WBR1A ", "WBR2A ", "WALLBB34", "WALLTN32", "TNTROOF1", "WALLBB33", "WALLBB32", "WALLBB16", "WALLBB8 ", "ROOF5 ", "ROOF7 ", "WALLRS32", "WALLRS16", "WALLRS8 ", "WALLBR32", "WALLBR16", "WALLBR8 ", "WALLBRDR", "WALLBRWN", "BRBASE ", "ROOF1 ", "ROOF2 ", "ROOF3 ", "ROOF4 ", "WALLCB32", "WALLCB16", "WALLCB8 ", "WALLCBDR", "WALLCBWN", "BRBASE2 ", "CWBCRV33", "CWBCRV32", "BRCRRF1 ", "ROOF6 ", "ROOF8 ", "WALLCF32", "WALLCF16", "WALLCF8 ", "WALLCFDR", "WALLCFWN", "WALLCFAR", "BRBASE3 ", "CWFCRV33", "CWFCRV32", "BRCRRF2 ", "ROOF9 ", "ROOF11 ", "ROOF10 ", "ROOF12 ", "CORROOF2", "WALLCO16", "CORROOF ", "WALLLT32", "WALLSK16", "WALLSK32", "SKTDW2 ", "SKTDW ", "SKTBASE ", "SKTBASET", "SUPPW2 ", "SUPPW1 ", "SUPPW3 ", "SUPPLEG1", "SUPPLEG2", "SUMRF ", "WALLRH32"
|
||||
"WBR1A ", "WBR2A ", "WALLBB34", "WALLTN32", "TNTROOF1", "WALLBB33", "WALLBB32", "WALLBB16", "WALLBB8 ", "ROOF5 ", "ROOF7 ", "WALLRS32", "WALLRS16", "WALLRS8 ", "WALLBR32", "WALLBR16", "WALLBR8 ", "WALLBRDR", "WALLBRWN", "BRBASE ", "ROOF1 ", "ROOF2 ", "ROOF3 ", "ROOF4 ", "WALLCB32", "WALLCB16", "WALLCB8 ", "WALLCBDR", "WALLCBWN", "BRBASE2 ", "CWBCRV33", "CWBCRV32", "BRCRRF1 ", "ROOF6 ", "ROOF8 ", "WALLCF32", "WALLCF16", "WALLCF8 ", "WALLCFDR", "WALLCFWN", "WALLCFAR", "BRBASE3 ", "CWFCRV33", "CWFCRV32", "BRCRRF2 ", "ROOF9 ", "ROOF11 ", "ROOF10 ", "ROOF12 ", "CORROOF2", "WALLCO16", "CORROOF ", "WALLLT32", "WALLSK16", "WALLSK32", "SKTDW2 ", "SKTDW ", "SKTBASE ", "SKTBASET", "SUPPW2 ", "SUPPW1 ", "SUPPW3 ", "SUPPLEG1", "SUPPLEG2", "SUMRF ", "WALLRH32",
|
||||
"WMF ", "WMFG ", "WSW ", "WSWG ", "WFW1 ", "WFWG ", "WPF ", "WPFG ", "WSW1 ", "WSW2 ", "WBR1 ", "WBRG ", "WBR2 ", "WBR3 ", "WALLMM16", "WALLMM17",
|
||||
"LAMP1 ", "LAMP2 ", "LITTER1 ", "BENCH1 ", "QTV1 ", "BN1 ", "WALLPOST", "WALLSIGN", "SSIG1 ", "SSIG2 ", "SSIG3 ", "SSIG4 " },
|
||||
// RCT1_SCENERY_THEME_MINE
|
||||
|
||||
Reference in New Issue
Block a user