mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Add progress bars to title sequence loading, but only the initial park
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <openrct2/entity/EntityRegistry.h>
|
||||
#include <openrct2/interface/Viewport.h>
|
||||
#include <openrct2/interface/Window.h>
|
||||
#include <openrct2/localisation/StringIds.h>
|
||||
#include <openrct2/management/NewsItem.h>
|
||||
#include <openrct2/object/ObjectManager.h>
|
||||
#include <openrct2/scenario/ScenarioRepository.h>
|
||||
@@ -48,6 +49,7 @@ namespace OpenRCT2::Title
|
||||
std::unique_ptr<TitleSequence> _sequence;
|
||||
int32_t _position = 0;
|
||||
int32_t _waitCounter = 0;
|
||||
bool _initialLoadCommand = true;
|
||||
|
||||
int32_t _previousWindowWidth = 0;
|
||||
int32_t _previousWindowHeight = 0;
|
||||
@@ -207,6 +209,7 @@ namespace OpenRCT2::Title
|
||||
{
|
||||
_position = 0;
|
||||
_waitCounter = 0;
|
||||
_initialLoadCommand = true;
|
||||
}
|
||||
|
||||
void Seek(int32_t targetPosition) override
|
||||
@@ -280,6 +283,20 @@ namespace OpenRCT2::Title
|
||||
return _position != entryPosition;
|
||||
}
|
||||
|
||||
void ReportProgress(uint8_t progress)
|
||||
{
|
||||
if (!_initialLoadCommand)
|
||||
return;
|
||||
|
||||
if (progress == 0)
|
||||
GetContext()->OpenProgress(STR_LOADING_TITLE_SEQUENCE);
|
||||
|
||||
GetContext()->SetProgress(progress, 100, STR_STRING_M_PERCENT, true);
|
||||
|
||||
if (progress == 100)
|
||||
GetContext()->CloseProgress();
|
||||
}
|
||||
|
||||
bool LoadParkFromFile(const u8string& path)
|
||||
{
|
||||
LOG_VERBOSE("TitleSequencePlayer::LoadParkFromFile(%s)", path.c_str());
|
||||
@@ -294,24 +311,33 @@ namespace OpenRCT2::Title
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportProgress(0);
|
||||
auto parkImporter = ParkImporter::Create(path);
|
||||
|
||||
auto result = parkImporter->Load(path);
|
||||
ReportProgress(30);
|
||||
|
||||
auto& objectManager = GetContext()->GetObjectManager();
|
||||
objectManager.LoadObjects(result.RequiredObjects);
|
||||
ReportProgress(70);
|
||||
|
||||
// TODO: Have a separate GameState and exchange once loaded.
|
||||
auto& gameState = GetGameState();
|
||||
parkImporter->Import(gameState);
|
||||
ReportProgress(100);
|
||||
|
||||
MapAnimationAutoCreate();
|
||||
}
|
||||
PrepareParkForPlayback();
|
||||
_initialLoadCommand = false;
|
||||
success = true;
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
Console::Error::WriteLine("Unable to load park: %s", path.c_str());
|
||||
GetContext()->CloseProgress();
|
||||
}
|
||||
|
||||
gLoadKeepWindowsOpen = false;
|
||||
return success;
|
||||
}
|
||||
@@ -334,25 +360,32 @@ namespace OpenRCT2::Title
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportProgress(0);
|
||||
bool isScenario = ParkImporter::ExtensionIsScenario(hintPath);
|
||||
auto parkImporter = ParkImporter::Create(hintPath);
|
||||
|
||||
auto result = parkImporter->LoadFromStream(stream, isScenario);
|
||||
ReportProgress(30);
|
||||
|
||||
auto& objectManager = GetContext()->GetObjectManager();
|
||||
objectManager.LoadObjects(result.RequiredObjects);
|
||||
ReportProgress(70);
|
||||
|
||||
// TODO: Have a separate GameState and exchange once loaded.
|
||||
auto& gameState = GetGameState();
|
||||
|
||||
parkImporter->Import(gameState);
|
||||
ReportProgress(100);
|
||||
|
||||
MapAnimationAutoCreate();
|
||||
}
|
||||
PrepareParkForPlayback();
|
||||
_initialLoadCommand = false;
|
||||
success = true;
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
Console::Error::WriteLine("Unable to load park: %s", hintPath.c_str());
|
||||
GetContext()->CloseProgress();
|
||||
}
|
||||
gLoadKeepWindowsOpen = false;
|
||||
return success;
|
||||
|
||||
@@ -669,8 +669,12 @@ namespace OpenRCT2
|
||||
// from the main thread, though, so this cannot be invoked when off main thread.
|
||||
// It's fine (and indeed useful!) for synchronous calls, so we keep it as an option.
|
||||
if (!gOpenRCT2Headless && forceDraw)
|
||||
{
|
||||
_uiContext->ProcessMessages();
|
||||
WindowUpdateAll();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
void CloseProgress() override
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user