1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Add the ability to temporarily load objects without registering them (#24521)

This commit is contained in:
Matt
2025-05-28 01:13:42 +03:00
committed by GitHub
parent a7b12594c8
commit d2e3430df2
5 changed files with 34 additions and 38 deletions

View File

@@ -19,6 +19,7 @@
- Fix: [#11071, #22958] The virtual floor does not always draw correctly.
- Fix: [#18220] Some custom RCT1 scenarios are detected as competition DLC scenarios.
- Fix: [#20158] Custom animated scenery .DATs with frame offsets draw a random sprite at the end of their animation.
- Fix: [#22628] Potential crash while rebuilding the scenario index.
- Fix: [#23289] Dodgems and Flying Saucer cars can spawn on top of each other when the ride is opened.
- Fix: [#24332] Banner font renders differently when using RCT Classic as the base game.
- Fix: [#24346] Possible crash during line drawing in OpenGL mode.

View File

@@ -163,6 +163,21 @@ public:
return objectList;
}
std::unique_ptr<Object> LoadTempObject(std::string_view id) override
{
const ObjectRepositoryItem* ori = _objectRepository.FindObject(id);
if (ori == nullptr)
{
LOG_ERROR("Object '%s' not found in repository.", std::string{ id }.c_str());
return nullptr;
}
auto object = _objectRepository.LoadObject(ori);
object->Load();
return object;
}
Object* LoadObject(std::string_view identifier) override
{
const ObjectRepositoryItem* ori = _objectRepository.FindObject(identifier);

View File

@@ -37,6 +37,7 @@ struct IObjectManager
virtual ObjectEntryIndex GetLoadedObjectEntryIndex(const Object* object) = 0;
virtual ObjectList GetLoadedObjects() = 0;
virtual std::unique_ptr<Object> LoadTempObject(std::string_view identifier) = 0;
virtual Object* LoadObject(std::string_view identifier) = 0;
virtual Object* LoadObject(const RCTObjectEntry* entry) = 0;
virtual Object* LoadObject(const ObjectEntryDescriptor& descriptor) = 0;

View File

@@ -96,8 +96,6 @@ static constexpr ObjectEntryIndex ObjectEntryIndexIgnore = 254;
namespace OpenRCT2::RCT1
{
static std::mutex mtx;
class S4Importer final : public IParkImporter
{
private:
@@ -272,19 +270,14 @@ namespace OpenRCT2::RCT1
{
auto& objManager = GetContext()->GetObjectManager();
// Ensure only one thread talks to the object manager at a time
std::lock_guard lock(mtx);
// Unload loaded scenario text object, if any.
if (auto* obj = objManager.GetLoadedObject<ScenarioTextObject>(0); obj != nullptr)
objManager.UnloadObjects({ obj->GetDescriptor() });
// Load the one specified
if (auto* obj = objManager.LoadObject(desc.textObjectId); obj != nullptr)
if (auto obj = objManager.LoadTempObject(desc.textObjectId); obj != nullptr)
{
auto* textObject = reinterpret_cast<ScenarioTextObject*>(obj);
name = textObject->GetScenarioName();
details = textObject->GetScenarioDetails();
auto& textObject = reinterpret_cast<ScenarioTextObject&>(*obj);
name = textObject.GetScenarioName();
details = textObject.GetScenarioDetails();
obj->Unload();
}
}
@@ -2415,20 +2408,13 @@ namespace OpenRCT2::RCT1
{
auto& objManager = GetContext()->GetObjectManager();
// Ensure only one thread talks to the object manager at a time
std::lock_guard lock(mtx);
// Unload loaded scenario text object, if any.
if (auto* obj = objManager.GetLoadedObject<ScenarioTextObject>(0); obj != nullptr)
objManager.UnloadObjects({ obj->GetDescriptor() });
// Load the one specified
if (auto* obj = objManager.LoadObject(desc.textObjectId); obj != nullptr)
if (auto obj = objManager.LoadTempObject(desc.textObjectId); obj != nullptr)
{
auto* textObject = reinterpret_cast<ScenarioTextObject*>(obj);
name = textObject->GetScenarioName();
parkName = textObject->GetParkName();
details = textObject->GetScenarioDetails();
auto& textObject = reinterpret_cast<ScenarioTextObject&>(*obj);
name = textObject.GetScenarioName();
parkName = textObject.GetParkName();
details = textObject.GetScenarioDetails();
}
}
}

View File

@@ -95,8 +95,6 @@ namespace OpenRCT2::RCT2
{
#define DECRYPT_MONEY(money) (static_cast<money32>(Numerics::rol32((money) ^ 0xF4EC9621, 13)))
static std::mutex mtx;
/**
* Class to import RollerCoaster Tycoon 2 scenarios (*.SC6) and saved games (*.SV6).
*/
@@ -298,19 +296,14 @@ namespace OpenRCT2::RCT2
{
auto& objManager = GetContext()->GetObjectManager();
// Ensure only one thread talks to the object manager at a time
std::lock_guard lock(mtx);
// Unload loaded scenario text object, if any.
if (auto* obj = objManager.GetLoadedObject<ScenarioTextObject>(0); obj != nullptr)
objManager.UnloadObjects({ obj->GetDescriptor() });
// Load the one specified
if (auto* obj = objManager.LoadObject(desc.textObjectId); obj != nullptr)
if (auto obj = objManager.LoadTempObject(desc.textObjectId); obj != nullptr)
{
auto* textObject = reinterpret_cast<ScenarioTextObject*>(obj);
dst->Name = textObject->GetScenarioName();
dst->Details = textObject->GetScenarioDetails();
auto& textObject = reinterpret_cast<ScenarioTextObject&>(*obj);
dst->Name = textObject.GetScenarioName();
dst->Details = textObject.GetScenarioDetails();
obj->Unload();
}
}