1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-27 16:54:52 +01:00

Use new S6 importer for title screen and fix issues

This commit is contained in:
Ted John
2017-01-31 18:37:55 +00:00
parent 8998b2ae18
commit 5d7a712672
6 changed files with 72 additions and 43 deletions

View File

@@ -0,0 +1,35 @@
#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/Path.hpp"
#include "core/String.hpp"
#include "ParkImporter.h"
IParkImporter * CreateParkImporterForPath(const std::string &path)
{
IParkImporter * parkImporter = nullptr;
std::string extension = Path::GetExtension(path);
if (String::Equals(extension, ".sc4", true) ||
String::Equals(extension, ".sv4", true))
{
parkImporter = CreateS4Importer();
}
else
{
parkImporter = CreateS6Importer();
}
return parkImporter;
}

View File

@@ -16,6 +16,7 @@
#pragma once
#include <string>
#include "common.h"
#include "scenario/ScenarioRepository.h"
@@ -38,3 +39,4 @@ public:
IParkImporter * CreateS4Importer();
IParkImporter * CreateS6Importer();
IParkImporter * CreateParkImporterForPath(const std::string &path);

View File

@@ -33,11 +33,12 @@ enum
class FileStream final : public IStream
{
private:
SDL_RWops * _file;
bool _canRead;
bool _canWrite;
bool _disposed;
uint64 _fileSize;
SDL_RWops * _file = 0;
bool _ownsFilePtr = false;
bool _canRead = false;
bool _canWrite = false;
bool _disposed = false;
uint64 _fileSize = 0;
public:
FileStream(const std::string &path, sint32 fileMode) :
@@ -68,9 +69,8 @@ public:
{
throw IOException(SDL_GetError());
}
_disposed = false;
_fileSize = SDL_RWsize(_file);
_ownsFilePtr = true;
}
FileStream(SDL_RWops * ops, sint32 fileMode)
@@ -88,8 +88,6 @@ public:
default:
throw;
}
_disposed = false;
_fileSize = SDL_RWsize(_file);
}
@@ -98,7 +96,10 @@ public:
if (!_disposed)
{
_disposed = true;
SDL_RWclose(_file);
if (_ownsFilePtr)
{
SDL_RWclose(_file);
}
}
}

View File

@@ -73,6 +73,7 @@
<ClCompile Include="audio\MemoryAudioSource.cpp" />
<ClCompile Include="audio\NullAudioSource.cpp" />
<ClCompile Include="FileClassifier.cpp" />
<ClCompile Include="ParkImporter.cpp" />
<ClCompile Include="rct12\SawyerEncoding.cpp" />
<ClCompile Include="rct2\addresses.c" />
<ClCompile Include="audio\audio.c" />

View File

@@ -14,6 +14,7 @@
*****************************************************************************/
#pragma endregion
#include "../core/Console.hpp"
#include "../core/Exception.hpp"
#include "../core/FileStream.hpp"
#include "../core/IStream.hpp"
@@ -127,6 +128,7 @@ public:
{
throw Exception("Park is not a scenario.");
}
SawyerEncoding::ReadChunkTolerant(&_s6.info, sizeof(_s6.info), stream);
}
else
{
@@ -136,8 +138,6 @@ public:
}
}
SawyerEncoding::ReadChunkTolerant(&_s6.info, sizeof(_s6.info), stream);
// Read packed objects
// TODO try to contain this more and not store objects until later
for (uint16 i = 0; i < _s6.header.num_packed_objects; i++)
@@ -407,6 +407,11 @@ public:
}
};
IParkImporter * CreateS6Importer()
{
return new S6Importer();
}
extern "C"
{
/**
@@ -436,11 +441,13 @@ extern "C"
sprite_position_tween_reset();
result = true;
}
catch (const ObjectLoadException &)
catch (const ObjectLoadException &ex)
{
Console::Error::WriteLine(ex.GetMessage());
}
catch (const Exception &)
catch (const Exception &ex)
{
Console::Error::WriteLine(ex.GetMessage());
}
delete s6Importer;

View File

@@ -14,6 +14,7 @@
*****************************************************************************/
#pragma endregion
#include <memory>
#include "../common.h"
#include <SDL.h>
#include "../core/Console.hpp"
@@ -352,33 +353,19 @@ private:
bool LoadParkFromFile(const utf8 * path)
{
log_verbose("TitleSequencePlayer::LoadParkFromFile(%s)", path);
bool success = false;
const utf8 * extension = Path::GetExtension(path);
if (String::Equals(extension, ".sc4", true) ||
String::Equals(extension, ".sv4", true))
try
{
try
{
bool isScenario = String::Equals(extension, ".sc4", true);
IParkImporter * s4Importer = CreateS4Importer();
s4Importer->Load(path);
s4Importer->Import();
PrepareParkForPlayback(isScenario);
success = true;
}
catch (Exception)
{
}
auto parkImporter = std::unique_ptr<IParkImporter>(CreateParkImporterForPath(path));
parkImporter->Load(path);
parkImporter->Import();
PrepareParkForPlayback();
success = true;
}
else
catch (Exception)
{
bool isScenario = String::Equals(extension, ".sc6", true);
SDL_RWops * rw = SDL_RWFromFile(path, "rb");
if (rw != nullptr)
{
success = LoadParkFromRW(rw, isScenario);
SDL_RWclose(rw);
}
Console::Error::WriteLine("Unable to load park: %s", path);
}
return success;
}
@@ -389,12 +376,12 @@ private:
game_load_sv6(rw);
if (successfulLoad)
{
PrepareParkForPlayback(isScenario);
PrepareParkForPlayback();
}
return successfulLoad;
}
void PrepareParkForPlayback(bool isScenario)
void PrepareParkForPlayback()
{
rct_window * w = window_get_main();
w->viewport_target_sprite = -1;
@@ -425,10 +412,6 @@ private:
reset_sprite_spatial_index();
reset_all_sprite_quadrant_placements();
window_new_ride_init_vars();
if (!isScenario)
{
sub_684AC3();
}
scenery_set_default_placement_configuration();
news_item_init_queue();
load_palette();