Index: source/graphics/CinemaManager.cpp =================================================================== --- source/graphics/CinemaManager.cpp +++ source/graphics/CinemaManager.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 @@ -76,16 +76,16 @@ if (!cmpCinemaManager) return; - for (const std::pair& p : cmpCinemaManager->GetPaths()) + for (const auto &[name, path] : cmpCinemaManager->GetPaths()) { - DrawSpline(p.second, CColor(0.2f, 0.2f, 1.f, 0.9f), 128, true); - DrawNodes(p.second, CColor(0.1f, 1.f, 0.f, 1.f)); + DrawSpline(path, CColor(0.2f, 0.2f, 1.f, 0.9f), 128, true); + DrawNodes(path, CColor(0.1f, 1.f, 0.f, 1.f)); - if (p.second.GetTargetSpline().GetAllNodes().empty()) + if (path.GetTargetSpline().GetAllNodes().empty()) continue; - DrawSpline(p.second.GetTargetSpline(), CColor(1.f, 0.3f, 0.4f, 0.9f), 128, true); - DrawNodes(p.second.GetTargetSpline(), CColor(1.f, 0.1f, 0.f, 1.f)); + DrawSpline(path.GetTargetSpline(), CColor(1.f, 0.3f, 0.4f, 0.9f), 128, true); + DrawNodes(path.GetTargetSpline(), CColor(1.f, 0.1f, 0.f, 1.f)); } } Index: source/graphics/ObjectEntry.cpp =================================================================== --- source/graphics/ObjectEntry.cpp +++ source/graphics/ObjectEntry.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 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 @@ -46,8 +46,8 @@ CObjectEntry::~CObjectEntry() { - for (const std::pair& anim : m_Animations) - delete anim.second; + for (const auto&[name, animation] : m_Animations) + delete animation; delete m_Model; } Index: source/graphics/ObjectManager.cpp =================================================================== --- source/graphics/ObjectManager.cpp +++ source/graphics/ObjectManager.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 @@ -170,12 +170,12 @@ void CObjectManager::UnloadObjects() { - for (const std::pair& p : m_Objects) - delete p.second; + for (const auto&[key, value] : m_Objects) + delete value; m_Objects.clear(); - for (const std::pair& p : m_ObjectBases) - delete p.second; + for (const auto&[key, value] : m_ObjectBases) + delete value; m_ObjectBases.clear(); } Index: source/graphics/TerrainTextureManager.cpp =================================================================== --- source/graphics/TerrainTextureManager.cpp +++ source/graphics/TerrainTextureManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 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 @@ -63,8 +63,8 @@ delete te; m_TextureEntries.clear(); - for (const std::pair& tg : m_TerrainGroups) - delete tg.second; + for (const auto&[key, group] : m_TerrainGroups) + delete group; m_TerrainGroups.clear(); m_LastGroupIndex = 0; Index: source/graphics/Unit.cpp =================================================================== --- source/graphics/Unit.cpp +++ source/graphics/Unit.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 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 @@ -90,8 +90,8 @@ void CUnit::SetEntitySelection(const std::map& selections) { - for (const std::pair& s : selections) - m_EntitySelections[s.first] = s.second.LowerCase(); + for (const auto&[name, selection] : selections) + m_EntitySelections[name] = selection.LowerCase(); ReloadObject(); } @@ -105,8 +105,8 @@ void CUnit::ReloadObject() { std::set entitySelections; - for (const std::pair& selection : m_EntitySelections) - entitySelections.insert(selection.second); + for (const auto&[name, selection] : m_EntitySelections) + entitySelections.insert(selection); std::vector > selections; selections.push_back(entitySelections); selections.push_back(m_ActorSelections); Index: source/gui/CGUI.cpp =================================================================== --- source/gui/CGUI.cpp +++ source/gui/CGUI.cpp @@ -77,11 +77,11 @@ CGUI::~CGUI() { - for (const std::pair& p : m_pAllObjects) - delete p.second; + for (const auto &[key, object] : m_pAllObjects) + delete object; - for (const std::pair& p : m_Sprites) - delete p.second; + for (const auto &[key, sprite] : m_Sprites) + delete sprite; } InReaction CGUI::HandleEvent(const SDL_Event_* ev) Index: source/gui/ObjectBases/IGUIObject.cpp =================================================================== --- source/gui/ObjectBases/IGUIObject.cpp +++ source/gui/ObjectBases/IGUIObject.cpp @@ -74,8 +74,8 @@ IGUIObject::~IGUIObject() { - for (const std::pair& p : m_Settings) - delete p.second; + for (const auto&[key, setting] : m_Settings) + delete setting; if (!m_ScriptHandlers.empty()) JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this); @@ -282,12 +282,12 @@ // Other styles are reported if they specify a Setting that does not exist, // so that the XML author is informed and can correct the style. - for (const std::pair& p : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) + for (const auto&[name, setting] : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) { - if (SettingExists(p.first)) - SetSettingFromString(p.first, p.second, true); + if (SettingExists(name)) + SetSettingFromString(name, setting, true); else if (StyleName != "default") - LOGWARNING("GUI object has no setting \"%s\", but the style \"%s\" defines it", p.first, StyleName.c_str()); + LOGWARNING("GUI object has no setting \"%s\", but the style \"%s\" defines it", name, StyleName.c_str()); } return true; } Index: source/gui/ObjectTypes/CDropDown.cpp =================================================================== --- source/gui/ObjectTypes/CDropDown.cpp +++ source/gui/ObjectTypes/CDropDown.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 @@ -307,8 +307,7 @@ // If we have inputed a character try to get the closest element to it. // TODO: not too nice and doesn't deal with dashes. if (m_Open && ((szChar >= SDLK_a && szChar <= SDLK_z) || szChar == SDLK_SPACE - || (szChar >= SDLK_0 && szChar <= SDLK_9) - || (szChar >= SDLK_KP_0 && szChar <= SDLK_KP_9))) + || (szChar >= SDLK_0 && szChar <= SDLK_9))) { // arbitrary 1 second limit to add to string or start fresh. // maximal amount of characters is 100, which imo is far more than enough. Index: source/lib/code_annotation.h =================================================================== --- source/lib/code_annotation.h +++ source/lib/code_annotation.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 @@ -79,6 +79,9 @@ #if GCC_VERSION # define NOTHROW_DECLARE __attribute__((nothrow)) # define NOTHROW_DEFINE // not supported for definitions +#elif CLANG_VERSION +# define NOTHROW_DECLARE __attribute__((nothrow)) +# define NOTHROW_DEFINE // not supported for definitions #elif MSC_VERSION // Kevin Frei, 2006-03-23: "I work on the Visual C++ compiler team, // and agree completely with Paul Parks: don't use throw(), because Index: source/lobby/XmppClient.cpp =================================================================== --- source/lobby/XmppClient.cpp +++ source/lobby/XmppClient.cpp @@ -543,17 +543,17 @@ ScriptInterface::CreateArray(rq, ret); int j = 0; - for (const std::pair& p : m_PlayerMap) + for (const auto &[name, splayer] : m_PlayerMap) { JS::RootedValue player(rq.cx); ScriptInterface::CreateObject( rq, &player, - "name", p.first, - "presence", p.second.m_Presence, - "rating", p.second.m_Rating, - "role", p.second.m_Role); + "name", name, + "presence", splayer.m_Presence, + "rating", splayer.m_Rating, + "role", splayer.m_Role); scriptInterface.SetPropertyInt(ret, j++, player); } Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -277,18 +277,18 @@ JS::RootedValue newAssignments(rq.cx); ScriptInterface::CreateObject(rq, &newAssignments); - for (const std::pair& p : m_PlayerAssignments) + for (const auto &[key, value]: m_PlayerAssignments) { JS::RootedValue assignment(rq.cx); ScriptInterface::CreateObject( rq, &assignment, - "name", p.second.m_Name, - "player", p.second.m_PlayerID, - "status", p.second.m_Status); + "name", value.m_Name, + "player", value.m_PlayerID, + "status", value.m_Status); - GetScriptInterface().SetProperty(newAssignments, p.first.c_str(), assignment); + GetScriptInterface().SetProperty(newAssignments, key.c_str(), assignment); } PushGuiMessage( Index: source/network/NetServer.cpp =================================================================== --- source/network/NetServer.cpp +++ source/network/NetServer.cpp @@ -738,9 +738,9 @@ { // Find all player IDs in active use; we mustn't give them to a second player (excluding the unassigned ID: -1) std::set usedIDs; - for (const std::pair& p : m_PlayerAssignments) - if (p.second.m_Enabled && p.second.m_PlayerID != -1) - usedIDs.insert(p.second.m_PlayerID); + for (const auto &[key, value] : m_PlayerAssignments) + if (value.m_Enabled && value.m_PlayerID != -1) + usedIDs.insert(value.m_PlayerID); // If the player is rejoining after disconnecting, try to give them // back their old player ID Index: source/network/NetServerTurnManager.cpp =================================================================== --- source/network/NetServerTurnManager.cpp +++ source/network/NetServerTurnManager.cpp @@ -72,10 +72,10 @@ void CNetServerTurnManager::CheckClientsReady() { // See if all clients (including self) are ready for a new turn - for (const std::pair& clientReady : m_ClientsReady) + for (const auto &[clientId, clientTurn] : m_ClientsReady) { - NETSERVERTURN_LOG(" %d: %d <=? %d\n", clientReady.first, clientReady.second, m_ReadyTurn); - if (clientReady.second <= m_ReadyTurn) + NETSERVERTURN_LOG(" %d: %d <=? %d\n", clientId, clientTurn, m_ReadyTurn); + if (clientTurn <= m_ReadyTurn) return; // wasn't ready for m_ReadyTurn+1 } @@ -122,9 +122,9 @@ // Find the newest turn which we know all clients have simulated u32 newest = std::numeric_limits::max(); - for (const std::pair& clientSimulated : m_ClientsSimulated) - if (clientSimulated.second < newest) - newest = clientSimulated.second; + for (const auto &[clientId, clientTurn] : m_ClientsSimulated) + if (clientTurn < newest) + newest = clientTurn; // For every set of state hashes that all clients have simulated, check for OOS for (const std::pair>& clientStateHash : m_ClientStateHashes) @@ -137,14 +137,14 @@ // Find all players that are OOS on that turn std::vector OOSPlayerNames; - for (const std::pair& hashPair : clientStateHash.second) + for (const auto &[clientId, clientHash] : clientStateHash.second) { NETSERVERTURN_LOG("sync check %d: %d = %hs\n", it->first, cit->first, Hexify(cit->second).c_str()); - if (hashPair.second != expected) + if (clientHash != expected) { // Oh no, out of sync m_HasSyncError = true; - OOSPlayerNames.push_back(m_ClientPlayernames[hashPair.first]); + OOSPlayerNames.push_back(m_ClientPlayernames[clientId]); } } Index: source/ps/ConfigDB.cpp =================================================================== --- source/ps/ConfigDB.cpp +++ source/ps/ConfigDB.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 @@ -188,13 +188,13 @@ // Loop upwards so that values in later namespaces can override // values in earlier namespaces for (int search_ns = 0; search_ns <= ns; ++search_ns) - for (const std::pair& p : m_Map[search_ns]) - if (boost::algorithm::starts_with(p.first, prefix)) - ret[p.first] = p.second; - - for (const std::pair& p : m_Map[CFG_COMMAND]) - if (boost::algorithm::starts_with(p.first, prefix)) - ret[p.first] = p.second; + for (const auto &[key, value] : m_Map[search_ns]) + if (boost::algorithm::starts_with(key, prefix)) + ret[key] = value; + + for (const auto &[key, value] : m_Map[CFG_COMMAND]) + if (boost::algorithm::starts_with(key, prefix)) + ret[key] = value; return ret; } @@ -431,13 +431,14 @@ shared_ptr buf; AllocateAligned(buf, 1*MiB, maxSectorSize); char* pos = (char*)buf.get(); - for (const std::pair& p : m_Map[ns]) + + for (const auto &[key, valueSet] : m_Map[ns]) { size_t i; - pos += sprintf(pos, "%s = ", p.first.c_str()); - for (i = 0; i < p.second.size() - 1; ++i) - pos += sprintf(pos, "\"%s\", ", EscapeString(p.second[i]).c_str()); - pos += sprintf(pos, "\"%s\"\n", EscapeString(p.second[i]).c_str()); + pos += sprintf(pos, "%s = ", key.c_str()); + for (i = 0; i < valueSet.size() - 1; ++i) + pos += sprintf(pos, "\"%s\", ", EscapeString(valueSet[i]).c_str()); + pos += sprintf(pos, "\"%s\"\n", EscapeString(valueSet[i]).c_str()); } const size_t len = pos - (char*)buf.get(); Index: source/ps/Hotkey.cpp =================================================================== --- source/ps/Hotkey.cpp +++ source/ps/Hotkey.cpp @@ -40,10 +40,10 @@ // all key combinations that trigger it. static void LoadConfigBindings() { - for (const std::pair& configPair : g_ConfigDB.GetValuesWithPrefix(CFG_COMMAND, "hotkey.")) + for (const auto&[key, valueSet] : g_ConfigDB.GetValuesWithPrefix(CFG_COMMAND, "hotkey.")) { - std::string hotkeyName = configPair.first.substr(7); // strip the "hotkey." prefix - for (const CStr& hotkey : configPair.second) + std::string hotkeyName = key.substr(7); // strip the "hotkey." prefix + for (const CStr& hotkey : valueSet) { if (hotkey.LowerCase() == "unused") continue; @@ -93,8 +93,8 @@ // Set up the state of the hotkeys given no key is down. // i.e. find those hotkeys triggered by all negations. - for (const std::pair& p : g_HotkeyMap) - for (const SHotkeyMapping& hotkey : p.second) + for (const auto&[key, hotkeys] : g_HotkeyMap) + for (const SHotkeyMapping& hotkey : hotkeys) { if (!hotkey.negated) continue; Index: source/ps/ProfileViewer.cpp =================================================================== --- source/ps/ProfileViewer.cpp +++ source/ps/ProfileViewer.cpp @@ -402,10 +402,11 @@ namespace { - struct WriteTable + class WriteTable { - std::ofstream& f; + public: WriteTable(std::ofstream& f) : f(f) {} + WriteTable(const WriteTable& writeTable) = default; void operator() (AbstractProfileTable* table) { @@ -480,6 +481,7 @@ } private: + std::ofstream& f; const WriteTable& operator=(const WriteTable&); }; Index: source/ps/Profiler2.cpp =================================================================== --- source/ps/Profiler2.cpp +++ source/ps/Profiler2.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 @@ -587,15 +587,15 @@ curTime += 0.000001; } // sub-events, aggregated - for (const std::pair& type : timeByType) + for (const auto & [key, value] : timeByType) { - CProfiler2::SItem_dt_id item = { (float)curTime, std::get<0>(type.second) }; + CProfiler2::SItem_dt_id item = { (float)curTime, std::get<0>(value) }; buffer[writePos] = (u8)CProfiler2::ITEM_ENTER; memcpy(buffer + writePos + 1, &item, sizeof(item)); writePos += sizeof(item) + 1; // write relevant attributes if present - for (const std::string& attrib : std::get<2>(type.second)) + for (const std::string& attrib : std::get<2>(value)) { buffer[writePos] = (u8)CProfiler2::ITEM_ATTRIBUTE; writePos++; @@ -611,7 +611,7 @@ writePos += length; } - curTime += std::get<1>(type.second); + curTime += std::get<1>(value); float leave_time = (float)curTime; buffer[writePos] = (u8)CProfiler2::ITEM_LEAVE; Index: source/ps/XML/XeroXMB.h =================================================================== --- source/ps/XML/XeroXMB.h +++ source/ps/XML/XeroXMB.h @@ -195,7 +195,7 @@ typedef std::forward_iterator_tag iterator_category; iterator(size_t size, const char* ptr, const char* endptr = NULL) - : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr), m_Pointer(ptr) {} + : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr) {} XMBElement operator*() const { return XMBElement(m_CurPointer); } XMBElement operator->() const { return **this; } iterator& operator++(); @@ -211,7 +211,6 @@ size_t m_Size; size_t m_CurItemID; const char* m_CurPointer; - const char* m_Pointer; }; iterator begin() { return iterator(m_Size, m_Pointer); } iterator end() { return iterator(m_Size, m_Pointer, m_EndPointer); } @@ -264,7 +263,7 @@ typedef std::forward_iterator_tag iterator_category; iterator(size_t size, const char* ptr, const char* endptr = NULL) - : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr), m_Pointer(ptr) {} + : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr) {} XMBAttribute operator*() const; XMBAttribute operator->() const { return **this; } iterator& operator++(); @@ -280,7 +279,6 @@ size_t m_Size; size_t m_CurItemID; const char* m_CurPointer; - const char* m_Pointer; }; iterator begin() const { return iterator(m_Size, m_Pointer); } iterator end() const { return iterator(m_Size, m_Pointer, m_EndPointer); } Index: source/ps/scripting/JSInterface_Hotkey.cpp =================================================================== --- source/ps/scripting/JSInterface_Hotkey.cpp +++ source/ps/scripting/JSInterface_Hotkey.cpp @@ -75,11 +75,12 @@ JS::RootedValue hotkeyMap(rq.cx); std::unordered_map>> hotkeys; - for (const std::pair& key : g_HotkeyMap) - for (const SHotkeyMapping& mapping : key.second) + + for (const auto&[scanCode, mappings] : g_HotkeyMap) + for (const SHotkeyMapping& mapping : mappings) { std::vector keymap; - keymap.push_back(FindScancodeName(static_cast(key.first))); + keymap.push_back(FindScancodeName(static_cast(scanCode))); for (const SKey& secondary_key : mapping.requires) keymap.push_back(FindScancodeName(static_cast(secondary_key.code))); // All hotkey permutations are present so only push one (arbitrarily). Index: source/ps/scripting/JSInterface_ModIo.cpp =================================================================== --- source/ps/scripting/JSInterface_ModIo.cpp +++ source/ps/scripting/JSInterface_ModIo.cpp @@ -99,8 +99,8 @@ JS::RootedValue m(rq.cx); ScriptInterface::CreateObject(rq, &m); - for (const std::pair& prop : mod.properties) - scriptInterface->SetProperty(m, prop.first.c_str(), prop.second, true); + for (const auto&[key, value] : mod.properties) + scriptInterface->SetProperty(m, key.c_str(), value, true); scriptInterface->SetProperty(m, "dependencies", mod.dependencies, true); scriptInterface->SetPropertyInt(mods, i++, m); Index: source/renderer/ModelRenderer.cpp =================================================================== --- source/renderer/ModelRenderer.cpp +++ source/renderer/ModelRenderer.cpp @@ -316,9 +316,12 @@ struct SMRMaterialBucketKey { +public: SMRMaterialBucketKey(CStrIntern effect, const CShaderDefines& defines) : effect(effect), defines(defines) { } + SMRMaterialBucketKey(const SMRMaterialBucketKey& entity) = default; + CStrIntern effect; CShaderDefines defines; Index: source/renderer/PatchRData.cpp =================================================================== --- source/renderer/PatchRData.cpp +++ source/renderer/PatchRData.cpp @@ -1130,10 +1130,10 @@ ENSURE(!(streamflags & ~(STREAM_POS|STREAM_POSTOUV0|STREAM_POSTOUV1))); // Render each batch - for (const std::pair& streamBatch : batches) + for (const auto&[buffer, streamBatch] : batches) { GLsizei stride = sizeof(SBaseVertex); - SBaseVertex *base = (SBaseVertex *)streamBatch.first->Bind(); + SBaseVertex *base = (SBaseVertex *)buffer->Bind(); shader->VertexPointer(3, GL_FLOAT, stride, &base->m_Position); if (streamflags & STREAM_POSTOUV0) @@ -1143,11 +1143,9 @@ shader->AssertPointersBound(); - for (const std::pair& batchIndexBuffer : streamBatch.second) + for (const auto& [vertexBuffer, batch] : streamBatch) { - batchIndexBuffer.first->Bind(); - - const StreamBatchElements& batch = batchIndexBuffer.second; + vertexBuffer->Bind(); if (!g_Renderer.m_SkipSubmit) { Index: source/renderer/TerrainRenderer.cpp =================================================================== --- source/renderer/TerrainRenderer.cpp +++ source/renderer/TerrainRenderer.cpp @@ -672,7 +672,7 @@ /*if (!g_RenderingOptions.GetPreferGLSL() && !superFancy) m->fancyWaterShader = g_Renderer.GetShaderManager().LoadProgram("arb/water_high", defines); else*/ - m->fancyWaterShader = g_Renderer.GetShaderManager().LoadProgram("glsl/water_high", defines); + m->fancyWaterShader = g_Renderer.GetShaderManager().LoadProgram("glsl/water_high", defines); if (!m->fancyWaterShader) { Index: source/simulation2/components/CCmpCinemaManager.cpp =================================================================== --- source/simulation2/components/CCmpCinemaManager.cpp +++ source/simulation2/components/CCmpCinemaManager.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 @@ -65,8 +65,8 @@ serializer.Bool("MapRevealed", m_MapRevealed); serializer.NumberU32_Unbounded("NumberOfPaths", m_Paths.size()); - for (const std::pair& it : m_Paths) - SerializePath(it.second, serializer); + for (const auto &[name, path] : m_Paths) + SerializePath(path, serializer); serializer.NumberU32_Unbounded("NumberOfQueuedPaths", m_PathQueue.size()); for (const CCinemaPath& path : m_PathQueue) Index: source/simulation2/components/CCmpPathfinder.cpp =================================================================== --- source/simulation2/components/CCmpPathfinder.cpp +++ source/simulation2/components/CCmpPathfinder.cpp @@ -258,12 +258,12 @@ void CCmpPathfinder::GetPassabilityClasses(std::map& nonPathfindingPassClasses, std::map& pathfindingPassClasses) const { - for (const std::pair& pair : m_PassClassMasks) + for (const auto &[passName, passClass] : m_PassClassMasks) { - if ((GetPassabilityFromMask(pair.second)->m_Obstructions == PathfinderPassability::PATHFINDING)) - pathfindingPassClasses[pair.first] = pair.second; + if ((GetPassabilityFromMask(passClass)->m_Obstructions == PathfinderPassability::PATHFINDING)) + pathfindingPassClasses[passName] = passClass; else - nonPathfindingPassClasses[pair.first] = pair.second; + nonPathfindingPassClasses[passName] = passClass; } } Index: source/simulation2/components/CCmpRangeManager.cpp =================================================================== --- source/simulation2/components/CCmpRangeManager.cpp +++ source/simulation2/components/CCmpRangeManager.cpp @@ -297,13 +297,16 @@ * It must only be passed entities that are in 'entities' * and are currently in the world. */ -struct EntityDistanceOrdering +class EntityDistanceOrdering { +public: EntityDistanceOrdering(const EntityMap& entities, const CFixedVector2D& source) : m_EntityData(entities), m_Source(source) { } + EntityDistanceOrdering(const EntityDistanceOrdering& entity) = default; + bool operator()(entity_id_t a, entity_id_t b) const { const EntityData& da = m_EntityData.find(a)->second; Index: source/simulation2/components/CCmpTemplateManager.cpp =================================================================== --- source/simulation2/components/CCmpTemplateManager.cpp +++ source/simulation2/components/CCmpTemplateManager.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 @@ -61,9 +61,9 @@ { std::map> templateMap; - for (const std::pair& templateEnt : m_LatestTemplates) - if (!ENTITY_IS_LOCAL(templateEnt.first)) - templateMap[templateEnt.second].push_back(templateEnt.first); + for (const auto &[id, name] : m_LatestTemplates) + if (!ENTITY_IS_LOCAL(id)) + templateMap[name].push_back(id); SerializeMap>()(serialize, "templates", templateMap); } @@ -72,11 +72,11 @@ { Init(paramNode); - std::map> templateMap; + std::map> templateMap; SerializeMap>()(deserialize, "templates", templateMap); - for (const std::pair>& mapEl : templateMap) - for (entity_id_t id : mapEl.second) - m_LatestTemplates[id] = mapEl.first; + for (const auto &[name, ids] : templateMap) + for (entity_id_t id : ids) + m_LatestTemplates[id] = name; } virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) @@ -219,9 +219,9 @@ std::vector CCmpTemplateManager::FindUsedTemplates() const { std::vector usedTemplates; - for (const std::pair& p : m_LatestTemplates) - if (std::find(usedTemplates.begin(), usedTemplates.end(), p.second) == usedTemplates.end()) - usedTemplates.push_back(p.second); + for (const auto &[id, name] : m_LatestTemplates) + if (std::find(usedTemplates.begin(), usedTemplates.end(), name) == usedTemplates.end()) + usedTemplates.push_back(name); return usedTemplates; } @@ -231,9 +231,9 @@ std::vector CCmpTemplateManager::GetEntitiesUsingTemplate(const std::string& templateName) const { std::vector entities; - for (const std::pair& p : m_LatestTemplates) - if (p.second == templateName) - entities.push_back(p.first); + for (const auto &[id, name] : m_LatestTemplates) + if (name == templateName) + entities.push_back(id); return entities; } Index: source/simulation2/components/CCmpTerritoryManager.cpp =================================================================== --- source/simulation2/components/CCmpTerritoryManager.cpp +++ source/simulation2/components/CCmpTerritoryManager.cpp @@ -459,15 +459,14 @@ // store the root influences to mark territory as connected std::vector rootInfluenceEntities; - for (const std::pair >& pair : influenceEntities) + for (const auto &[playerId, ents] : influenceEntities) { // entityGrid stores the weight for a single entity, and is reset per entity Grid entityGrid(tilesW, tilesH); // playerGrid stores the combined weight of all entities for this player Grid playerGrid(tilesW, tilesH); - u8 owner = (u8)pair.first; - const std::vector& ents = pair.second; + u8 owner = static_cast(playerId); // With 2^16 entities, we're safe against overflows as the weight is also limited to 2^16 ENSURE(ents.size() < 1 << 16); // Compute the influence map of the current entity, then add it to the player grid Index: source/simulation2/helpers/HierarchicalPathfinder.cpp =================================================================== --- source/simulation2/helpers/HierarchicalPathfinder.cpp +++ source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -467,9 +467,8 @@ if (!dirtinessGrid.any_set_in_square(i0, j0, i1, j1)) continue; - for (const std::pair& passClassMask : m_PassClassMasks) + for (const auto &[passName, passClass] : m_PassClassMasks) { - pass_class_t passClass = passClassMask.second; Chunk& a = m_Chunks[passClass].at(ci + cj*m_ChunksW); // Clean up edges and global region ID @@ -627,22 +626,24 @@ { // Use FindReachableRegions because we cannot be sure, even if we find a non-dirty chunk nearby, // that we weren't the only bridge connecting that chunk to the rest of the global region. - for (const std::pair >& regionsInNeed : needNewGlobalRegionMap) - for (const RegionID& reg : regionsInNeed.second) + for (const auto &[passClass, regionIds] : needNewGlobalRegionMap) + { + for (const RegionID& reg : regionIds) { - std::map& globalRegions = m_GlobalRegions[regionsInNeed.first]; + std::map& globalRegions = m_GlobalRegions[passClass]; // If we have already been given a region, skip us. if (globalRegions.find(reg) != globalRegions.end()) continue; std::set reachable; - FindReachableRegions(reg, reachable, regionsInNeed.first); + FindReachableRegions(reg, reachable, passClass); GlobalRegionID ID = m_NextGlobalRegionID++; for (const RegionID& regionId : reachable) globalRegions[regionId] = ID; } + } } HierarchicalPathfinder::RegionID HierarchicalPathfinder::Get(u16 i, u16 j, pass_class_t passClass) const Index: source/soundmanager/SoundManager.cpp =================================================================== --- source/soundmanager/SoundManager.cpp +++ source/soundmanager/SoundManager.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 @@ -275,8 +275,8 @@ } AL_CHECK; - for (const std::pair& p : m_SoundGroups) - delete p.second; + for (const auto& [key, soundGroup] : m_SoundGroups) + delete soundGroup; m_SoundGroups.clear(); if (m_PlayListItems) Index: source/third_party/jsonspirit/json_spirit_value.h =================================================================== --- source/third_party/jsonspirit/json_spirit_value.h +++ source/third_party/jsonspirit/json_spirit_value.h @@ -32,7 +32,7 @@ { enum Value_type{ obj_type, array_type, str_type, bool_type, int_type, real_type, null_type }; - static std::string value_type_to_string( Value_type vtype ); + static inline std::string value_type_to_string( Value_type vtype ); struct Null{}; @@ -584,7 +584,7 @@ return internal_::get_value( *this, internal_::Type_to_type< T >() ); } - static std::string value_type_to_string( const Value_type vtype ) + static inline std::string value_type_to_string( const Value_type vtype ) { switch( vtype ) { Index: source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp =================================================================== --- source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp +++ source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp @@ -239,9 +239,9 @@ m_MapSettingsVictoryConditions.insert(std::string(victoryCondition)); // Clear Checkboxes before loading data. We don't update victory condition just yet because it might reenable some of the checkboxes. - for (const std::pair& vc : m_VictoryConditions) + for (const auto&[id, vc] : m_VictoryConditions) { - wxCheckBox* checkBox = wxDynamicCast(FindWindow(vc.first), wxCheckBox); + wxCheckBox* checkBox = wxDynamicCast(FindWindow(id), wxCheckBox); if (!checkBox) continue; @@ -249,19 +249,19 @@ checkBox->Enable(true); } - for (const std::pair& vc : m_VictoryConditions) + for (const auto&[id, vc] : m_VictoryConditions) { - std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); + std::string escapedTitle = wxString::FromUTF8(vc["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); if (m_MapSettingsVictoryConditions.find(escapedTitle) == m_MapSettingsVictoryConditions.end()) continue; - wxCheckBox* checkBox = wxDynamicCast(FindWindow(vc.first), wxCheckBox); + wxCheckBox* checkBox = wxDynamicCast(FindWindow(id), wxCheckBox); if (!checkBox) continue; checkBox->SetValue(true); - OnVictoryConditionChanged(vc.first); + OnVictoryConditionChanged(id); } // lock teams @@ -298,12 +298,12 @@ AtObj victoryCondition; wxCheckBox* modifiedCheckbox = wxDynamicCast(FindWindow(controlId), wxCheckBox); - for (const std::pair& vc : m_VictoryConditions) + for (const auto&[id, vc] : m_VictoryConditions) { - if(vc.first != controlId) + if(id != controlId) continue; - victoryCondition = vc.second; + victoryCondition = vc; break; } @@ -311,35 +311,35 @@ { for (AtIter victoryConditionPair = victoryCondition["Data"]["ChangeOnChecked"]; victoryConditionPair.defined(); ++victoryConditionPair) { - for (const std::pair& vc : m_VictoryConditions) + for (const auto&[id, vc] : m_VictoryConditions) { - std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); + std::string escapedTitle = wxString::FromUTF8(vc["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); if (victoryConditionPair[escapedTitle.c_str()].defined()) { - wxCheckBox* victoryConditionCheckBox = wxDynamicCast(FindWindow(vc.first), wxCheckBox); + wxCheckBox* victoryConditionCheckBox = wxDynamicCast(FindWindow(id), wxCheckBox); victoryConditionCheckBox->SetValue(wxString::FromUTF8(victoryConditionPair[escapedTitle.c_str()]).Lower().ToStdString() == "true"); } } } } - for (const std::pair& vc : m_VictoryConditions) + for (const auto&[id, vc] : m_VictoryConditions) { - if (vc.first == controlId) + if (id == controlId) continue; - wxCheckBox* otherCheckbox = wxDynamicCast(FindWindow(vc.first), wxCheckBox); + wxCheckBox* otherCheckbox = wxDynamicCast(FindWindow(id), wxCheckBox); otherCheckbox->Enable(true); - for (const std::pair& vc2 : m_VictoryConditions) + for (const auto&[id2, vc2] : m_VictoryConditions) { - for (AtIter victoryConditionTitle = vc2.second["Data"]["DisabledWhenChecked"]; victoryConditionTitle.defined(); ++victoryConditionTitle) + for (AtIter victoryConditionTitle = vc2["Data"]["DisabledWhenChecked"]; victoryConditionTitle.defined(); ++victoryConditionTitle) { - std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); + std::string escapedTitle = wxString::FromUTF8(vc2["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); - if (escapedTitle == wxString::FromUTF8(victoryConditionTitle["item"]).ToStdString() && wxDynamicCast(FindWindow(vc2.first), wxCheckBox)->GetValue()) + if (escapedTitle == wxString::FromUTF8(victoryConditionTitle["item"]).ToStdString() && wxDynamicCast(FindWindow(id2), wxCheckBox)->GetValue()) { otherCheckbox->Enable(false); otherCheckbox->SetValue(false); @@ -371,11 +371,11 @@ else \ m_MapSettingsVictoryConditions.erase(name); - for (const std::pair& vc : m_VictoryConditions) + for (const auto&[id, vc] : m_VictoryConditions) { - std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); + std::string escapedTitle = wxString::FromUTF8(vc["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); - INSERT_VICTORY_CONDITION_CHECKBOX(escapedTitle, vc.first) + INSERT_VICTORY_CONDITION_CHECKBOX(escapedTitle, id) } #undef INSERT_VICTORY_CONDITION_CHECKBOX Index: source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ source/tools/atlas/GameInterface/Handlers/CinemaHandler.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 @@ -491,9 +491,8 @@ CVector2D cursor; msg->pos->GetScreenSpace(cursor.X, cursor.Y); - for (const std::pair& p : cmpCinemaManager->GetPaths()) + for (const auto&[name, path] : cmpCinemaManager->GetPaths()) { - const CCinemaPath& path = p.second; if (isPathNodePicked(path, cursor, node, false) || isPathNodePicked(path.GetTargetSpline(), cursor, node, true)) { node.name = path.GetName(); Index: source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -518,10 +518,8 @@ const CFixedVector3D offset = CFixedVector3D(fixed::FromInt(offsetX), fixed::FromInt(0), fixed::FromInt(offsetZ)); const CSimulation2::InterfaceListUnordered& ents = sim.GetEntitiesWithInterfaceUnordered(IID_Selectable); - for (const std::pair& ent : ents) + for (const auto& [entityId, component] : ents) { - const entity_id_t entityId = ent.first; - CmpPtr cmpPosition(sim, entityId); if (cmpPosition && cmpPosition->IsInWorld() && Within(cmpPosition->GetPosition(), mapCenterX, mapCenterZ, radiusInTerrainUnits)) Index: source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -767,16 +767,16 @@ void SetPos(const std::map& map) { - for (const std::pair& p : map) + for (const auto& [entityId, position] : map) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); + CmpPtr cmpPosition(*g_Game->GetSimulation2(), entityId); if (!cmpPosition) return; // Set 2D position, ignoring height - cmpPosition->JumpTo(entity_pos_t::FromFloat(p.second.X), entity_pos_t::FromFloat(p.second.Z)); + cmpPosition->JumpTo(entity_pos_t::FromFloat(position.X), entity_pos_t::FromFloat(position.Z)); - CheckObstructionAndUpdateVisual(p.first); + CheckObstructionAndUpdateVisual(entityId); } } @@ -859,22 +859,22 @@ void SetPos(const std::map& position, const std::map& angle) { - for (const std::pair& p : position) + for (const auto&[entityId, position] : position) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); + CmpPtr cmpPosition(*g_Game->GetSimulation2(), entityId); if (!cmpPosition) return; // Set 2D position, ignoring height - cmpPosition->JumpTo(entity_pos_t::FromFloat(p.second.X), entity_pos_t::FromFloat(p.second.Z)); + cmpPosition->JumpTo(entity_pos_t::FromFloat(position.X), entity_pos_t::FromFloat(position.Z)); if (msg->rotateObject) - cmpPosition->SetYRotation(entity_angle_t::FromFloat(angle.at(p.first))); + cmpPosition->SetYRotation(entity_angle_t::FromFloat(angle.at(entityId))); } - for (const std::pair& p: position) - CheckObstructionAndUpdateVisual(p.first); + for (const auto&[entityId, position] : position) + CheckObstructionAndUpdateVisual(entityId); } void Redo() @@ -963,13 +963,13 @@ void SetAngle(const std::map& angles) { - for (const std::pair& p : angles) + for (const auto&[entityId, angle] : angles) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); + CmpPtr cmpPosition(*g_Game->GetSimulation2(), entityId); if (!cmpPosition) return; - cmpPosition->SetYRotation(entity_angle_t::FromFloat(p.second)); + cmpPosition->SetYRotation(entity_angle_t::FromFloat(angle)); } } Index: source/tools/atlas/GameInterface/View.cpp =================================================================== --- source/tools/atlas/GameInterface/View.cpp +++ source/tools/atlas/GameInterface/View.cpp @@ -179,8 +179,8 @@ AtlasViewGame::~AtlasViewGame() { - for (const std::pair& p : m_SavedStates) - delete p.second; + for (const auto&[key, savedState] : m_SavedStates) + delete savedState; } CSimulation2* AtlasViewGame::GetSimulation2()