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

Merge pull request #14712 from CookiePLMonster/startup-speed-optimization

Startup speed optimizations
This commit is contained in:
Michael Steenbeek
2021-05-21 20:49:44 +02:00
committed by GitHub
9 changed files with 58 additions and 30 deletions

View File

@@ -20,6 +20,7 @@
- Fix: [#14587] Confusing message when joining server with mismatched network version.
- Fix: [#14604] American-style Steam Trains are not imported correctly from RCT1 saves.
- Fix: [#14638] The “About OpenRCT2” window cannot be themed.
- Improved: [#14712]: Improve startup times.
0.3.3 (2021-03-13)
------------------------------------------------------------------------

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -57,8 +57,7 @@ namespace File
}
std::vector<uint8_t> result;
fs.seekg(0, std::ios::end);
auto fsize = static_cast<size_t>(fs.tellg());
auto fsize = Platform::GetFileSize(path);
if (fsize > SIZE_MAX)
{
std::string message = String::StdFormat(
@@ -68,7 +67,6 @@ namespace File
else
{
result.resize(fsize);
fs.seekg(0);
fs.read(reinterpret_cast<char*>(result.data()), result.size());
fs.exceptions(fs.failbit);
}
@@ -123,6 +121,11 @@ namespace File
{
return Platform::GetLastModified(path);
}
uint64_t GetSize(std::string_view path)
{
return Platform::GetFileSize(path);
}
} // namespace File
bool writeentirefile(const utf8* path, const void* buffer, size_t length)

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -26,4 +26,5 @@ namespace File
std::vector<std::string> ReadAllLines(std::string_view path);
void WriteAllBytes(const std::string& path, const void* buffer, size_t length);
uint64_t GetLastModified(const std::string& path);
uint64_t GetSize(std::string_view path);
} // namespace File

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -16,6 +16,8 @@
#ifndef _WIN32
# include <sys/stat.h>
#else
# include <io.h>
#endif
#if defined(__linux__) && !defined(__ANDROID__)
@@ -98,9 +100,12 @@ namespace OpenRCT2
throw IOException(String::StdFormat("Unable to open '%s'", path));
}
Seek(0, STREAM_SEEK_END);
_fileSize = GetPosition();
Seek(0, STREAM_SEEK_BEGIN);
#ifdef _WIN32
_fileSize = _filelengthi64(_fileno(_file));
#else
std::error_code ec;
_fileSize = fs::file_size(fs::u8path(path), ec);
#endif
_ownsFilePtr = true;
}
@@ -160,13 +165,9 @@ namespace OpenRCT2
void FileStream::Read(void* buffer, uint64_t length)
{
uint64_t remainingBytes = GetLength() - GetPosition();
if (length <= remainingBytes)
if (fread(buffer, 1, static_cast<size_t>(length), _file) == length)
{
if (fread(buffer, static_cast<size_t>(length), 1, _file) == 1)
{
return;
}
return;
}
throw IOException("Attempted to read past end of file.");
}

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -252,18 +252,11 @@ bool ObjectAsset::IsAvailable() const
}
}
size_t ObjectAsset::GetSize() const
uint64_t ObjectAsset::GetSize() const
{
if (_zipPath.empty())
{
try
{
return File::ReadAllBytes(_path).size();
}
catch (...)
{
return 0;
}
return File::GetSize(_path);
}
else
{

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -223,7 +223,7 @@ public:
}
bool IsAvailable() const;
size_t GetSize() const;
uint64_t GetSize() const;
std::unique_ptr<OpenRCT2::IStream> GetStream() const;
};

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -177,6 +177,19 @@ namespace Platform
return lastModified;
}
uint64_t GetFileSize(std::string_view path)
{
uint64_t size = 0;
struct stat statInfo
{
};
if (stat(std::string(path).c_str(), &statInfo) == 0)
{
size = statInfo.st_size;
}
return size;
}
bool ShouldIgnoreCase()
{
return false;

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -554,6 +554,21 @@ namespace Platform
return lastModified;
}
uint64_t GetFileSize(std::string_view path)
{
uint64_t size = 0;
auto pathW = String::ToWideChar(path);
WIN32_FILE_ATTRIBUTE_DATA attributes;
if (GetFileAttributesExW(pathW.c_str(), GetFileExInfoStandard, &attributes) != FALSE)
{
ULARGE_INTEGER fileSize;
fileSize.LowPart = attributes.nFileSizeLow;
fileSize.HighPart = attributes.nFileSizeHigh;
size = fileSize.QuadPart;
}
return size;
}
bool ShouldIgnoreCase()
{
return true;

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -39,6 +39,7 @@ namespace Platform
bool IsPathSeparator(char c);
utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath);
uint64_t GetLastModified(const std::string& path);
uint64_t GetFileSize(std::string_view path);
std::string ResolveCasing(const std::string& path, bool fileExists);
rct2_time GetTimeLocal();
rct2_date GetDateLocal();