Merge branch 'num_of_conflicts' of https://github.com/wolfreak99/OpenRCT2 into wolfreak99-num_of_conflicts

This commit is contained in:
Ted John 2016-12-27 23:56:59 +00:00
commit 5095e7037a
4 changed files with 27 additions and 5 deletions

View File

@ -190,7 +190,7 @@ extern "C"
// TODO Ideally we want to delay this until we show the title so that we can
// still open the game window and draw a progress screen for the creation
// of the object cache.
objRepo->LoadOrConstruct();
objRepo->LoadOrConstruct(false);
// TODO Like objects, this can take a while if there are a lot of track designs
// its also really something really we might want to do in the background

View File

@ -30,6 +30,7 @@ extern "C"
#include "../core/Path.hpp"
#include "../core/String.hpp"
#include "../network/network.h"
#include "../object/ObjectRepository.h"
#include "CommandLine.hpp"
#ifdef USE_BREAKPAD
@ -66,6 +67,7 @@ static utf8 * _userDataPath = nullptr;
static utf8 * _openrctDataPath = nullptr;
static utf8 * _rct2DataPath = nullptr;
static bool _silentBreakpad = false;
static bool _forceScan = false;
static const CommandLineOptionDefinition StandardOptions[]
{
@ -89,6 +91,7 @@ static const CommandLineOptionDefinition StandardOptions[]
#ifdef USE_BREAKPAD
{ CMDLINE_TYPE_SWITCH, &_silentBreakpad, NAC, "silent-breakpad", "make breakpad crash reporting silent" },
#endif // USE_BREAKPAD
{ CMDLINE_TYPE_SWITCH, &_forceScan, 'f', "force-scan", "forces scanning of object repository" },
OptionTableEnd
};
@ -194,6 +197,14 @@ exitcode_t CommandLine::HandleCommandDefault()
gOpenRCT2Headless = _headless;
gOpenRCT2SilentBreakpad = _silentBreakpad || _headless;
if (_forceScan)
{
IObjectRepository * objectRepository = GetObjectRepository();
objectRepository->LoadOrConstruct(true);
result = EXITCODE_OK;
}
if (_userDataPath != nullptr)
{
String::Set(gCustomUserDataPath, sizeof(gCustomUserDataPath), _userDataPath);

View File

@ -99,6 +99,7 @@ class ObjectRepository : public IObjectRepository
QueryDirectoryResult _queryDirectoryResult = { 0 };
ObjectEntryMap _itemMap;
uint16 _languageId = 0;
int _numConflicts;
public:
ObjectRepository(IPlatformEnvironment * env)
@ -111,7 +112,7 @@ public:
ClearItems();
}
void LoadOrConstruct() override
void LoadOrConstruct(bool forceScan) override
{
ClearItems();
@ -122,8 +123,12 @@ public:
QueryDirectory(&_queryDirectoryResult, rct2Path);
QueryDirectory(&_queryDirectoryResult, openrct2Path);
if (!Load())
if (forceScan || !Load())
{
if (forceScan)
{
Console::WriteLine("Forcing object repository scan.");
}
_languageId = gCurrentLanguage;
Construct();
@ -247,6 +252,7 @@ private:
Path::GetDirectory(objectDirectory, sizeof(objectDirectory), gRCT2AddressObjectDataPath);
Console::WriteLine("Scanning %lu objects...", _queryDirectoryResult.TotalFiles);
_numConflicts = 0;
auto stopwatch = Stopwatch();
stopwatch.Start();
@ -258,6 +264,10 @@ private:
stopwatch.Stop();
Console::WriteLine("Scanning complete in %.2f seconds.", stopwatch.GetElapsedMilliseconds() / 1000.0f);
if (_numConflicts > 0)
{
Console::WriteLine("%d object conflicts found.", _numConflicts);
}
}
void ScanDirectory(const std::string &directory)
@ -390,6 +400,7 @@ private:
}
else
{
_numConflicts++;
Console::Error::WriteLine("Object conflict: '%s'", conflict->Path);
Console::Error::WriteLine(" : '%s'", item->Path);
return false;
@ -659,7 +670,7 @@ extern "C"
void object_list_load()
{
IObjectRepository * objectRepository = GetObjectRepository();
objectRepository->LoadOrConstruct();
objectRepository->LoadOrConstruct(false);
IObjectManager * objectManager = GetObjectManager();
objectManager->UnloadAll();

View File

@ -63,7 +63,7 @@ interface IObjectRepository
{
virtual ~IObjectRepository() { }
virtual void LoadOrConstruct() abstract;
virtual void LoadOrConstruct(bool forceScan) abstract;
virtual size_t GetNumObjects() const abstract;
virtual const ObjectRepositoryItem * GetObjects() const abstract;
virtual const ObjectRepositoryItem * FindObject(const utf8 * name) const abstract;