1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

clang-format title

This commit is contained in:
clang-format
2018-06-22 23:15:14 +02:00
committed by Hielke Morsink
parent 861715a169
commit abb097124c
6 changed files with 299 additions and 298 deletions

View File

@@ -7,34 +7,34 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../config/Config.h"
#include "../Context.h"
#include "../core/Console.hpp"
#include "../GameState.h"
#include "../interface/Screenshot.h"
#include "../network/network.h"
#include "../OpenRCT2.h"
#include "../scenario/Scenario.h"
#include "../scenario/ScenarioRepository.h"
#include "TitleScreen.h"
#include "TitleSequence.h"
#include "TitleSequenceManager.h"
#include "TitleSequencePlayer.h"
#include "../audio/audio.h"
#include "../drawing/Drawing.h"
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../Input.h"
#include "../OpenRCT2.h"
#include "../audio/audio.h"
#include "../config/Config.h"
#include "../core/Console.hpp"
#include "../drawing/Drawing.h"
#include "../interface/Screenshot.h"
#include "../interface/Viewport.h"
#include "../interface/Window.h"
#include "../localisation/Localisation.h"
#include "../network/network.h"
#include "../scenario/Scenario.h"
#include "../scenario/ScenarioRepository.h"
#include "../ui/UiContext.h"
#include "TitleSequence.h"
#include "TitleSequenceManager.h"
#include "TitleSequencePlayer.h"
using namespace OpenRCT2;
// TODO Remove when no longer required.
bool gPreviewingTitleSequenceInGame;
static TitleScreen * _singleton = nullptr;
static TitleScreen* _singleton = nullptr;
TitleScreen::TitleScreen(GameState& gameState)
: _gameState(gameState)
@@ -47,7 +47,7 @@ TitleScreen::~TitleScreen()
_singleton = nullptr;
}
ITitleSequencePlayer * TitleScreen::GetSequencePlayer()
ITitleSequencePlayer* TitleScreen::GetSequencePlayer()
{
return _sequencePlayer;
}
@@ -83,7 +83,7 @@ void TitleScreen::StopPreviewingSequence()
{
if (_previewingSequence)
{
rct_window * mainWindow = window_get_main();
rct_window* mainWindow = window_get_main();
if (mainWindow != nullptr)
{
window_unfollow_sprite(mainWindow);
@@ -163,7 +163,8 @@ void TitleScreen::Update()
_sequencePlayer->Update();
int32_t numUpdates = 1;
if (gGameSpeed > 1) {
if (gGameSpeed > 1)
{
numUpdates = 1 << (gGameSpeed - 1);
}
for (int32_t i = 0; i < numUpdates; i++)
@@ -194,7 +195,7 @@ void TitleScreen::ChangePresetSequence(size_t preset)
return;
}
const utf8 * configId = title_sequence_manager_get_config_id(preset);
const utf8* configId = title_sequence_manager_get_config_id(preset);
SafeFree(gConfigInterface.current_title_sequence_preset);
gConfigInterface.current_title_sequence_preset = _strdup(configId);
@@ -251,7 +252,7 @@ bool TitleScreen::TryLoadSequence(bool loadPreview)
if (targetSequence != _currentSequence && !loadPreview)
{
// Forcefully change the preset to a preset that works.
const utf8 * configId = title_sequence_manager_get_config_id(targetSequence);
const utf8* configId = title_sequence_manager_get_config_id(targetSequence);
SafeFree(gConfigInterface.current_title_sequence_preset);
gConfigInterface.current_title_sequence_preset = _strdup(configId);
}
@@ -260,8 +261,7 @@ bool TitleScreen::TryLoadSequence(bool loadPreview)
return true;
}
targetSequence = (targetSequence + 1) % numSequences;
}
while (targetSequence != _currentSequence && !loadPreview);
} while (targetSequence != _currentSequence && !loadPreview);
}
Console::Error::WriteLine("Unable to play any title sequences.");
_sequencePlayer->Eject();
@@ -292,9 +292,9 @@ void title_create_windows()
}
}
void * title_get_sequence_player()
void* title_get_sequence_player()
{
void * result = nullptr;
void* result = nullptr;
if (_singleton != nullptr)
{
result = _singleton->GetSequencePlayer();
@@ -369,12 +369,12 @@ bool title_is_previewing_sequence()
return false;
}
void DrawOpenRCT2(rct_drawpixelinfo * dpi, int32_t x, int32_t y)
void DrawOpenRCT2(rct_drawpixelinfo* dpi, int32_t x, int32_t y)
{
utf8 buffer[256];
// Write format codes
utf8 * ch = buffer;
utf8* ch = buffer;
ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT);
ch = utf8_write_codepoint(ch, FORMAT_OUTLINE);
ch = utf8_write_codepoint(ch, FORMAT_WHITE);
@@ -391,4 +391,3 @@ void DrawOpenRCT2(rct_drawpixelinfo * dpi, int32_t x, int32_t y)
snprintf(ch, 256 - (ch - buffer), "%s (%s)", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE);
gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5);
}

View File

