Skip to content

Commit

Permalink
reinstate exit codes; Util namespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Apr 17, 2017
1 parent 5ed91e4 commit 71e5416
Show file tree
Hide file tree
Showing 77 changed files with 449 additions and 440 deletions.
2 changes: 1 addition & 1 deletion rts/ExternalAI/AIInterfaceLibrary.cpp
Expand Up @@ -36,7 +36,7 @@ CAIInterfaceLibrary::CAIInterfaceLibrary(const CAIInterfaceLibraryInfo& _info)

CAIInterfaceLibrary::~CAIInterfaceLibrary() {
ReleaseStatic();
SafeDelete(sharedLib);
spring::SafeDelete(sharedLib);
}

void CAIInterfaceLibrary::InitStatic() {
Expand Down
2 changes: 1 addition & 1 deletion rts/ExternalAI/EngineOutHandler.cpp
Expand Up @@ -68,7 +68,7 @@ void CEngineOutHandler::Destroy() {
if (singleton != NULL) {
singleton->PreDestroy();

SafeDelete(singleton);
spring::SafeDelete(singleton);
IAILibraryManager::Destroy();

numInstances -= 1;
Expand Down
2 changes: 1 addition & 1 deletion rts/ExternalAI/IAILibraryManager.cpp
Expand Up @@ -21,7 +21,7 @@ IAILibraryManager* IAILibraryManager::GetInstance() {
}

void IAILibraryManager::Destroy() {
// SafeDelete
// spring::SafeDelete
IAILibraryManager* tmp = gAILibraryManager;
gAILibraryManager = NULL;
delete tmp;
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/AviVideoCapturing.cpp
Expand Up @@ -39,7 +39,7 @@ void AviVideoCapturing::StopCapturing() {
if (IsCapturing()) {
capturing = false;
globalRendering->isVideoCapturing = false;
SafeDelete(aviGenerator);
spring::SafeDelete(aviGenerator);
//delete aviGenerator;
//aviGenerator = NULL;
}
Expand Down
88 changes: 44 additions & 44 deletions rts/Game/Game.cpp
Expand Up @@ -318,8 +318,8 @@ CGame::~CGame()
KillSimulation();

LOG("[Game::%s][2]", __func__);
SafeDelete(saveFile); // ILoadSaveHandler, depends on vfsHandler via ~IArchive
SafeDelete(jobDispatcher);
spring::SafeDelete(saveFile); // ILoadSaveHandler, depends on vfsHandler via ~IArchive
spring::SafeDelete(jobDispatcher);

LOG("[Game::%s][3]", __func__);
CWordCompletion::DestroyInstance();
Expand Down Expand Up @@ -709,7 +709,7 @@ void CGame::LoadLua()
loadscreen->SetLoadMessage("Loading LuaUI");
CLuaUI::LoadFreeHandler();

SafeDelete(defsParser);
spring::SafeDelete(defsParser);
}

void CGame::LoadSkirmishAIs()
Expand Down Expand Up @@ -823,33 +823,33 @@ void CGame::KillMisc()
void CGame::KillRendering()
{
LOG("[Game::%s][1]", __func__);
SafeDelete(infoTextureHandler);
SafeDelete(icon::iconHandler);
SafeDelete(geometricObjects);
SafeDelete(worldDrawer);
spring::SafeDelete(infoTextureHandler);
spring::SafeDelete(icon::iconHandler);
spring::SafeDelete(geometricObjects);
spring::SafeDelete(worldDrawer);
}

void CGame::KillInterface()
{
LOG("[Game::%s][1]", __func__);
ProfileDrawer::SetEnabled(false);
SafeDelete(guihandler);
SafeDelete(minimap);
SafeDelete(resourceBar);
SafeDelete(tooltip); // CTooltipConsole*
SafeDelete(infoConsole);
SafeDelete(consoleHistory);
SafeDelete(keyBindings);
SafeDelete(selectionKeys); // CSelectionKeyHandler*
SafeDelete(mouse); // CMouseHandler*
SafeDelete(inMapDrawerModel);
SafeDelete(inMapDrawer);
spring::SafeDelete(guihandler);
spring::SafeDelete(minimap);
spring::SafeDelete(resourceBar);
spring::SafeDelete(tooltip); // CTooltipConsole*
spring::SafeDelete(infoConsole);
spring::SafeDelete(consoleHistory);
spring::SafeDelete(keyBindings);
spring::SafeDelete(selectionKeys); // CSelectionKeyHandler*
spring::SafeDelete(mouse); // CMouseHandler*
spring::SafeDelete(inMapDrawerModel);
spring::SafeDelete(inMapDrawer);

LOG("[Game::%s][2]", __func__);
SafeDelete(camHandler);
spring::SafeDelete(camHandler);

for (unsigned int i = 0; i < grouphandlers.size(); i++) {
SafeDelete(grouphandlers[i]);
spring::SafeDelete(grouphandlers[i]);
}

grouphandlers.clear();
Expand All @@ -871,28 +871,28 @@ void CGame::KillSimulation()

LOG("[Game::%s][2]", __func__);
if (unitHandler) unitHandler->DeleteScripts();
SafeDelete(featureHandler); // depends on unitHandler (via ~CFeature)
SafeDelete(unitHandler);
SafeDelete(projectileHandler);
spring::SafeDelete(featureHandler); // depends on unitHandler (via ~CFeature)
spring::SafeDelete(unitHandler);
spring::SafeDelete(projectileHandler);

LOG("[Game::%s][3]", __func__);
IPathManager::FreeInstance(pathManager);

SafeDelete(readMap);
SafeDelete(smoothGround);
SafeDelete(groundBlockingObjectMap);
SafeDelete(buildingMaskMap);
SafeDelete(losHandler);
SafeDelete(mapDamage);
SafeDelete(quadField);
SafeDelete(moveDefHandler);
SafeDelete(unitDefHandler);
SafeDelete(featureDefHandler);
SafeDelete(weaponDefHandler);
SafeDelete(damageArrayHandler);
SafeDelete(explGenHandler);
SafeDelete(helper);
SafeDelete((mapInfo = const_cast<CMapInfo*>(mapInfo)));
spring::SafeDelete(readMap);
spring::SafeDelete(smoothGround);
spring::SafeDelete(groundBlockingObjectMap);
spring::SafeDelete(buildingMaskMap);
spring::SafeDelete(losHandler);
spring::SafeDelete(mapDamage);
spring::SafeDelete(quadField);
spring::SafeDelete(moveDefHandler);
spring::SafeDelete(unitDefHandler);
spring::SafeDelete(featureDefHandler);
spring::SafeDelete(weaponDefHandler);
spring::SafeDelete(damageArrayHandler);
spring::SafeDelete(explGenHandler);
spring::SafeDelete(helper);
spring::SafeDelete((mapInfo = const_cast<CMapInfo*>(mapInfo)));

LOG("[Game::%s][4]", __func__);
CCommandAI::KillCommandDescriptionCache();
Expand Down Expand Up @@ -1015,7 +1015,7 @@ int CGame::TextInput(const std::string& utf8Text)
const bool caught = eventHandler.TextInput(utf8Text);

if (userWriting && !caught){
std::string text = ignoreNextChar ? utf8Text.substr(Utf8NextChar(utf8Text, 0)) : utf8Text;
std::string text = ignoreNextChar ? utf8Text.substr(utf8::NextChar(utf8Text, 0)) : utf8Text;
writingPos = Clamp<int>(writingPos, 0, userInput.length());
userInput.insert(writingPos, text);
writingPos += text.length();
Expand Down Expand Up @@ -1435,7 +1435,7 @@ void CGame::DrawInputText()
const float caretPos = fontSize * font->GetTextWidth(caretStr) * globalRendering->pixelX;
const float caretHeight = fontSize * font->GetLineHeight() * globalRendering->pixelY;
int cpos = writingPos;
char32_t c = Utf8GetNextChar(userInput, cpos);
char32_t c = utf8::GetNextChar(userInput, cpos);
if (c == 0) c = ' '; // make caret always visible
const float cw = fontSize * font->GetCharacterWidth(c) * globalRendering->pixelX;
const float csx = inputTextPosX + caretPos;
Expand Down Expand Up @@ -2039,7 +2039,7 @@ bool CGame::ProcessKeyPressAction(unsigned int key, const Action& action) {

if (action.command == "edit_backspace") {
if (!userInput.empty() && (writingPos > 0)) {
const int prev = Utf8PrevChar(userInput, writingPos);
const int prev = utf8::PrevChar(userInput, writingPos);
userInput.erase(prev, writingPos - prev);
writingPos = prev;
}
Expand All @@ -2049,7 +2049,7 @@ bool CGame::ProcessKeyPressAction(unsigned int key, const Action& action) {

if (action.command == "edit_delete") {
if (!userInput.empty() && (writingPos < (int)userInput.size())) {
userInput.erase(writingPos, Utf8CharLen(userInput, writingPos));
userInput.erase(writingPos, utf8::CharLen(userInput, writingPos));
}

return true;
Expand All @@ -2068,12 +2068,12 @@ bool CGame::ProcessKeyPressAction(unsigned int key, const Action& action) {


if (action.command == "edit_prev_char") {
writingPos = Utf8PrevChar(userInput, writingPos);
writingPos = utf8::PrevChar(userInput, writingPos);
return true;
}

if (action.command == "edit_next_char") {
writingPos = Utf8NextChar(userInput, writingPos);
writingPos = utf8::NextChar(userInput, writingPos);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion rts/Game/GlobalUnsynced.cpp
Expand Up @@ -64,7 +64,7 @@ CGlobalUnsynced::CGlobalUnsynced()

CGlobalUnsynced::~CGlobalUnsynced()
{
SafeDelete(playerHandler);
spring::SafeDelete(playerHandler);
assert(playerHandler == nullptr);
}

Expand Down
8 changes: 4 additions & 4 deletions rts/Game/LoadScreen.cpp
Expand Up @@ -73,7 +73,7 @@ CLoadScreen::~CLoadScreen()
if (netHeartbeatThread != nullptr)
netHeartbeatThread->join();

SafeDelete(netHeartbeatThread);
spring::SafeDelete(netHeartbeatThread);

if (!gu->globalQuit) {
activeController = game;
Expand Down Expand Up @@ -171,7 +171,7 @@ bool CLoadScreen::Init()
gameLoadThread = new COffscreenGLThread(std::bind(&CGame::LoadGame, game, mapName));
return true;
} catch (const opengl_error& gle) {
SafeDelete(gameLoadThread);
spring::SafeDelete(gameLoadThread);
LOG_L(L_WARNING, "[LoadScreen::%s] offscreen GL context creation failed (error: \"%s\")", __func__, gle.what());

mtLoading = false;
Expand All @@ -192,7 +192,7 @@ void CLoadScreen::Kill()
// at this point, the thread running CGame::LoadGame
// has finished and deregistered itself from WatchDog
gameLoadThread->Join();
SafeDelete(gameLoadThread);
spring::SafeDelete(gameLoadThread);

CglFont::threadSafety = false;
}
Expand All @@ -218,7 +218,7 @@ void CLoadScreen::DeleteInstance()
return;

singleton->Kill();
SafeDelete(singleton);
spring::SafeDelete(singleton);
}


Expand Down
3 changes: 2 additions & 1 deletion rts/Game/PreGame.cpp
Expand Up @@ -257,6 +257,7 @@ void CPreGame::UpdateClientNet()

LOG_L(L_WARNING, "[PreGame] Server Connection Timeout");

spring::exitCode = SPRING_EXIT_CODE_TIMEOUT;
gu->globalQuit = true;
return;
}
Expand Down Expand Up @@ -470,7 +471,7 @@ void CPreGame::GameDataReceived(std::shared_ptr<const netcode::RawPacket> packet
// modified version (cf StartServerForDemo) which the server already has that
// contains an extra player
if (gameSetup != nullptr)
SafeDelete(gameSetup);
spring::SafeDelete(gameSetup);

if (CGameSetup::LoadReceivedScript(gameData->GetSetupText(), clientSetup->isHost)) {
assert(gameSetup != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/SyncedGameCommands.cpp
Expand Up @@ -513,7 +513,7 @@ void SyncedGameCommands::CreateInstance() {

void SyncedGameCommands::DestroyInstance() {
if (singleton != NULL) {
SafeDelete(singleton);
spring::SafeDelete(singleton);
} else {
// this might happen during shutdown after an unclean init
LOG_L(L_WARNING, "SyncedGameCommands singleton was not initialized or is already destroyed");
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/UI/Groups/GroupHandler.cpp
Expand Up @@ -184,5 +184,5 @@ void CGroupHandler::RemoveGroup(CGroup* group)

void CGroupHandler::PushGroupChange(int id)
{
VectorInsertUnique(changedGroups, id, true);
spring::VectorInsertUnique(changedGroups, id, true);
}
2 changes: 1 addition & 1 deletion rts/Game/UI/MouseCursor.cpp
Expand Up @@ -77,7 +77,7 @@ CMouseCursor::CMouseCursor(const string& name, HotSpot hs)

CMouseCursor::~CMouseCursor()
{
SafeDelete(hwCursor);
spring::SafeDelete(hwCursor);

for (auto it = images.begin(); it != images.end(); ++it)
glDeleteTextures(1, &it->texture);
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/UI/ProfileDrawer.cpp
Expand Up @@ -55,7 +55,7 @@ void ProfileDrawer::SetEnabled(bool enable)
for (auto& p: profiler.profile)
p.second.peak = 0.0f;
} else {
SafeDelete(instance);
spring::SafeDelete(instance);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rts/Game/UnsyncedGameCommands.cpp
Expand Up @@ -3214,7 +3214,7 @@ void UnsyncedGameCommands::CreateInstance() {

void UnsyncedGameCommands::DestroyInstance() {
if (singleton != NULL) {
SafeDelete(singleton);
spring::SafeDelete(singleton);
} else {
// this might happen during shutdown after an unclean init
LOG_L(L_WARNING, "UnsyncedGameCommands singleton was not initialized or is already destroyed");
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/WordCompletion.cpp
Expand Up @@ -26,7 +26,7 @@ void CWordCompletion::CreateInstance() {

void CWordCompletion::DestroyInstance() {
if (singleton != NULL) {
SafeDelete(singleton);
spring::SafeDelete(singleton);
} else {
throw std::logic_error("WordCompletion singleton was not initialized or is already destroyed");
}
Expand Down
8 changes: 4 additions & 4 deletions rts/Lua/LuaParser.cpp
Expand Up @@ -239,8 +239,8 @@ bool LuaParser::Execute()
}


void LuaParser::AddTable(LuaTable* tbl) { VectorInsertUnique(tables, tbl); }
void LuaParser::RemoveTable(LuaTable* tbl) { VectorErase(tables, tbl); }
void LuaParser::AddTable(LuaTable* tbl) { spring::VectorInsertUnique(tables, tbl); }
void LuaParser::RemoveTable(LuaTable* tbl) { spring::VectorErase(tables, tbl); }


LuaTable LuaParser::GetRoot()
Expand Down Expand Up @@ -578,7 +578,7 @@ int LuaParser::Include(lua_State* L)
}

#if 0
VectorInsertUnique(currentParser->accessedFiles, StringToLower(filename), true);
spring::VectorInsertUnique(currentParser->accessedFiles, StringToLower(filename), true);
#endif
return (lua_gettop(L) - paramTop);
}
Expand Down Expand Up @@ -612,7 +612,7 @@ int LuaParser::LoadFile(lua_State* L)
lua_pushstring(L, data.c_str());

#if 0
VectorInsertUnique(currentParser->accessedFiles, StringToLower(filename), true);
spring::VectorInsertUnique(currentParser->accessedFiles, StringToLower(filename), true);
#endif
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion rts/Lua/LuaUnsyncedCtrl.cpp
Expand Up @@ -2134,7 +2134,7 @@ static int ReloadOrRestart(const std::string& springArgs, const std::string& scr
ISound::Shutdown();
#endif
// close local socket to avoid "bind: Address already in use"
SafeDelete(gameServer);
spring::SafeDelete(gameServer);

LOG("[%s] Spring \"%s\" should be restarting", __func__, springFullName.c_str());
Platform::ExecuteProcess(springFullName, processArgs, newProcess);
Expand Down
6 changes: 3 additions & 3 deletions rts/Lua/LuaVFSDownload.cpp
Expand Up @@ -164,7 +164,7 @@ void DownloadQueue::Join()
breakLoop = true;
if (thread != nullptr) {
thread->join();
SafeDelete(thread);
spring::SafeDelete(thread);
}
breakLoop = false;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ void DownloadQueue::Push(const DownloadItem& downloadItem)
lck.unlock();

thread->join();
SafeDelete(thread);
spring::SafeDelete(thread);

lck.lock();
}
Expand Down Expand Up @@ -338,7 +338,7 @@ void LuaVFSDownload::Update()
{
dlEventQueueMutex.unlock();
ev->processEvent();
SafeDelete(ev);
spring::SafeDelete(ev);
dlEventQueueMutex.lock();
}
}
Expand Down
4 changes: 2 additions & 2 deletions rts/Lua/LuaZip.cpp
Expand Up @@ -321,11 +321,11 @@ int LuaZipFileReader::meta_gc(lua_State* L)
ZipFileReaderUserdata* f = toreader(L);

if (f->stream) {
SafeDelete(f->stream);
spring::SafeDelete(f->stream);
}

if (f->archive && !f->dontClose) {
SafeDelete(f->archive);
spring::SafeDelete(f->archive);
lua_pushboolean(L, 1);
return 1;
}
Expand Down

1 comment on commit 71e5416

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the namespace changes broke unitsync and AIs compilation

Please sign in to comment.