From c383f1dc43f5ab19be388e70883069412b0251c8 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Sat, 27 Jun 2015 19:58:14 -0400 Subject: [PATCH] Fix compile errors on Clang by implementing own enum. --- core/HalfLife2.cpp | 28 +++++++++------------------- core/HalfLife2.h | 12 +++++++++--- core/smn_halflife.cpp | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 8fb9c646..87745032 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -1208,17 +1208,7 @@ const char *CHalfLife2::GetEntityClassname(CBaseEntity *pEntity) return *(const char **)(((unsigned char *)pEntity) + offset); } -#if SOURCE_ENGINE != SE_TF2 -enum eFindMapResult { - eFindMap_Found, - eFindMap_NotFound, - eFindMap_FuzzyMatch, - eFindMap_NonCanonical, - eFindMap_PossiblyAvailable -}; -#endif - -eFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) +SMFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) { #if SOURCE_ENGINE >= SE_LEFT4DEAD static char mapNameTmp[PLATFORM_MAX_PATH]; @@ -1228,7 +1218,7 @@ eFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) // If this is already an exact match, don't attempt to autocomplete it further (de_dust -> de_dust2). // ... but still check that map file is actually valid. // We check FileExists first to avoid console message about IsMapValid with invalid map. - return engine->IsMapValid(pMapName) == 0 ? eFindMap_NotFound : eFindMap_Found; + return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found; } static ConCommand *pHelperCmd = g_pCVar->FindCommand("changelevel"); @@ -1236,7 +1226,7 @@ eFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) // This shouldn't happen. if (!pHelperCmd || !pHelperCmd->CanAutoComplete()) { - return engine->IsMapValid(pMapName) == 0 ? eFindMap_NotFound : eFindMap_Found; + return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found; } static size_t helperCmdLen = strlen(pHelperCmd->GetName()); @@ -1244,7 +1234,7 @@ eFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) CUtlVector results; pHelperCmd->AutoCompleteSuggest(pMapName, results); if (results.Count() == 0) - return eFindMap_NotFound; + return SMFindMapResult::NotFound; // Results come back as you'd see in autocomplete. (ie. "changelevel fullmapnamehere"), // so skip ahead to start of map path/name @@ -1254,17 +1244,17 @@ eFindMapResult CHalfLife2::FindMap(char *pMapName, int nMapNameMax) bool bExactMatch = Q_strcmp(pMapName, &results[0][helperCmdLen + 1]) == 0; if (bExactMatch) { - return eFindMap_Found; + return SMFindMapResult::Found; } else { strncopy(pMapName, &results[0][helperCmdLen + 1], nMapNameMax); - return eFindMap_FuzzyMatch; + return SMFindMapResult::FuzzyMatch; } #elif SOURCE_ENGINE == SE_TF2 - return engine->FindMap(pMapName, nMapNameMax); + return static_cast(engine->FindMap(pMapName, nMapNameMax)); #else - return engine->IsMapValid(pMapName) == 0 ? eFindMap_NotFound : eFindMap_Found; + return engine->IsMapValid(pMapName) == 0 ? SMFindMapResult::NotFound : SMFindMapResult::Found; #endif } @@ -1276,5 +1266,5 @@ bool CHalfLife2::IsMapValid(const char *map) static char szTmp[PLATFORM_MAX_PATH]; strncopy(szTmp, map, sizeof(szTmp)); - return FindMap(szTmp, sizeof(szTmp)) != eFindMap_NotFound; + return FindMap(szTmp, sizeof(szTmp)) != SMFindMapResult::NotFound; } diff --git a/core/HalfLife2.h b/core/HalfLife2.h index 114f4886..f48f687d 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -129,9 +129,15 @@ public: #endif }; -// See TF2 eiface.h for description. +// Corresponds to TF2's eFindMapResult in eiface.h // Not yet in other games, but eventually in others on same branch. -enum eFindMapResult : int; +enum class SMFindMapResult : cell_t { + Found, + NotFound, + FuzzyMatch, + NonCanonical, + PossiblyAvailable +}; class CHalfLife2 : public SMGlobalClass, @@ -178,7 +184,7 @@ public: //IGameHelpers const char *GetEntityClassname(edict_t *pEdict); const char *GetEntityClassname(CBaseEntity *pEntity); bool IsMapValid(const char *map); - eFindMapResult FindMap(char *pMapName, int nMapNameMax); + SMFindMapResult FindMap(char *pMapName, int nMapNameMax); public: void AddToFakeCliCmdQueue(int client, int userid, const char *cmd); void ProcessFakeCliCmdQueue(); diff --git a/core/smn_halflife.cpp b/core/smn_halflife.cpp index 31404789..b32cb9e2 100644 --- a/core/smn_halflife.cpp +++ b/core/smn_halflife.cpp @@ -74,7 +74,7 @@ static cell_t FindMap(IPluginContext *pContext, const cell_t *params) cell_t size = params[2]; - return g_HL2.FindMap(pMapname, size); + return static_cast(g_HL2.FindMap(pMapname, size)); } static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)