mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-20 05:23:04 +01:00
Modify object loading for JSON-only objects
This commit is contained in:
@@ -33,9 +33,74 @@ ObjectType& operator++(ObjectType& d, int)
|
||||
return d = (d == ObjectType::Count) ? ObjectType::Ride : static_cast<ObjectType>(static_cast<uint8_t>(d) + 1);
|
||||
}
|
||||
|
||||
Object::Object(const rct_object_entry& entry)
|
||||
ObjectEntryDescriptor::ObjectEntryDescriptor(const rct_object_entry& newEntry)
|
||||
{
|
||||
_objectEntry = entry;
|
||||
if (!newEntry.IsEmpty())
|
||||
{
|
||||
Generation = ObjectGeneration::DAT;
|
||||
Entry = newEntry;
|
||||
}
|
||||
}
|
||||
|
||||
ObjectEntryDescriptor::ObjectEntryDescriptor(std::string_view newIdentifier)
|
||||
{
|
||||
Generation = ObjectGeneration::JSON;
|
||||
Identifier = std::string(newIdentifier);
|
||||
}
|
||||
|
||||
ObjectEntryDescriptor::ObjectEntryDescriptor(ObjectType type, std::string_view newIdentifier)
|
||||
{
|
||||
Generation = ObjectGeneration::JSON;
|
||||
Identifier = std::string(newIdentifier);
|
||||
Type = type;
|
||||
}
|
||||
|
||||
ObjectEntryDescriptor::ObjectEntryDescriptor(const ObjectRepositoryItem& ori)
|
||||
{
|
||||
if (!ori.Identifier.empty())
|
||||
{
|
||||
Generation = ObjectGeneration::JSON;
|
||||
Identifier = std::string(ori.Identifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
Generation = ObjectGeneration::DAT;
|
||||
Entry = ori.ObjectEntry;
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectEntryDescriptor::HasValue() const
|
||||
{
|
||||
return Generation != ObjectGeneration::JSON || !Identifier.empty();
|
||||
};
|
||||
|
||||
ObjectType ObjectEntryDescriptor::GetType() const
|
||||
{
|
||||
return Generation == ObjectGeneration::JSON ? Type : Entry.GetType();
|
||||
}
|
||||
|
||||
std::string_view ObjectEntryDescriptor::GetName() const
|
||||
{
|
||||
return Generation == ObjectGeneration::JSON ? Identifier : Entry.GetName();
|
||||
}
|
||||
|
||||
bool ObjectEntryDescriptor::operator==(const ObjectEntryDescriptor& rhs) const
|
||||
{
|
||||
if (Generation != rhs.Generation)
|
||||
return false;
|
||||
if (Generation == ObjectGeneration::DAT)
|
||||
{
|
||||
return Entry == rhs.Entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Type == rhs.Type && Identifier == rhs.Identifier;
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectEntryDescriptor::operator!=(const ObjectEntryDescriptor& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
void* Object::GetLegacyData()
|
||||
@@ -171,6 +236,61 @@ std::optional<uint8_t> rct_object_entry::GetSceneryType() const
|
||||
}
|
||||
}
|
||||
|
||||
bool rct_object_entry::IsEmpty() const
|
||||
{
|
||||
uint64_t a, b;
|
||||
std::memcpy(&a, reinterpret_cast<const uint8_t*>(this), 8);
|
||||
std::memcpy(&b, reinterpret_cast<const uint8_t*>(this) + 8, 8);
|
||||
|
||||
if (a == 0xFFFFFFFFFFFFFFFF && b == 0xFFFFFFFFFFFFFFFF)
|
||||
return true;
|
||||
if (a == 0 && b == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool rct_object_entry::operator==(const rct_object_entry& rhs) const
|
||||
{
|
||||
const auto a = this;
|
||||
const auto b = &rhs;
|
||||
|
||||
// If an official object don't bother checking checksum
|
||||
if ((a->flags & 0xF0) || (b->flags & 0xF0))
|
||||
{
|
||||
if (a->GetType() != b->GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int32_t match = memcmp(a->name, b->name, 8);
|
||||
if (match)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a->flags != b->flags)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int32_t match = memcmp(a->name, b->name, 8);
|
||||
if (match)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (a->checksum != b->checksum)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rct_object_entry::operator!=(const rct_object_entry& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
bool ObjectAsset::IsAvailable() const
|
||||
{
|
||||
if (_zipPath.empty())
|
||||
@@ -227,20 +347,6 @@ std::unique_ptr<IStream> ObjectAsset::GetStream() const
|
||||
return {};
|
||||
}
|
||||
|
||||
ObjectEntryDescriptor::ObjectEntryDescriptor(const ObjectRepositoryItem& ori)
|
||||
{
|
||||
if (!ori.Identifier.empty())
|
||||
{
|
||||
Generation = ObjectGeneration::JSON;
|
||||
Identifier = std::string(ori.Identifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
Generation = ObjectGeneration::DAT;
|
||||
Entry = ori.ObjectEntry;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user