From 2b10b273fd8c43bbfa73b38972fd708ef9388bba Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Thu, 3 Mar 2022 22:43:07 +0100 Subject: [PATCH] don't use enum class until we remove tolua++ --- src/include/fow.h | 2 +- src/include/net_message.h | 2 +- src/include/settings.h | 24 +++++++++++++++++------- src/stratagus/player.cpp | 6 +++--- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/include/fow.h b/src/include/fow.h index a1f1f335f..82835dda3 100644 --- a/src/include/fow.h +++ b/src/include/fow.h @@ -44,7 +44,7 @@ /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ -enum class FogOfWarTypes { cTiled, cEnhanced, cTiledLegacy, cNumOfTypes }; /// Types of the fog of war +ENUM_CLASS FogOfWarTypes { cTiled, cEnhanced, cTiledLegacy, cNumOfTypes }; /// Types of the fog of war class CFogOfWar { public: diff --git a/src/include/net_message.h b/src/include/net_message.h index 9b73b5e69..2d75569fb 100644 --- a/src/include/net_message.h +++ b/src/include/net_message.h @@ -68,7 +68,7 @@ public: char PlyName[NetPlayerNameSize]; /// Name of player }; -enum class SlotOption : uint8_t { +ENUM_CLASS SlotOption : uint8_t { Available, Computer, Closed diff --git a/src/include/settings.h b/src/include/settings.h index b74f77030..432103e05 100644 --- a/src/include/settings.h +++ b/src/include/settings.h @@ -43,6 +43,16 @@ #include <functional> #include <variant> +/*---------------------------------------------------------------------------- +-- TODO: Remove this once we move off of tolua++ and can properly support strongly typed enums +----------------------------------------------------------------------------*/ +#if 1 +// using tolua++ +#define ENUM_CLASS enum +#else +#define ENUM_CLASS enum class +#endif + /*---------------------------------------------------------------------------- -- Settings ----------------------------------------------------------------------------*/ @@ -87,9 +97,9 @@ constexpr int8_t SettingsPresetMapDefault = -1; /// Special: Use map supplied ** can rescue them. If the city center is rescued, than all units ** of this player are rescued. */ -enum class PlayerTypes : int8_t { +ENUM_CLASS PlayerTypes : int8_t { MapDefault = SettingsPresetMapDefault, /// use default - Unset = 0, /// not set + PlayerUnset = 0, /// not set PlayerNeutral = 2, /// neutral PlayerNobody = 3, /// unused slot PlayerComputer = 4, /// computer player @@ -144,7 +154,7 @@ struct SettingsPresets { } }; -enum class RevealTypes : uint8_t { +ENUM_CLASS RevealTypes : uint8_t { cNoRevelation, cAllUnits, cBuildingsOnly @@ -153,7 +163,7 @@ enum class RevealTypes : uint8_t { /** ** Single or multiplayer settings */ -enum class NetGameTypes : uint8_t { +ENUM_CLASS NetGameTypes : uint8_t { SettingsSinglePlayerGame, SettingsMultiPlayerGame, Unset @@ -162,7 +172,7 @@ enum class NetGameTypes : uint8_t { /** ** GameType settings */ -enum class GameTypes : int8_t { +ENUM_CLASS GameTypes : int8_t { SettingsGameTypeMapDefault = SettingsPresetMapDefault, SettingsGameTypeMelee = 0, SettingsGameTypeFreeForAll, @@ -187,14 +197,14 @@ enum class GameTypes : int8_t { /// Map revealing modes: cHidden - unrevealed, cKnown - you can see unexplored tiles, but they are darker than explored /// cExplored - all tiles became explored, and covered only by the fog of war if it's enabled. -enum class MapRevealModes : uint8_t { +ENUM_CLASS MapRevealModes : uint8_t { cHidden = 0, cKnown, cExplored, cNumOfModes }; -enum class FieldOfViewTypes : uint8_t { +ENUM_CLASS FieldOfViewTypes : uint8_t { cShadowCasting, cSimpleRadial, NumOfTypes diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp index 3a9cc88a4..301c8ed55 100644 --- a/src/stratagus/player.cpp +++ b/src/stratagus/player.cpp @@ -371,7 +371,7 @@ void InitPlayers() { for (int p = 0; p < PlayerMax; ++p) { Players[p].Index = p; - if (Players[p].Type == PlayerTypes::Unset) { + if (Players[p].Type == PlayerTypes::PlayerUnset) { Players[p].Type = PlayerTypes::PlayerNobody; } } @@ -769,7 +769,7 @@ void CPlayer::Clear() { Index = 0; Name.clear(); - Type = PlayerTypes::Unset; + Type = PlayerTypes::PlayerUnset; Race = 0; AiName.clear(); Team = 0; @@ -1291,7 +1291,7 @@ void DebugPlayers() const char *playertype; switch (Players[i].Type) { - case PlayerTypes::Unset: playertype = "unset "; break; + case PlayerTypes::PlayerUnset: playertype = "unset "; break; case PlayerTypes::PlayerNeutral: playertype = "neutral "; break; case PlayerTypes::PlayerNobody: playertype = "nobody "; break; case PlayerTypes::PlayerComputer: playertype = "computer "; break;