Merge pull request #7430 from IntelOrca/fix/scan-objects

Fix scan objects and run before tests
This commit is contained in:
Ted John 2018-04-22 22:11:03 +01:00 committed by GitHub
commit 41b3a33af4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 83 additions and 60 deletions

View File

@ -185,7 +185,14 @@
<MSBuild Projects="openrct2.sln" Targets="Rebuild" Properties="$(SlnProperties)" />
</Target>
<Target Name="Test" DependsOnTargets="Build">
<Target Name="Test">
<!-- Scan repositories prior to running tests as it can take a while -->
<Message Text="Building OpenRCT2 repository indexes..." Importance="high" />
<Exec Command="$(TargetDir)openrct2.exe scan-objects"
WorkingDirectory="$(TargetDir)"
StandardOutputImportance="normal" />
<Message Text="Running tests..." Importance="high" />
<Exec Command="$(TargetDir)tests.exe &quot;--gtest_output=xml:$(ArtifactsDir)test-results.xml&quot;"
WorkingDirectory="$(TargetDir)" />
</Target>

View File

@ -28,15 +28,15 @@ pushd build
if [[ $TARGET == "docker64" ]]
then
# CMAKE and MAKE opts from environment
docker run -v "$PARENT":"$PARENT" -w "$PARENT"/build -i -t openrct2/openrct2:64bit-only bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && ninja all install $OPENRCT_MAKE_OPTS && ctest --output-on-failure"
docker run -v "$PARENT":"$PARENT" -w "$PARENT"/build -i -t openrct2/openrct2:64bit-only bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && ninja all install $OPENRCT_MAKE_OPTS && ./openrct2-cli scan-objects && ctest --output-on-failure"
elif [[ $TARGET == "ubuntu_i686" ]]
then
# CMAKE and MAKE opts from environment
docker run -v "$PARENT":"$PARENT" -w "$PARENT"/build -i -t openrct2/openrct2:ubuntu_i686 bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && ninja all testpaint install $OPENRCT_MAKE_OPTS && ctest --output-on-failure && ( ./testpaint --quiet || if [[ \$? -eq 1 ]] ; then echo Allowing failed tests to pass ; else echo here ; false; fi )"
docker run -v "$PARENT":"$PARENT" -w "$PARENT"/build -i -t openrct2/openrct2:ubuntu_i686 bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && ninja all testpaint install $OPENRCT_MAKE_OPTS && ./openrct2-cli scan-objects && ctest --output-on-failure && ( ./testpaint --quiet || if [[ \$? -eq 1 ]] ; then echo Allowing failed tests to pass ; else echo here ; false; fi )"
elif [[ $TARGET == "ubuntu_amd64" ]]
then
# CMAKE and MAKE opts from environment
docker run -v "$PARENT":"$PARENT" -w "$PARENT"/build -i -t openrct2/openrct2:ubuntu_amd64 bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && ninja $OPENRCT_MAKE_OPTS install && ctest --output-on-failure"
docker run -v "$PARENT":"$PARENT" -w "$PARENT"/build -i -t openrct2/openrct2:ubuntu_amd64 bash -c "cmake ../ -DWITH_TESTS=on $OPENRCT2_CMAKE_OPTS && ninja $OPENRCT_MAKE_OPTS install && ./openrct2-cli scan-objects && ctest --output-on-failure"
elif [[ $TARGET == "windows" ]]
then
# CMAKE and MAKE opts from environment

View File

@ -15,12 +15,13 @@
#pragma endregion
#include <ctime>
#include <memory>
#include "../config/Config.h"
#include "../Context.h"
#include "../platform/Crash.h"
#include "../platform/platform.h"
#include "../localisation/Language.h"
#include "../core/Console.hpp"
#include "../core/Memory.hpp"
#include "../core/Path.hpp"
@ -394,12 +395,15 @@ static exitcode_t HandleCommandScanObjects([[maybe_unused]] CommandLineArgEnumer
return result;
}
auto env = OpenRCT2::CreatePlatformEnvironment();
gOpenRCT2Headless = true;
auto context = std::unique_ptr<OpenRCT2::IContext>(OpenRCT2::CreateContext());
auto env = context->GetPlatformEnvironment();
auto objectRepository = std::unique_ptr<IObjectRepository>(CreateObjectRepository(env));
// HACK: set gCurrentLanguage otherwise it be wrong for the index file
gCurrentLanguage = gConfigGeneral.language;
auto objectRepository = CreateObjectRepository(env);
objectRepository->Construct();
return EXITCODE_OK;
}

