refactor(Core/Common): code cleanup (part 12) (#7520)

This commit is contained in:
Francesco Borzì
2021-08-26 18:02:08 +02:00
committed by GitHub
parent 5bb2e5f2f9
commit d8b8e123f6
15 changed files with 27 additions and 56 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org> * Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/ */
@@ -185,16 +185,12 @@ namespace MMAP
LOG_DEBUG("maps", "MMAP:loadMap: Loaded mmtile %03i[%02i,%02i] into %03i[%02i,%02i]", mapId, x, y, mapId, header->x, header->y); LOG_DEBUG("maps", "MMAP:loadMap: Loaded mmtile %03i[%02i,%02i] into %03i[%02i,%02i]", mapId, x, y, mapId, header->x, header->y);
return true; return true;
} }
else
{
LOG_ERROR("maps", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y); LOG_ERROR("maps", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y);
dtFree(data); dtFree(data);
return false; return false;
} }
return false;
}
bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y) bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y)
{ {
// check if we have this map loaded // check if we have this map loaded
@@ -228,17 +224,13 @@ namespace MMAP
LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y); LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y);
ABORT(); ABORT();
} }
else
{
mmap->loadedTileRefs.erase(packedGridPos); mmap->loadedTileRefs.erase(packedGridPos);
--loadedTiles; --loadedTiles;
LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile %03i[%02i,%02i] from %03i", mapId, x, y, mapId); LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile %03i[%02i,%02i] from %03i", mapId, x, y, mapId);
return true; return true;
} }
return false;
}
bool MMapManager::unloadMap(uint32 mapId) bool MMapManager::unloadMap(uint32 mapId)
{ {
MMapDataSet::iterator itr = loadedMMaps.find(mapId); MMapDataSet::iterator itr = loadedMMaps.find(mapId);
@@ -21,7 +21,6 @@
#include "MapDefines.h" #include "MapDefines.h"
#include "MapTree.h" #include "MapTree.h"
#include "ModelInstance.h" #include "ModelInstance.h"
#include "VMapDefinitions.h"
#include "WorldModel.h" #include "WorldModel.h"
#include <G3D/Vector3.h> #include <G3D/Vector3.h>
#include <iomanip> #include <iomanip>
@@ -243,7 +242,7 @@ namespace VMAP
{ {
Vector3 pos = convertPositionToInternalRep(x, y, z); Vector3 pos = convertPositionToInternalRep(x, y, z);
float height = instanceTree->second->getHeight(pos, maxSearchDist); float height = instanceTree->second->getHeight(pos, maxSearchDist);
if (!(height < G3D::finf())) if (height >= G3D::finf())
{ {
return height = VMAP_INVALID_HEIGHT_VALUE; // No height return height = VMAP_INVALID_HEIGHT_VALUE; // No height
} }
+1 -15
View File
@@ -1,18 +1,5 @@
/* /*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org> * Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
*
* This program 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 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _VMAPMANAGER2_H #ifndef _VMAPMANAGER2_H
@@ -56,7 +43,6 @@ namespace VMAP
ManagedModel() { } ManagedModel() { }
void setModel(WorldModel* model) { iModel = model; } void setModel(WorldModel* model) { iModel = model; }
WorldModel* getModel() { return iModel; } WorldModel* getModel() { return iModel; }
void incRefCount() { ++iRefCount; }
int decRefCount() { return --iRefCount; } int decRefCount() { return --iRefCount; }
protected: protected:
WorldModel* iModel{nullptr}; WorldModel* iModel{nullptr};
@@ -6,7 +6,6 @@
#include "ModelInstance.h" #include "ModelInstance.h"
#include "MapTree.h" #include "MapTree.h"
#include "VMapDefinitions.h"
#include "WorldModel.h" #include "WorldModel.h"
using G3D::Vector3; using G3D::Vector3;
+1 -1
View File
@@ -65,4 +65,4 @@ namespace VMAP
}; };
} // namespace VMAP } // namespace VMAP
#endif // _MODELINSTANCE #endif // _MODELINSTANCE_H_
+9 -4
View File
@@ -160,7 +160,7 @@ namespace VMAP
// check if tile shall be used for liquid level // check if tile shall be used for liquid level
// checking for 0x08 *might* be enough, but disabled tiles always are 0x?F: // checking for 0x08 *might* be enough, but disabled tiles always are 0x?F:
if ((iFlags[tx + ty * iTilesX] & 0x0F) == 0x0F) if (iFlags && (iFlags[tx + ty * iTilesX] & 0x0F) == 0x0F)
{ {
return false; return false;
} }
@@ -182,6 +182,11 @@ namespace VMAP
0 1 0 1
*/ */
if (!iHeight)
{
return false;
}
const uint32 rowOffset = iTilesX + 1; const uint32 rowOffset = iTilesX + 1;
if (dx > dy) // case (a) if (dx > dy) // case (a)
{ {
@@ -289,7 +294,7 @@ namespace VMAP
bool result = true; bool result = true;
uint32 chunkSize, count; uint32 chunkSize, count;
if (result && fwrite(&iBound, sizeof(G3D::AABox), 1, wf) != 1) { result = false; } if (fwrite(&iBound, sizeof(G3D::AABox), 1, wf) != 1) { result = false; }
if (result && fwrite(&iMogpFlags, sizeof(uint32), 1, wf) != 1) { result = false; } if (result && fwrite(&iMogpFlags, sizeof(uint32), 1, wf) != 1) { result = false; }
if (result && fwrite(&iGroupWMOID, sizeof(uint32), 1, wf) != 1) { result = false; } if (result && fwrite(&iGroupWMOID, sizeof(uint32), 1, wf) != 1) { result = false; }
@@ -343,7 +348,7 @@ namespace VMAP
delete iLiquid; delete iLiquid;
iLiquid = nullptr; iLiquid = nullptr;
if (result && fread(&iBound, sizeof(G3D::AABox), 1, rf) != 1) { result = false; } if (fread(&iBound, sizeof(G3D::AABox), 1, rf) != 1) { result = false; }
if (result && fread(&iMogpFlags, sizeof(uint32), 1, rf) != 1) { result = false; } if (result && fread(&iMogpFlags, sizeof(uint32), 1, rf) != 1) { result = false; }
if (result && fread(&iGroupWMOID, sizeof(uint32), 1, rf) != 1) { result = false; } if (result && fread(&iGroupWMOID, sizeof(uint32), 1, rf) != 1) { result = false; }
@@ -621,7 +626,7 @@ namespace VMAP
{ {
//if (fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false; //if (fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
if (result && fread(&count, sizeof(uint32), 1, rf) != 1) { result = false; } if (fread(&count, sizeof(uint32), 1, rf) != 1) { result = false; }
if (result) { groupModels.resize(count); } if (result) { groupModels.resize(count); }
//if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false; //if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false;
for (uint32 i = 0; i < count && result; ++i) for (uint32 i = 0; i < count && result; ++i)
-1
View File
@@ -6,7 +6,6 @@
#include "Cryptography/BigNumber.h" #include "Cryptography/BigNumber.h"
#include "Errors.h" #include "Errors.h"
#include <algorithm> #include <algorithm>
#include <cstring>
#include <memory> #include <memory>
#include <openssl/bn.h> #include <openssl/bn.h>
@@ -5,7 +5,6 @@
*/ */
#include <OpenSSLCrypto.h> #include <OpenSSLCrypto.h>
#include <openssl/crypto.h>
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL
#include <vector> #include <vector>
-1
View File
@@ -4,7 +4,6 @@
*/ */
#include "TOTP.h" #include "TOTP.h"
#include <cstring>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/hmac.h> #include <openssl/hmac.h>
-1
View File
@@ -4,7 +4,6 @@
*/ */
#include "IPLocation.h" #include "IPLocation.h"
#include "Common.h"
#include "Config.h" #include "Config.h"
#include "Errors.h" #include "Errors.h"
#include "IpAddress.h" #include "IpAddress.h"
-1
View File
@@ -10,7 +10,6 @@
#include "StringFormat.h" #include "StringFormat.h"
#include "Tokenize.h" #include "Tokenize.h"
#include "Util.h" #include "Util.h"
#include <sstream>
#if AC_PLATFORM == AC_PLATFORM_WINDOWS #if AC_PLATFORM == AC_PLATFORM_WINDOWS
#include <Windows.h> #include <Windows.h>
+3 -4
View File
@@ -6,7 +6,6 @@
#include "Log.h" #include "Log.h"
#include "AppenderConsole.h" #include "AppenderConsole.h"
#include "AppenderFile.h" #include "AppenderFile.h"
#include "Common.h"
#include "Config.h" #include "Config.h"
#include "Errors.h" #include "Errors.h"
#include "LogMessage.h" #include "LogMessage.h"
@@ -158,16 +157,16 @@ void Log::CreateLoggerFromConfig(std::string const& appenderName)
logger = std::make_unique<Logger>(name, level); logger = std::make_unique<Logger>(name, level);
//fprintf(stdout, "Log::CreateLoggerFromConfig: Created Logger %s, Level %u\n", name.c_str(), level); //fprintf(stdout, "Log::CreateLoggerFromConfig: Created Logger %s, Level %u\n", name.c_str(), level);
for (std::string_view appenderName : Acore::Tokenize(tokens[1], ' ', false)) for (std::string_view appendName : Acore::Tokenize(tokens[1], ' ', false))
{ {
if (Appender* appender = GetAppenderByName(appenderName)) if (Appender* appender = GetAppenderByName(appendName))
{ {
logger->addAppender(appender->getId(), appender); logger->addAppender(appender->getId(), appender);
//fprintf(stdout, "Log::CreateLoggerFromConfig: Added Appender %s to Logger %s\n", appender->getName().c_str(), name.c_str()); //fprintf(stdout, "Log::CreateLoggerFromConfig: Added Appender %s to Logger %s\n", appender->getName().c_str(), name.c_str());
} }
else else
{ {
fprintf(stderr, "Error while configuring Appender %s in Logger %s. Appender does not exist\n", std::string(appenderName).c_str(), name.c_str()); fprintf(stderr, "Error while configuring Appender %s in Logger %s. Appender does not exist\n", std::string(appendName).c_str(), name.c_str());
} }
} }
} }
+4 -4
View File
@@ -182,21 +182,21 @@ namespace Acore
return CreateChildProcess([&](child& c) -> int return CreateChildProcess([&](child& c) -> int
{ {
int result; int exitCode;
my_child = std::reference_wrapper<child>(c); my_child = std::reference_wrapper<child>(c);
try try
{ {
c.wait(); c.wait();
result = c.exit_code(); exitCode = c.exit_code();
} }
catch (...) catch (...)
{ {
result = EXIT_FAILURE; exitCode = EXIT_FAILURE;
} }
my_child.reset(); my_child.reset();
return was_terminated ? EXIT_FAILURE : result; return was_terminated ? EXIT_FAILURE : exitCode;
}, executable, args, logger, input_file, is_secure); }, executable, args, logger, input_file, is_secure);
} }
+1 -5
View File
@@ -8,7 +8,6 @@
#include "Common.h" #include "Common.h"
#include "Containers.h" #include "Containers.h"
#include "IpAddress.h" #include "IpAddress.h"
#include "StringConvert.h"
#include "StringFormat.h" #include "StringFormat.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@@ -17,9 +16,6 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <cctype>
#include <cstdarg>
#include <ctime>
#include <utf8.h> #include <utf8.h>
Tokenizer::Tokenizer(const std::string& src, const char sep, uint32 vectorReserve) Tokenizer::Tokenizer(const std::string& src, const char sep, uint32 vectorReserve)
@@ -518,7 +514,7 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension)
{ {
std::wstring const& ending = **itr; std::wstring const& ending = **itr;
std::size_t const endLen = ending.length(); std::size_t const endLen = ending.length();
if (!(endLen <= thisLen)) if (endLen > thisLen)
{ {
continue; continue;
} }