1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

Implement ride music objects and refactor

This commit is contained in:
Ted John
2021-01-09 20:54:02 +00:00
parent db4841ca45
commit 2f39442d25
35 changed files with 1401 additions and 674 deletions

View File

@@ -10,8 +10,10 @@
#include "Object.h"
#include "../Context.h"
#include "../core/File.h"
#include "../core/Memory.hpp"
#include "../core/String.hpp"
#include "../core/Zip.h"
#include "../localisation/Language.h"
#include "../localisation/LocalisationService.h"
#include "../localisation/StringIds.h"
@@ -165,6 +167,84 @@ std::optional<uint8_t> rct_object_entry::GetSceneryType() const
}
}
class zipstreamwrapper final : public std::istream
{
private:
std::unique_ptr<IZipArchive> _zipArchive;
std::unique_ptr<std::istream> _base;
public:
zipstreamwrapper(std::unique_ptr<IZipArchive> zipArchive, std::unique_ptr<std::istream> base)
: std::istream(base->rdbuf())
, _zipArchive(std::move(zipArchive))
, _base(std::move(base))
{
}
};
bool ObjectAsset::IsAvailable() const
{
if (_zipPath.empty())
{
return File::Exists(_path);
}
else
{
auto zipArchive = Zip::TryOpen(_zipPath, ZIP_ACCESS::READ);
return zipArchive != nullptr && zipArchive->Exists(_path);
}
}
size_t ObjectAsset::GetLength() const
{
if (_zipPath.empty())
{
try
{
return File::ReadAllBytes(_path).size();
}
catch (...)
{
return 0;
}
}
else
{
auto zipArchive = Zip::TryOpen(_zipPath, ZIP_ACCESS::READ);
if (zipArchive != nullptr)
{
auto index = zipArchive->GetIndexFromPath(_path);
if (index)
{
auto size = zipArchive->GetFileSize(*index);
return size;
}
}
}
return 0;
}
std::unique_ptr<std::istream> ObjectAsset::GetStream() const
{
if (_zipPath.empty())
{
return std::make_unique<std::ifstream>(_path, std::ios::binary);
}
else
{
auto zipArchive = Zip::TryOpen(_zipPath, ZIP_ACCESS::READ);
if (zipArchive != nullptr)
{
auto stream = zipArchive->GetFileStream(_path);
if (stream != nullptr)
{
return std::make_unique<zipstreamwrapper>(std::move(zipArchive), std::move(stream));
}
}
}
return {};
}
#ifdef __WARN_SUGGEST_FINAL_METHODS__
# pragma GCC diagnostic pop
#endif