View File

@ -18,6 +18,7 @@
#include "../drawing/Drawing.h"
#include "../localisation/Language.h"
#include "../object/Object.h"
#include "../object/ObjectRepository.h"
#include "BannerObject.h"
#include "ObjectJsonHelpers.h"
#include "ObjectList.h"
@ -46,16 +47,20 @@ void BannerObject::ReadLegacy(IReadObjectContext * context, IStream * stream)
// Add banners to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
const std::string identifier = GetIdentifier();
const rct_object_entry * objectEntry = object_list_find_by_name(identifier.c_str());
static const rct_object_entry scgPathX = Object::GetScgPathXHeader();
auto identifier = GetIdentifier();
if (objectEntry != nullptr &&
(object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_WACKY_WORLDS ||
object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_TIME_TWISTER ||
object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_CUSTOM))
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);
if (item != nullptr)
{
SetPrimarySceneryGroup(&scgPathX);
auto objectEntry = &item->ObjectEntry;
if (object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_WACKY_WORLDS ||
object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_TIME_TWISTER ||
object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_CUSTOM)
{
auto scgPathX = Object::GetScgPathXHeader();
SetPrimarySceneryGroup(&scgPathX);
}
}
}

View File

@ -20,6 +20,7 @@
#include "../interface/Cursors.h"
#include "../localisation/Localisation.h"
#include "../object/Object.h"
#include "../object/ObjectRepository.h"
#include "ObjectList.h"
#include "FootpathItemObject.h"
#include "ObjectJsonHelpers.h"
@ -49,16 +50,20 @@ void FootpathItemObject::ReadLegacy(IReadObjectContext * context, IStream * stre
// Add path bits to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
const std::string identifier = GetIdentifier();
const rct_object_entry * objectEntry = object_list_find_by_name(identifier.c_str());
static const rct_object_entry scgPathX = Object::GetScgPathXHeader();
auto identifier = GetIdentifier();
if (objectEntry != nullptr &&
(object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_WACKY_WORLDS ||
object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_TIME_TWISTER ||
object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_CUSTOM))
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);
if (item != nullptr)
{
SetPrimarySceneryGroup(&scgPathX);
auto sourceGame = object_entry_get_source_game(&item->ObjectEntry);
if (sourceGame == OBJECT_SOURCE_WACKY_WORLDS ||
sourceGame == OBJECT_SOURCE_TIME_TWISTER ||
sourceGame == OBJECT_SOURCE_CUSTOM)
{
auto scgPathX = Object::GetScgPathXHeader();
SetPrimarySceneryGroup(&scgPathX);
}
}
}

View File

