2016-07-04 00:05:39 +01:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-07-04 00:05:39 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-07-04 00:05:39 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-07-04 00:05:39 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "ObjectManager.h"
|
|
|
|
|
|
|
|
|
|
#include "../Context.h"
|
|
|
|
|
#include "../ParkImporter.h"
|
|
|
|
|
#include "../core/Console.hpp"
|
|
|
|
|
#include "../core/Memory.hpp"
|
|
|
|
|
#include "../localisation/StringIds.h"
|
2020-11-09 11:53:29 +01:00
|
|
|
#include "../util/Util.h"
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "FootpathItemObject.h"
|
|
|
|
|
#include "LargeSceneryObject.h"
|
|
|
|
|
#include "Object.h"
|
|
|
|
|
#include "ObjectList.h"
|
|
|
|
|
#include "ObjectRepository.h"
|
2020-03-20 17:07:31 +00:00
|
|
|
#include "RideObject.h"
|
2018-06-22 23:03:20 +02:00
|
|
|
#include "SceneryGroupObject.h"
|
|
|
|
|
#include "SmallSceneryObject.h"
|
|
|
|
|
#include "WallObject.h"
|
|
|
|
|
|
2018-01-31 13:02:45 +00:00
|
|
|
#include <algorithm>
|
2016-07-04 00:05:39 +01:00
|
|
|
#include <array>
|
2016-07-07 23:05:55 +01:00
|
|
|
#include <memory>
|
2018-05-27 01:32:49 +01:00
|
|
|
#include <mutex>
|
|
|
|
|
#include <thread>
|
2016-07-04 00:05:39 +01:00
|
|
|
#include <unordered_set>
|
|
|
|
|
|
2017-01-13 12:12:50 +01:00
|
|
|
class ObjectManager final : public IObjectManager
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
private:
|
2018-08-29 01:17:15 +02:00
|
|
|
IObjectRepository& _objectRepository;
|
2021-09-03 13:43:06 +03:00
|
|
|
|
|
|
|
|
std::vector<Object*> _loadedObjects;
|
2020-03-20 19:28:39 +01:00
|
|
|
std::array<std::vector<ObjectEntryIndex>, RIDE_TYPE_COUNT> _rideTypeToObjectMap;
|
2020-03-20 17:07:31 +00:00
|
|
|
|
|
|
|
|
// Used to return a safe empty vector back from GetAllRideEntries, can be removed when std::span is available
|
2020-03-20 19:28:39 +01:00
|
|
|
std::vector<ObjectEntryIndex> _nullRideTypeEntries;
|
2016-07-04 00:05:39 +01:00
|
|
|
|
|
|
|
|
public:
|
2018-08-29 01:17:15 +02:00
|
|
|
explicit ObjectManager(IObjectRepository& objectRepository)
|
2018-04-20 22:16:37 +01:00
|
|
|
: _objectRepository(objectRepository)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-02-11 22:49:11 +00:00
|
|
|
_loadedObjects.resize(OBJECT_ENTRY_COUNT);
|
2016-12-12 01:17:47 +00:00
|
|
|
|
|
|
|
|
UpdateSceneryGroupIndexes();
|
2018-04-20 23:17:01 +01:00
|
|
|
ResetTypeToRideEntryIndexMap();
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ObjectManager() override
|
|
|
|
|
{
|
2018-02-11 22:49:11 +00:00
|
|
|
UnloadAll();
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
Object* GetLoadedObject(size_t index) override
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-02-11 22:49:11 +00:00
|
|
|
if (index >= _loadedObjects.size())
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2021-09-03 13:43:06 +03:00
|
|
|
return _loadedObjects[index];
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-09 11:53:29 +01:00
|
|
|
Object* GetLoadedObject(ObjectType objectType, size_t index) override
|
2018-02-11 20:30:48 +00:00
|
|
|
{
|
2020-11-09 12:07:38 +01:00
|
|
|
if (index >= static_cast<size_t>(object_entry_group_counts[EnumValue(objectType)]))
|
2018-02-11 22:09:38 +00:00
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
2018-03-13 20:48:16 +01:00
|
|
|
log_warning("Object index %u exceeds maximum for type %d.", index, objectType);
|
2018-02-11 22:09:38 +00:00
|
|
|
#endif
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 12:27:25 +01:00
|
|
|
auto objectIndex = GetIndexFromTypeEntry(objectType, index);
|
2018-02-11 20:30:48 +00:00
|
|
|
return GetLoadedObject(objectIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 11:04:04 +01:00
|
|
|
Object* GetLoadedObject(const ObjectEntryDescriptor& entry) override
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2018-08-29 01:17:15 +02:00
|
|
|
const ObjectRepositoryItem* ori = _objectRepository.FindObject(entry);
|
2021-09-03 13:43:06 +03:00
|
|
|
if (ori == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
return ori->LoadedObject.get();
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-20 19:28:39 +01:00
|
|
|
ObjectEntryIndex GetLoadedObjectEntryIndex(const Object* object) override
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2020-03-20 19:28:39 +01:00
|
|
|
ObjectEntryIndex result = OBJECT_ENTRY_INDEX_NULL;
|
2016-07-06 22:31:14 +01:00
|
|
|
size_t index = GetLoadedObjectIndex(object);
|
|
|
|
|
if (index != SIZE_MAX)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2016-07-06 22:31:14 +01:00
|
|
|
get_type_entry_index(index, nullptr, &result);
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 11:40:52 +01:00
|
|
|
Object* LoadObject(std::string_view identifier) override
|
2020-11-05 21:19:43 +01:00
|
|
|
{
|
|
|
|
|
const ObjectRepositoryItem* ori = _objectRepository.FindObject(identifier);
|
|
|
|
|
return RepositoryItemToObject(ori);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object* LoadObject(const rct_object_entry* entry) override
|
|
|
|
|
{
|
|
|
|
|
const ObjectRepositoryItem* ori = _objectRepository.FindObject(entry);
|
|
|
|
|
return RepositoryItemToObject(ori);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
void LoadObjects(const rct_object_entry* entries, size_t count) override
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
// Find all the required objects
|
2018-05-26 19:44:59 +01:00
|
|
|
auto requiredObjects = GetRequiredObjects(entries, count);
|
2016-07-04 00:05:39 +01:00
|
|
|
|
2018-05-26 19:44:59 +01:00
|
|
|
// Load the required objects
|
2021-09-03 14:01:34 +03:00
|
|
|
{
|
|
|
|
|
auto loadedObjects = LoadObjects(requiredObjects);
|
|
|
|
|
SetNewLoadedObjectList(std::move(loadedObjects));
|
|
|
|
|
}
|
2016-07-04 00:05:39 +01:00
|
|
|
|
2021-09-03 14:01:34 +03:00
|
|
|
// Load defaults.
|
2018-05-26 19:44:59 +01:00
|
|
|
LoadDefaultObjects();
|
2021-09-03 14:01:34 +03:00
|
|
|
|
|
|
|
|
// Update indices.
|
2018-05-26 19:44:59 +01:00
|
|
|
UpdateSceneryGroupIndexes();
|
|
|
|
|
ResetTypeToRideEntryIndexMap();
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 00:25:35 -04:00
|
|
|
void UnloadObjects(const std::vector<rct_object_entry>& entries) override
|
2016-07-06 22:31:14 +01:00
|
|
|
{
|
|
|
|
|
// TODO there are two performance issues here:
|
|
|
|
|
// - FindObject for every entry which is a dictionary lookup
|
|
|
|
|
// - GetLoadedObjectIndex for every entry which enumerates _loadedList
|
|
|
|
|
|
|
|
|
|
size_t numObjectsUnloaded = 0;
|
2020-07-17 00:25:35 -04:00
|
|
|
for (const auto& entry : entries)
|
2016-07-06 22:31:14 +01:00
|
|
|
{
|
2020-07-17 00:25:35 -04:00
|
|
|
const ObjectRepositoryItem* ori = _objectRepository.FindObject(&entry);
|
2016-07-06 22:31:14 +01:00
|
|
|
if (ori != nullptr)
|
|
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
Object* loadedObject = ori->LoadedObject.get();
|
2016-07-10 00:00:23 +01:00
|
|
|
if (loadedObject != nullptr)
|
|
|
|
|
{
|
|
|
|
|
UnloadObject(loadedObject);
|
|
|
|
|
numObjectsUnloaded++;
|
|
|
|
|
}
|
2016-07-06 22:31:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (numObjectsUnloaded > 0)
|
|
|
|
|
{
|
2016-07-09 02:01:27 +01:00
|
|
|
UpdateSceneryGroupIndexes();
|
2018-04-20 23:17:01 +01:00
|
|
|
ResetTypeToRideEntryIndexMap();
|
2016-07-06 22:31:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 00:05:39 +01:00
|
|
|
void UnloadAll() override
|
|
|
|
|
{
|
2020-10-14 16:56:48 -03:00
|
|
|
for (auto& object : _loadedObjects)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
UnloadObject(object);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2016-07-09 02:01:27 +01:00
|
|
|
UpdateSceneryGroupIndexes();
|
2018-04-20 23:17:01 +01:00
|
|
|
ResetTypeToRideEntryIndexMap();
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2016-07-07 23:32:45 +01:00
|
|
|
void ResetObjects() override
|
|
|
|
|
{
|
2020-10-14 16:56:48 -03:00
|
|
|
for (auto& loadedObject : _loadedObjects)
|
2016-07-07 23:32:45 +01:00
|
|
|
{
|
2018-02-11 22:49:11 +00:00
|
|
|
if (loadedObject != nullptr)
|
2016-07-07 23:32:45 +01:00
|
|
|
{
|
2018-02-11 22:49:11 +00:00
|
|
|
loadedObject->Unload();
|
|
|
|
|
loadedObject->Load();
|
2016-07-07 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-11 22:49:11 +00:00
|
|
|
UpdateSceneryGroupIndexes();
|
2018-04-20 23:17:01 +01:00
|
|
|
ResetTypeToRideEntryIndexMap();
|
2016-07-07 23:32:45 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
std::vector<const ObjectRepositoryItem*> GetPackableObjects() override
|
2017-02-05 15:45:23 +00:00
|
|
|
{
|
2018-06-22 23:03:20 +02:00
|
|
|
std::vector<const ObjectRepositoryItem*> objects;
|
2018-08-29 01:17:15 +02:00
|
|
|
size_t numObjects = _objectRepository.GetNumObjects();
|
2017-02-05 15:45:23 +00:00
|
|
|
for (size_t i = 0; i < numObjects; i++)
|
|
|
|
|
{
|
2018-08-29 01:17:15 +02:00
|
|
|
const ObjectRepositoryItem* item = &_objectRepository.GetObjects()[i];
|
2020-04-19 13:18:12 +01:00
|
|
|
if (item->LoadedObject != nullptr && IsObjectCustom(item) && item->LoadedObject->GetLegacyData() != nullptr
|
|
|
|
|
&& !item->LoadedObject->IsJsonObject())
|
2017-02-05 15:45:23 +00:00
|
|
|
{
|
|
|
|
|
objects.push_back(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return objects;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 12:27:25 +01:00
|
|
|
void LoadDefaultObjects() override
|
|
|
|
|
{
|
|
|
|
|
// We currently will load new object types here that apply to all
|
|
|
|
|
// loaded RCT1 and RCT2 save files.
|
2018-12-05 20:33:45 +00:00
|
|
|
|
|
|
|
|
// Surfaces
|
2020-11-05 21:33:13 +01:00
|
|
|
LoadObject("rct2.surface.grass");
|
|
|
|
|
LoadObject("rct2.surface.sand");
|
|
|
|
|
LoadObject("rct2.surface.dirt");
|
|
|
|
|
LoadObject("rct2.surface.rock");
|
|
|
|
|
LoadObject("rct2.surface.martian");
|
|
|
|
|
LoadObject("rct2.surface.chequerboard");
|
|
|
|
|
LoadObject("rct2.surface.grassclumps");
|
|
|
|
|
LoadObject("rct2.surface.ice");
|
|
|
|
|
LoadObject("rct2.surface.gridred");
|
|
|
|
|
LoadObject("rct2.surface.gridyellow");
|
|
|
|
|
LoadObject("rct2.surface.gridpurple");
|
|
|
|
|
LoadObject("rct2.surface.gridgreen");
|
|
|
|
|
LoadObject("rct2.surface.sandred");
|
|
|
|
|
LoadObject("rct2.surface.sandbrown");
|
2020-12-20 21:38:34 +01:00
|
|
|
LoadObject("rct1.aa.surface.roofred");
|
|
|
|
|
LoadObject("rct1.ll.surface.roofgrey");
|
|
|
|
|
LoadObject("rct1.ll.surface.rust");
|
|
|
|
|
LoadObject("rct1.ll.surface.wood");
|
2018-12-05 20:33:45 +00:00
|
|
|
|
|
|
|
|
// Edges
|
2020-11-05 21:33:13 +01:00
|
|
|
LoadObject("rct2.edge.rock");
|
|
|
|
|
LoadObject("rct2.edge.woodred");
|
|
|
|
|
LoadObject("rct2.edge.woodblack");
|
|
|
|
|
LoadObject("rct2.edge.ice");
|
|
|
|
|
LoadObject("rct1.edge.brick");
|
|
|
|
|
LoadObject("rct1.edge.iron");
|
|
|
|
|
LoadObject("rct1.aa.edge.grey");
|
|
|
|
|
LoadObject("rct1.aa.edge.yellow");
|
|
|
|
|
LoadObject("rct1.aa.edge.red");
|
|
|
|
|
LoadObject("rct1.ll.edge.purple");
|
|
|
|
|
LoadObject("rct1.ll.edge.green");
|
|
|
|
|
LoadObject("rct1.ll.edge.stonebrown");
|
|
|
|
|
LoadObject("rct1.ll.edge.stonegrey");
|
|
|
|
|
LoadObject("rct1.ll.edge.skyscrapera");
|
|
|
|
|
LoadObject("rct1.ll.edge.skyscraperb");
|
2018-12-05 20:33:45 +00:00
|
|
|
|
|
|
|
|
// Stations
|
2020-11-05 21:33:13 +01:00
|
|
|
LoadObject("rct2.station.plain");
|
|
|
|
|
LoadObject("rct2.station.wooden");
|
|
|
|
|
LoadObject("rct2.station.canvastent");
|
|
|
|
|
LoadObject("rct2.station.castlegrey");
|
|
|
|
|
LoadObject("rct2.station.castlebrown");
|
|
|
|
|
LoadObject("rct2.station.jungle");
|
|
|
|
|
LoadObject("rct2.station.log");
|
|
|
|
|
LoadObject("rct2.station.classical");
|
|
|
|
|
LoadObject("rct2.station.abstract");
|
|
|
|
|
LoadObject("rct2.station.snow");
|
|
|
|
|
LoadObject("rct2.station.pagoda");
|
|
|
|
|
LoadObject("rct2.station.space");
|
|
|
|
|
LoadObject("openrct2.station.noentrance");
|
2021-01-09 20:54:02 +00:00
|
|
|
|
|
|
|
|
// Music
|
2021-01-27 19:11:10 +00:00
|
|
|
auto baseIndex = GetIndexFromTypeEntry(ObjectType::Music, 0);
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_DODGEMS_BEAT, "rct2.music.dodgems");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_FAIRGROUND_ORGAN, "rct2.music.fairground");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ROMAN_FANFARE, "rct2.music.roman");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ORIENTAL, "rct2.music.oriental");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_MARTIAN, "rct2.music.martian");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_JUNGLE_DRUMS, "rct2.music.jungle");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_EGYPTIAN, "rct2.music.egyptian");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_TOYLAND, "rct2.music.toyland");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_SPACE, "rct2.music.space");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_HORROR, "rct2.music.horror");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_TECHNO, "rct2.music.techno");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_GENTLE, "rct2.music.gentle");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_SUMMER, "rct2.music.summer");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_WATER, "rct2.music.water");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_WILD_WEST, "rct2.music.wildwest");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_JURASSIC, "rct2.music.jurassic");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ROCK, "rct2.music.rock1");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_RAGTIME, "rct2.music.ragtime");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_FANTASY, "rct2.music.fantasy");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ROCK_STYLE_2, "rct2.music.rock2");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ICE, "rct2.music.ice");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_SNOW, "rct2.music.snow");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_CUSTOM_MUSIC_1, "rct2.music.custom1");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_CUSTOM_MUSIC_2, "rct2.music.custom2");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_MEDIEVAL, "rct2.music.medieval");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_URBAN, "rct2.music.urban");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ORGAN, "rct2.music.organ");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_MECHANICAL, "rct2.music.mechanical");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_MODERN, "rct2.music.modern");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_PIRATES, "rct2.music.pirate");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_ROCK_STYLE_3, "rct2.music.rock3");
|
|
|
|
|
LoadObject(baseIndex + MUSIC_STYLE_CANDY_STYLE, "rct2.music.candy");
|
2018-05-14 12:27:25 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-17 13:27:02 -07:00
|
|
|
static rct_string_id GetObjectSourceGameString(const ObjectSourceGame sourceGame)
|
2017-07-19 10:04:00 +01:00
|
|
|
{
|
2018-07-03 13:46:45 +02:00
|
|
|
switch (sourceGame)
|
2017-07-19 10:04:00 +01:00
|
|
|
{
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::RCT1:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_SCENARIO_CATEGORY_RCT1;
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::AddedAttractions:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_SCENARIO_CATEGORY_RCT1_AA;
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::LoopyLandscapes:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_SCENARIO_CATEGORY_RCT1_LL;
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::RCT2:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_ROLLERCOASTER_TYCOON_2_DROPDOWN;
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::WackyWorlds:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_OBJECT_FILTER_WW;
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::TimeTwister:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_OBJECT_FILTER_TT;
|
2020-10-17 13:27:02 -07:00
|
|
|
case ObjectSourceGame::OpenRCT2Official:
|
2018-06-22 23:03:20 +02:00
|
|
|
return STR_OBJECT_FILTER_OPENRCT2_OFFICIAL;
|
|
|
|
|
default:
|
|
|
|
|
return STR_OBJECT_FILTER_CUSTOM;
|
2017-07-19 10:04:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-20 19:28:39 +01:00
|
|
|
const std::vector<ObjectEntryIndex>& GetAllRideEntries(uint8_t rideType) override
|
2020-03-20 17:07:31 +00:00
|
|
|
{
|
|
|
|
|
if (rideType >= RIDE_TYPE_COUNT)
|
|
|
|
|
{
|
|
|
|
|
// Return an empty vector
|
|
|
|
|
return _nullRideTypeEntries;
|
|
|
|
|
}
|
|
|
|
|
return _rideTypeToObjectMap[rideType];
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 00:05:39 +01:00
|
|
|
private:
|
2021-01-27 19:11:10 +00:00
|
|
|
Object* LoadObject(int32_t slot, std::string_view identifier)
|
|
|
|
|
{
|
|
|
|
|
const ObjectRepositoryItem* ori = _objectRepository.FindObject(identifier);
|
|
|
|
|
return RepositoryItemToObject(ori, slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object* RepositoryItemToObject(const ObjectRepositoryItem* ori, std::optional<int32_t> slot = {})
|
|
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
if (ori == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
Object* loadedObject = ori->LoadedObject.get();
|
|
|
|
|
if (loadedObject != nullptr)
|
|
|
|
|
return loadedObject;
|
|
|
|
|
|
|
|
|
|
ObjectType objectType = ori->ObjectEntry.GetType();
|
|
|
|
|
if (slot)
|
2021-01-27 19:11:10 +00:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
if (_loadedObjects.size() > static_cast<size_t>(*slot) && _loadedObjects[*slot] != nullptr)
|
2021-01-27 19:11:10 +00:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
// Slot already taken
|
|
|
|
|
return nullptr;
|
2021-01-27 19:11:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-03 13:43:06 +03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
slot = FindSpareSlot(objectType);
|
|
|
|
|
}
|
|
|
|
|
if (slot)
|
|
|
|
|
{
|
|
|
|
|
auto object = GetOrLoadObject(ori);
|
|
|
|
|
if (object != nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (_loadedObjects.size() <= static_cast<size_t>(*slot))
|
|
|
|
|
{
|
|
|
|
|
_loadedObjects.resize(*slot + 1);
|
|
|
|
|
}
|
|
|
|
|
loadedObject = object;
|
|
|
|
|
_loadedObjects[*slot] = object;
|
|
|
|
|
UpdateSceneryGroupIndexes();
|
|
|
|
|
ResetTypeToRideEntryIndexMap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 19:11:10 +00:00
|
|
|
return loadedObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<int32_t> FindSpareSlot(ObjectType objectType)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2018-05-14 12:27:25 +01:00
|
|
|
size_t firstIndex = GetIndexFromTypeEntry(objectType, 0);
|
2020-11-09 12:07:38 +01:00
|
|
|
size_t endIndex = firstIndex + object_entry_group_counts[EnumValue(objectType)];
|
2018-05-14 12:27:25 +01:00
|
|
|
for (size_t i = firstIndex; i < endIndex; i++)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2018-05-14 12:27:25 +01:00
|
|
|
if (_loadedObjects.size() <= i)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2018-05-14 12:27:25 +01:00
|
|
|
_loadedObjects.resize(i + 1);
|
2020-04-22 17:09:29 +02:00
|
|
|
return static_cast<int32_t>(i);
|
2018-05-14 12:27:25 +01:00
|
|
|
}
|
|
|
|
|
else if (_loadedObjects[i] == nullptr)
|
|
|
|
|
{
|
2020-04-22 17:09:29 +02:00
|
|
|
return static_cast<int32_t>(i);
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-27 19:11:10 +00:00
|
|
|
return {};
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
size_t GetLoadedObjectIndex(const Object* object)
|
2016-07-06 22:31:14 +01:00
|
|
|
{
|
2016-07-16 14:17:36 +01:00
|
|
|
Guard::ArgumentNotNull(object, GUARD_LINE);
|
2016-07-09 20:37:12 +01:00
|
|
|
|
2018-02-11 22:49:11 +00:00
|
|
|
auto result = std::numeric_limits<size_t>().max();
|
2021-09-03 13:43:06 +03:00
|
|
|
auto it = std::find_if(_loadedObjects.begin(), _loadedObjects.end(), [object](auto& obj) { return obj == object; });
|
2018-02-11 22:49:11 +00:00
|
|
|
if (it != _loadedObjects.end())
|
2016-07-06 22:31:14 +01:00
|
|
|
{
|
2018-02-11 22:49:11 +00:00
|
|
|
result = std::distance(_loadedObjects.begin(), it);
|
2016-07-06 22:31:14 +01:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 13:43:06 +03:00
|
|
|
void SetNewLoadedObjectList(std::vector<Object*>&& newLoadedObjects)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2019-04-20 20:39:47 +02:00
|
|
|
if (newLoadedObjects.empty())
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
UnloadAll();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UnloadObjectsExcept(newLoadedObjects);
|
|
|
|
|
}
|
2020-10-14 16:56:48 -03:00
|
|
|
_loadedObjects = std::move(newLoadedObjects);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
void UnloadObject(Object* object)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
if (object == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
object->Unload();
|
|
|
|
|
|
|
|
|
|
// TODO try to prevent doing a repository search
|
|
|
|
|
const ObjectRepositoryItem* ori = _objectRepository.FindObject(object->GetObjectEntry());
|
|
|
|
|
if (ori != nullptr)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
_objectRepository.UnregisterLoadedObject(ori, object);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2021-09-03 13:43:06 +03:00
|
|
|
|
|
|
|
|
// Because it's possible to have the same loaded object for multiple
|
|
|
|
|
// slots, we have to make sure find and set all of them to nullptr
|
|
|
|
|
std::replace(_loadedObjects.begin(), _loadedObjects.end(), object, static_cast<Object*>(nullptr));
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-03 13:43:06 +03:00
|
|
|
void UnloadObjectsExcept(const std::vector<Object*>& newLoadedObjects)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
// Build a hash set for quick checking
|
2018-06-22 23:03:20 +02:00
|
|
|
auto exceptSet = std::unordered_set<Object*>();
|
2020-10-14 16:56:48 -03:00
|
|
|
for (auto& object : newLoadedObjects)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
if (object != nullptr)
|
|
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
exceptSet.insert(object);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unload objects that are not in the hash set
|
|
|
|
|
size_t totalObjectsLoaded = 0;
|
|
|
|
|
size_t numObjectsUnloaded = 0;
|
2020-10-14 16:56:48 -03:00
|
|
|
for (auto& object : _loadedObjects)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
|
|
|
|
if (object != nullptr)
|
|
|
|
|
{
|
|
|
|
|
totalObjectsLoaded++;
|
2021-09-03 13:43:06 +03:00
|
|
|
if (exceptSet.find(object) == exceptSet.end())
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
UnloadObject(object);
|
2016-07-04 00:05:39 +01:00
|
|
|
numObjectsUnloaded++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-10 16:34:54 +01:00
|
|
|
log_verbose("%u / %u objects unloaded", numObjectsUnloaded, totalObjectsLoaded);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-03 14:17:53 +03:00
|
|
|
template<typename T> void UpdateSceneryGroupIndexes(Object* object)
|
2021-09-03 14:08:17 +03:00
|
|
|
{
|
|
|
|
|
auto* sceneryEntry = static_cast<T*>(object->GetLegacyData());
|
2021-09-03 14:17:53 +03:00
|
|
|
sceneryEntry->scenery_tab_id = GetPrimarySceneryGroupEntryIndex(object);
|
2021-09-03 14:08:17 +03:00
|
|
|
}
|
|
|
|
|
|
2016-07-09 02:01:27 +01:00
|
|
|
void UpdateSceneryGroupIndexes()
|
|
|
|
|
{
|
2020-10-14 16:56:48 -03:00
|
|
|
for (auto& loadedObject : _loadedObjects)
|
2016-07-09 02:01:27 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
// The list can contain unused slots, skip them.
|
|
|
|
|
if (loadedObject == nullptr)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
switch (loadedObject->GetObjectType())
|
2016-07-09 02:01:27 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
case ObjectType::SmallScenery:
|
2021-09-03 14:08:17 +03:00
|
|
|
UpdateSceneryGroupIndexes<SmallSceneryEntry>(loadedObject);
|
2021-09-03 13:43:06 +03:00
|
|
|
break;
|
|
|
|
|
case ObjectType::LargeScenery:
|
2021-09-03 14:08:17 +03:00
|
|
|
UpdateSceneryGroupIndexes<LargeSceneryEntry>(loadedObject);
|
2021-09-03 13:43:06 +03:00
|
|
|
break;
|
|
|
|
|
case ObjectType::Walls:
|
2021-09-03 14:08:17 +03:00
|
|
|
UpdateSceneryGroupIndexes<WallSceneryEntry>(loadedObject);
|
2021-09-03 13:43:06 +03:00
|
|
|
break;
|
|
|
|
|
case ObjectType::Banners:
|
2021-09-03 14:08:17 +03:00
|
|
|
UpdateSceneryGroupIndexes<BannerSceneryEntry>(loadedObject);
|
2021-09-03 13:43:06 +03:00
|
|
|
break;
|
|
|
|
|
case ObjectType::PathBits:
|
2021-09-03 14:08:17 +03:00
|
|
|
UpdateSceneryGroupIndexes<PathBitEntry>(loadedObject);
|
2021-09-03 13:43:06 +03:00
|
|
|
break;
|
|
|
|
|
case ObjectType::SceneryGroup:
|
2021-09-03 14:17:53 +03:00
|
|
|
{
|
|
|
|
|
auto sgObject = dynamic_cast<SceneryGroupObject*>(loadedObject);
|
|
|
|
|
sgObject->UpdateEntryIndexes();
|
2021-09-03 13:43:06 +03:00
|
|
|
break;
|
2021-09-03 14:17:53 +03:00
|
|
|
}
|
2021-09-03 13:43:06 +03:00
|
|
|
default:
|
|
|
|
|
// This switch only handles scenery ObjectTypes.
|
|
|
|
|
break;
|
2016-07-09 02:01:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-11 22:49:11 +00:00
|
|
|
|
|
|
|
|
// HACK Scenery window will lose its tabs after changing the scenery group indexing
|
|
|
|
|
// for now just close it, but it will be better to later tell it to invalidate the tabs
|
|
|
|
|
window_close_by_class(WC_SCENERY);
|
2016-07-09 02:01:27 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-20 19:28:39 +01:00
|
|
|
ObjectEntryIndex GetPrimarySceneryGroupEntryIndex(Object* loadedObject)
|
2016-07-09 20:37:12 +01:00
|
|
|
{
|
2018-06-22 23:03:20 +02:00
|
|
|
auto sceneryObject = dynamic_cast<SceneryObject*>(loadedObject);
|
2021-03-12 11:04:04 +01:00
|
|
|
const auto& primarySGEntry = sceneryObject->GetPrimarySceneryGroup();
|
2018-06-22 23:03:20 +02:00
|
|
|
Object* sgObject = GetLoadedObject(primarySGEntry);
|
2016-07-09 20:37:12 +01:00
|
|
|
|
2020-03-18 21:27:53 +01:00
|
|
|
auto entryIndex = OBJECT_ENTRY_INDEX_NULL;
|
2016-07-09 20:37:12 +01:00
|
|
|
if (sgObject != nullptr)
|
|
|
|
|
{
|
|
|
|
|
entryIndex = GetLoadedObjectEntryIndex(sgObject);
|
|
|
|
|
}
|
|
|
|
|
return entryIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
std::vector<const ObjectRepositoryItem*> GetRequiredObjects(const rct_object_entry* entries, size_t count)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-06-22 23:03:20 +02:00
|
|
|
std::vector<const ObjectRepositoryItem*> requiredObjects;
|
2018-05-26 19:44:59 +01:00
|
|
|
std::vector<rct_object_entry> missingObjects;
|
|
|
|
|
|
2018-05-28 00:31:37 +01:00
|
|
|
for (size_t i = 0; i < count; i++)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-06-22 23:03:20 +02:00
|
|
|
const rct_object_entry* entry = &entries[i];
|
|
|
|
|
const ObjectRepositoryItem* ori = nullptr;
|
2016-09-29 17:52:16 +01:00
|
|
|
if (!object_entry_is_empty(entry))
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-08-29 01:17:15 +02:00
|
|
|
ori = _objectRepository.FindObject(entry);
|
2020-11-09 10:36:37 +01:00
|
|
|
if (ori == nullptr && entry->GetType() != ObjectType::ScenarioText)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-05-26 19:44:59 +01:00
|
|
|
missingObjects.push_back(*entry);
|
2016-07-04 00:05:39 +01:00
|
|
|
ReportMissingObject(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-11 22:49:11 +00:00
|
|
|
requiredObjects.push_back(ori);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2018-05-26 19:44:59 +01:00
|
|
|
|
2019-04-20 20:39:47 +02:00
|
|
|
if (!missingObjects.empty())
|
2018-05-26 19:44:59 +01:00
|
|
|
{
|
|
|
|
|
throw ObjectLoadException(std::move(missingObjects));
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-11 22:49:11 +00:00
|
|
|
return requiredObjects;
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
template<typename T, typename TFunc> static void ParallelFor(const std::vector<T>& items, TFunc func)
|
2018-05-27 01:36:55 +01:00
|
|
|
{
|
|
|
|
|
auto partitions = std::thread::hardware_concurrency();
|
|
|
|
|
auto partitionSize = (items.size() + (partitions - 1)) / partitions;
|
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
|
for (size_t n = 0; n < partitions; n++)
|
|
|
|
|
{
|
|
|
|
|
auto begin = n * partitionSize;
|
|
|
|
|
auto end = std::min(items.size(), begin + partitionSize);
|
|
|
|
|
threads.emplace_back(
|
2018-06-22 23:03:20 +02:00
|
|
|
[func](size_t pbegin, size_t pend) {
|
2018-05-28 00:31:37 +01:00
|
|
|
for (size_t i = pbegin; i < pend; i++)
|
2018-05-27 01:36:55 +01:00
|
|
|
{
|
|
|
|
|
func(i);
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-21 13:51:54 +02:00
|
|
|
begin, end);
|
2018-05-27 01:36:55 +01:00
|
|
|
}
|
|
|
|
|
for (auto& t : threads)
|
|
|
|
|
{
|
|
|
|
|
t.join();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 14:01:34 +03:00
|
|
|
std::vector<Object*> LoadObjects(std::vector<const ObjectRepositoryItem*>& requiredObjects)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
std::vector<Object*> objects;
|
|
|
|
|
std::vector<Object*> newLoadedObjects;
|
2018-05-26 19:44:59 +01:00
|
|
|
std::vector<rct_object_entry> badObjects;
|
2018-05-27 01:32:49 +01:00
|
|
|
objects.resize(OBJECT_ENTRY_COUNT);
|
2021-09-03 13:43:06 +03:00
|
|
|
newLoadedObjects.reserve(OBJECT_ENTRY_COUNT);
|
2018-05-27 01:32:49 +01:00
|
|
|
|
|
|
|
|
// Read objects
|
|
|
|
|
std::mutex commonMutex;
|
2021-09-03 13:43:06 +03:00
|
|
|
ParallelFor(requiredObjects, [this, &commonMutex, requiredObjects, &objects, &badObjects, &newLoadedObjects](size_t i) {
|
2020-10-15 03:54:22 +03:00
|
|
|
auto requiredObject = requiredObjects[i];
|
2021-09-03 13:43:06 +03:00
|
|
|
Object* object = nullptr;
|
2020-10-15 03:54:22 +03:00
|
|
|
if (requiredObject != nullptr)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
auto loadedObject = requiredObject->LoadedObject.get();
|
2018-06-22 23:03:20 +02:00
|
|
|
if (loadedObject == nullptr)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2020-10-15 03:54:22 +03:00
|
|
|
// Object requires to be loaded, if the object successfully loads it will register it
|
|
|
|
|
// as a loaded object otherwise placed into the badObjects list.
|
2021-09-03 13:43:06 +03:00
|
|
|
auto newObject = _objectRepository.LoadObject(requiredObject);
|
2020-10-15 03:54:22 +03:00
|
|
|
std::lock_guard<std::mutex> guard(commonMutex);
|
2021-09-03 13:43:06 +03:00
|
|
|
if (newObject == nullptr)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2020-10-15 03:54:22 +03:00
|
|
|
badObjects.push_back(requiredObject->ObjectEntry);
|
|
|
|
|
ReportObjectLoadProblem(&requiredObject->ObjectEntry);
|
2018-06-22 23:03:20 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
object = newObject.get();
|
|
|
|
|
newLoadedObjects.push_back(object);
|
2018-06-22 23:03:20 +02:00
|
|
|
// Connect the ori to the registered object
|
2021-09-03 13:43:06 +03:00
|
|
|
_objectRepository.RegisterLoadedObject(requiredObject, std::move(newObject));
|
2020-10-15 03:54:22 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
object = loadedObject;
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2018-06-22 23:03:20 +02:00
|
|
|
}
|
2021-09-03 13:43:06 +03:00
|
|
|
objects[i] = object;
|
2018-06-22 23:03:20 +02:00
|
|
|
});
|
2018-05-27 01:32:49 +01:00
|
|
|
|
|
|
|
|
// Load objects
|
2021-09-03 13:43:06 +03:00
|
|
|
for (auto obj : newLoadedObjects)
|
2018-05-27 01:32:49 +01:00
|
|
|
{
|
|
|
|
|
obj->Load();
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2018-05-26 19:44:59 +01:00
|
|
|
|
2019-04-20 20:39:47 +02:00
|
|
|
if (!badObjects.empty())
|
2018-05-26 19:44:59 +01:00
|
|
|
{
|
|
|
|
|
// Unload all the new objects we loaded
|
2021-09-03 13:43:06 +03:00
|
|
|
for (auto object : newLoadedObjects)
|
2018-05-26 19:44:59 +01:00
|
|
|
{
|
|
|
|
|
UnloadObject(object);
|
|
|
|
|
}
|
|
|
|
|
throw ObjectLoadException(std::move(badObjects));
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 14:01:34 +03:00
|
|
|
log_verbose("%u / %u new objects loaded", newLoadedObjects.size(), requiredObjects.size());
|
2018-05-26 19:44:59 +01:00
|
|
|
return objects;
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-03 13:43:06 +03:00
|
|
|
Object* GetOrLoadObject(const ObjectRepositoryItem* ori)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2021-09-03 13:43:06 +03:00
|
|
|
auto* loadedObject = ori->LoadedObject.get();
|
|
|
|
|
if (loadedObject != nullptr)
|
|
|
|
|
return loadedObject;
|
2016-07-05 19:33:12 +01:00
|
|
|
|
2021-09-03 13:43:06 +03:00
|
|
|
// Try to load object
|
|
|
|
|
auto object = _objectRepository.LoadObject(ori);
|
|
|
|
|
if (object != nullptr)
|
|
|
|
|
{
|
|
|
|
|
loadedObject = object.get();
|
|
|
|
|
|
|
|
|
|
object->Load();
|
|
|
|
|
|
|
|
|
|
// Connect the ori to the registered object
|
|
|
|
|
_objectRepository.RegisterLoadedObject(ori, std::move(object));
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
2021-09-03 13:43:06 +03:00
|
|
|
|
|
|
|
|
return loadedObject;
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-20 23:17:01 +01:00
|
|
|
void ResetTypeToRideEntryIndexMap()
|
|
|
|
|
{
|
2020-03-20 17:07:31 +00:00
|
|
|
// Clear all ride objects
|
|
|
|
|
for (auto& v : _rideTypeToObjectMap)
|
|
|
|
|
{
|
|
|
|
|
v.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build object lists
|
2020-11-09 11:53:29 +01:00
|
|
|
auto maxRideObjects = static_cast<size_t>(object_entry_group_counts[EnumValue(ObjectType::Ride)]);
|
2020-03-20 17:07:31 +00:00
|
|
|
for (size_t i = 0; i < maxRideObjects; i++)
|
|
|
|
|
{
|
2020-11-09 10:36:37 +01:00
|
|
|
auto rideObject = static_cast<RideObject*>(GetLoadedObject(ObjectType::Ride, i));
|
2020-03-20 17:07:31 +00:00
|
|
|
if (rideObject != nullptr)
|
|
|
|
|
{
|
|
|
|
|
const auto entry = static_cast<rct_ride_entry*>(rideObject->GetLegacyData());
|
|
|
|
|
if (entry != nullptr)
|
|
|
|
|
{
|
|
|
|
|
for (auto rideType : entry->ride_type)
|
|
|
|
|
{
|
|
|
|
|
if (rideType < _rideTypeToObjectMap.size())
|
|
|
|
|
{
|
|
|
|
|
auto& v = _rideTypeToObjectMap[rideType];
|
2020-03-20 19:28:39 +01:00
|
|
|
v.push_back(static_cast<ObjectEntryIndex>(i));
|
2020-03-20 17:07:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-20 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
static void ReportMissingObject(const rct_object_entry* entry)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-01-02 20:36:42 +01:00
|
|
|
utf8 objName[DAT_NAME_LENGTH + 1] = { 0 };
|
2018-02-01 12:52:39 +00:00
|
|
|
std::copy_n(entry->name, DAT_NAME_LENGTH, objName);
|
2016-07-09 15:02:05 +01:00
|
|
|
Console::Error::WriteLine("[%s] Object not found.", objName);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:03:20 +02:00
|
|
|
void ReportObjectLoadProblem(const rct_object_entry* entry)
|
2016-07-04 00:05:39 +01:00
|
|
|
{
|
2018-01-02 20:36:42 +01:00
|
|
|
utf8 objName[DAT_NAME_LENGTH + 1] = { 0 };
|
2018-02-01 12:52:39 +00:00
|
|
|
std::copy_n(entry->name, DAT_NAME_LENGTH, objName);
|
2016-07-09 15:02:05 +01:00
|
|
|
Console::Error::WriteLine("[%s] Object could not be loaded.", objName);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2016-07-05 19:33:12 +01:00
|
|
|
|
2020-11-09 12:07:38 +01:00
|
|
|
static int32_t GetIndexFromTypeEntry(ObjectType objectType, size_t entryIndex)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t result = 0;
|
2020-11-09 12:07:38 +01:00
|
|
|
for (int32_t i = 0; i < EnumValue(objectType); i++)
|
2016-07-05 19:33:12 +01:00
|
|
|
{
|
|
|
|
|
result += object_entry_group_counts[i];
|
|
|
|
|
}
|
2020-04-22 17:09:29 +02:00
|
|
|
result += static_cast<int32_t>(entryIndex);
|
2016-07-05 19:33:12 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
2016-07-04 00:05:39 +01:00
|
|
|
};
|
|
|
|
|
|
2018-08-29 01:17:15 +02:00
|
|
|
std::unique_ptr<IObjectManager> CreateObjectManager(IObjectRepository& objectRepository)
|
2017-06-22 18:56:32 +01:00
|
|
|
{
|
2018-04-20 22:16:37 +01:00
|
|
|
return std::make_unique<ObjectManager>(objectRepository);
|
2016-07-04 00:05:39 +01:00
|
|
|
}
|
2016-07-05 19:33:12 +01:00
|
|
|
|
2021-03-27 13:48:27 +01:00
|
|
|
Object* object_manager_get_loaded_object(const ObjectEntryDescriptor& entry)
|
2018-02-01 18:49:14 +01:00
|
|
|
{
|
2018-08-29 00:52:10 +02:00
|
|
|
auto& objectManager = OpenRCT2::GetContext()->GetObjectManager();
|
2021-03-27 13:48:27 +01:00
|
|
|
Object* loadedObject = objectManager.GetLoadedObject(entry);
|
2020-10-14 16:56:48 -03:00
|
|
|
return loadedObject;
|
2018-02-01 18:49:14 +01:00
|
|
|
}
|
2016-07-05 19:33:12 +01:00
|
|
|
|
2021-03-27 13:48:27 +01:00
|
|
|
ObjectEntryIndex object_manager_get_loaded_object_entry_index(const Object* loadedObject)
|
2018-02-01 18:49:14 +01:00
|
|
|
{
|
2018-08-29 00:52:10 +02:00
|
|
|
auto& objectManager = OpenRCT2::GetContext()->GetObjectManager();
|
2021-03-27 13:48:27 +01:00
|
|
|
auto entryIndex = objectManager.GetLoadedObjectEntryIndex(loadedObject);
|
2018-02-01 18:49:14 +01:00
|
|
|
return entryIndex;
|
|
|
|
|
}
|
2016-07-05 19:33:12 +01:00
|
|
|
|
2021-03-27 13:48:27 +01:00
|
|
|
ObjectEntryIndex object_manager_get_loaded_object_entry_index(const ObjectEntryDescriptor& entry)
|
|
|
|
|
{
|
|
|
|
|
return object_manager_get_loaded_object_entry_index(object_manager_get_loaded_object(entry));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object* object_manager_load_object(const rct_object_entry* entry)
|
2018-02-01 18:49:14 +01:00
|
|
|
{
|
2018-08-29 00:52:10 +02:00
|
|
|
auto& objectManager = OpenRCT2::GetContext()->GetObjectManager();
|
|
|
|
|
Object* loadedObject = objectManager.LoadObject(entry);
|
2021-03-27 13:48:27 +01:00
|
|
|
return loadedObject;
|
2018-02-01 18:49:14 +01:00
|
|
|
}
|
2016-07-06 22:31:14 +01:00
|
|
|
|
2020-07-17 00:25:35 -04:00
|
|
|
void object_manager_unload_objects(const std::vector<rct_object_entry>& entries)
|
2018-02-01 18:49:14 +01:00
|
|
|
{
|
2018-08-29 00:52:10 +02:00
|
|
|
auto& objectManager = OpenRCT2::GetContext()->GetObjectManager();
|
2020-07-17 00:25:35 -04:00
|
|
|
objectManager.UnloadObjects(entries);
|
2018-02-01 18:49:14 +01:00
|
|
|
}
|
2016-07-07 00:09:31 +01:00
|
|
|
|
2018-02-01 18:49:14 +01:00
|
|
|
void object_manager_unload_all_objects()
|
|
|
|
|
{
|
2018-08-29 00:52:10 +02:00
|
|
|
auto& objectManager = OpenRCT2::GetContext()->GetObjectManager();
|
|
|
|
|
objectManager.UnloadAll();
|
2016-07-05 19:33:12 +01:00
|
|
|
}
|
2018-02-01 18:49:14 +01:00
|
|
|
|
2020-10-17 13:27:02 -07:00
|
|
|
rct_string_id object_manager_get_source_game_string(const ObjectSourceGame sourceGame)
|
2018-02-01 18:49:14 +01:00
|
|
|
{
|
2018-07-03 13:46:45 +02:00
|
|
|
return ObjectManager::GetObjectSourceGameString(sourceGame);
|
2018-02-01 18:49:14 +01:00
|
|
|
}
|