@@ -10,7 +10,6 @@
#pragma once
#include "../common.h"
#include "../drawing/Drawing.h"
interface ITitleSequencePlayer;
@@ -25,13 +24,13 @@ namespace OpenRCT2
TitleScreen(GameState& gameState);
~TitleScreen();
ITitleSequencePlayer * GetSequencePlayer();
size_t GetCurrentSequence();
bool PreviewSequence(size_t value);
void StopPreviewingSequence();
bool IsPreviewingSequence();
bool ShouldHideVersionInfo();
void SetHideVersionInfo(bool value);
ITitleSequencePlayer* GetSequencePlayer();
size_t GetCurrentSequence();
bool PreviewSequence(size_t value);
void StopPreviewingSequence();
bool IsPreviewingSequence();
bool ShouldHideVersionInfo();
void SetHideVersionInfo(bool value);
void Load();
void Update();
@@ -39,25 +38,25 @@ namespace OpenRCT2
void ChangePresetSequence(size_t preset);
private:
GameState& _gameState;
GameState& _gameState;
ITitleSequencePlayer * _sequencePlayer = nullptr;
size_t _loadedTitleSequenceId = SIZE_MAX;
size_t _currentSequence = SIZE_MAX;
bool _hideVersionInfo = false;
bool _previewingSequence = false;
ITitleSequencePlayer* _sequencePlayer = nullptr;
size_t _loadedTitleSequenceId = SIZE_MAX;
size_t _currentSequence = SIZE_MAX;
bool _hideVersionInfo = false;
bool _previewingSequence = false;
void TitleInitialise();
bool TryLoadSequence(bool loadPreview = false);
};
}
} // namespace OpenRCT2
// When testing title sequences within a normal game
extern bool gPreviewingTitleSequenceInGame;
void title_load();
void title_create_windows();
void * title_get_sequence_player();
void* title_get_sequence_player();
void title_sequence_change_preset(size_t preset);
bool title_should_hide_version_info();
void title_set_hide_version_info(bool value);
@@ -66,5 +65,4 @@ size_t title_get_current_sequence();
bool title_preview_sequence(size_t value);
void title_stop_previewing_sequence();
bool title_is_previewing_sequence();
void DrawOpenRCT2(rct_drawpixelinfo * dpi, int32_t x, int32_t y);
void DrawOpenRCT2(rct_drawpixelinfo* dpi, int32_t x, int32_t y);

View File

@@ -7,8 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <memory>
#include <vector>
#include "TitleSequence.h"
#include "../common.h"
#include "../core/Collections.hpp"
#include "../core/Console.hpp"
@@ -26,32 +26,33 @@
#include "../scenario/ScenarioRepository.h"
#include "../scenario/ScenarioSources.h"
#include "../util/Util.h"
#include "TitleSequence.h"
#include <memory>
#include <vector>
static std::vector<utf8 *> GetSaves(const utf8 * path);
static std::vector<utf8 *> GetSaves(IZipArchive * zip);
static std::vector<TitleCommand> LegacyScriptRead(utf8 * script, size_t scriptLength, std::vector<utf8 *> saves);
static void LegacyScriptGetLine(IStream * stream, char * parts);
static std::vector<uint8_t> ReadScriptFile(const utf8 * path);
static std::string LegacyScriptWrite(TitleSequence * seq);
static std::vector<utf8*> GetSaves(const utf8* path);
static std::vector<utf8*> GetSaves(IZipArchive* zip);
static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLength, std::vector<utf8*> saves);
static void LegacyScriptGetLine(IStream* stream, char* parts);
static std::vector<uint8_t> ReadScriptFile(const utf8* path);
static std::string LegacyScriptWrite(TitleSequence* seq);
TitleSequence * CreateTitleSequence()
TitleSequence* CreateTitleSequence()
{
TitleSequence * seq = Memory::Allocate<TitleSequence>();
TitleSequence* seq = Memory::Allocate<TitleSequence>();
*seq = {};
return seq;
}
TitleSequence * LoadTitleSequence(const utf8 * path)
TitleSequence* LoadTitleSequence(const utf8* path)
{
std::vector<uint8_t> script;
std::vector<utf8 *> saves;
std::vector<utf8*> saves;
bool isZip;
log_verbose("Loading title sequence: %s", path);
const utf8 * ext = Path::GetExtension(path);
const utf8* ext = Path::GetExtension(path);
if (String::Equals(ext, TITLE_SEQUENCE_EXTENSION))
{
auto zip = std::unique_ptr<IZipArchive>(Zip::TryOpen(path, ZIP_ACCESS::READ));
@@ -87,9 +88,9 @@ TitleSequence * LoadTitleSequence(const utf8 * path)
isZip = false;
}
auto commands = LegacyScriptRead((utf8 *)script.data(), script.size(), saves);
auto commands = LegacyScriptRead((utf8*)script.data(), script.size(), saves);
TitleSequence * seq = CreateTitleSequence();
TitleSequence* seq = CreateTitleSequence();
seq->Name = Path::GetFileNameWithoutExtension(path);
seq->Path = String::Duplicate(path);
seq->NumSaves = saves.size();
@@ -100,7 +101,7 @@ TitleSequence * LoadTitleSequence(const utf8 * path)
return seq;
}
void FreeTitleSequence(TitleSequence * seq)
void FreeTitleSequence(TitleSequence* seq)
{
if (seq != nullptr)
{
@@ -116,12 +117,12 @@ void FreeTitleSequence(TitleSequence * seq)
}
}
TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index)
TitleSequenceParkHandle* TitleSequenceGetParkHandle(TitleSequence* seq, size_t index)
{
TitleSequenceParkHandle * handle = nullptr;
TitleSequenceParkHandle* handle = nullptr;
if (index <= seq->NumSaves)
{
const utf8 * filename = seq->Saves[index];
const utf8* filename = seq->Saves[index];
if (seq->IsZip)
{
auto zip = std::unique_ptr<IZipArchive>(Zip::TryOpen(seq->Path, ZIP_ACCESS::READ));
@@ -135,7 +136,9 @@ TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t
handle = Memory::Allocate<TitleSequenceParkHandle>();
handle->Stream = ms;
handle->HintPath = String::Duplicate(filename);
} else {
}
else
{
Console::Error::WriteLine("Failed to open zipped path '%s' from zip '%s'", filename, seq->Path);
}
}
@@ -166,17 +169,17 @@ TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t
return handle;
}
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle)
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle* handle)
{
if (handle != nullptr)
{
Memory::Free(handle->HintPath);
delete ((IStream *)handle->Stream);
delete ((IStream*)handle->Stream);
Memory::Free(handle);
}
}
bool TitleSequenceSave(TitleSequence * seq)
bool TitleSequenceSave(TitleSequence* seq)
{
try
{
@@ -194,13 +197,13 @@ bool TitleSequenceSave(TitleSequence * seq)
}
return true;
}
catch (const std::exception &)
catch (const std::exception&)
{
return false;
}
}
bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name)
bool TitleSequenceAddPark(TitleSequence* seq, const utf8* path, const utf8* name)
{
// Get new save index
size_t index = SIZE_MAX;
@@ -234,7 +237,7 @@ bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * n
}
zip->SetFileData(name, std::move(fdata));
}
catch (const std::exception &ex)
catch (const std::exception& ex)
{
Console::Error::WriteLine(ex.what());
}
@@ -254,11 +257,11 @@ bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * n
return true;
}
bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name)
bool TitleSequenceRenamePark(TitleSequence* seq, size_t index, const utf8* name)
{
Guard::Assert(index < seq->NumSaves, GUARD_LINE);
utf8 * oldRelativePath = seq->Saves[index];
utf8* oldRelativePath = seq->Saves[index];
if (seq->IsZip)
{
auto zip = Zip::TryOpen(seq->Path, ZIP_ACCESS::WRITE);
@@ -289,12 +292,12 @@ bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * nam
return true;
}
bool TitleSequenceRemovePark(TitleSequence * seq, size_t index)
bool TitleSequenceRemovePark(TitleSequence* seq, size_t index)
{
Guard::Assert(index < seq->NumSaves, GUARD_LINE);
// Delete park file
utf8 * relativePath = seq->Saves[index];
utf8* relativePath = seq->Saves[index];
if (seq->IsZip)
{
auto zip = Zip::TryOpen(seq->Path, ZIP_ACCESS::WRITE);
@@ -328,7 +331,7 @@ bool TitleSequenceRemovePark(TitleSequence * seq, size_t index)
// Update load commands
for (size_t i = 0; i < seq->NumCommands; i++)
{
TitleCommand * command = &seq->Commands[i];
TitleCommand* command = &seq->Commands[i];
if (command->Type == TITLE_SCRIPT_LOAD)
{
if (command->SaveIndex == index)
@@ -347,33 +350,32 @@ bool TitleSequenceRemovePark(TitleSequence * seq, size_t index)
return true;
}
static std::vector<utf8 *> GetSaves(const utf8 * directory)
static std::vector<utf8*> GetSaves(const utf8* directory)
{
std::vector<utf8 *> saves;
std::vector<utf8*> saves;
utf8 pattern[MAX_PATH];
String::Set(pattern, sizeof(pattern), directory);
Path::Append(pattern, sizeof(pattern), "*.sc6;*.sv6");
IFileScanner * scanner = Path::ScanDirectory(pattern, true);
IFileScanner* scanner = Path::ScanDirectory(pattern, true);
while (scanner->Next())
{
const utf8 * path = scanner->GetPathRelative();
const utf8* path = scanner->GetPathRelative();
saves.push_back(String::Duplicate(path));
}
return saves;
}
static std::vector<utf8 *> GetSaves(IZipArchive * zip)
static std::vector<utf8*> GetSaves(IZipArchive* zip)
{
std::vector<utf8 *> saves;
std::vector<utf8*> saves;
size_t numFiles = zip->GetNumFiles();
for (size_t i = 0; i < numFiles; i++)
{
auto name = zip->GetFileName(i);
auto ext = Path::GetExtension(name);
if (String::Equals(ext, ".sv6", true) ||
String::Equals(ext, ".sc6", true))
if (String::Equals(ext, ".sv6", true) || String::Equals(ext, ".sc6", true))
{
saves.push_back(String::Duplicate(name));
}
@@ -381,7 +383,7 @@ static std::vector<utf8 *> GetSaves(IZipArchive * zip)
return saves;
}
static std::vector<TitleCommand> LegacyScriptRead(utf8 * script, size_t scriptLength, std::vector<utf8 *> saves)
static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLength, std::vector<utf8*> saves)
{
std::vector<TitleCommand> commands;
auto fs = MemoryStream(script, scriptLength);
@@ -464,10 +466,10 @@ static std::vector<TitleCommand> LegacyScriptRead(utf8 * script, size_t scriptLe
{
command.Type = TITLE_SCRIPT_LOADSC;
// Confirm the scenario exists
//source_desc desc;
//if (ScenarioSources::TryGetByName(part1, &desc))
// source_desc desc;
// if (ScenarioSources::TryGetByName(part1, &desc))
//{
safe_strcpy(command.Scenario, part1, sizeof(command.Scenario));
safe_strcpy(command.Scenario, part1, sizeof(command.Scenario));
//}
}
}
@@ -475,12 +477,11 @@ static std::vector<TitleCommand> LegacyScriptRead(utf8 * script, size_t scriptLe
{
commands.push_back(command);
}
}
while (fs.GetPosition() < scriptLength);
} while (fs.GetPosition() < scriptLength);
return commands;
}
static void LegacyScriptGetLine(IStream * stream, char * parts)
static void LegacyScriptGetLine(IStream* stream, char* parts)
{
for (int32_t i = 0; i < 3; i++)
{
@@ -513,8 +514,9 @@ static void LegacyScriptGetLine(IStream * stream, char * parts)
{
if (!whitespace)
{
if (part == 0 && ((cindex == 4 && _strnicmp(parts, "LOAD", 4) == 0) ||
(cindex == 6 && _strnicmp(parts, "LOADSC", 6) == 0)))
if (part == 0
&& ((cindex == 4 && _strnicmp(parts, "LOAD", 4) == 0)
|| (cindex == 6 && _strnicmp(parts, "LOADSC", 6) == 0)))
{
load = true;
}
@@ -545,7 +547,7 @@ static void LegacyScriptGetLine(IStream * stream, char * parts)
}
}
static std::vector<uint8_t> ReadScriptFile(const utf8 * path)
static std::vector<uint8_t> ReadScriptFile(const utf8* path)
{
std::vector<uint8_t> result;
try
@@ -555,7 +557,7 @@ static std::vector<uint8_t> ReadScriptFile(const utf8 * path)
result.resize(size);
fs.Read(result.data(), size);
}
catch (const std::exception &)
catch (const std::exception&)
{
result.clear();
result.shrink_to_fit();
@@ -563,7 +565,7 @@ static std::vector<uint8_t> ReadScriptFile(const utf8 * path)
return result;
}
static std::string LegacyScriptWrite(TitleSequence * seq)
static std::string LegacyScriptWrite(TitleSequence* seq)
{
utf8 buffer[128];
auto sb = StringBuilder(128);
@@ -573,67 +575,68 @@ static std::string LegacyScriptWrite(TitleSequence * seq)
sb.Append("\n");
for (size_t i = 0; i < seq->NumCommands; i++)
{
const TitleCommand * command = &seq->Commands[i];
switch (command->Type) {
case TITLE_SCRIPT_LOADMM:
sb.Append("LOADMM");
break;
case TITLE_SCRIPT_LOADRCT1:
String::Format(buffer, sizeof(buffer), "LOADRCT1 %u", command->SaveIndex);
sb.Append(buffer);
break;
case TITLE_SCRIPT_LOAD:
if (command->SaveIndex == 0xFF)
{
sb.Append("LOAD <No save file>");
}
else
{
sb.Append("LOAD ");
sb.Append(seq->Saves[command->SaveIndex]);
}
break;
case TITLE_SCRIPT_LOADSC:
if (command->Scenario[0] == '\0')
{
sb.Append("LOADSC <No scenario name>");
}
else
{
sb.Append("LOADSC ");
sb.Append(command->Scenario);
}
break;
case TITLE_SCRIPT_LOCATION:
String::Format(buffer, sizeof(buffer), "LOCATION %u %u", command->X, command->Y);
sb.Append(buffer);
break;
case TITLE_SCRIPT_ROTATE:
String::Format(buffer, sizeof(buffer), "ROTATE %u", command->Rotations);
sb.Append(buffer);
break;
case TITLE_SCRIPT_ZOOM:
String::Format(buffer, sizeof(buffer), "ZOOM %u", command->Zoom);
sb.Append(buffer);
break;
case TITLE_SCRIPT_FOLLOW:
String::Format(buffer, sizeof(buffer), "FOLLOW %u ", command->SpriteIndex);
sb.Append(buffer);
sb.Append(command->SpriteName);
break;
case TITLE_SCRIPT_SPEED:
String::Format(buffer, sizeof(buffer), "SPEED %u", command->Speed);
sb.Append(buffer);
break;
case TITLE_SCRIPT_WAIT:
String::Format(buffer, sizeof(buffer), "WAIT %u", command->Milliseconds);
sb.Append(buffer);
break;
case TITLE_SCRIPT_RESTART:
sb.Append("RESTART");
break;
case TITLE_SCRIPT_END:
sb.Append("END");
const TitleCommand* command = &seq->Commands[i];
switch (command->Type)
{
case TITLE_SCRIPT_LOADMM:
sb.Append("LOADMM");
break;
case TITLE_SCRIPT_LOADRCT1:
String::Format(buffer, sizeof(buffer), "LOADRCT1 %u", command->SaveIndex);
sb.Append(buffer);
break;
case TITLE_SCRIPT_LOAD:
if (command->SaveIndex == 0xFF)
{
sb.Append("LOAD <No save file>");
}
else
{
sb.Append("LOAD ");
sb.Append(seq->Saves[command->SaveIndex]);
}
break;
case TITLE_SCRIPT_LOADSC:
if (command->Scenario[0] == '\0')
{
sb.Append("LOADSC <No scenario name>");
}
else
{
sb.Append("LOADSC ");
sb.Append(command->Scenario);
}
break;
case TITLE_SCRIPT_LOCATION:
String::Format(buffer, sizeof(buffer), "LOCATION %u %u", command->X, command->Y);
sb.Append(buffer);
break;
case TITLE_SCRIPT_ROTATE:
String::Format(buffer, sizeof(buffer), "ROTATE %u", command->Rotations);
sb.Append(buffer);
break;
case TITLE_SCRIPT_ZOOM:
String::Format(buffer, sizeof(buffer), "ZOOM %u", command->Zoom);
sb.Append(buffer);
break;
case TITLE_SCRIPT_FOLLOW:
String::Format(buffer, sizeof(buffer), "FOLLOW %u ", command->SpriteIndex);
sb.Append(buffer);
sb.Append(command->SpriteName);
break;
case TITLE_SCRIPT_SPEED:
String::Format(buffer, sizeof(buffer), "SPEED %u", command->Speed);
sb.Append(buffer);
break;
case TITLE_SCRIPT_WAIT:
String::Format(buffer, sizeof(buffer), "WAIT %u", command->Milliseconds);
sb.Append(buffer);
break;
case TITLE_SCRIPT_RESTART:
sb.Append("RESTART");
break;
case TITLE_SCRIPT_END:
sb.Append("END");
}
sb.Append("\n");
}
@@ -641,15 +644,16 @@ static std::string LegacyScriptWrite(TitleSequence * seq)
return sb.GetBuffer();
}
bool TitleSequenceIsLoadCommand(const TitleCommand * command)
bool TitleSequenceIsLoadCommand(const TitleCommand* command)
{
switch (command->Type) {
case TITLE_SCRIPT_LOADMM:
case TITLE_SCRIPT_LOAD:
case TITLE_SCRIPT_LOADRCT1:
case TITLE_SCRIPT_LOADSC:
return true;
default:
return false;
switch (command->Type)
{
case TITLE_SCRIPT_LOADMM:
case TITLE_SCRIPT_LOAD:
case TITLE_SCRIPT_LOADRCT1:
case TITLE_SCRIPT_LOADSC:
return true;
default:
return false;
}
}

View File

@@ -17,44 +17,45 @@
struct TitleCommand
{
uint8_t Type;
union {
uint8_t SaveIndex; // LOAD (this index is internal only)
struct // LOCATION
union
{
uint8_t SaveIndex; // LOAD (this index is internal only)
struct // LOCATION
{
uint8_t X;
uint8_t Y;
};
uint8_t Rotations; // ROTATE (counter-clockwise)
uint8_t Zoom; // ZOOM
struct // FOLLOW
uint8_t Rotations; // ROTATE (counter-clockwise)
uint8_t Zoom; // ZOOM
struct // FOLLOW
{
uint16_t SpriteIndex;
utf8 SpriteName[USER_STRING_MAX_LENGTH];
};
uint8_t Speed; // SPEED
uint16_t Milliseconds; // WAIT
utf8 Scenario[TITLE_COMMAND_SCENARIO_LENGTH]; // LOADSC
uint8_t Speed; // SPEED
uint16_t Milliseconds; // WAIT
utf8 Scenario[TITLE_COMMAND_SCENARIO_LENGTH]; // LOADSC
};
};
struct TitleSequence
{
const utf8 * Name;
const utf8 * Path;
const utf8* Name;
const utf8* Path;
size_t NumCommands;
TitleCommand * Commands;
size_t NumCommands;
TitleCommand* Commands;
size_t NumSaves;
utf8 * * Saves;
size_t NumSaves;
utf8** Saves;
bool IsZip;
};
struct TitleSequenceParkHandle
{
const utf8 * HintPath;
void * Stream;
const utf8* HintPath;
void* Stream;
};
enum TITLE_SCRIPT
@@ -76,24 +77,23 @@ enum TITLE_SCRIPT
TITLE_SCRIPT_LOADSC,
};
constexpr const utf8 * TITLE_SEQUENCE_EXTENSION = ".parkseq";
constexpr uint8_t SAVE_INDEX_INVALID = UINT8_MAX;
constexpr const utf8* TITLE_SEQUENCE_EXTENSION = ".parkseq";
constexpr uint8_t SAVE_INDEX_INVALID = UINT8_MAX;
TitleSequence * CreateTitleSequence();
TitleSequence * LoadTitleSequence(const utf8 * path);
void FreeTitleSequence(TitleSequence * seq);
TitleSequence* CreateTitleSequence();
TitleSequence* LoadTitleSequence(const utf8* path);
void FreeTitleSequence(TitleSequence* seq);
TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index);
TitleSequenceParkHandle* TitleSequenceGetParkHandle(TitleSequence* seq, size_t index);
/**
* Close a title sequence park handle.
* The pointer to the handle is invalid after calling this function.
*/
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle);
bool TitleSequenceSave(TitleSequence * seq);
bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name);
bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name);
bool TitleSequenceRemovePark(TitleSequence * seq, size_t index);
bool TitleSequenceIsLoadCommand(const TitleCommand * command);
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle* handle);
bool TitleSequenceSave(TitleSequence* seq);
bool TitleSequenceAddPark(TitleSequence* seq, const utf8* path, const utf8* name);
bool TitleSequenceRenamePark(TitleSequence* seq, size_t index, const utf8* name);
bool TitleSequenceRemovePark(TitleSequence* seq, size_t index);
bool TitleSequenceIsLoadCommand(const TitleCommand* command);

View File

@@ -7,57 +7,57 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <vector>
#include "TitleSequenceManager.h"
#include "../OpenRCT2.h"
#include "../core/Collections.hpp"
#include "../core/FileScanner.h"
#include "../core/Memory.hpp"
#include "../core/Path.hpp"
#include "../core/String.hpp"
#include "../core/Util.hpp"
#include "../OpenRCT2.h"
#include "TitleSequence.h"
#include "TitleSequenceManager.h"
#include "../localisation/Localisation.h"
#include "../platform/platform.h"
#include "TitleSequence.h"
#include <algorithm>
#include <vector>
namespace TitleSequenceManager
{
struct PredefinedSequence
{
const utf8 * ConfigId;
const utf8 * Filename;
const utf8* ConfigId;
const utf8* Filename;
rct_string_id StringId;
};
const PredefinedSequence PredefinedSequences[] =
{
{ "*RCT1", "rct1.parkseq", STR_TITLE_SEQUENCE_RCT1 },
{ "*RCT1AA", "rct1aa.parkseq", STR_TITLE_SEQUENCE_RCT1_AA },
{ "*RCT1AALL", "rct1aall.parkseq", STR_TITLE_SEQUENCE_RCT1_AA_LL },
{ "*RCT2", "rct2.parkseq", STR_TITLE_SEQUENCE_RCT2 },
{ "*OPENRCT2", "openrct2.parkseq", STR_TITLE_SEQUENCE_OPENRCT2 },
const PredefinedSequence PredefinedSequences[] = {
{ "*RCT1", "rct1.parkseq", STR_TITLE_SEQUENCE_RCT1 },
{ "*RCT1AA", "rct1aa.parkseq", STR_TITLE_SEQUENCE_RCT1_AA },
{ "*RCT1AALL", "rct1aall.parkseq", STR_TITLE_SEQUENCE_RCT1_AA_LL },
{ "*RCT2", "rct2.parkseq", STR_TITLE_SEQUENCE_RCT2 },
{ "*OPENRCT2", "openrct2.parkseq", STR_TITLE_SEQUENCE_OPENRCT2 },
};
static std::vector<TitleSequenceManagerItem> _items;
static std::string GetNewTitleSequencePath(const std::string &name, bool isZip);
static size_t FindItemIndexByPath(const utf8 * path);
static void Scan(const utf8 * directory);
static void AddSequence(const utf8 * scanPath);
static std::string GetNewTitleSequencePath(const std::string& name, bool isZip);
static size_t FindItemIndexByPath(const utf8* path);
static void Scan(const utf8* directory);
static void AddSequence(const utf8* scanPath);
static void SortSequences();
static std::string GetNameFromSequencePath(const std::string &path);
static void GetDataSequencesPath(utf8 * buffer, size_t bufferSize);
static void GetUserSequencesPath(utf8 * buffer, size_t bufferSize);
static bool IsNameReserved(const std::string &name);
static std::string GetNameFromSequencePath(const std::string& path);
static void GetDataSequencesPath(utf8* buffer, size_t bufferSize);
static void GetUserSequencesPath(utf8* buffer, size_t bufferSize);
static bool IsNameReserved(const std::string& name);
size_t GetCount()
{
return _items.size();
}
const TitleSequenceManagerItem * GetItem(size_t i)
const TitleSequenceManagerItem* GetItem(size_t i)
{
if (i >= _items.size())
{
@@ -66,12 +66,10 @@ namespace TitleSequenceManager
return &_items[i];
}
static size_t FindItemIndexByPath(const utf8 * path)
static size_t FindItemIndexByPath(const utf8* path)
{
size_t index = Collections::IndexOf(_items, [path](const TitleSequenceManagerItem &item) -> bool
{
return String::Equals(path, item.Path.c_str());
});
size_t index = Collections::IndexOf(
_items, [path](const TitleSequenceManagerItem& item) -> bool { return String::Equals(path, item.Path.c_str()); });
return index;
}
@@ -82,7 +80,7 @@ namespace TitleSequenceManager
{
return;
}
const utf8 * path = item->Path.c_str();
const utf8* path = item->Path.c_str();
if (item->IsZip)
{
platform_file_delete(path);
@@ -94,10 +92,10 @@ namespace TitleSequenceManager
_items.erase(_items.begin() + i);
}
size_t RenameItem(size_t i, const utf8 * newName)
size_t RenameItem(size_t i, const utf8* newName)
{
auto item = &_items[i];
const utf8 * oldPath = item->Path.c_str();
const utf8* oldPath = item->Path.c_str();
utf8 newPath[MAX_PATH];
Path::GetDirectory(newPath, sizeof(newPath), oldPath);
@@ -120,10 +118,10 @@ namespace TitleSequenceManager
return index;
}
size_t DuplicateItem(size_t i, const utf8 * name)
size_t DuplicateItem(size_t i, const utf8* name)
{
auto item = &_items[i];
const utf8 * srcPath = item->Path.c_str();
const utf8* srcPath = item->Path.c_str();
std::string dstPath = GetNewTitleSequencePath(std::string(name), item->IsZip);
if (!platform_file_copy(srcPath, dstPath.c_str(), true))
@@ -137,10 +135,10 @@ namespace TitleSequenceManager
return index;
}
size_t CreateItem(const utf8 * name)
size_t CreateItem(const utf8* name)
{
std::string path = GetNewTitleSequencePath(std::string(name), true);
TitleSequence * seq = CreateTitleSequence();
TitleSequence* seq = CreateTitleSequence();
seq->Name = String::Duplicate(name);
seq->Path = String::Duplicate(path.c_str());
seq->IsZip = true;
@@ -158,7 +156,7 @@ namespace TitleSequenceManager
return index;
}
static std::string GetNewTitleSequencePath(const std::string &name, bool isZip)
static std::string GetNewTitleSequencePath(const std::string& name, bool isZip)
{
utf8 path[MAX_PATH];
GetUserSequencesPath(path, sizeof(path));
@@ -171,9 +169,9 @@ namespace TitleSequenceManager
return std::string(path);
}
static size_t GetPredefinedIndex(const std::string &path)
static size_t GetPredefinedIndex(const std::string& path)
{
const utf8 * filename = Path::GetFileName(path.c_str());
const utf8* filename = Path::GetFileName(path.c_str());
for (size_t i = 0; i < Util::CountOf(PredefinedSequences); i++)
{
if (String::Equals(filename, PredefinedSequences[i].Filename, true))
@@ -187,19 +185,18 @@ namespace TitleSequenceManager
static void SortSequences()
{
// Sort sequences by predefined index and then name
std::sort(_items.begin(), _items.end(), [](const TitleSequenceManagerItem &a,
const TitleSequenceManagerItem &b) -> bool
{
if (a.PredefinedIndex < b.PredefinedIndex)
{
return true;
}
else if (a.PredefinedIndex > b.PredefinedIndex)
{
return false;
}
return _strcmpi(a.Name.c_str(), b.Name.c_str()) < 0;
});
std::sort(
_items.begin(), _items.end(), [](const TitleSequenceManagerItem& a, const TitleSequenceManagerItem& b) -> bool {
if (a.PredefinedIndex < b.PredefinedIndex)
{
return true;
}
else if (a.PredefinedIndex > b.PredefinedIndex)
{
return false;
}
return _strcmpi(a.Name.c_str(), b.Name.c_str()) < 0;
});
}
void Scan()
@@ -219,22 +216,22 @@ namespace TitleSequenceManager
SortSequences();
}
static void Scan(const utf8 * directory)
static void Scan(const utf8* directory)
{
utf8 pattern[MAX_PATH];
String::Set(pattern, sizeof(pattern), directory);
Path::Append(pattern, sizeof(pattern), "script.txt;*.parkseq");
IFileScanner * fileScanner = Path::ScanDirectory(pattern, true);
IFileScanner* fileScanner = Path::ScanDirectory(pattern, true);
while (fileScanner->Next())
{
const utf8 * path = fileScanner->GetPath();
const utf8* path = fileScanner->GetPath();
AddSequence(path);
}
delete fileScanner;
}
static void AddSequence(const utf8 * scanPath)
static void AddSequence(const utf8* scanPath)
{
TitleSequenceManagerItem item;
@@ -243,7 +240,7 @@ namespace TitleSequenceManager
if (String::Equals(Path::GetExtension(scanPath), ".txt", true))
{
// If we are given a .txt file, set the path to the containing directory
utf8 * utf8Path = Path::GetDirectory(scanPath);
utf8* utf8Path = Path::GetDirectory(scanPath);
path = std::string(utf8Path);
Memory::Free(utf8Path);
isZip = false;
@@ -272,30 +269,30 @@ namespace TitleSequenceManager
_items.push_back(item);
}
static std::string GetNameFromSequencePath(const std::string &path)
static std::string GetNameFromSequencePath(const std::string& path)
{
utf8 * name = Path::GetFileNameWithoutExtension(path.c_str());
utf8* name = Path::GetFileNameWithoutExtension(path.c_str());
std::string result = std::string(name);
Memory::Free(name);
return result;
}
static void GetDataSequencesPath(utf8 * buffer, size_t bufferSize)
static void GetDataSequencesPath(utf8* buffer, size_t bufferSize)
{
platform_get_openrct_data_path(buffer, bufferSize);
Path::Append(buffer, bufferSize, "title");
}
static void GetUserSequencesPath(utf8 * buffer, size_t bufferSize)
static void GetUserSequencesPath(utf8* buffer, size_t bufferSize)
{
platform_get_user_directory(buffer, "title sequences", bufferSize);
}
static bool IsNameReserved(const std::string &name)
static bool IsNameReserved(const std::string& name)
{
for (const auto &pseq : TitleSequenceManager::PredefinedSequences)
for (const auto& pseq : TitleSequenceManager::PredefinedSequences)
{
const utf8 * predefinedName = Path::GetFileNameWithoutExtension(pseq.Filename);
const utf8* predefinedName = Path::GetFileNameWithoutExtension(pseq.Filename);
std::string reservedName = std::string(predefinedName);
Memory::Free(predefinedName);
if (String::Equals(name, reservedName, true))
@@ -312,36 +309,38 @@ size_t title_sequence_manager_get_count()
return TitleSequenceManager::GetCount();
}
const utf8 * title_sequence_manager_get_name(size_t index)
const utf8* title_sequence_manager_get_name(size_t index)
{
auto item = TitleSequenceManager::GetItem(index);
if (item == nullptr)
{
return nullptr;
}
const utf8 * name = item->Name.c_str();
const utf8* name = item->Name.c_str();
return name;
}
const utf8 * title_sequence_manager_get_path(size_t index)
const utf8* title_sequence_manager_get_path(size_t index)
{
auto item = TitleSequenceManager::GetItem(index);
if (item == nullptr) {
if (item == nullptr)
{
return nullptr;
}
const utf8 * name = item->Path.c_str();
const utf8* name = item->Path.c_str();
return name;
}
const utf8 * title_sequence_manager_get_config_id(size_t index)
const utf8* title_sequence_manager_get_config_id(size_t index)
{
auto item = TitleSequenceManager::GetItem(index);
if (item == nullptr) {
if (item == nullptr)
{
return nullptr;
}
const utf8 * name = item->Name.c_str();
const utf8 * filename = Path::GetFileName(item->Path.c_str());
for (const auto &pseq : TitleSequenceManager::PredefinedSequences)
const utf8* name = item->Name.c_str();
const utf8* filename = Path::GetFileName(item->Path.c_str());
for (const auto& pseq : TitleSequenceManager::PredefinedSequences)
{
if (String::Equals(filename, pseq.Filename, true))
{
@@ -354,19 +353,20 @@ const utf8 * title_sequence_manager_get_config_id(size_t index)
size_t title_sequence_manager_get_predefined_index(size_t index)
{
auto item = TitleSequenceManager::GetItem(index);
if (item == nullptr) {
if (item == nullptr)
{
return 0;
}
size_t predefinedIndex = item->PredefinedIndex;
return predefinedIndex;
}
size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId)
size_t title_sequence_manager_get_index_for_config_id(const utf8* configId)
{
size_t count = TitleSequenceManager::GetCount();
for (size_t i = 0; i < count; i++)
{
const utf8 * cid = title_sequence_manager_get_config_id(i);
const utf8* cid = title_sequence_manager_get_config_id(i);
if (String::Equals(cid, configId))
{
return i;
@@ -375,12 +375,12 @@ size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId)
return SIZE_MAX;
}
size_t title_sequence_manager_get_index_for_name(const utf8 * name)
size_t title_sequence_manager_get_index_for_name(const utf8* name)
{
size_t count = TitleSequenceManager::GetCount();
for (size_t i = 0; i < count; i++)
{
const utf8 * tn = title_sequence_manager_get_name(i);
const utf8* tn = title_sequence_manager_get_name(i);
if (String::Equals(tn, name))
{
return i;
@@ -389,7 +389,7 @@ size_t title_sequence_manager_get_index_for_name(const utf8 * name)
return SIZE_MAX;
}
bool title_sequence_manager_is_name_reserved(const utf8 * name)
bool title_sequence_manager_is_name_reserved(const utf8* name)
{
return TitleSequenceManager::IsNameReserved(name);
}
@@ -404,17 +404,17 @@ void title_sequence_manager_delete(size_t i)
TitleSequenceManager::DeleteItem(i);
}
size_t title_sequence_manager_rename(size_t i, const utf8 * name)
size_t title_sequence_manager_rename(size_t i, const utf8* name)
{
return TitleSequenceManager::RenameItem(i, name);
}
size_t title_sequence_manager_duplicate(size_t i, const utf8 * name)
size_t title_sequence_manager_duplicate(size_t i, const utf8* name)
{
return TitleSequenceManager::DuplicateItem(i, name);
}
size_t title_sequence_manager_create(const utf8 * name)
size_t title_sequence_manager_create(const utf8* name)
{
return TitleSequenceManager::CreateItem(name);
}

View File

@@ -8,41 +8,41 @@
*****************************************************************************/
#pragma once
#include <string>
#include "../common.h"
#include <string>
struct TitleSequenceManagerItem
{
std::string Name;
std::string Path;
size_t PredefinedIndex;
bool IsZip;
size_t PredefinedIndex;
bool IsZip;
};
namespace TitleSequenceManager
{
size_t GetCount();
const TitleSequenceManagerItem * GetItem(size_t i);
const TitleSequenceManagerItem* GetItem(size_t i);
void DeleteItem(size_t i);
size_t RenameItem(size_t i, const utf8 * name);
size_t DuplicateItem(size_t i, const utf8 * name);
size_t CreateItem(const utf8 * name);
size_t RenameItem(size_t i, const utf8* name);
size_t DuplicateItem(size_t i, const utf8* name);
size_t CreateItem(const utf8* name);
void Scan();
}
} // namespace TitleSequenceManager
constexpr const size_t PREDEFINED_INDEX_CUSTOM = SIZE_MAX;
size_t title_sequence_manager_get_count();
const utf8 * title_sequence_manager_get_name(size_t index);
const utf8 * title_sequence_manager_get_path(size_t index);
const utf8 * title_sequence_manager_get_config_id(size_t index);
const utf8* title_sequence_manager_get_name(size_t index);
const utf8* title_sequence_manager_get_path(size_t index);
const utf8* title_sequence_manager_get_config_id(size_t index);
size_t title_sequence_manager_get_predefined_index(size_t index);
size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId);
size_t title_sequence_manager_get_index_for_name(const utf8 * name);
bool title_sequence_manager_is_name_reserved(const utf8 * name);
size_t title_sequence_manager_get_index_for_config_id(const utf8* configId);
size_t title_sequence_manager_get_index_for_name(const utf8* name);
bool title_sequence_manager_is_name_reserved(const utf8* name);
void title_sequence_manager_scan();
void title_sequence_manager_delete(size_t i);
size_t title_sequence_manager_rename(size_t i, const utf8 * name);
size_t title_sequence_manager_duplicate(size_t i, const utf8 * name);
size_t title_sequence_manager_create(const utf8 * name);
size_t title_sequence_manager_rename(size_t i, const utf8* name);
size_t title_sequence_manager_duplicate(size_t i, const utf8* name);
size_t title_sequence_manager_create(const utf8* name);