@ -111,6 +111,7 @@ struct rct_object_filters {
assert_struct_size(rct_object_filters, 3);
#pragma pack(pop)
interface IObjectRepository;
interface IStream;
struct ObjectRepositoryItem;
struct rct_drawpixelinfo;
@ -119,6 +120,7 @@ interface IReadObjectContext
{
virtual ~IReadObjectContext() = default;
virtual IObjectRepository& GetObjectRepository() abstract;
virtual bool ShouldLoadImages() abstract;
virtual void LogWarning(uint32 code, const utf8 * text) abstract;
@ -206,7 +208,6 @@ sint32 object_calculate_checksum(const rct_object_entry * entry, const void * da
bool find_object_in_entry_group(const rct_object_entry* entry, uint8* entry_type, uint8* entry_index);
void object_create_identifier_name(char* string_buffer, size_t size, const rct_object_entry* object);
const rct_object_entry * object_list_find_by_name(const char *name);
const rct_object_entry * object_list_find(rct_object_entry *entry);
void object_entry_get_name_fixed(utf8 * buffer, size_t bufferSize, const rct_object_entry * entry);

View File

@ -41,6 +41,8 @@
class ReadObjectContext : public IReadObjectContext
{
private:
IObjectRepository& _objectRepository;
std::string _objectName;
bool _loadImages;
bool _wasWarning = false;
@ -50,12 +52,18 @@ public:
bool WasWarning() const { return _wasWarning; }
bool WasError() const { return _wasError; }
ReadObjectContext(const std::string &objectName, bool loadImages)
: _objectName(objectName),
ReadObjectContext(IObjectRepository& objectRepository, const std::string &objectName, bool loadImages)
: _objectRepository(objectRepository),
_objectName(objectName),
_loadImages(loadImages)
{
}
IObjectRepository& GetObjectRepository() override
{
return _objectRepository;
}
bool ShouldLoadImages() override
{
return _loadImages;
@ -101,9 +109,9 @@ namespace ObjectFactory
}
}
Object * CreateObjectFromLegacyFile(const utf8 * path)
Object * CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8 * path)
{
log_verbose("CreateObjectFromLegacyFile(\"%s\")", path);
log_verbose("CreateObjectFromLegacyFile(..., \"%s\")", path);
Object * result = nullptr;
try
@ -122,7 +130,7 @@ namespace ObjectFactory
log_verbose(" size: %zu", chunk->GetLength());
auto chunkStream = MemoryStream(chunk->GetData(), chunk->GetLength());
auto readContext = ReadObjectContext(objectName, !gOpenRCT2Headless);
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2Headless);
ReadObjectLegacy(result, &readContext, &chunkStream);
if (readContext.WasError())
{
@ -137,7 +145,7 @@ namespace ObjectFactory
return result;
}
Object * CreateObjectFromLegacyData(const rct_object_entry * entry, const void * data, size_t dataSize)
Object * CreateObjectFromLegacyData(IObjectRepository& objectRepository, const rct_object_entry * entry, const void * data, size_t dataSize)
{
Guard::ArgumentNotNull(entry, GUARD_LINE);
Guard::ArgumentNotNull(data, GUARD_LINE);
@ -148,7 +156,7 @@ namespace ObjectFactory
utf8 objectName[DAT_NAME_LENGTH + 1];
object_entry_get_name_fixed(objectName, sizeof(objectName), entry);
auto readContext = ReadObjectContext(objectName, !gOpenRCT2Headless);
auto readContext = ReadObjectContext(objectRepository, objectName, !gOpenRCT2Headless);
auto chunkStream = MemoryStream(data, dataSize);
ReadObjectLegacy(result, &readContext, &chunkStream);
@ -220,7 +228,7 @@ namespace ObjectFactory
return 0xFF;
}
Object * CreateObjectFromJsonFile(const std::string &path)
Object * CreateObjectFromJsonFile(IObjectRepository& objectRepository, const std::string &path)
{
log_verbose("CreateObjectFromJsonFile(\"%s\")", path.c_str());
@ -249,7 +257,7 @@ namespace ObjectFactory
memcpy(entry.name, originalName.c_str(), minLength);
result = CreateObject(entry);
auto readContext = ReadObjectContext(id, !gOpenRCT2Headless);
auto readContext = ReadObjectContext(objectRepository, id, !gOpenRCT2Headless);
result->ReadJson(&readContext, jRoot);
if (readContext.WasError())
{

View File

@ -18,14 +18,15 @@
#include "../common.h"
interface IObjectRepository;
class Object;
struct rct_object_entry;
namespace ObjectFactory
{
Object * CreateObjectFromLegacyFile(const utf8 * path);
Object * CreateObjectFromLegacyData(const rct_object_entry * entry, const void * data, size_t dataSize);
Object * CreateObjectFromLegacyFile(IObjectRepository& objectRepository, const utf8 * path);
Object * CreateObjectFromLegacyData(IObjectRepository& objectRepository, const rct_object_entry * entry, const void * data, size_t dataSize);
Object * CreateObject(const rct_object_entry &entry);
Object * CreateObjectFromJsonFile(const std::string &path);
Object * CreateObjectFromJsonFile(IObjectRepository& objectRepository, const std::string &path);
}

View File

@ -234,7 +234,7 @@ namespace ObjectJsonHelpers
{
std::vector<rct_g1_element> result;
auto objectPath = FindLegacyObject(name);
auto obj = ObjectFactory::CreateObjectFromLegacyFile(objectPath.c_str());
auto obj = ObjectFactory::CreateObjectFromLegacyFile(context->GetObjectRepository(), objectPath.c_str());
if (obj != nullptr)
{
auto &imgTable = static_cast<const Object *>(obj)->GetImageTable();

View File

@ -83,8 +83,10 @@ private:
static constexpr uint16 VERSION = 17;
static constexpr auto PATTERN = "*.dat;*.pob;*.json";
IObjectRepository& _objectRepository;
public:
explicit ObjectFileIndex(IPlatformEnvironment * env) :
explicit ObjectFileIndex(IObjectRepository& objectRepository, IPlatformEnvironment * env) :
FileIndex("object index",
MAGIC_NUMBER,
VERSION,
@ -92,7 +94,8 @@ public:
std::string(PATTERN),
std::vector<std::string>({
env->GetDirectoryPath(DIRBASE::OPENRCT2, DIRID::OBJECT),
env->GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT) }))
env->GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT) })),
_objectRepository(objectRepository)
{
}
@ -102,7 +105,7 @@ public:
auto extension = Path::GetExtension(path);
if (String::Equals(extension, ".json", true))
{
auto object = ObjectFactory::CreateObjectFromJsonFile(path);
auto object = ObjectFactory::CreateObjectFromJsonFile(_objectRepository, path);
if (object != nullptr)
{
ObjectRepositoryItem item = { 0 };
@ -116,7 +119,7 @@ public:
}
else
{
auto object = ObjectFactory::CreateObjectFromLegacyFile(path.c_str());
auto object = ObjectFactory::CreateObjectFromLegacyFile(_objectRepository, path.c_str());
if (object != nullptr)
{
ObjectRepositoryItem item = { 0 };
@ -213,7 +216,7 @@ class ObjectRepository final : public IObjectRepository
public:
explicit ObjectRepository(IPlatformEnvironment * env)
: _env(env),
_fileIndex(env)
_fileIndex(*this, env)
{
}
@ -279,11 +282,11 @@ public:
auto extension = Path::GetExtension(ori->Path);
if (String::Equals(extension, ".json", true))
{
return ObjectFactory::CreateObjectFromJsonFile(ori->Path);
return ObjectFactory::CreateObjectFromJsonFile(*this, ori->Path);
}
else
{
return ObjectFactory::CreateObjectFromLegacyFile(ori->Path);
return ObjectFactory::CreateObjectFromLegacyFile(*this, ori->Path);
}
}
@ -310,7 +313,7 @@ public:
object_entry_get_name_fixed(objectName, sizeof(objectName), objectEntry);
// Check that the object is loadable before writing it
Object * object = ObjectFactory::CreateObjectFromLegacyData(objectEntry, data, dataSize);
Object * object = ObjectFactory::CreateObjectFromLegacyData(*this, objectEntry, data, dataSize);
if (object == nullptr)
{
Console::Error::WriteLine("[%s] Unable to export object.", objectName);
@ -659,18 +662,6 @@ const rct_object_entry * object_list_find(rct_object_entry * entry)
return result;
}
const rct_object_entry * object_list_find_by_name(const char * name)
{
const rct_object_entry * result = nullptr;
auto objRepo = GetContext()->GetObjectRepository();
auto item = objRepo->FindObject(name);
if (item != nullptr)
{
result = &item->ObjectEntry;
}
return result;
}
void object_list_load()
{
auto context = GetContext();

View File

@ -551,10 +551,11 @@ private:
std::vector<const char *> objects = RCT1::GetSceneryObjects(sceneryTheme);
for (const char * objectName : objects)
{
const rct_object_entry * foundEntry = object_list_find_by_name(objectName);
if (foundEntry != nullptr)
auto objectRepository = OpenRCT2::GetContext()->GetObjectRepository();
auto foundObject = objectRepository->FindObject(objectName);
if (foundObject != nullptr)
{
uint8 objectType = object_entry_get_type(foundEntry);
uint8 objectType = object_entry_get_type(&foundObject->ObjectEntry);
switch (objectType) {
case OBJECT_TYPE_SMALL_SCENERY:
case OBJECT_TYPE_LARGE_SCENERY: