Index: build/premake/premake5.lua =================================================================== --- build/premake/premake5.lua +++ build/premake/premake5.lua @@ -199,6 +199,13 @@ -- being used as a DLL (which is currently not the case in 0ad) defines { "LIB_STATIC_LINK" } + -- Enable C++14 standard. + filter "action:vs*" + buildoptions { "/std:c++14" } + filter "action:not vs*" + buildoptions { "-std=c++14" } + filter {} + -- various platform-specific build flags if os.istarget("windows") then @@ -291,11 +298,6 @@ end end - buildoptions { - -- Enable C++11 standard. - "-std=c++0x" - } - if arch == "arm" then -- disable warnings about va_list ABI change and use -- compile-time flags for futher configuration. @@ -1085,7 +1087,7 @@ -- Platform Specifics if os.istarget("windows") then -- Link to required libraries - links { "winmm", "comctl32", "rpcrt4", "delayimp", "ws2_32" } + links { "winmm", "delayimp" } elseif os.istarget("linux") or os.istarget("bsd") then buildoptions { "-rdynamic", "-fPIC" } Index: source/graphics/MapReader.cpp =================================================================== --- source/graphics/MapReader.cpp +++ source/graphics/MapReader.cpp @@ -421,7 +421,9 @@ int el_garrison; int el_turrets; int el_actor; - int at_x, at_y, at_z; + int at_x; + int at_y; + int at_z; int at_group, at_group2; int at_angle; int at_uid; @@ -656,20 +658,20 @@ { XERO_ITER_EL(element, fog) { - int element_name = fog.GetNodeName(); - if (element_name == el_fogcolor) + int sub_element_name = fog.GetNodeName(); + if (sub_element_name == el_fogcolor) { - XMBAttributeList attrs = fog.GetAttributes(); + XMBAttributeList fogAttributes = fog.GetAttributes(); m_MapReader.m_LightEnv.m_FogColor = RGBColor( - attrs.GetNamedItem(at_r).ToFloat(), - attrs.GetNamedItem(at_g).ToFloat(), - attrs.GetNamedItem(at_b).ToFloat()); + fogAttributes.GetNamedItem(at_r).ToFloat(), + fogAttributes.GetNamedItem(at_g).ToFloat(), + fogAttributes.GetNamedItem(at_b).ToFloat()); } - else if (element_name == el_fogfactor) + else if (sub_element_name == el_fogfactor) { m_MapReader.m_LightEnv.m_FogFactor = fog.GetText().ToFloat(); } - else if (element_name == el_fogthickness) + else if (sub_element_name == el_fogthickness) { m_MapReader.m_LightEnv.m_FogMax = fog.GetText().ToFloat(); } Index: source/graphics/ParticleEmitter.cpp =================================================================== --- source/graphics/ParticleEmitter.cpp +++ source/graphics/ParticleEmitter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -69,7 +69,7 @@ m_IndexArray.SetNumVertices(m_Type->m_MaxParticles * 6); m_IndexArray.Layout(); VertexArrayIterator index = m_IndexArray.GetIterator(); - for (size_t i = 0; i < m_Type->m_MaxParticles; ++i) + for (u16 i = 0; i < m_Type->m_MaxParticles; ++i) { *index++ = i*4 + 0; *index++ = i*4 + 1; Index: source/graphics/ParticleEmitterType.h =================================================================== --- source/graphics/ParticleEmitterType.h +++ source/graphics/ParticleEmitterType.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -100,7 +100,7 @@ bool m_UseRelativeVelocity; float m_MaxLifetime; - size_t m_MaxParticles; + u16 m_MaxParticles; CBoundingBoxAligned m_MaxBounds; typedef shared_ptr IParticleVarPtr; Index: source/graphics/tests/test_Camera.h =================================================================== --- source/graphics/tests/test_Camera.h +++ source/graphics/tests/test_Camera.h @@ -128,7 +128,7 @@ void CompareQuads(const CCamera::Quad& quad, const CCamera::Quad& expected_quad) { - const float EPS = 1e-4; + const float EPS = 1e-4f; for (size_t index = 0; index < expected_quad.size(); ++index) { TS_ASSERT_DELTA(quad[index].X, expected_quad[index].X, EPS); Index: source/graphics/tests/test_Terrain.h =================================================================== --- source/graphics/tests/test_Terrain.h +++ source/graphics/tests/test_Terrain.h @@ -451,16 +451,16 @@ ss << "Terrain (" << terrain.GetPatchesPerSide() << "x" << terrain.GetPatchesPerSide() << "):"; TS_WARN(ss.str()); - for (ssize_t jTile = 0; jTile < expectedSize; ++jTile) + for (ssize_t jj = 0; jj < expectedSize; ++jj) { ss.str(std::string()); ss << "["; - for (ssize_t iTile = 0; iTile < expectedSize; ++iTile) + for (ssize_t ii = 0; ii < expectedSize; ++ii) { - if (iTile) + if (ii) ss << ", "; - ss << GetVertex(terrain, iTile * PATCH_SIZE, - jTile * PATCH_SIZE); + ss << GetVertex(terrain, ii * PATCH_SIZE, + jj * PATCH_SIZE); } ss << "]"; TS_WARN(ss.str()); Index: source/gui/GUIManager.h =================================================================== --- source/gui/GUIManager.h +++ source/gui/GUIManager.h @@ -149,7 +149,7 @@ */ void PerformCallbackFunction(ScriptInterface::StructuredClone args); - CStrW name; + CStrW m_Name; std::unordered_set inputs; // for hotloading ScriptInterface::StructuredClone initData; // data to be passed to the init() function shared_ptr gui; // the actual GUI page Index: source/gui/GUIManager.cpp =================================================================== --- source/gui/GUIManager.cpp +++ source/gui/GUIManager.cpp @@ -122,7 +122,7 @@ } CGUIManager::SGUIPage::SGUIPage(const CStrW& pageName, const ScriptInterface::StructuredClone initData) - : name(pageName), initData(initData), inputs(), gui(), callbackFunction() + : m_Name(pageName), initData(initData), inputs(), gui(), callbackFunction() { } @@ -147,7 +147,7 @@ gui->AddObjectTypes(); - VfsPath path = VfsPath("gui") / name; + VfsPath path = VfsPath("gui") / m_Name; inputs.insert(path); CXeromyces xero; @@ -162,7 +162,7 @@ if (root.GetNodeName() != elmt_page) { - LOGERROR("GUI page '%s' must have root element ", utf8_from_wstring(name)); + LOGERROR("GUI page '%s' must have root element ", utf8_from_wstring(m_Name)); return; } @@ -170,12 +170,12 @@ { if (node.GetNodeName() != elmt_include) { - LOGERROR("GUI page '%s' must only have elements inside ", utf8_from_wstring(name)); + LOGERROR("GUI page '%s' must only have elements inside ", utf8_from_wstring(m_Name)); continue; } - std::string name = node.GetText(); - CStrW nameW (node.GetText().FromUTF8()); + CStr8 name = node.GetText(); + CStrW nameW = node.GetText().FromUTF8(); PROFILE2("load gui xml"); PROFILE2_ATTR("name: %s", name.c_str()); @@ -183,16 +183,16 @@ TIMER(nameW.c_str()); if (name.back() == '/') { - VfsPath directory = VfsPath("gui") / nameW; - VfsPaths pathnames; - vfs::GetPathnames(g_VFS, directory, L"*.xml", pathnames); - for (const VfsPath& path : pathnames) - gui->LoadXmlFile(path, inputs); + VfsPath currentDirectory = VfsPath("gui") / nameW; + VfsPaths directories; + vfs::GetPathnames(g_VFS, currentDirectory, L"*.xml", directories); + for (const VfsPath& directory : directories) + gui->LoadXmlFile(directory, inputs); } else { - VfsPath path = VfsPath("gui") / nameW; - gui->LoadXmlFile(path, inputs); + VfsPath directory = VfsPath("gui") / nameW; + gui->LoadXmlFile(directory, inputs); } } @@ -213,7 +213,7 @@ if (scriptInterface->HasProperty(global, "init") && !scriptInterface->CallFunctionVoid(global, "init", initDataVal, hotloadDataVal)) - LOGERROR("GUI page '%s': Failed to call init() function", utf8_from_wstring(name)); + LOGERROR("GUI page '%s': Failed to call init() function", utf8_from_wstring(m_Name)); } void CGUIManager::SGUIPage::SetCallbackFunction(ScriptInterface& scriptInterface, JS::HandleValue callbackFunc) @@ -268,7 +268,7 @@ for (SGUIPage& p : m_PageStack) if (p.inputs.find(path) != p.inputs.end()) { - LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(p.name)); + LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(p.m_Name)); p.LoadPage(m_ScriptContext); // TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators } Index: source/gui/ObjectTypes/CChart.cpp =================================================================== --- source/gui/ObjectTypes/CChart.cpp +++ source/gui/ObjectTypes/CChart.cpp @@ -70,14 +70,8 @@ // IGUITextOwner::HandleMessage(Message); performed in UpdateSeries // TODO: implement zoom - switch (Message.type) - { - case GUIM_SETTINGS_UPDATED: - { + if(Message.type == GUIM_SETTINGS_UPDATED) UpdateSeries(); - break; - } - } } void CChart::DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector& vertices) const Index: source/gui/ObjectTypes/CInput.cpp =================================================================== --- source/gui/ObjectTypes/CInput.cpp +++ source/gui/ObjectTypes/CInput.cpp @@ -1280,18 +1280,18 @@ // Anyway, since the drawing procedure needs "To" to be // greater than from, we need virtual values that might switch // place. - - int VirtualFrom, VirtualTo; + int virtualFrom = 0; + int virtualTo = 0; if (m_iBufferPos_Tail >= m_iBufferPos) { - VirtualFrom = m_iBufferPos; - VirtualTo = m_iBufferPos_Tail; + virtualFrom = m_iBufferPos; + virtualTo = m_iBufferPos_Tail; } else { - VirtualFrom = m_iBufferPos_Tail; - VirtualTo = m_iBufferPos; + virtualFrom = m_iBufferPos_Tail; + virtualTo = m_iBufferPos; } @@ -1307,7 +1307,7 @@ // (often compared against ints, so don't make it size_t) for (int i = 0; i < (int)it->m_ListOfX.size()+2; ++i) { - if (it->m_ListStart + i == VirtualFrom) + if (it->m_ListStart + i == virtualFrom) { // we won't actually draw it now, because we don't // know the width of each glyph to that position. @@ -1321,13 +1321,13 @@ const bool at_end = (i == (int)it->m_ListOfX.size()+1); - if (drawing_box && (it->m_ListStart + i == VirtualTo || at_end)) + if (drawing_box && (it->m_ListStart + i == virtualTo || at_end)) { // Depending on if it's just a row change, or if it's // the end of the select box, do slightly different things. if (at_end) { - if (it->m_ListStart + i != VirtualFrom) + if (it->m_ListStart + i != virtualFrom) // and actually add a white space! yes, this is done in any common input x_pointer += font.GetCharacterWidth(L' '); } @@ -1755,10 +1755,10 @@ // actually remove the entire lines they are on, it'll all have // to be redone. And when going along, we'll delete a row at a time // when continuing to see how much more after 'to' we need to remake. - int i = 0; + for (std::list::iterator it = m_CharacterPositions.begin(); it != m_CharacterPositions.end(); - ++it, ++i) + ++it) { if (!destroy_row_from_used && it->m_ListStart > check_point_row_start) { Index: source/gui/ObjectTypes/CMiniMap.cpp =================================================================== --- source/gui/ObjectTypes/CMiniMap.cpp +++ source/gui/ObjectTypes/CMiniMap.cpp @@ -592,9 +592,9 @@ } // Add the pinged vertices at the end, so they are drawn on top - for (size_t v = 0; v < pingingVertices.size(); ++v) + for (const MinimapUnitVertex& vertice : pingingVertices) { - addVertex(pingingVertices[v], attrColor, attrPos); + addVertex(vertice, attrColor, attrPos); ++m_EntitiesDrawn; } Index: source/gui/ObjectTypes/COList.cpp =================================================================== --- source/gui/ObjectTypes/COList.cpp +++ source/gui/ObjectTypes/COList.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -364,21 +364,21 @@ // Draw sort arrows in colum header if (m_Sortable) { - const CGUISpriteInstance* sprite; + const CGUISpriteInstance* pSprite; if (m_SelectedColumn == column.m_Id) { if (m_SelectedColumnOrder == 0) LOGERROR("selected_column_order must not be 0"); if (m_SelectedColumnOrder != -1) - sprite = &m_SpriteAsc; + pSprite = &m_SpriteAsc; else - sprite = &m_SpriteDesc; + pSprite = &m_SpriteDesc; } else - sprite = &m_SpriteNotSorted; + pSprite = &m_SpriteNotSorted; - m_pGUI.DrawSprite(*sprite, m_CellID, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); + m_pGUI.DrawSprite(*pSprite, m_CellID, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); } // Draw column header text @@ -413,12 +413,12 @@ // Draw all items for that column xpos = 0; - size_t col = 0; + size_t colIdx = 0; for (const COListColumn& column : m_Columns) { if (column.m_Hidden) { - ++col; + ++colIdx; continue; } @@ -436,9 +436,9 @@ cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight); // Draw list item - DrawText(objectsCount * (i +/*Heading*/1) + col, column.m_TextColor, textPos, bz + 0.1f, cliparea2); + DrawText(objectsCount * (i +/*Heading*/1) + colIdx, column.m_TextColor, textPos, bz + 0.1f, cliparea2); xpos += width; - ++col; + ++colIdx; } } } Index: source/i18n/L10n.h =================================================================== --- source/i18n/L10n.h +++ source/i18n/L10n.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -23,15 +23,16 @@ #ifndef INCLUDED_L10N #define INCLUDED_L10N -#include -#include - #include "lib/code_annotation.h" #include "lib/external_libraries/icu.h" #include "lib/external_libraries/tinygettext.h" #include "lib/file/vfs/vfs_path.h" #include "ps/Singleton.h" +#include +#include +#include + #define g_L10n L10n::GetSingleton() /** @@ -482,7 +483,7 @@ * * @sa LoadDictionaryForCurrentLocale() */ - tinygettext::Dictionary* dictionary; + std::unique_ptr m_Dictionary; /** * Locale that the game is currently using. @@ -507,7 +508,7 @@ * @sa GetSupportedLocaleBaseNames() * @sa GetSupportedLocaleDisplayNames() */ - std::vector availableLocales; + std::vector> availableLocales; /** * Whether the game is using the default game locale (@c true), ‘en_US’, or Index: source/i18n/L10n.cpp =================================================================== --- source/i18n/L10n.cpp +++ source/i18n/L10n.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -43,7 +43,7 @@ } L10n::L10n() - : dictionary(new tinygettext::Dictionary()), currentLocaleIsOriginalGameLocale(false), useLongStrings(false) + : m_Dictionary(new tinygettext::Dictionary()), currentLocaleIsOriginalGameLocale(false), useLongStrings(false) { // Determine whether or not to print tinygettext messages to the standard // error output, which it tinygettext’s default behavior, but not ours. @@ -66,10 +66,6 @@ L10n::~L10n() { UnregisterFileReloadFunc(ReloadChangedFileCB, this); - - for (icu::Locale* const& locale : availableLocales) - delete locale; - delete dictionary; } icu::Locale L10n::GetCurrentLocale() const @@ -135,7 +131,7 @@ { std::wstringstream stream; - std::function checkLangAndCountry = [&locale](const icu::Locale* const& l) { + std::function&)> checkLangAndCountry = [&locale](const std::unique_ptr& l) { return strcmp(locale.getLanguage(), l->getLanguage()) == 0 && strcmp(locale.getCountry(), l->getCountry()) == 0; }; @@ -147,7 +143,7 @@ return stream.str(); } - std::function checkLang = [&locale](const icu::Locale* const& l) { + std::function&)> checkLang = [&locale](const std::unique_ptr& l) { return strcmp(locale.getLanguage(), l->getLanguage()) == 0; }; @@ -231,7 +227,7 @@ std::vector L10n::GetSupportedLocaleBaseNames() const { std::vector supportedLocaleCodes; - for (icu::Locale* const& locale : availableLocales) + for (const std::unique_ptr& locale : availableLocales) { if (!InDevelopmentCopy() && strcmp(locale->getBaseName(), "long") == 0) continue; @@ -243,7 +239,7 @@ std::vector L10n::GetSupportedLocaleDisplayNames() const { std::vector supportedLocaleDisplayNames; - for (icu::Locale* const& locale : availableLocales) + for (const std::unique_ptr& locale : availableLocales) { if (strcmp(locale->getBaseName(), "long") == 0) { @@ -296,7 +292,7 @@ std::string L10n::Translate(const std::string& sourceString) const { if (!currentLocaleIsOriginalGameLocale) - return dictionary->translate(sourceString); + return m_Dictionary->translate(sourceString); return sourceString; } @@ -304,7 +300,7 @@ std::string L10n::TranslateWithContext(const std::string& context, const std::string& sourceString) const { if (!currentLocaleIsOriginalGameLocale) - return dictionary->translate_ctxt(context, sourceString); + return m_Dictionary->translate_ctxt(context, sourceString); return sourceString; } @@ -312,7 +308,7 @@ std::string L10n::TranslatePlural(const std::string& singularSourceString, const std::string& pluralSourceString, int number) const { if (!currentLocaleIsOriginalGameLocale) - return dictionary->translate_plural(singularSourceString, pluralSourceString, number); + return m_Dictionary->translate_plural(singularSourceString, pluralSourceString, number); if (number == 1) return singularSourceString; @@ -323,7 +319,7 @@ std::string L10n::TranslatePluralWithContext(const std::string& context, const std::string& singularSourceString, const std::string& pluralSourceString, int number) const { if (!currentLocaleIsOriginalGameLocale) - return dictionary->translate_ctxt_plural(context, singularSourceString, pluralSourceString, number); + return m_Dictionary->translate_ctxt_plural(context, singularSourceString, pluralSourceString, number); if (number == 1) return singularSourceString; @@ -457,7 +453,7 @@ } std::string content = file.DecodeUTF8(); - ReadPoIntoDictionary(content, dictionary); + ReadPoIntoDictionary(content, m_Dictionary.get()); if (g_GUI) g_GUI->ReloadAllPages(); @@ -467,9 +463,8 @@ void L10n::LoadDictionaryForCurrentLocale() { - delete dictionary; - dictionary = new tinygettext::Dictionary(); - + m_Dictionary.reset(); + m_Dictionary = std::move(std::unique_ptr(new tinygettext::Dictionary())); VfsPaths filenames; if (useLongStrings) @@ -492,18 +487,19 @@ CVFSFile file; file.Load(g_VFS, path); std::string content = file.DecodeUTF8(); - ReadPoIntoDictionary(content, dictionary); + ReadPoIntoDictionary(content, m_Dictionary.get()); } } void L10n::LoadListOfAvailableLocales() { - for (icu::Locale* const& locale : availableLocales) - delete locale; + for (std::unique_ptr& locale : availableLocales) + locale.reset(); + availableLocales.clear(); - icu::Locale* defaultLocale = new icu::Locale(icu::Locale::getUS()); - availableLocales.push_back(defaultLocale); // Always available. + std::unique_ptr defaultLocale = std::unique_ptr(new icu::Locale(icu::Locale::getUS())); + availableLocales.push_back(std::move(defaultLocale)); // Always available. VfsPaths filenames; if (vfs::GetPathnames(g_VFS, L"l10n/", L"*.po", filenames) < 0) @@ -515,18 +511,18 @@ std::string filename = utf8_from_wstring(path.string()).substr(strlen("l10n/")); size_t lengthToFirstDot = filename.find('.'); std::string localeCode = filename.substr(0, lengthToFirstDot); - icu::Locale* locale = new icu::Locale(icu::Locale::createCanonical(localeCode.c_str())); + std::unique_ptr locale = std::unique_ptr(new icu::Locale(icu::Locale::createCanonical(localeCode.c_str()))); - std::vector::iterator it = std::find_if(availableLocales.begin(), availableLocales.end(), [&locale](icu::Locale* const& l) { - return *locale == *l; + std::vector>::iterator it = std::find_if(availableLocales.begin(), availableLocales.end(), [&locale](const std::unique_ptr& l) { + return locale.get() == l.get(); }); if (it != availableLocales.end()) { - delete locale; + locale.reset(); continue; } - availableLocales.push_back(locale); + availableLocales.push_back(std::move(locale)); } } Index: source/lobby/scripting/JSInterface_Lobby.cpp =================================================================== --- source/lobby/scripting/JSInterface_Lobby.cpp +++ source/lobby/scripting/JSInterface_Lobby.cpp @@ -73,7 +73,7 @@ bool JSI_Lobby::HasXmppClient(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) { - return g_XmppClient; + return !!g_XmppClient; } void JSI_Lobby::SetRankedGame(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool isRanked) Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -1093,7 +1093,7 @@ session->SetUserName(username); session->SetHostID(newHostID); - session->SetLocalClient(message->m_IsLocalClient); + session->SetLocalClient(!!message->m_IsLocalClient); CAuthenticateResultMessage authenticateResult; authenticateResult.m_Code = isRejoining ? ARC_OK_REJOINING : ARC_OK; @@ -1405,7 +1405,7 @@ if (session->GetGUID() == server.m_HostGUID) { CKickedMessage* message = (CKickedMessage*)event->GetParamRef(); - server.KickPlayer(message->m_Name, message->m_Ban); + server.KickPlayer(message->m_Name, !!message->m_Ban); } return true; } @@ -1452,11 +1452,9 @@ } // Send messages to clients that are in game, and are not the client who paused. - for (CNetServerSession* session : server.m_Sessions) - { - if (session->GetCurrState() == NSS_INGAME && message->m_GUID != session->GetGUID()) - session->SendMessage(message); - } + for (CNetServerSession* netSession : server.m_Sessions) + if (netSession->GetCurrState() == NSS_INGAME && message->m_GUID != netSession->GetGUID()) + netSession->SendMessage(message); return true; } Index: source/network/NetServerTurnManager.cpp =================================================================== --- source/network/NetServerTurnManager.cpp +++ source/network/NetServerTurnManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -153,10 +153,10 @@ CSyncErrorMessage msg; msg.m_Turn = clientStateHash.first; msg.m_HashExpected = expected; - for (const CStrW& playername : OOSPlayerNames) + for (const CStrW& oosPlayername : OOSPlayerNames) { CSyncErrorMessage::S_m_PlayerNames h; - h.m_Name = playername; + h.m_Name = oosPlayername; msg.m_PlayerNames.push_back(h); } m_NetServer.Broadcast(&msg, { NSS_INGAME }); Index: source/network/scripting/JSInterface_Network.cpp =================================================================== --- source/network/scripting/JSInterface_Network.cpp +++ source/network/scripting/JSInterface_Network.cpp @@ -38,12 +38,12 @@ bool JSI_Network::HasNetServer(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) { - return g_NetServer; + return g_NetServer != nullptr; } bool JSI_Network::HasNetClient(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) { - return g_NetClient; + return g_NetClient != nullptr; } JS::Value JSI_Network::FindStunEndpoint(ScriptInterface::CmptPrivate* pCmptPrivate, int port) @@ -58,7 +58,7 @@ ENSURE(!g_Game); // Always use lobby authentication for lobby matches to prevent impersonation and smurfing, in particular through mods that implemented an UI for arbitrary or other players nicknames. - g_NetServer = new CNetServer(static_cast(g_XmppClient)); + g_NetServer = new CNetServer(!!g_XmppClient); if (!g_NetServer->SetupConnection(serverPort)) { ScriptRequest rq(pCmptPrivate->pScriptInterface); Index: source/ps/ModIo.cpp =================================================================== --- source/ps/ModIo.cpp +++ source/ps/ModIo.cpp @@ -418,12 +418,11 @@ if (!message) continue; - CURLcode err = message->data.result; - if (err == CURLE_OK) + if (message->data.result == CURLE_OK) continue; std::string error = fmt::sprintf( - g_L10n.Translate("Download failure. Server response: %s; %s."), curl_easy_strerror(err), m_ErrorBuffer); + g_L10n.Translate("Download failure. Server response: %s; %s."), curl_easy_strerror(message->data.result), m_ErrorBuffer); TearDownRequest(); if (m_DownloadProgressData.status == DownloadProgressStatus::GAMEID) m_DownloadProgressData.status = DownloadProgressStatus::FAILED_GAMEID; Index: source/ps/ProfileViewer.cpp =================================================================== --- source/ps/ProfileViewer.cpp +++ source/ps/ProfileViewer.cpp @@ -282,19 +282,19 @@ currentExpandId++; } - float colX = 0.0f; + float rowColX = 0.0f; for (size_t col = 0; col < columns.size(); ++col) { CStrW text = table->GetCellText(row, col).FromUTF8(); int w, h; font.CalculateStringSize(text.c_str(), w, h); - float x = colX; + float x = rowColX; if (col > 0) // right-align all but the first column x += columns[col].width - w; textRenderer.Put(x, 0.0f, text.c_str()); - colX += columns[col].width; + rowColX += columns[col].width; } textRenderer.Translate(0.0f, lineSpacing, 0.0f); Index: source/renderer/OverlayRenderer.cpp =================================================================== --- source/renderer/OverlayRenderer.cpp +++ source/renderer/OverlayRenderer.cpp @@ -178,14 +178,14 @@ // indices are always the same; we can therefore fill in all the indices once and pretty much forget about // them. We then also no longer need its backing store, since we never change any indices afterwards. VertexArrayIterator index = quadIndices.GetIterator(); - for (size_t i = 0; i < MAX_QUAD_OVERLAYS; ++i) + for (u16 i = 0; i < static_cast(MAX_QUAD_OVERLAYS); ++i) { - *index++ = i*4 + 0; - *index++ = i*4 + 1; - *index++ = i*4 + 2; - *index++ = i*4 + 2; - *index++ = i*4 + 3; - *index++ = i*4 + 0; + *index++ = i * 4 + 0; + *index++ = i * 4 + 1; + *index++ = i * 4 + 2; + *index++ = i * 4 + 2; + *index++ = i * 4 + 3; + *index++ = i * 4 + 0; } quadIndices.Upload(); quadIndices.FreeBackingStore(); Index: source/renderer/PatchRData.cpp =================================================================== --- source/renderer/PatchRData.cpp +++ source/renderer/PatchRData.cpp @@ -308,7 +308,7 @@ // Update the indices to include the base offset of the vertex data for (size_t k = 0; k < blendIndices.size(); ++k) - blendIndices[k] += m_VBBlends->m_Index; + blendIndices[k] += static_cast(m_VBBlends->m_Index); m_VBBlendIndices = g_VBMan.Allocate(sizeof(u16), blendIndices.size(), GL_STATIC_DRAW, GL_ELEMENT_ARRAY_BUFFER); m_VBBlendIndices->m_Owner->UpdateChunkVertices(m_VBBlendIndices, &blendIndices[0]); @@ -369,7 +369,7 @@ CVector3D normal; - size_t index = blendVertices.size(); + u16 index = static_cast(blendVertices.size()); terrain->CalcPosition(gx, gz, dst.m_Position); terrain->CalcNormal(gx, gz, normal); @@ -464,10 +464,11 @@ // build indices for base splats size_t base=m_VBBase->m_Index; - for (size_t i=0;i& patches, const CShaderProgramPtr& shader, int streamflags) { // Each batch has a list of index counts, and a list of pointers-to-first-indexes - typedef std::pair, std::vector > BatchElements; + using StreamBatchElements = std::pair, std::vector > ; // Group batches by index buffer - typedef std::map IndexBufferBatches; + using StreamIndexBufferBatches = std::map ; // Group batches by vertex buffer - typedef std::map VertexBufferBatches; + using StreamVertexBufferBatches = std::map ; - VertexBufferBatches batches; + using StreamBatchElement = const std::pair&; + using StreamIndexBufferBatch = const std::pair&; + StreamVertexBufferBatches batches; PROFILE_START("compute batches"); // Collect all the patches into their appropriate batches - for (size_t i = 0; i < patches.size(); ++i) - { - CPatchRData* patch = patches[i]; - BatchElements& batch = batches[patch->m_VBBase->m_Owner][patch->m_VBBaseIndices->m_Owner]; + for (const CPatchRData* patch : patches) + { + StreamBatchElements& batch = batches[patch->m_VBBase->m_Owner][patch->m_VBBaseIndices->m_Owner]; batch.first.push_back(patch->m_VBBaseIndices->m_Count); @@ -1130,10 +1132,10 @@ ENSURE(!(streamflags & ~(STREAM_POS|STREAM_POSTOUV0|STREAM_POSTOUV1))); // Render each batch - for (VertexBufferBatches::iterator itv = batches.begin(); itv != batches.end(); ++itv) + for (StreamBatchElement streamBatch : batches) { GLsizei stride = sizeof(SBaseVertex); - SBaseVertex *base = (SBaseVertex *)itv->first->Bind(); + SBaseVertex *base = (SBaseVertex *)streamBatch.first->Bind(); shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position); if (streamflags & STREAM_POSTOUV0) @@ -1143,11 +1145,11 @@ shader->AssertPointersBound(); - for (IndexBufferBatches::iterator it = itv->second.begin(); it != itv->second.end(); ++it) + for (StreamIndexBufferBatch batchIndexBuffer : streamBatch.second) { - it->first->Bind(); + batchIndexBuffer.first->Bind(); - BatchElements& batch = it->second; + const StreamBatchElements& batch = batchIndexBuffer.second; if (!g_Renderer.m_SkipSubmit) { @@ -1381,7 +1383,7 @@ vertex.m_WaterData = CVector2D(WaterMgr->m_WindStrength[xx + zz*mapSize], depth); - water_index_map[z+moves[i][1]][x+moves[i][0]] = water_vertex_data.size(); + water_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast(water_vertex_data.size()); water_vertex_data.push_back(vertex); } water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); @@ -1414,7 +1416,7 @@ vertex.m_WaterData = CVector2D(0.0f, -5.0f); - water_shore_index_map[z+moves[i][1]][x+moves[i][0]] = water_vertex_data_shore.size(); + water_shore_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast(water_vertex_data.size()); water_vertex_data_shore.push_back(vertex); } if (terrain->GetTriangulationDir(x + px, z + pz)) Index: source/renderer/TexturedLineRData.cpp =================================================================== --- source/renderer/TexturedLineRData.cpp +++ source/renderer/TexturedLineRData.cpp @@ -167,8 +167,9 @@ vertices.push_back(vertex1); vertices.push_back(vertex2); - u16 index1 = vertices.size() - 2; // index of vertex1 in this iteration (TR of this quad) - u16 index2 = vertices.size() - 1; // index of the vertex2 in this iteration (TL of this quad) + u16 vertexCount = static_cast(vertices.size()); + u16 index1 = vertexCount - 2; // index of vertex1 in this iteration (TR of this quad) + u16 index2 = vertexCount - 1; // index of the vertex2 in this iteration (TL of this quad) if (i == 0) { @@ -178,10 +179,10 @@ } else { - u16 index1Prev = vertices.size() - 4; // index of the vertex1 in the previous iteration (BR of this quad) - u16 index2Prev = vertices.size() - 3; // index of the vertex2 in the previous iteration (BL of this quad) - ENSURE(index1Prev < vertices.size()); - ENSURE(index2Prev < vertices.size()); + u16 index1Prev = vertexCount - 4; // index of the vertex1 in the previous iteration (BR of this quad) + u16 index2Prev = vertexCount - 3; // index of the vertex2 in the previous iteration (BL of this quad) + ENSURE(index1Prev < vertexCount); + ENSURE(index2Prev < vertexCount); // Add two corner points from last iteration and join with one of our own corners to create triangle 1 // (don't need to do this if i == 1 because i == 0 are the first two ones, they don't need to be copied) if (i > 1) @@ -224,15 +225,17 @@ if (closed) { + // close the path if (n % 2 == 0) { - indices.push_back(vertices.size()-2); - indices.push_back(vertices.size()-1); + u16 vertexCount = static_cast(vertices.size()); + indices.push_back(vertexCount - 2); + indices.push_back(vertexCount - 1); indices.push_back(0); indices.push_back(0); - indices.push_back(vertices.size()-1); + indices.push_back(vertexCount - 1); indices.push_back(1); } else @@ -243,13 +246,14 @@ vertices.push_back(vertex1); vertices.push_back(vertex2); - indices.push_back(vertices.size()-4); - indices.push_back(vertices.size()-3); - indices.push_back(vertices.size()-2); - - indices.push_back(vertices.size()-2); - indices.push_back(vertices.size()-3); - indices.push_back(vertices.size()-1); + u16 vertexCount = static_cast(vertices.size()); + indices.push_back(vertexCount - 4); + indices.push_back(vertexCount - 3); + indices.push_back(vertexCount - 2); + + indices.push_back(vertexCount - 2); + indices.push_back(vertexCount - 3); + indices.push_back(vertexCount - 1); } } else @@ -274,7 +278,7 @@ ); for (unsigned i = 0; i < capIndices.size(); i++) - capIndices[i] += vertices.size(); + capIndices[i] += static_cast(vertices.size()); vertices.insert(vertices.end(), capVertices.begin(), capVertices.end()); indices.insert(indices.end(), capIndices.begin(), capIndices.end()); @@ -296,7 +300,7 @@ ); for (unsigned i = 0; i < capIndices.size(); i++) - capIndices[i] += vertices.size(); + capIndices[i] += static_cast(vertices.size()); vertices.insert(vertices.end(), capVertices.begin(), capVertices.end()); indices.insert(indices.end(), capIndices.begin(), capIndices.end()); @@ -314,7 +318,7 @@ m_VB->m_Owner->UpdateChunkVertices(m_VB, &vertices[0]); // copy data into VBO for (size_t k = 0; k < indices.size(); ++k) - indices[k] += m_VB->m_Index; + indices[k] += static_cast(m_VB->m_Index); m_VBIndices = g_VBMan.Allocate(sizeof(u16), indices.size(), GL_STATIC_DRAW, GL_ELEMENT_ARRAY_BUFFER); if (m_VBIndices) @@ -347,7 +351,7 @@ CVector3D centerPoint = (corner1 + corner2) * 0.5f; SVertex centerVertex(centerPoint, 0.5f, 0.5f); - u16 indexOffset = verticesOut.size(); // index offset in verticesOut from where we start adding our vertices + u16 indexOffset = static_cast(verticesOut.size()); // index offset in verticesOut from where we start adding our vertices switch (endCapType) { Index: source/renderer/WaterManager.cpp =================================================================== --- source/renderer/WaterManager.cpp +++ source/renderer/WaterManager.cpp @@ -611,20 +611,20 @@ } // Fourth step: create waves themselves, using those chains. We basically create subchains. - size_t waveSizes = 14; // maximal size in width. + GLushort waveSizes = 14; // maximal size in width. // Construct indices buffer (we can afford one for all of them) std::vector water_indices; - for (size_t a = 0; a < waveSizes-1;++a) + for (GLushort a = 0; a < waveSizes - 1; ++a) { - for (size_t rect = 0; rect < 7; ++rect) + for (GLushort rect = 0; rect < 7; ++rect) { - water_indices.push_back(a*9 + rect); - water_indices.push_back(a*9 + 9 + rect); - water_indices.push_back(a*9 + 1 + rect); - water_indices.push_back(a*9 + 9 + rect); - water_indices.push_back(a*9 + 10 + rect); - water_indices.push_back(a*9 + 1 + rect); + water_indices.push_back(a * 9 + rect); + water_indices.push_back(a * 9 + 9 + rect); + water_indices.push_back(a * 9 + 1 + rect); + water_indices.push_back(a * 9 + 9 + rect); + water_indices.push_back(a * 9 + 10 + rect); + water_indices.push_back(a * 9 + 1 + rect); } } // Generic indexes, max-length @@ -640,14 +640,14 @@ if (CoastalPointsChains[i].size()- 1 - j < waveSizes) break; - size_t width = waveSizes; + GLushort width = waveSizes; // First pass to get some parameters out. float outmost = 0.0f; // how far to move on the shore. float avgDepth = 0.0f; int sign = 1; CVector2D firstPerp(0,0), perp(0,0), lastPerp(0,0); - for (size_t a = 0; a < waveSizes;++a) + for (GLushort a = 0; a < waveSizes;++a) { lastPerp = perp; perp = CVector2D(0,0); @@ -728,9 +728,9 @@ shoreWave->m_TimeDiff = diff; diff += (rand() % 100) / 25.0f + 4.0f; - for (size_t a = 0; a < width;++a) + for (GLushort a = 0; a < width;++a) { - CVector2D perp = CVector2D(0,0); + perp = CVector2D(0,0); int nb = 0; CVector2D pos = CoastalPointsChains[i][j+a].position; CVector2D posPlus; Index: source/simulation2/Simulation2.cpp =================================================================== --- source/simulation2/Simulation2.cpp +++ source/simulation2/Simulation2.cpp @@ -198,12 +198,12 @@ return false; bool ok = true; - for (const VfsPath& path : pathnames) + for (const VfsPath& scriptPath : pathnames) { if (loadedScripts) - loadedScripts->insert(path); - LOGMESSAGE("Loading simulation script '%s'", path.string8()); - if (!componentManager.LoadScript(path)) + loadedScripts->insert(scriptPath); + LOGMESSAGE("Loading simulation script '%s'", scriptPath.string8()); + if (!componentManager.LoadScript(scriptPath)) ok = false; } return ok; @@ -921,10 +921,10 @@ { // Load JSON file CVFSFile file; - PSRETURN ret = file.Load(g_VFS, p); - if (ret != PSRETURN_OK) + PSRETURN loadStatus = file.Load(g_VFS, p); + if (loadStatus != PSRETURN_OK) { - LOGERROR("GetJSONData: Failed to load file '%s': %s", p.string8(), GetErrorString(ret)); + LOGERROR("GetJSONData: Failed to load file '%s': %s", p.string8(), GetErrorString(loadStatus)); continue; } Index: source/simulation2/components/CCmpObstruction.cpp =================================================================== --- source/simulation2/components/CCmpObstruction.cpp +++ source/simulation2/components/CCmpObstruction.cpp @@ -771,18 +771,15 @@ return; // Attempt to replace colliding entities' control groups with a persistent one. - for (std::vector::iterator it = normalEnts.begin(); it != normalEnts.end(); ++it) + for (const entity_id_t normalEnt : normalEnts) { - entity_id_t ent = *it; - - CmpPtr cmpObstruction(GetSimContext(), ent); - for (std::vector::iterator it = persistentEnts.begin(); it != persistentEnts.end(); ++it) + CmpPtr cmpObstruction(GetSimContext(), normalEnt); + for (const entity_id_t persistent : normalEnts) { - entity_id_t persistent = *it; entity_id_t group = cmpObstruction->GetControlGroup(); // Only clobber 'default' control groups. - if (group == ent) + if (group == normalEnt) cmpObstruction->SetControlGroup(persistent); else if (cmpObstruction->GetControlGroup2() == INVALID_ENTITY && group != persistent) cmpObstruction->SetControlGroup2(persistent); Index: source/simulation2/components/CCmpObstructionManager.cpp =================================================================== --- source/simulation2/components/CCmpObstructionManager.cpp +++ source/simulation2/components/CCmpObstructionManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -825,8 +825,8 @@ fixed dist = DistanceToPoint(ent, px, pz); // Treat -1 max range as infinite return dist != fixed::FromInt(-1) && - (dist <= (maxRange + fixed::FromFloat(0.0001)) || maxRange < fixed::Zero()) && - (opposite ? MaxDistanceToPoint(ent, px, pz) : dist) >= minRange - fixed::FromFloat(0.0001); + (dist <= (maxRange + fixed::FromFloat(0.0001f)) || maxRange < fixed::Zero()) && + (opposite ? MaxDistanceToPoint(ent, px, pz) : dist) >= minRange - fixed::FromFloat(0.0001f); } bool CCmpObstructionManager::IsInTargetRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const @@ -834,15 +834,15 @@ fixed dist = DistanceToTarget(ent, target); // Treat -1 max range as infinite return dist != fixed::FromInt(-1) && - (dist <= (maxRange + fixed::FromFloat(0.0001)) || maxRange < fixed::Zero()) && - (opposite ? MaxDistanceToTarget(ent, target) : dist) >= minRange - fixed::FromFloat(0.0001); + (dist <= (maxRange + fixed::FromFloat(0.0001f)) || maxRange < fixed::Zero()) && + (opposite ? MaxDistanceToTarget(ent, target) : dist) >= minRange - fixed::FromFloat(0.0001f); } bool CCmpObstructionManager::IsPointInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange) const { entity_pos_t distance = (CFixedVector2D(x, z) - CFixedVector2D(px, pz)).Length(); // Treat -1 max range as infinite - return (distance <= (maxRange + fixed::FromFloat(0.0001)) || maxRange < fixed::Zero()) && - distance >= minRange - fixed::FromFloat(0.0001); + return (distance <= (maxRange + fixed::FromFloat(0.0001f)) || maxRange < fixed::Zero()) && + distance >= minRange - fixed::FromFloat(0.0001f); } bool CCmpObstructionManager::AreShapesInRange(const ObstructionSquare& source, const ObstructionSquare& target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const @@ -850,8 +850,8 @@ fixed dist = DistanceBetweenShapes(source, target); // Treat -1 max range as infinite return dist != fixed::FromInt(-1) && - (dist <= (maxRange + fixed::FromFloat(0.0001)) || maxRange < fixed::Zero()) && - (opposite ? MaxDistanceBetweenShapes(source, target) : dist) >= minRange - fixed::FromFloat(0.0001); + (dist <= (maxRange + fixed::FromFloat(0.0001f)) || maxRange < fixed::Zero()) && + (opposite ? MaxDistanceBetweenShapes(source, target) : dist) >= minRange - fixed::FromFloat(0.0001f); } bool CCmpObstructionManager::TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, bool relaxClearanceForUnits) const Index: source/simulation2/components/CCmpPosition.cpp =================================================================== --- source/simulation2/components/CCmpPosition.cpp +++ source/simulation2/components/CCmpPosition.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -835,15 +835,15 @@ if (newTerritory != m_Territory) { m_Territory = newTerritory; - CMessageTerritoryPositionChanged msg(GetEntityId(), m_Territory); - GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); + CMessageTerritoryPositionChanged posMsg(GetEntityId(), m_Territory); + GetSimContext().GetComponentManager().PostMessage(GetEntityId(), posMsg); } } else if (m_Territory != INVALID_PLAYER) { m_Territory = INVALID_PLAYER; - CMessageTerritoryPositionChanged msg(GetEntityId(), m_Territory); - GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); + CMessageTerritoryPositionChanged posMsg(GetEntityId(), m_Territory); + GetSimContext().GetComponentManager().PostMessage(GetEntityId(), posMsg); } break; } Index: source/simulation2/components/CCmpRangeManager.cpp =================================================================== --- source/simulation2/components/CCmpRangeManager.cpp +++ source/simulation2/components/CCmpRangeManager.cpp @@ -126,7 +126,7 @@ */ static inline bool HasVisionSharing(u16 visionSharing, player_id_t player) { - return visionSharing & 1 << (player-1); + return (visionSharing & (1 << (player - 1))) != 0; } /** @@ -1051,12 +1051,12 @@ virtual std::vector GetNonGaiaEntities() const { - return GetEntitiesByMask(~3); // bit 0 for owner=-1 and bit 1 for gaia + return GetEntitiesByMask(~3u); // bit 0 for owner=-1 and bit 1 for gaia } virtual std::vector GetGaiaAndNonGaiaEntities() const { - return GetEntitiesByMask(~1); // bit 0 for owner=-1 + return GetEntitiesByMask(~1u); // bit 0 for owner=-1 } std::vector GetEntitiesByMask(u32 ownerMask) const @@ -1440,8 +1440,8 @@ else { // elevation bonus is part of the 3D position. As if the unit is really that much higher - CFixedVector3D pos = cmpSourcePosition->GetPosition(); - pos.Y += q.elevationBonus; + CFixedVector3D pos3D = cmpSourcePosition->GetPosition(); + pos3D.Y += q.elevationBonus; std::vector coords; @@ -1449,7 +1449,7 @@ if (ParabolicRangesOutlines.find(q.source.GetId()) != ParabolicRangesOutlines.end()) { EntityParabolicRangeOutline e = ParabolicRangesOutlines[q.source.GetId()]; - if (e.position == pos && e.range == q.maxRange) + if (e.position == pos3D && e.range == q.maxRange) { // outline is cached correctly, use it coords = e.outline; @@ -1459,10 +1459,10 @@ // outline was cached, but important parameters changed // (position, elevation, range) // update it - coords = getParabolicRangeForm(pos,q.maxRange,q.maxRange*2, entity_pos_t::Zero(), entity_pos_t::FromFloat(2.0f*3.14f),70); + coords = getParabolicRangeForm(pos3D,q.maxRange,q.maxRange*2, entity_pos_t::Zero(), entity_pos_t::FromFloat(2.0f*3.14f),70); e.outline = coords; e.range = q.maxRange; - e.position = pos; + e.position = pos3D; ParabolicRangesOutlines[q.source.GetId()] = e; } } @@ -1471,11 +1471,11 @@ // outline wasn't cached (first time you enable the range overlay // or you created a new entiy) // cache a new outline - coords = getParabolicRangeForm(pos,q.maxRange,q.maxRange*2, entity_pos_t::Zero(), entity_pos_t::FromFloat(2.0f*3.14f),70); + coords = getParabolicRangeForm(pos3D,q.maxRange,q.maxRange*2, entity_pos_t::Zero(), entity_pos_t::FromFloat(2.0f*3.14f),70); EntityParabolicRangeOutline e; e.source = q.source.GetId(); e.range = q.maxRange; - e.position = pos; + e.position = pos3D; e.outline = coords; ParabolicRangesOutlines[q.source.GetId()] = e; } @@ -1486,10 +1486,10 @@ for (size_t i = 3; i < coords.size(); i += 2) { std::vector c; - c.push_back((coords[i-3]+pos.X).ToFloat()); - c.push_back((coords[i-2]+pos.Z).ToFloat()); - c.push_back((coords[i-1]+pos.X).ToFloat()); - c.push_back((coords[i]+pos.Z).ToFloat()); + c.push_back((coords[i - 3] + pos3D.X).ToFloat()); + c.push_back((coords[i - 2] + pos3D.Z).ToFloat()); + c.push_back((coords[i - 1] + pos3D.X).ToFloat()); + c.push_back((coords[i] + pos3D.Z).ToFloat()); m_DebugOverlayLines.push_back(SOverlayLine()); m_DebugOverlayLines.back().m_Color = thiscolor; SimRender::ConstructLineOnGround(GetSimContext(), c, m_DebugOverlayLines.back(), true); Index: source/simulation2/components/CCmpSelectable.cpp =================================================================== --- source/simulation2/components/CCmpSelectable.cpp +++ source/simulation2/components/CCmpSelectable.cpp @@ -347,11 +347,11 @@ /// Total duration of a single fade, in seconds. Assumed constant for now; feel free to change this into /// a member variable if you need to adjust it per component. - static const double FADE_DURATION; + static const float FADE_DURATION; static const char* TEXTUREBASEPATH; }; -const double CCmpSelectable::FADE_DURATION = 0.3; +const float CCmpSelectable::FADE_DURATION = 0.3f; const char* CCmpSelectable::TEXTUREBASEPATH = "art/textures/selection/"; void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global)) Index: source/simulation2/components/CCmpTerritoryManager.cpp =================================================================== --- source/simulation2/components/CCmpTerritoryManager.cpp +++ source/simulation2/components/CCmpTerritoryManager.cpp @@ -209,8 +209,7 @@ if (m_TriggerEvent) { m_TriggerEvent = false; - CMessageTerritoriesChanged msg; - GetSimContext().GetComponentManager().BroadcastMessage(msg); + GetSimContext().GetComponentManager().BroadcastMessage(CMessageTerritoriesChanged()); } break; } @@ -326,7 +325,7 @@ }; // Floodfill templates that expand neighbours from a certain source onwards -// (x, z) are the coordinates of the currently expanded tile +// (posX, posZ) are the coordinates of the currently expanded tile // (nx, nz) are the coordinates of the current neighbour handled // The user of this floodfill should use "continue" on every neighbour that // shouldn't be expanded on its own. (without continue, an infinite loop will happen) @@ -339,13 +338,13 @@ openTiles.emplace(i, j);\ while (!openTiles.empty())\ {\ - u16 x = openTiles.front().x;\ - u16 z = openTiles.front().z;\ + u16 posX = openTiles.front().x;\ + u16 posZ = openTiles.front().z;\ openTiles.pop();\ for (int n = 0; n < NUM_NEIGHBOURS; ++n)\ {\ - u16 nx = x + NEIGHBOURS_X[n];\ - u16 nz = z + NEIGHBOURS_Z[n];\ + u16 nx = posX + NEIGHBOURS_X[n];\ + u16 nz = posZ + NEIGHBOURS_Z[n];\ /* Check the bounds, underflow will cause the values to be big again */\ if (nx >= tilesW || nz >= tilesH)\ continue;\ @@ -505,16 +504,16 @@ u32 dg = falloff * m_CostGrid->get(nx, nz); // diagonal neighbour -> multiply with approx sqrt(2) - if (nx != x && nz != z) + if (nx != posX && nz != posZ) dg = (dg * 362) / 256; // Don't expand if new cost is not better than previous value for that tile // (arranged to avoid underflow if entityGrid.get(x, z) < dg) - if (entityGrid.get(x, z) <= entityGrid.get(nx, nz) + dg) + if (entityGrid.get(posX, posZ) <= entityGrid.get(nx, nz) + dg) continue; // weight of this tile = weight of predecessor - falloff from predecessor - u32 newWeight = entityGrid.get(x, z) - dg; + u32 newWeight = entityGrid.get(posX, posZ) - dg; u32 totalWeight = playerGrid.get(nx, nz) - entityGrid.get(nx, nz) + newWeight; playerGrid.set(nx, nz, totalWeight); entityGrid.set(nx, nz, newWeight); Index: source/simulation2/components/CCmpUnitMotion.cpp =================================================================== --- source/simulation2/components/CCmpUnitMotion.cpp +++ source/simulation2/components/CCmpUnitMotion.cpp @@ -834,8 +834,8 @@ { // Get close enough - this will likely help the short path efficiency, and if we end up taking a wrong way // we'll easily be able to revert it using a long path. - PathGoal goal = { PathGoal::CIRCLE, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z, ShortPathWaypointRange(m_LongPath) }; - RequestShortPath(pos, goal, true); + PathGoal closeGoal = { PathGoal::CIRCLE, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z, ShortPathWaypointRange(m_LongPath) }; + RequestShortPath(pos, closeGoal, true); return; } } @@ -1087,8 +1087,8 @@ { // Get close enough - this will likely help the short path efficiency, and if we end up taking a wrong way // we'll easily be able to revert it using a long path. - PathGoal goal = { PathGoal::CIRCLE, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z, ShortPathWaypointRange(m_LongPath) }; - RequestShortPath(pos, goal, true); + PathGoal closeGoal = { PathGoal::CIRCLE, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z, ShortPathWaypointRange(m_LongPath) }; + RequestShortPath(pos, closeGoal, true); return true; } } Index: source/simulation2/components/ICmpTurretHolder.cpp =================================================================== --- source/simulation2/components/ICmpTurretHolder.cpp +++ source/simulation2/components/ICmpTurretHolder.cpp @@ -50,7 +50,7 @@ /** * Correlation between entities (ID) and the turret point they ought to occupy (name). */ - virtual void SetInitEntities(std::vector > entities) + virtual void SetInitEntities(const std::vector > entities) { for (const std::pair& p : entities) m_Script.CallVoid("SetInitEntity", p.first, p.second); Index: source/simulation2/components/tests/test_HierPathfinder.h =================================================================== --- source/simulation2/components/tests/test_HierPathfinder.h +++ source/simulation2/components/tests/test_HierPathfinder.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -74,8 +74,8 @@ { // test that the map has the same global region everywhere HierarchicalPathfinder::GlobalRegionID globalRegionID = hierPath.GetGlobalRegion(35, 23, PASS_1); - for (size_t i = 0; i < mapSize; ++i) - for (size_t j = 0; j < mapSize; ++j) + for (u16 i = 0; i < mapSize; ++i) + for (u16 j = 0; j < mapSize; ++j) { TS_ASSERT(globalRegionID == hierPath.GetGlobalRegion(i, j, PASS_1)); TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); @@ -137,19 +137,19 @@ // Global region: check we are now split in two. TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) != hierPath.GetGlobalRegion(150, 50, PASS_1)); - for (size_t j = 0; j < mapSize; ++j) + for (u16 j = 0; j < mapSize; ++j) { TS_ASSERT(hierPath.Get(125, j, PASS_1).r == 0); TS_ASSERT(hierPath.GetGlobalRegion(125, j, PASS_1) == 0); } - for (size_t i = 0; i < 125; ++i) - for (size_t j = 0; j < mapSize; ++j) + for (u16 i = 0; i < 125; ++i) + for (u16 j = 0; j < mapSize; ++j) { TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); } - for (size_t i = 126; i < mapSize; ++i) - for (size_t j = 0; j < mapSize; ++j) + for (u16 i = 126; i < mapSize; ++i) + for (u16 j = 0; j < mapSize; ++j) { TS_ASSERT(hierPath.GetGlobalRegion(150, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); Index: source/simulation2/components/tests/test_ObstructionManager.h =================================================================== --- source/simulation2/components/tests/test_ObstructionManager.h +++ source/simulation2/components/tests/test_ObstructionManager.h @@ -562,21 +562,21 @@ TS_ASSERT_EQUALS(fixed::Zero(), cmp->DistanceToTarget(ent3, ent2)); // Due to rounding errors we need to use some leeway - TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(80)), cmp->MaxDistanceToTarget(ent2, ent3), fixed::FromFloat(0.0001)); - TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(80)), cmp->MaxDistanceToTarget(ent3, ent2), fixed::FromFloat(0.0001)); + TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(80)), cmp->MaxDistanceToTarget(ent2, ent3), fixed::FromFloat(0.0001f)); + TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(80)), cmp->MaxDistanceToTarget(ent3, ent2), fixed::FromFloat(0.0001f)); TS_ASSERT_EQUALS(fixed::Zero(), cmp->DistanceToTarget(ent1, ent3)); TS_ASSERT_EQUALS(fixed::Zero(), cmp->DistanceToTarget(ent3, ent1)); TS_ASSERT_EQUALS(fixed::FromInt(6), cmp->DistanceToTarget(ent1, ent4)); TS_ASSERT_EQUALS(fixed::FromInt(6), cmp->DistanceToTarget(ent4, ent1)); - TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(125) + 3), cmp->MaxDistanceToTarget(ent1, ent4), fixed::FromFloat(0.0001)); - TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(125) + 3), cmp->MaxDistanceToTarget(ent4, ent1), fixed::FromFloat(0.0001)); + TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(125) + 3), cmp->MaxDistanceToTarget(ent1, ent4), fixed::FromFloat(0.0001f)); + TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(125) + 3), cmp->MaxDistanceToTarget(ent4, ent1), fixed::FromFloat(0.0001f)); TS_ASSERT_EQUALS(fixed::FromInt(7), cmp->DistanceToTarget(ent1, ent5)); TS_ASSERT_EQUALS(fixed::FromInt(7), cmp->DistanceToTarget(ent5, ent1)); - TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(178)), cmp->MaxDistanceToTarget(ent1, ent5), fixed::FromFloat(0.0001)); - TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(178)), cmp->MaxDistanceToTarget(ent5, ent1), fixed::FromFloat(0.0001)); + TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(178)), cmp->MaxDistanceToTarget(ent1, ent5), fixed::FromFloat(0.0001f)); + TS_ASSERT_DELTA(fixed::FromFloat(std::sqrt(178)), cmp->MaxDistanceToTarget(ent5, ent1), fixed::FromFloat(0.0001f)); TS_ASSERT(cmp->IsInTargetRange(ent1, ent2, fixed::Zero(), fixed::FromInt(1), true)); TS_ASSERT(cmp->IsInTargetRange(ent1, ent2, fixed::Zero(), fixed::FromInt(1), false)); Index: source/simulation2/helpers/HierarchicalPathfinder.h =================================================================== --- source/simulation2/helpers/HierarchicalPathfinder.h +++ source/simulation2/helpers/HierarchicalPathfinder.h @@ -306,11 +306,14 @@ virtual void BuildTextureRGBA(u8* data, size_t w, size_t h) { + ENSURE(h <= std::numeric_limits::max() && w <= std::numeric_limits::max()); + u16 height = static_cast(h); + u16 width = static_cast(w); pass_class_t passClass = m_PathfinderHier.GetPassabilityClass("default"); - for (size_t j = 0; j < h; ++j) + for (u16 j = 0; j < height; ++j) { - for (size_t i = 0; i < w; ++i) + for (u16 i = 0; i < width; ++i) { SColor4ub color; Index: source/simulation2/system/ParamNode.cpp =================================================================== --- source/simulation2/system/ParamNode.cpp +++ source/simulation2/system/ParamNode.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -187,6 +187,8 @@ case MUL_ROUND: node.m_Value = fixed::FromInt(oldval.Multiply(mod).ToInt_RoundToNearest()).ToString().FromUTF8(); break; + default: + break; } hasSetValue = true; } Index: source/soundmanager/scripting/SoundGroup.cpp =================================================================== --- source/soundmanager/scripting/SoundGroup.cpp +++ source/soundmanager/scripting/SoundGroup.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -99,7 +99,7 @@ const int screenHeight = g_Game->GetView()->GetCamera()->GetViewPort().m_Height; const float xBufferSize = screenWidth * 0.1f; const float yBufferSize = 15.f; - const float radianCap = M_PI / 3.f; + const float radianCap = static_cast(M_PI / 3); float x, y; g_Game->GetView()->GetCamera()->GetScreenCoordinates(position, x, y); Index: source/tools/atlas/AtlasObject/AtlasObjectJS.cpp =================================================================== --- source/tools/atlas/AtlasObject/AtlasObjectJS.cpp +++ source/tools/atlas/AtlasObject/AtlasObjectJS.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,12 +18,13 @@ #include "AtlasObject.h" #include "AtlasObjectImpl.h" -#include "JSONSpiritInclude.h" - #if defined(_MSC_VER) # pragma warning(disable:4996) // deprecated CRT +# pragma warning(disable: 4459) // global declaration hidden #endif +#include "JSONSpiritInclude.h" + #include static AtSmartPtr ConvertNode(json_spirit::Value node); Index: source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -56,6 +56,11 @@ #include "simulation2/components/ICmpVisual.h" #include "simulation2/system/ParamNode.h" + +#ifdef _MSC_VER +# pragma warning(disable: 4458) // Declaration hides class member. +#endif + namespace { void InitGame() Index: source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -486,18 +486,20 @@ CFixedVector3D fTargetPos(entity_pos_t::FromFloat(targetPos.X), entity_pos_t::FromFloat(targetPos.Y), entity_pos_t::FromFloat(targetPos.Z)); CFixedVector3D dir = fTargetPos - referencePos; - for (size_t i = 0; i < g_PreviewEntitiesID.size(); ++i) + for (const entity_id_t id : g_PreviewEntitiesID) { - entity_id_t id = (entity_id_t)g_PreviewEntitiesID[i]; - CFixedVector3D posFinal; - CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); - if (cmpPosition && cmpPosition->IsInWorld()) + CmpPtr cmpPreviewPosition(*g_Game->GetSimulation2(), id); + if (cmpPreviewPosition) { - // Calculate this object's position - CFixedVector3D posFixed = cmpPosition->GetPosition(); - posFinal = posFixed + dir; + CFixedVector3D posFinal; + if (cmpPreviewPosition->IsInWorld()) + { + // Calculate this object's position + CFixedVector3D posFixed = cmpPreviewPosition->GetPosition(); + posFinal = posFixed + dir; + } + cmpPreviewPosition->JumpTo(posFinal.X, posFinal.Z); } - cmpPosition->JumpTo(posFinal.X, posFinal.Z); CheckObstructionAndUpdateVisual(id); }