mirror of https://github.com/OpenRCT2/OpenRCT2.git
add reading of entrance objects
This commit is contained in:
parent
c9a1357994
commit
2449b7dbf0
|
@ -121,6 +121,7 @@
|
|||
<ClCompile Include="src\object\EntranceObject.cpp" />
|
||||
<ClCompile Include="src\object\ImageTable.cpp" />
|
||||
<ClCompile Include="src\object\Object.cpp" />
|
||||
<ClCompile Include="src\object\ObjectFactory.cpp" />
|
||||
<ClCompile Include="src\object\ObjectRepository.cpp" />
|
||||
<ClCompile Include="src\object\StringTable.cpp" />
|
||||
<ClCompile Include="src\object_list.c" />
|
||||
|
@ -426,6 +427,7 @@
|
|||
<ClInclude Include="src\object\EntranceObject.h" />
|
||||
<ClInclude Include="src\object\ImageTable.h" />
|
||||
<ClInclude Include="src\object\Object.h" />
|
||||
<ClInclude Include="src\object\ObjectFactory.h" />
|
||||
<ClInclude Include="src\object\ObjectRepository.h" />
|
||||
<ClInclude Include="src\object\StringTable.h" />
|
||||
<ClInclude Include="src\object_list.h" />
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "../core/IStream.hpp"
|
||||
#include "EntranceObject.h"
|
||||
|
||||
void EntranceObject::Load(IStream * stream)
|
||||
void EntranceObject::ReadLegacy(IStream * stream)
|
||||
{
|
||||
_legacyType.string_idx = stream->ReadValue<rct_string_id>();
|
||||
_legacyType.image_id = stream->ReadValue<uint32>();
|
||||
|
@ -27,3 +27,13 @@ void EntranceObject::Load(IStream * stream)
|
|||
LoadStringTable(stream, 0);
|
||||
LoadImageTable(stream);
|
||||
}
|
||||
|
||||
void EntranceObject::Load()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EntranceObject::Unload()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
const rct_object_entry * GetObjectEntry() override { return &_objectEntry; }
|
||||
void * GetLegacyData() override { return &_legacyType; }
|
||||
|
||||
protected:
|
||||
void Load(IStream * stream) override;
|
||||
void ReadLegacy(IStream * stream) override;
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
};
|
||||
|
|
|
@ -40,10 +40,11 @@ public:
|
|||
virtual const rct_object_entry * GetObjectEntry() abstract;
|
||||
virtual void * GetLegacyData() abstract;
|
||||
|
||||
protected:
|
||||
virtual void Load(IStream * stream) abstract;
|
||||
virtual void ReadLegacy(IStream * stream) abstract;
|
||||
virtual void Load() abstract;
|
||||
virtual void Unload() abstract;
|
||||
|
||||
protected:
|
||||
void LoadStringTable(IStream * stream, uint8 id);
|
||||
void LoadImageTable(IStream * stream);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* A full copy of the GNU General Public License can be found in licence.txt
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "../core/FileStream.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../core/MemoryStream.h"
|
||||
#include "EntranceObject.h"
|
||||
#include "Object.h"
|
||||
#include "ObjectFactory.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../object.h"
|
||||
#include "../util/sawyercoding.h"
|
||||
}
|
||||
|
||||
namespace ObjectFactory
|
||||
{
|
||||
Object * CreateObjectFromLegacyFile(utf8 * path)
|
||||
{
|
||||
Object * result = nullptr;
|
||||
|
||||
SDL_RWops * file = SDL_RWFromFile(path, "rb");
|
||||
if (file != nullptr)
|
||||
{
|
||||
rct_object_entry entry;
|
||||
if (SDL_RWread(file, &entry, sizeof(entry), 1) == 1)
|
||||
{
|
||||
uint8 objectType = entry.flags & 0x0F;
|
||||
result = CreateObject(objectType);
|
||||
if (result != nullptr)
|
||||
{
|
||||
size_t bufferSize = 0x600000;
|
||||
void * buffer = Memory::Allocate<void>(bufferSize);
|
||||
bufferSize = sawyercoding_read_chunk_with_size(file, (uint8 *)buffer, bufferSize);
|
||||
buffer = Memory::Reallocate(buffer, bufferSize);
|
||||
auto ms = MemoryStream(buffer, bufferSize);
|
||||
result->ReadLegacy(&ms);
|
||||
}
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Object * CreateObject(uint8 type)
|
||||
{
|
||||
Object * result = nullptr;
|
||||
|
||||
switch (type) {
|
||||
case OBJECT_TYPE_PARK_ENTRANCE:
|
||||
result = new EntranceObject();
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* A full copy of the GNU General Public License can be found in licence.txt
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
class Object;
|
||||
|
||||
namespace ObjectFactory
|
||||
{
|
||||
Object * CreateObjectFromLegacyFile(utf8 * path);
|
||||
Object * CreateObject(uint8 type);
|
||||
}
|
|
@ -23,6 +23,8 @@
|
|||
#include "../core/Memory.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "Object.h"
|
||||
#include "ObjectFactory.h"
|
||||
#include "ObjectRepository.h"
|
||||
|
||||
extern "C"
|
||||
|
@ -135,13 +137,11 @@ private:
|
|||
|
||||
void ScanObject(utf8 * path)
|
||||
{
|
||||
rct_object_entry entry;
|
||||
if (!object_load_entry(path, &entry))
|
||||
Object * object = ObjectFactory::CreateObjectFromLegacyFile(path);
|
||||
if (object != nullptr)
|
||||
{
|
||||
return;
|
||||
// TODO
|
||||
}
|
||||
|
||||
__nop();
|
||||
}
|
||||
|
||||
bool Load()
|
||||
|
|
|
@ -36,6 +36,14 @@ bool StringIsBlank(utf8 * str)
|
|||
return true;
|
||||
}
|
||||
|
||||
StringTable::~StringTable()
|
||||
{
|
||||
for (auto entry : _strings)
|
||||
{
|
||||
Memory::Free(entry.Text);
|
||||
}
|
||||
}
|
||||
|
||||
void StringTable::Read(IStream * stream, uint8 id)
|
||||
{
|
||||
uint8 languageId;
|
||||
|
@ -58,24 +66,36 @@ void StringTable::Read(IStream * stream, uint8 id)
|
|||
|
||||
void StringTable::Sort()
|
||||
{
|
||||
std::sort(_strings.begin(), _strings.end(), [](const StringTableEntry &a, const StringTableEntry &b) -> int
|
||||
std::sort(_strings.begin(), _strings.end(), [](const StringTableEntry &a, const StringTableEntry &b) -> bool
|
||||
{
|
||||
if (a.Id == b.Id)
|
||||
{
|
||||
if (a.LanguageId == b.LanguageId)
|
||||
{
|
||||
return _strcmpi(a.Text, b.Text);
|
||||
return _strcmpi(a.Text, b.Text) == -1;
|
||||
}
|
||||
if (a.LanguageId == LanguagesDescriptors[gCurrentLanguage].rct2_original_id)
|
||||
|
||||
uint8 currentLanguage = LanguagesDescriptors[gCurrentLanguage].rct2_original_id;
|
||||
if (a.LanguageId == currentLanguage)
|
||||
{
|
||||
return -1;
|
||||
return true;
|
||||
}
|
||||
if (b.LanguageId == currentLanguage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a.LanguageId == RCT2_LANGUAGE_ID_ENGLISH_UK)
|
||||
{
|
||||
return -1;
|
||||
return true;
|
||||
}
|
||||
return 1;
|
||||
if (b.LanguageId == RCT2_LANGUAGE_ID_ENGLISH_UK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return a.LanguageId < b.LanguageId;
|
||||
}
|
||||
return a.Id - b.Id;
|
||||
return a.Id < b.Id;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ private:
|
|||
std::vector<StringTableEntry> _strings;
|
||||
|
||||
public:
|
||||
~StringTable();
|
||||
void Read(IStream * stream, uint8 id);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue