Close #12442: Refactor SCENARIO_SOURCE to use strong enum (#12608)

This commit is contained in:
Sidney 2020-08-08 14:38:43 +02:00 committed by GitHub
parent 399e0abe2e
commit 933570fd62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 32 deletions

View File

@ -212,9 +212,9 @@ static void window_scenarioselect_init_tabs(rct_window* w)
const scenario_index_entry* scenario = scenario_repository_get_by_index(i);
if (gConfigGeneral.scenario_select_mode == SCENARIO_SELECT_MODE_ORIGIN || _titleEditor)
{
if (_titleEditor && scenario->source_game == SCENARIO_SOURCE_OTHER)
if (_titleEditor && scenario->source_game == ScenarioSource::Other)
continue;
showPages |= 1 << scenario->source_game;
showPages |= 1 << static_cast<uint8_t>(scenario->source_game);
}
else
{
@ -695,14 +695,14 @@ static void initialise_list_items(rct_window* w)
if (!is_scenario_visible(w, scenario))
continue;
if (_titleEditor && scenario->source_game == SCENARIO_SOURCE_OTHER)
if (_titleEditor && scenario->source_game == ScenarioSource::Other)
continue;
// Category heading
rct_string_id headingStringId = STR_NONE;
if (gConfigGeneral.scenario_select_mode == SCENARIO_SELECT_MODE_ORIGIN || _titleEditor)
{
if (w->selected_tab != SCENARIO_SOURCE_REAL && currentHeading != scenario->category)
if (w->selected_tab != static_cast<uint8_t>(ScenarioSource::Real) && currentHeading != scenario->category)
{
currentHeading = scenario->category;
headingStringId = ScenarioCategoryStringIds[currentHeading];
@ -712,9 +712,9 @@ static void initialise_list_items(rct_window* w)
{
if (w->selected_tab <= SCENARIO_CATEGORY_EXPERT)
{
if (currentHeading != scenario->source_game)
if (currentHeading != static_cast<uint8_t>(scenario->source_game))
{
currentHeading = scenario->source_game;
currentHeading = static_cast<uint8_t>(scenario->source_game);
headingStringId = ScenarioOriginStringIds[currentHeading];
}
}
@ -805,7 +805,7 @@ static bool is_scenario_visible(rct_window* w, const scenario_index_entry* scena
{
if (gConfigGeneral.scenario_select_mode == SCENARIO_SELECT_MODE_ORIGIN || _titleEditor)
{
if (scenario->source_game != w->selected_tab)
if (static_cast<uint8_t>(scenario->source_game) != w->selected_tab)
{
return false;
}

View File

@ -222,7 +222,7 @@ public:
bool isOfficial = ScenarioSources::TryGetById(_s4.scenario_slot_index, &desc);
dst->category = desc.category;
dst->source_game = desc.source;
dst->source_game = ScenarioSource{ desc.source };
dst->source_index = desc.index;
dst->sc_id = desc.id;

View File

@ -63,16 +63,16 @@ struct rct_s6_info
};
assert_struct_size(rct_s6_info, 0x198);
enum SCENARIO_SOURCE
enum class ScenarioSource : uint8_t
{
SCENARIO_SOURCE_RCT1,
SCENARIO_SOURCE_RCT1_AA,
SCENARIO_SOURCE_RCT1_LL,
SCENARIO_SOURCE_RCT2,
SCENARIO_SOURCE_RCT2_WW,
SCENARIO_SOURCE_RCT2_TT,
SCENARIO_SOURCE_REAL,
SCENARIO_SOURCE_OTHER,
RCT1,
RCT1_AA,
RCT1_LL,
RCT2,
RCT2_WW,
RCT2_TT,
Real,
Other
};
struct rct_stex_entry

View File

@ -66,7 +66,7 @@ static int32_t scenario_index_entry_CompareByCategory(const scenario_index_entry
default:
if (entryA.source_game != entryB.source_game)
{
return entryA.source_game - entryB.source_game;
return static_cast<int32_t>(entryA.source_game) - static_cast<int32_t>(entryB.source_game);
}
return strcmp(entryA.name, entryB.name);
case SCENARIO_CATEGORY_REAL:
@ -80,11 +80,11 @@ static int32_t scenario_index_entry_CompareByIndex(const scenario_index_entry& e
// Order by source game
if (entryA.source_game != entryB.source_game)
{
return entryA.source_game - entryB.source_game;
return static_cast<int32_t>(entryA.source_game) - static_cast<int32_t>(entryB.source_game);
}
// Then by index / category / name
uint8_t sourceGame = entryA.source_game;
ScenarioSource sourceGame = ScenarioSource{ entryA.source_game };
switch (sourceGame)
{
default:
@ -111,7 +111,7 @@ static int32_t scenario_index_entry_CompareByIndex(const scenario_index_entry& e
{
return entryA.source_index - entryB.source_index;
}
case SCENARIO_SOURCE_REAL:
case ScenarioSource::Real:
return scenario_index_entry_CompareByCategory(entryA, entryB);
}
}
@ -185,7 +185,7 @@ protected:
item.timestamp = stream->ReadValue<uint64_t>();
item.category = stream->ReadValue<uint8_t>();
item.source_game = stream->ReadValue<uint8_t>();
item.source_game = ScenarioSource{ stream->ReadValue<uint8_t>() };
item.source_index = stream->ReadValue<int16_t>();
item.sc_id = stream->ReadValue<uint16_t>();
@ -302,7 +302,7 @@ private:
{
entry.sc_id = desc.id;
entry.source_index = desc.index;
entry.source_game = desc.source;
entry.source_game = ScenarioSource{ desc.source };
entry.category = desc.category;
}
else
@ -311,11 +311,11 @@ private:
entry.source_index = -1;
if (entry.category == SCENARIO_CATEGORY_REAL)
{
entry.source_game = SCENARIO_SOURCE_REAL;
entry.source_game = ScenarioSource::Real;
}
else
{
entry.source_game = SCENARIO_SOURCE_OTHER;
entry.source_game = ScenarioSource::Other;
}
}
@ -401,7 +401,7 @@ public:
{
const scenario_index_entry* scenario = &_scenarios[i];
if (scenario->source_game == SCENARIO_SOURCE_OTHER && scenario->sc_id == SC_UNIDENTIFIED)
if (scenario->source_game == ScenarioSource::Other && scenario->sc_id == SC_UNIDENTIFIED)
continue;
// Note: this is always case insensitive search for cross platform consistency

View File

@ -10,6 +10,7 @@
#pragma once
#include "../common.h"
#include "../scenario/Scenario.h"
#include <memory>
@ -30,7 +31,7 @@ struct scenario_index_entry
// Category / sequence
uint8_t category;
uint8_t source_game;
ScenarioSource source_game;
int16_t source_index;
uint16_t sc_id;

View File

@ -357,7 +357,7 @@ namespace ScenarioSources
outDesc->title = nullptr;
outDesc->id = SC_UNIDENTIFIED;
outDesc->source = SCENARIO_SOURCE_OTHER;
outDesc->source = static_cast<uint8_t>(ScenarioSource::Other);
outDesc->index = -1;
outDesc->category = SCENARIO_CATEGORY_OTHER;
return false;
@ -388,7 +388,7 @@ namespace ScenarioSources
outDesc->title = "";
outDesc->id = SC_UNIDENTIFIED;
outDesc->source = SCENARIO_SOURCE_OTHER;
outDesc->source = static_cast<uint8_t>(ScenarioSource::Other);
outDesc->index = -1;
outDesc->category = SCENARIO_CATEGORY_OTHER;
return false;

View File

@ -234,15 +234,15 @@ void TitleScreen::TitleInitialise()
for (size_t s = 0; s < scenarioCount; s++)
{
if (scenario_repository_get_by_index(s)->source_game == SCENARIO_SOURCE_RCT1)
if (scenario_repository_get_by_index(s)->source_game == ScenarioSource::RCT1)
{
RCT1Count++;
}
if (scenario_repository_get_by_index(s)->source_game == SCENARIO_SOURCE_RCT1_AA)
if (scenario_repository_get_by_index(s)->source_game == ScenarioSource::RCT1_AA)
{
RCT1AAInstalled = true;
}
if (scenario_repository_get_by_index(s)->source_game == SCENARIO_SOURCE_RCT1_LL)
if (scenario_repository_get_by_index(s)->source_game == ScenarioSource::RCT1_LL)
{
RCT1LLInstalled = true;
}