diff --git a/src/game/editor/auto_map.cpp b/src/game/editor/auto_map.cpp index 72babb730..adef6723c 100644 --- a/src/game/editor/auto_map.cpp +++ b/src/game/editor/auto_map.cpp @@ -76,14 +76,16 @@ void CAutoMapper::Load(const char *pTileName) NewConf.m_StartY = 0; NewConf.m_EndX = 0; NewConf.m_EndY = 0; - int ConfigurationID = m_lConfigs.add(NewConf); + m_lConfigs.push_back(NewConf); + int ConfigurationID = m_lConfigs.size() - 1; pCurrentConf = &m_lConfigs[ConfigurationID]; str_copy(pCurrentConf->m_aName, pLine, str_length(pLine)); // add start run CRun NewRun; NewRun.m_AutomapCopy = true; - int RunID = pCurrentConf->m_aRuns.add(NewRun); + pCurrentConf->m_aRuns.push_back(NewRun); + int RunID = pCurrentConf->m_aRuns.size() - 1; pCurrentRun = &pCurrentConf->m_aRuns[RunID]; } else if(str_startswith(pLine, "NewRun") && pCurrentConf) @@ -91,7 +93,8 @@ void CAutoMapper::Load(const char *pTileName) // add new run CRun NewRun; NewRun.m_AutomapCopy = true; - int RunID = pCurrentConf->m_aRuns.add(NewRun); + pCurrentConf->m_aRuns.push_back(NewRun); + int RunID = pCurrentConf->m_aRuns.size() - 1; pCurrentRun = &pCurrentConf->m_aRuns[RunID]; } else if(str_startswith(pLine, "Index") && pCurrentRun) @@ -143,7 +146,8 @@ void CAutoMapper::Load(const char *pTileName) } // add the index rule object and make it current - int IndexRuleID = pCurrentRun->m_aIndexRules.add(NewIndexRule); + pCurrentRun->m_aIndexRules.push_back(NewIndexRule); + int IndexRuleID = pCurrentRun->m_aIndexRules.size() - 1; pCurrentIndex = &pCurrentRun->m_aIndexRules[IndexRuleID]; } else if(str_startswith(pLine, "Pos") && pCurrentIndex) @@ -151,7 +155,7 @@ void CAutoMapper::Load(const char *pTileName) int x = 0, y = 0; char aValue[128]; int Value = CPosRule::NORULE; - array NewIndexList; + std::vector NewIndexList; sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue); @@ -159,15 +163,15 @@ void CAutoMapper::Load(const char *pTileName) { Value = CPosRule::INDEX; CIndexInfo NewIndexInfo = {0, 0, false}; - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); } else if(!str_comp(aValue, "FULL")) { Value = CPosRule::NOTINDEX; CIndexInfo NewIndexInfo1 = {0, 0, false}; //CIndexInfo NewIndexInfo2 = {-1, 0}; - NewIndexList.add(NewIndexInfo1); - //NewIndexList.add(NewIndexInfo2); + NewIndexList.push_back(NewIndexInfo1); + //NewIndexList.push_back(NewIndexInfo2); } else if(!str_comp(aValue, "INDEX") || !str_comp(aValue, "NOTINDEX")) { @@ -193,7 +197,7 @@ void CAutoMapper::Load(const char *pTileName) if(!str_comp(aOrientation1, "OR")) { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); pWord += 2; continue; } @@ -213,13 +217,13 @@ void CAutoMapper::Load(const char *pTileName) } else { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); break; } if(!str_comp(aOrientation2, "OR")) { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); pWord += 3; continue; } @@ -234,13 +238,13 @@ void CAutoMapper::Load(const char *pTileName) } else { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); break; } if(!str_comp(aOrientation3, "OR")) { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); pWord += 4; continue; } @@ -255,19 +259,19 @@ void CAutoMapper::Load(const char *pTileName) } else { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); break; } if(!str_comp(aOrientation4, "OR")) { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); pWord += 5; continue; } else { - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); break; } } @@ -276,7 +280,7 @@ void CAutoMapper::Load(const char *pTileName) if(Value != CPosRule::NORULE) { CPosRule NewPosRule = {x, y, Value, NewIndexList}; - pCurrentIndex->m_aRules.add(NewPosRule); + pCurrentIndex->m_aRules.push_back(NewPosRule); pCurrentConf->m_StartX = minimum(pCurrentConf->m_StartX, NewPosRule.m_X); pCurrentConf->m_StartY = minimum(pCurrentConf->m_StartY, NewPosRule.m_Y); @@ -285,9 +289,9 @@ void CAutoMapper::Load(const char *pTileName) if(x == 0 && y == 0) { - for(int i = 0; i < NewIndexList.size(); ++i) + for(const auto &Index : NewIndexList) { - if(Value == CPosRule::INDEX && NewIndexList[i].m_ID == 0) + if(Value == CPosRule::INDEX && Index.m_ID == 0) pCurrentIndex->m_SkipFull = true; else pCurrentIndex->m_SkipEmpty = true; @@ -321,38 +325,36 @@ void CAutoMapper::Load(const char *pTileName) } // add default rule for Pos 0 0 if there is none - for(int g = 0; g < m_lConfigs.size(); ++g) + for(auto &Config : m_lConfigs) { - for(int h = 0; h < m_lConfigs[g].m_aRuns.size(); ++h) + for(auto &Run : Config.m_aRuns) { - for(int i = 0; i < m_lConfigs[g].m_aRuns[h].m_aIndexRules.size(); ++i) + for(auto &IndexRule : Run.m_aIndexRules) { - CIndexRule *pIndexRule = &m_lConfigs[g].m_aRuns[h].m_aIndexRules[i]; bool Found = false; - for(int j = 0; j < pIndexRule->m_aRules.size(); ++j) + for(const auto &Rule : IndexRule.m_aRules) { - CPosRule *pRule = &pIndexRule->m_aRules[j]; - if(pRule && pRule->m_X == 0 && pRule->m_Y == 0) + if(Rule.m_X == 0 && Rule.m_Y == 0) { Found = true; break; } } - if(!Found && pIndexRule->m_DefaultRule) + if(!Found && IndexRule.m_DefaultRule) { - array NewIndexList; + std::vector NewIndexList; CIndexInfo NewIndexInfo = {0, 0, false}; - NewIndexList.add(NewIndexInfo); + NewIndexList.push_back(NewIndexInfo); CPosRule NewPosRule = {0, 0, CPosRule::NOTINDEX, NewIndexList}; - pIndexRule->m_aRules.add(NewPosRule); + IndexRule.m_aRules.push_back(NewPosRule); - pIndexRule->m_SkipEmpty = true; - pIndexRule->m_SkipFull = false; + IndexRule.m_SkipEmpty = true; + IndexRule.m_SkipFull = false; } - if(pIndexRule->m_SkipEmpty && pIndexRule->m_SkipFull) + if(IndexRule.m_SkipEmpty && IndexRule.m_SkipFull) { - pIndexRule->m_SkipEmpty = false; - pIndexRule->m_SkipFull = false; + IndexRule.m_SkipEmpty = false; + IndexRule.m_SkipFull = false; } } } @@ -368,7 +370,7 @@ void CAutoMapper::Load(const char *pTileName) const char *CAutoMapper::GetConfigName(int Index) { - if(Index < 0 || Index >= m_lConfigs.size()) + if(Index < 0 || Index >= (int)m_lConfigs.size()) return ""; return m_lConfigs[Index].m_aName; @@ -376,7 +378,7 @@ const char *CAutoMapper::GetConfigName(int Index) void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed, int X, int Y, int Width, int Height) { - if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= m_lConfigs.size()) + if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= (int)m_lConfigs.size()) return; if(Width < 0) @@ -428,7 +430,7 @@ void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed, void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedOffsetX, int SeedOffsetY) { - if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= m_lConfigs.size()) + if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= (int)m_lConfigs.size()) return; if(Seed == 0) @@ -437,7 +439,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO CConfiguration *pConf = &m_lConfigs[ConfigID]; // for every run: copy tiles, automap, overwrite tiles - for(int h = 0; h < pConf->m_aRuns.size(); ++h) + for(size_t h = 0; h < pConf->m_aRuns.size(); ++h) { CRun *pRun = &pConf->m_aRuns[h]; @@ -471,7 +473,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO CTile *pTile = &(pLayer->m_pTiles[y * pLayer->m_Width + x]); m_pEditor->m_Map.m_Modified = true; - for(int i = 0; i < pRun->m_aIndexRules.size(); ++i) + for(size_t i = 0; i < pRun->m_aIndexRules.size(); ++i) { CIndexRule *pIndexRule = &pRun->m_aIndexRules[i]; if(pIndexRule->m_SkipEmpty && pTile->m_Index == 0) // skip empty tiles @@ -480,7 +482,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO continue; bool RespectRules = true; - for(int j = 0; j < pIndexRule->m_aRules.size() && RespectRules; ++j) + for(size_t j = 0; j < pIndexRule->m_aRules.size() && RespectRules; ++j) { CPosRule *pRule = &pIndexRule->m_aRules[j]; @@ -502,9 +504,9 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO if(pRule->m_Value == CPosRule::INDEX) { RespectRules = false; - for(int k = 0; k < pRule->m_aIndexList.size(); ++k) + for(auto &Index : pRule->m_aIndexList) { - if(CheckIndex == pRule->m_aIndexList[k].m_ID && (!pRule->m_aIndexList[k].m_TestFlag || CheckFlags == pRule->m_aIndexList[k].m_Flag)) + if(CheckIndex == Index.m_ID && (!Index.m_TestFlag || CheckFlags == Index.m_Flag)) { RespectRules = true; break; @@ -513,9 +515,9 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO } else if(pRule->m_Value == CPosRule::NOTINDEX) { - for(int k = 0; k < pRule->m_aIndexList.size(); ++k) + for(auto &Index : pRule->m_aIndexList) { - if(CheckIndex == pRule->m_aIndexList[k].m_ID && (!pRule->m_aIndexList[k].m_TestFlag || CheckFlags == pRule->m_aIndexList[k].m_Flag)) + if(CheckIndex == Index.m_ID && (!Index.m_TestFlag || CheckFlags == Index.m_Flag)) { RespectRules = false; break; diff --git a/src/game/editor/auto_map.h b/src/game/editor/auto_map.h index b9748dd57..10ae70b2d 100644 --- a/src/game/editor/auto_map.h +++ b/src/game/editor/auto_map.h @@ -1,7 +1,7 @@ #ifndef GAME_EDITOR_AUTO_MAP_H #define GAME_EDITOR_AUTO_MAP_H -#include +#include class CAutoMapper { @@ -17,7 +17,7 @@ class CAutoMapper int m_X; int m_Y; int m_Value; - array m_aIndexList; + std::vector m_aIndexList; enum { @@ -30,7 +30,7 @@ class CAutoMapper struct CIndexRule { int m_ID; - array m_aRules; + std::vector m_aRules; int m_Flag; float m_RandomProbability; bool m_DefaultRule; @@ -40,13 +40,13 @@ class CAutoMapper struct CRun { - array m_aIndexRules; + std::vector m_aIndexRules; bool m_AutomapCopy; }; struct CConfiguration { - array m_aRuns; + std::vector m_aRuns; char m_aName[128]; int m_StartX; int m_StartY; @@ -67,7 +67,7 @@ public: bool IsLoaded() const { return m_FileLoaded; } private: - array m_lConfigs; + std::vector m_lConfigs; class CEditor *m_pEditor; bool m_FileLoaded; }; diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 150424225..94cda708f 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -5,7 +5,6 @@ #include #include -#include #if defined(CONF_FAMILY_UNIX) #include @@ -115,9 +114,17 @@ CLayerGroup::CLayerGroup() m_ClipH = 0; } +template +static void DeleteAll(std::vector &List) +{ + for(auto &Item : List) + delete Item; + List.clear(); +} + CLayerGroup::~CLayerGroup() { - m_lLayers.delete_all(); + DeleteAll(m_lLayers); } void CLayerGroup::Convert(CUIRect *pRect) @@ -164,29 +171,29 @@ void CLayerGroup::Render() (int)((x1 - x0) * pGraphics->ScreenWidth()), (int)((y1 - y0) * pGraphics->ScreenHeight())); } - for(int i = 0; i < m_lLayers.size(); i++) + for(auto &pLayer : m_lLayers) { - if(m_lLayers[i]->m_Visible) + if(pLayer->m_Visible) { - if(m_lLayers[i]->m_Type == LAYERTYPE_TILES) + if(pLayer->m_Type == LAYERTYPE_TILES) { - CLayerTiles *pTiles = static_cast(m_lLayers[i]); + CLayerTiles *pTiles = static_cast(pLayer); if(pTiles->m_Game || pTiles->m_Front || pTiles->m_Tele || pTiles->m_Speedup || pTiles->m_Tune || pTiles->m_Switch) continue; } - if(m_pMap->m_pEditor->m_ShowDetail || !(m_lLayers[i]->m_Flags & LAYERFLAG_DETAIL)) - m_lLayers[i]->Render(); + if(m_pMap->m_pEditor->m_ShowDetail || !(pLayer->m_Flags & LAYERFLAG_DETAIL)) + pLayer->Render(); } } - for(int i = 0; i < m_lLayers.size(); i++) + for(auto &pLayer : m_lLayers) { - if(m_lLayers[i]->m_Visible && m_lLayers[i]->m_Type == LAYERTYPE_TILES && m_lLayers[i] != m_pMap->m_pGameLayer && m_lLayers[i] != m_pMap->m_pFrontLayer && m_lLayers[i] != m_pMap->m_pTeleLayer && m_lLayers[i] != m_pMap->m_pSpeedupLayer && m_lLayers[i] != m_pMap->m_pSwitchLayer && m_lLayers[i] != m_pMap->m_pTuneLayer) + if(pLayer->m_Visible && pLayer->m_Type == LAYERTYPE_TILES && pLayer != m_pMap->m_pGameLayer && pLayer != m_pMap->m_pFrontLayer && pLayer != m_pMap->m_pTeleLayer && pLayer != m_pMap->m_pSpeedupLayer && pLayer != m_pMap->m_pSwitchLayer && pLayer != m_pMap->m_pTuneLayer) { - CLayerTiles *pTiles = static_cast(m_lLayers[i]); + CLayerTiles *pTiles = static_cast(pLayer); if(pTiles->m_Game || pTiles->m_Front || pTiles->m_Tele || pTiles->m_Speedup || pTiles->m_Tune || pTiles->m_Switch) { - m_lLayers[i]->Render(); + pLayer->Render(); } } } @@ -197,15 +204,15 @@ void CLayerGroup::Render() void CLayerGroup::AddLayer(CLayer *l) { m_pMap->m_Modified = true; - m_lLayers.add(l); + m_lLayers.push_back(l); } void CLayerGroup::DeleteLayer(int Index) { - if(Index < 0 || Index >= m_lLayers.size()) + if(Index < 0 || Index >= (int)m_lLayers.size()) return; delete m_lLayers[Index]; - m_lLayers.remove_index(Index); + m_lLayers.erase(m_lLayers.begin() + Index); m_pMap->m_Modified = true; } @@ -213,10 +220,10 @@ void CLayerGroup::GetSize(float *w, float *h) const { *w = 0; *h = 0; - for(int i = 0; i < m_lLayers.size(); i++) + for(const auto &pLayer : m_lLayers) { float lw, lh; - m_lLayers[i]->GetSize(&lw, &lh); + pLayer->GetSize(&lw, &lh); *w = maximum(*w, lw); *h = maximum(*h, lh); } @@ -224,9 +231,9 @@ void CLayerGroup::GetSize(float *w, float *h) const int CLayerGroup::SwapLayers(int Index0, int Index1) { - if(Index0 < 0 || Index0 >= m_lLayers.size()) + if(Index0 < 0 || Index0 >= (int)m_lLayers.size()) return Index0; - if(Index1 < 0 || Index1 >= m_lLayers.size()) + if(Index1 < 0 || Index1 >= (int)m_lLayers.size()) return Index0; if(Index0 == Index1) return Index0; @@ -270,7 +277,7 @@ void CEditorImage::AnalyseTileFlags() void CEditor::EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, void *pUser) { CEditor *pThis = (CEditor *)pUser; - if(Env < 0 || Env >= pThis->m_Map.m_lEnvelopes.size()) + if(Env < 0 || Env >= (int)pThis->m_Map.m_lEnvelopes.size()) { pChannels[0] = 0; pChannels[1] = 0; @@ -640,7 +647,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in CLayerGroup *CEditor::GetSelectedGroup() const { - if(m_SelectedGroup >= 0 && m_SelectedGroup < m_Map.m_lGroups.size()) + if(m_SelectedGroup >= 0 && m_SelectedGroup < (int)m_Map.m_lGroups.size()) return m_Map.m_lGroups[m_SelectedGroup]; return 0x0; } @@ -651,12 +658,12 @@ CLayer *CEditor::GetSelectedLayer(int Index) const if(!pGroup) return 0x0; - if(Index < 0 || Index >= m_lSelectedLayers.size()) + if(Index < 0 || Index >= (int)m_lSelectedLayers.size()) return 0x0; int LayerIndex = m_lSelectedLayers[Index]; - if(LayerIndex >= 0 && LayerIndex < m_Map.m_lGroups[m_SelectedGroup]->m_lLayers.size()) + if(LayerIndex >= 0 && LayerIndex < (int)m_Map.m_lGroups[m_SelectedGroup]->m_lLayers.size()) return pGroup->m_lLayers[LayerIndex]; return 0x0; } @@ -669,14 +676,14 @@ CLayer *CEditor::GetSelectedLayerType(int Index, int Type) const return 0x0; } -array CEditor::GetSelectedQuads() +std::vector CEditor::GetSelectedQuads() { CLayerQuads *ql = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS); - array lQuads; + std::vector lQuads; if(!ql) return lQuads; - lQuads.set_size(m_lSelectedQuads.size()); - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + lQuads.resize(m_lSelectedQuads.size()); + for(int i = 0; i < (int)m_lSelectedQuads.size(); ++i) lQuads[i] = &ql->m_lQuads[m_lSelectedQuads[i]]; return lQuads; } @@ -686,7 +693,7 @@ CSoundSource *CEditor::GetSelectedSource() CLayerSounds *pSounds = (CLayerSounds *)GetSelectedLayerType(0, LAYERTYPE_SOUNDS); if(!pSounds) return 0; - if(m_SelectedSource >= 0 && m_SelectedSource < pSounds->m_lSources.size()) + if(m_SelectedSource >= 0 && m_SelectedSource < (int)pSounds->m_lSources.size()) return &pSounds->m_lSources[m_SelectedSource]; return 0; } @@ -702,7 +709,7 @@ void CEditor::SelectLayer(int LayerIndex, int GroupIndex) void CEditor::AddSelectedLayer(int LayerIndex) { - m_lSelectedLayers.add(LayerIndex); + m_lSelectedLayers.push_back(LayerIndex); m_QuadKnifeActive = false; } @@ -710,7 +717,7 @@ void CEditor::AddSelectedLayer(int LayerIndex) void CEditor::SelectQuad(int Index) { m_lSelectedQuads.clear(); - m_lSelectedQuads.add(Index); + m_lSelectedQuads.push_back(Index); } void CEditor::DeleteSelectedQuads() @@ -719,28 +726,26 @@ void CEditor::DeleteSelectedQuads() if(!pLayer) return; - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(int i = 0; i < (int)m_lSelectedQuads.size(); ++i) { - pLayer->m_lQuads.remove_index(m_lSelectedQuads[i]); - for(int j = i + 1; j < m_lSelectedQuads.size(); ++j) + pLayer->m_lQuads.erase(pLayer->m_lQuads.begin() + m_lSelectedQuads[i]); + for(int j = i + 1; j < (int)m_lSelectedQuads.size(); ++j) if(m_lSelectedQuads[j] > m_lSelectedQuads[i]) m_lSelectedQuads[j]--; - m_lSelectedQuads.remove_index(i--); + m_lSelectedQuads.erase(m_lSelectedQuads.begin() + i); + i--; } } bool CEditor::IsQuadSelected(int Index) const { - for(int i = 0; i < m_lSelectedQuads.size(); ++i) - if(m_lSelectedQuads[i] == Index) - return true; - return false; + return FindSelectedQuadIndex(Index) >= 0; } int CEditor::FindSelectedQuadIndex(int Index) const { - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(size_t i = 0; i < m_lSelectedQuads.size(); ++i) if(m_lSelectedQuads[i] == Index) return i; return -1; @@ -954,16 +959,16 @@ void CEditor::DoToolbar(CUIRect ToolBar) static int s_FlipXButton = 0; if(DoButton_Ex(&s_FlipXButton, "X/X", Enabled, &Button, 0, "[N] Flip brush horizontal", CUI::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) - m_Brush.m_lLayers[i]->BrushFlipX(); + for(auto &pLayer : m_Brush.m_lLayers) + pLayer->BrushFlipX(); } TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_FlipyButton = 0; if(DoButton_Ex(&s_FlipyButton, "Y/Y", Enabled, &Button, 0, "[M] Flip brush vertical", CUI::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) - m_Brush.m_lLayers[i]->BrushFlipY(); + for(auto &pLayer : m_Brush.m_lLayers) + pLayer->BrushFlipY(); } // rotate buttons @@ -971,8 +976,8 @@ void CEditor::DoToolbar(CUIRect ToolBar) static int s_RotationAmount = 90; bool TileLayer = false; // check for tile layers in brush selection - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) - if(m_Brush.m_lLayers[i]->m_Type == LAYERTYPE_TILES) + for(auto &pLayer : m_Brush.m_lLayers) + if(pLayer->m_Type == LAYERTYPE_TILES) { TileLayer = true; s_RotationAmount = maximum(90, (s_RotationAmount / 90) * 90); @@ -984,16 +989,16 @@ void CEditor::DoToolbar(CUIRect ToolBar) static int s_CcwButton = 0; if(DoButton_Ex(&s_CcwButton, "CCW", Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", CUI::CORNER_L) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) - m_Brush.m_lLayers[i]->BrushRotate(-s_RotationAmount / 360.0f * pi * 2); + for(auto &pLayer : m_Brush.m_lLayers) + pLayer->BrushRotate(-s_RotationAmount / 360.0f * pi * 2); } TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_CwButton = 0; if(DoButton_Ex(&s_CwButton, "CW", Enabled, &Button, 0, "[T] Rotates the brush clockwise", CUI::CORNER_R) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) - m_Brush.m_lLayers[i]->BrushRotate(s_RotationAmount / 360.0f * pi * 2); + for(auto &pLayer : m_Brush.m_lLayers) + pLayer->BrushRotate(s_RotationAmount / 360.0f * pi * 2); } TB_Top.VSplitLeft(5.0f, &Button, &TB_Top); @@ -1175,22 +1180,22 @@ void CEditor::DoToolbar(CUIRect ToolBar) if(pLayer->m_Type == LAYERTYPE_QUADS) { - CLayerQuads *pQuadLayer = (CLayerQuads *)pLayer; + CLayerQuads *pLayerQuads = (CLayerQuads *)pLayer; int Width = 64; int Height = 64; - if(pQuadLayer->m_Image >= 0) + if(pLayerQuads->m_Image >= 0) { - Width = m_Map.m_lImages[pQuadLayer->m_Image]->m_Width; - Height = m_Map.m_lImages[pQuadLayer->m_Image]->m_Height; + Width = m_Map.m_lImages[pLayerQuads->m_Image]->m_Width; + Height = m_Map.m_lImages[pLayerQuads->m_Image]->m_Height; } - pQuadLayer->NewQuad(x, y, Width, Height); + pLayerQuads->NewQuad(x, y, Width, Height); } else if(pLayer->m_Type == LAYERTYPE_SOUNDS) { - CLayerSounds *pSoundLayer = (CLayerSounds *)pLayer; - pSoundLayer->NewSource(x, y); + CLayerSounds *pLayerSounds = (CLayerSounds *)pLayer; + pLayerSounds->NewSource(x, y); } } TB_Bottom.VSplitLeft(5.0f, &Button, &TB_Bottom); @@ -1346,7 +1351,7 @@ void CEditor::DoQuad(CQuad *pQuad, int Index) // some basic values void *pID = &pQuad->m_aPoints[4]; // use pivot addr as id - static array> s_lRotatePoints; + static std::vector> s_lRotatePoints; static int s_Operation = OP_NONE; static float s_RotateAngle = 0; float wx = UI()->MouseWorldX(); @@ -1425,9 +1430,9 @@ void CEditor::DoQuad(CQuad *pQuad, int Index) int OffsetX = f2fx(x) - pQuad->m_aPoints[4].x; int OffsetY = f2fx(y) - pQuad->m_aPoints[4].y; - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(auto &Selected : m_lSelectedQuads) { - CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; + CQuad *pCurrentQuad = &pLayer->m_lQuads[Selected]; for(auto &Point : pCurrentQuad->m_aPoints) { Point.x += OffsetX; @@ -1440,9 +1445,9 @@ void CEditor::DoQuad(CQuad *pQuad, int Index) int OffsetX = f2fx(wx) - pQuad->m_aPoints[4].x; int OffsetY = f2fx(wy) - pQuad->m_aPoints[4].y; - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(auto &Selected : m_lSelectedQuads) { - CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; + CQuad *pCurrentQuad = &pLayer->m_lQuads[Selected]; for(auto &Point : pCurrentQuad->m_aPoints) { Point.x += OffsetX; @@ -1454,7 +1459,7 @@ void CEditor::DoQuad(CQuad *pQuad, int Index) else if(s_Operation == OP_ROTATE) { CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS); - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(size_t i = 0; i < m_lSelectedQuads.size(); ++i) { CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; for(int v = 0; v < 4; v++) @@ -1536,12 +1541,12 @@ void CEditor::DoQuad(CQuad *pQuad, int Index) CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS); s_lRotatePoints.clear(); - s_lRotatePoints.set_size(m_lSelectedQuads.size()); - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + s_lRotatePoints.resize(m_lSelectedQuads.size()); + for(size_t i = 0; i < m_lSelectedQuads.size(); ++i) { CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; - s_lRotatePoints[i].set_size(4); + s_lRotatePoints[i].resize(4); s_lRotatePoints[i][0] = pCurrentQuad->m_aPoints[0]; s_lRotatePoints[i][1] = pCurrentQuad->m_aPoints[1]; s_lRotatePoints[i][2] = pCurrentQuad->m_aPoints[2]; @@ -1656,9 +1661,9 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V) int OffsetX = f2fx(x) - pQuad->m_aPoints[V].x; int OffsetY = f2fx(y) - pQuad->m_aPoints[V].y; - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(auto &Selected : m_lSelectedQuads) { - CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; + CQuad *pCurrentQuad = &pLayer->m_lQuads[Selected]; for(int m = 0; m < 4; m++) if(m_SelectedPoints & (1 << m)) { @@ -1672,9 +1677,9 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V) int OffsetX = f2fx(wx) - pQuad->m_aPoints[V].x; int OffsetY = f2fx(wy) - pQuad->m_aPoints[V].y; - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(auto &Selected : m_lSelectedQuads) { - CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; + CQuad *pCurrentQuad = &pLayer->m_lQuads[Selected]; for(int m = 0; m < 4; m++) if(m_SelectedPoints & (1 << m)) { @@ -1687,9 +1692,9 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V) else if(s_Operation == OP_MOVEUV) { CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS); - for(int i = 0; i < m_lSelectedQuads.size(); ++i) + for(auto &Selected : m_lSelectedQuads) { - CQuad *pCurrentQuad = &pLayer->m_lQuads[m_lSelectedQuads[i]]; + CQuad *pCurrentQuad = &pLayer->m_lQuads[Selected]; for(int m = 0; m < 4; m++) if(m_SelectedPoints & (1 << m)) { @@ -2043,15 +2048,15 @@ void CEditor::DoQuadKnife(int QuadIndex) Graphics()->QuadsEnd(); } -void CEditor::DoQuadEnvelopes(const array &lQuads, IGraphics::CTextureHandle Texture) +void CEditor::DoQuadEnvelopes(const std::vector &lQuads, IGraphics::CTextureHandle Texture) { - int Num = lQuads.size(); + size_t Num = lQuads.size(); CEnvelope **apEnvelope = new CEnvelope *[Num]; mem_zero(apEnvelope, sizeof(CEnvelope *) * Num); // NOLINT(bugprone-sizeof-expression) - for(int i = 0; i < Num; i++) + for(size_t i = 0; i < Num; i++) { if((m_ShowEnvelopePreview == 1 && lQuads[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2) - if(lQuads[i].m_PosEnv >= 0 && lQuads[i].m_PosEnv < m_Map.m_lEnvelopes.size()) + if(lQuads[i].m_PosEnv >= 0 && lQuads[i].m_PosEnv < (int)m_Map.m_lEnvelopes.size()) apEnvelope[i] = m_Map.m_lEnvelopes[lQuads[i].m_PosEnv]; } @@ -2059,14 +2064,14 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, IGraphics::CTextureHan Graphics()->TextureClear(); Graphics()->LinesBegin(); Graphics()->SetColor(80.0f / 255, 150.0f / 255, 230.f / 255, 0.5f); - for(int j = 0; j < Num; j++) + for(size_t j = 0; j < Num; j++) { if(!apEnvelope[j]) continue; //QuadParams const CPoint *pPoints = lQuads[j].m_aPoints; - for(int i = 0; i < apEnvelope[j]->m_lPoints.size() - 1; i++) + for(size_t i = 0; i < apEnvelope[j]->m_lPoints.size() - 1; i++) { float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); float OffsetY = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[1]); @@ -2087,7 +2092,7 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, IGraphics::CTextureHan Graphics()->TextureSet(Texture); Graphics()->QuadsBegin(); - for(int j = 0; j < Num; j++) + for(size_t j = 0; j < Num; j++) { if(!apEnvelope[j]) continue; @@ -2095,7 +2100,7 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, IGraphics::CTextureHan //QuadParams const CPoint *pPoints = lQuads[j].m_aPoints; - for(int i = 0; i < apEnvelope[j]->m_lPoints.size(); i++) + for(size_t i = 0; i < apEnvelope[j]->m_lPoints.size(); i++) { //Calc Env Position float OffsetX = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[0]); @@ -2103,7 +2108,7 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, IGraphics::CTextureHan float Rot = fx2f(apEnvelope[j]->m_lPoints[i].m_aValues[2]) / 360.0f * pi * 2; //Set Colours - float Alpha = (m_SelectedQuadEnvelope == lQuads[j].m_PosEnv && m_SelectedEnvelopePoint == i) ? 0.65f : 0.35f; + float Alpha = (m_SelectedQuadEnvelope == lQuads[j].m_PosEnv && m_SelectedEnvelopePoint == (int)i) ? 0.65f : 0.35f; IGraphics::CColorVertex aArray[4] = { IGraphics::CColorVertex(0, lQuads[j].m_aColors[0].r, lQuads[j].m_aColors[0].g, lQuads[j].m_aColors[0].b, Alpha), IGraphics::CColorVertex(1, lQuads[j].m_aColors[1].r, lQuads[j].m_aColors[1].g, lQuads[j].m_aColors[1].b, Alpha), @@ -2148,13 +2153,13 @@ void CEditor::DoQuadEnvelopes(const array &lQuads, IGraphics::CTextureHan Graphics()->QuadsBegin(); // Draw QuadPoints - for(int j = 0; j < Num; j++) + for(size_t j = 0; j < Num; j++) { if(!apEnvelope[j]) continue; //QuadParams - for(int i = 0; i < apEnvelope[j]->m_lPoints.size() - 1; i++) + for(size_t i = 0; i < apEnvelope[j]->m_lPoints.size() - 1; i++) DoQuadEnvPoint(&lQuads[j], j, i); } Graphics()->QuadsEnd(); @@ -2279,17 +2284,17 @@ void CEditor::DoMapEditor(CUIRect View) // render all good stuff if(!m_ShowPicker) { - for(int g = 0; g < m_Map.m_lGroups.size(); g++) + for(auto &pGroup : m_Map.m_lGroups) { // don't render the front, tele, speedup and switch layer now we will do it later to make them on top of others if( - m_Map.m_lGroups[g] == (CLayerGroup *)m_Map.m_pFrontLayer || - m_Map.m_lGroups[g] == (CLayerGroup *)m_Map.m_pTeleLayer || - m_Map.m_lGroups[g] == (CLayerGroup *)m_Map.m_pSpeedupLayer || - m_Map.m_lGroups[g] == (CLayerGroup *)m_Map.m_pSwitchLayer || - m_Map.m_lGroups[g] == (CLayerGroup *)m_Map.m_pTuneLayer) + pGroup == (CLayerGroup *)m_Map.m_pFrontLayer || + pGroup == (CLayerGroup *)m_Map.m_pTeleLayer || + pGroup == (CLayerGroup *)m_Map.m_pSpeedupLayer || + pGroup == (CLayerGroup *)m_Map.m_pSwitchLayer || + pGroup == (CLayerGroup *)m_Map.m_pTuneLayer) continue; - if(m_Map.m_lGroups[g]->m_Visible) - m_Map.m_lGroups[g]->Render(); + if(pGroup->m_Visible) + pGroup->Render(); //UI()->ClipEnable(&view); } @@ -2297,17 +2302,17 @@ void CEditor::DoMapEditor(CUIRect View) if(m_Map.m_pGameGroup->m_Visible) { m_Map.m_pGameGroup->MapScreen(); - for(int i = 0; i < m_Map.m_pGameGroup->m_lLayers.size(); i++) + for(auto &pLayer : m_Map.m_pGameGroup->m_lLayers) { if( - m_Map.m_pGameGroup->m_lLayers[i]->m_Visible && - (m_Map.m_pGameGroup->m_lLayers[i] == m_Map.m_pGameLayer || - m_Map.m_pGameGroup->m_lLayers[i] == m_Map.m_pFrontLayer || - m_Map.m_pGameGroup->m_lLayers[i] == m_Map.m_pTeleLayer || - m_Map.m_pGameGroup->m_lLayers[i] == m_Map.m_pSpeedupLayer || - m_Map.m_pGameGroup->m_lLayers[i] == m_Map.m_pSwitchLayer || - m_Map.m_pGameGroup->m_lLayers[i] == m_Map.m_pTuneLayer)) - m_Map.m_pGameGroup->m_lLayers[i]->Render(); + pLayer->m_Visible && + (pLayer == m_Map.m_pGameLayer || + pLayer == m_Map.m_pFrontLayer || + pLayer == m_Map.m_pTeleLayer || + pLayer == m_Map.m_pSpeedupLayer || + pLayer == m_Map.m_pSwitchLayer || + pLayer == m_Map.m_pTuneLayer)) + pLayer->Render(); } } @@ -2411,7 +2416,7 @@ void CEditor::DoMapEditor(CUIRect View) // draw layer borders CLayer *pEditLayers[128]; - int NumEditLayers = 0; + size_t NumEditLayers = 0; if(m_ShowPicker && GetSelectedLayer(0) && GetSelectedLayer(0)->m_Type == LAYERTYPE_TILES) { @@ -2427,7 +2432,7 @@ void CEditor::DoMapEditor(CUIRect View) { // pick a type of layers to edit, prefering Tiles layers. int EditingType = -1; - for(int i = 0; i < m_lSelectedLayers.size(); i++) + for(size_t i = 0; i < m_lSelectedLayers.size(); i++) { CLayer *Layer = GetSelectedLayer(i); if(Layer && (EditingType == -1 || Layer->m_Type == LAYERTYPE_TILES)) @@ -2437,7 +2442,7 @@ void CEditor::DoMapEditor(CUIRect View) break; } } - for(int i = 0; i < m_lSelectedLayers.size() && NumEditLayers < 128; i++) + for(size_t i = 0; i < m_lSelectedLayers.size() && NumEditLayers < 128; i++) { pEditLayers[NumEditLayers] = GetSelectedLayerType(i, EditingType); if(pEditLayers[NumEditLayers]) @@ -2453,7 +2458,7 @@ void CEditor::DoMapEditor(CUIRect View) RenderGrid(g); - for(int i = 0; i < NumEditLayers; i++) + for(size_t i = 0; i < NumEditLayers; i++) { if(pEditLayers[i]->m_Type != LAYERTYPE_TILES) continue; @@ -2554,9 +2559,9 @@ void CEditor::DoMapEditor(CUIRect View) if(!m_Brush.IsEmpty()) { // draw with brush - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) { - int BrushIndex = k % m_Brush.m_lLayers.size(); + size_t BrushIndex = k % m_Brush.m_lLayers.size(); if(pEditLayers[k]->m_Type == m_Brush.m_lLayers[BrushIndex]->m_Type) { if(pEditLayers[k]->m_Type == LAYERTYPE_TILES) @@ -2584,7 +2589,7 @@ void CEditor::DoMapEditor(CUIRect View) CLayerQuads *t = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS); if(t) { - for(int i = 0; i < t->m_lQuads.size(); i++) + for(size_t i = 0; i < t->m_lQuads.size(); i++) { CQuad *q = &t->m_lQuads[i]; float px = fx2f(q->m_aPoints[4].x); @@ -2592,7 +2597,7 @@ void CEditor::DoMapEditor(CUIRect View) if(px > r.x && px < r.x + r.w && py > r.y && py < r.y + r.h) if(!IsQuadSelected(i)) - m_lSelectedQuads.add(i); + m_lSelectedQuads.push_back(i); } } } @@ -2605,13 +2610,13 @@ void CEditor::DoMapEditor(CUIRect View) // TODO: do all layers int Grabs = 0; - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) Grabs += pEditLayers[k]->BrushGrab(&m_Brush, r); if(Grabs == 0) m_Brush.Clear(); - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) - m_Brush.m_lLayers[i]->m_BrushRefCount = 1; + for(auto &pLayer : m_Brush.m_lLayers) + pLayer->m_BrushRefCount = 1; m_lSelectedQuads.clear(); m_SelectedPoints = 0; @@ -2620,7 +2625,7 @@ void CEditor::DoMapEditor(CUIRect View) else { //editor.map.groups[selected_group]->mapscreen(); - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) pEditLayers[k]->BrushSelecting(r); UI()->MapScreen(); } @@ -2629,9 +2634,9 @@ void CEditor::DoMapEditor(CUIRect View) { if(!UI()->MouseButton(0)) { - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) { - int BrushIndex = k; + size_t BrushIndex = k; if(m_Brush.m_lLayers.size() != NumEditLayers) BrushIndex = 0; pEditLayers[k]->FillSelection(m_Brush.IsEmpty(), m_Brush.m_lLayers[BrushIndex], r); @@ -2640,7 +2645,7 @@ void CEditor::DoMapEditor(CUIRect View) else { //editor.map.groups[selected_group]->mapscreen(); - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) pEditLayers[k]->BrushSelecting(r); UI()->MapScreen(); } @@ -2650,10 +2655,10 @@ void CEditor::DoMapEditor(CUIRect View) { if(UI()->MouseButton(1)) { - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) + for(auto &pLayer : m_Brush.m_lLayers) { - if(m_Brush.m_lLayers[i]->m_BrushRefCount == 1) - delete m_Brush.m_lLayers[i]; + if(pLayer->m_BrushRefCount == 1) + delete pLayer; } m_Brush.Clear(); } @@ -2667,9 +2672,9 @@ void CEditor::DoMapEditor(CUIRect View) else { s_Operation = OP_BRUSH_DRAW; - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) { - int BrushIndex = k; + size_t BrushIndex = k; if(m_Brush.m_lLayers.size() != NumEditLayers) BrushIndex = 0; if(pEditLayers[k]->m_Type == m_Brush.m_lLayers[BrushIndex]->m_Type) @@ -2686,9 +2691,9 @@ void CEditor::DoMapEditor(CUIRect View) { m_Brush.m_OffsetX = -(int)wx; m_Brush.m_OffsetY = -(int)wy; - for(int i = 0; i < m_Brush.m_lLayers.size(); i++) + for(const auto &pLayer : m_Brush.m_lLayers) { - if(m_Brush.m_lLayers[i]->m_Type == LAYERTYPE_TILES) + if(pLayer->m_Type == LAYERTYPE_TILES) { m_Brush.m_OffsetX = -(int)(wx / 32.0f) * 32; m_Brush.m_OffsetY = -(int)(wy / 32.0f) * 32; @@ -2730,7 +2735,7 @@ void CEditor::DoMapEditor(CUIRect View) if(g) g->MapScreen(); - for(int k = 0; k < NumEditLayers; k++) + for(size_t k = 0; k < NumEditLayers; k++) { if(pEditLayers[k]->m_Type == LAYERTYPE_QUADS) { @@ -2745,7 +2750,7 @@ void CEditor::DoMapEditor(CUIRect View) { Graphics()->TextureClear(); Graphics()->QuadsBegin(); - for(int i = 0; i < pLayer->m_lQuads.size(); i++) + for(size_t i = 0; i < pLayer->m_lQuads.size(); i++) { for(int v = 0; v < 4; v++) DoQuadPoint(&pLayer->m_lQuads[i], i, v); @@ -2762,7 +2767,7 @@ void CEditor::DoMapEditor(CUIRect View) Graphics()->TextureClear(); Graphics()->QuadsBegin(); - for(int i = 0; i < pLayer->m_lSources.size(); i++) + for(size_t i = 0; i < pLayer->m_lSources.size(); i++) { DoSoundSource(&pLayer->m_lSources[i], i); } @@ -2943,7 +2948,7 @@ void CEditor::DoMapEditor(CUIRect View) CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayer(0); IGraphics::CTextureHandle Texture; - if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size()) + if(pLayer->m_Image >= 0 && pLayer->m_Image < (int)m_Map.m_lImages.size()) Texture = m_Map.m_lImages[pLayer->m_Image]->m_Texture; DoQuadEnvelopes(pLayer->m_lQuads, Texture); @@ -3198,7 +3203,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * else if(pProps[i].m_Type == PROPTYPE_AUTOMAPPER) { char aBuf[64]; - if(pProps[i].m_Value < 0 || pProps[i].m_Min < 0 || pProps[i].m_Min >= m_Map.m_lImages.size()) + if(pProps[i].m_Value < 0 || pProps[i].m_Min < 0 || pProps[i].m_Min >= (int)m_Map.m_lImages.size()) str_copy(aBuf, "None", sizeof(aBuf)); else str_format(aBuf, sizeof(aBuf), "%s", m_Map.m_lImages[pProps[i].m_Min]->m_AutoMapper.GetConfigName(pProps[i].m_Value)); @@ -3262,13 +3267,13 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) float LayersHeight = 12.0f; // Height of AddGroup button static float s_ScrollValue = 0; - for(int g = 0; g < m_Map.m_lGroups.size(); g++) + for(auto &pGroup : m_Map.m_lGroups) { // Each group is 19.0f // Each layer is 14.0f LayersHeight += 19.0f; - if(!m_Map.m_lGroups[g]->m_Collapse) - LayersHeight += m_Map.m_lGroups[g]->m_lLayers.size() * 14.0f; + if(!pGroup->m_Collapse) + LayersHeight += pGroup->m_lLayers.size() * 14.0f; } float ScrollDifference = LayersHeight - LayersBox.h; @@ -3301,7 +3306,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) // render layers { - for(int g = 0; g < m_Map.m_lGroups.size(); g++) + for(int g = 0; g < (int)m_Map.m_lGroups.size(); g++) { if(LayerCur > LayerStopAt) break; @@ -3332,7 +3337,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) if((Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) && m_SelectedGroup == g) { m_lSelectedLayers.clear(); - for(int i = 0; i < m_Map.m_lGroups[g]->m_lLayers.size(); i++) + for(size_t i = 0; i < m_Map.m_lGroups[g]->m_lLayers.size(); i++) { AddSelectedLayer(i); } @@ -3342,14 +3347,14 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) if(Result == 2) UiInvokePopupMenu(&s_GroupPopupId, 0, UI()->MouseX(), UI()->MouseY(), 145, 230, PopupGroup); - if(m_Map.m_lGroups[g]->m_lLayers.size() && Input()->MouseDoubleClick()) + if(!m_Map.m_lGroups[g]->m_lLayers.empty() && Input()->MouseDoubleClick()) m_Map.m_lGroups[g]->m_Collapse ^= 1; } LayersBox.HSplitTop(2.0f, &Slot, &LayersBox); } LayerCur += 14.0f; - for(int i = 0; i < m_Map.m_lGroups[g]->m_lLayers.size(); i++) + for(int i = 0; i < (int)m_Map.m_lGroups[g]->m_lLayers.size(); i++) { if(LayerCur > LayerStopAt) break; @@ -3399,9 +3404,9 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) int Checked = 0; if(g == m_SelectedGroup) { - for(int j = 0; j < m_lSelectedLayers.size(); j++) + for(const auto &Selected : m_lSelectedLayers) { - if(m_lSelectedLayers[j] == i) + if(Selected == i) { Checked = 1; break; @@ -3426,7 +3431,10 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) { if((Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) && m_SelectedGroup == g) { - if(!m_lSelectedLayers.remove(i)) + auto Position = std::find(m_lSelectedLayers.begin(), m_lSelectedLayers.end(), i); + if(Position != m_lSelectedLayers.end()) + m_lSelectedLayers.erase(Position); + else AddSelectedLayer(i); } else if(!(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT))) @@ -3440,9 +3448,9 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) if(m_SelectedGroup == g) { - for(int x = 0; x < m_lSelectedLayers.size(); x++) + for(const auto &Selected : m_lSelectedLayers) { - if(m_lSelectedLayers[x] == i) + if(Selected == i) { IsLayerSelected = true; break; @@ -3458,10 +3466,10 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) if(m_lSelectedLayers.size() > 1) { bool AllTile = true; - for(int j = 0; AllTile && j < m_lSelectedLayers.size(); j++) + for(size_t j = 0; AllTile && j < m_lSelectedLayers.size(); j++) { if(m_Map.m_lGroups[m_SelectedGroup]->m_lLayers[m_lSelectedLayers[j]]->m_Type == LAYERTYPE_TILES) - s_LayerPopupContext.m_aLayers.add((CLayerTiles *)m_Map.m_lGroups[m_SelectedGroup]->m_lLayers[m_lSelectedLayers[j]]); + s_LayerPopupContext.m_aLayers.push_back((CLayerTiles *)m_Map.m_lGroups[m_SelectedGroup]->m_lLayers[m_lSelectedLayers[j]]); else AllTile = false; } @@ -3490,25 +3498,25 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) { if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) { - if(m_lSelectedLayers[m_lSelectedLayers.size() - 1] < m_Map.m_lGroups[m_SelectedGroup]->m_lLayers.size() - 1) + if(m_lSelectedLayers[m_lSelectedLayers.size() - 1] < (int)m_Map.m_lGroups[m_SelectedGroup]->m_lLayers.size() - 1) AddSelectedLayer(m_lSelectedLayers[m_lSelectedLayers.size() - 1] + 1); } else { int CurrentLayer = 0; - for(int i = 0; i < m_lSelectedLayers.size(); i++) - CurrentLayer = maximum(m_lSelectedLayers[i], CurrentLayer); + for(const auto &Selected : m_lSelectedLayers) + CurrentLayer = maximum(Selected, CurrentLayer); SelectLayer(CurrentLayer); - if(m_lSelectedLayers[0] < m_Map.m_lGroups[m_SelectedGroup]->m_lLayers.size() - 1) + if(m_lSelectedLayers[0] < (int)m_Map.m_lGroups[m_SelectedGroup]->m_lLayers.size() - 1) { SelectLayer(m_lSelectedLayers[0] + 1); } else { - for(int Group = m_SelectedGroup + 1; Group < m_Map.m_lGroups.size(); Group++) + for(size_t Group = m_SelectedGroup + 1; Group < m_Map.m_lGroups.size(); Group++) { - if(m_Map.m_lGroups[Group]->m_lLayers.size() > 0) + if(!m_Map.m_lGroups[Group]->m_lLayers.empty()) { SelectLayer(0, Group); break; @@ -3527,8 +3535,8 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) else { int CurrentLayer = std::numeric_limits::max(); - for(int i = 0; i < m_lSelectedLayers.size(); i++) - CurrentLayer = minimum(m_lSelectedLayers[i], CurrentLayer); + for(const auto &Selected : m_lSelectedLayers) + CurrentLayer = minimum(Selected, CurrentLayer); SelectLayer(CurrentLayer); if(m_lSelectedLayers[0] > 0) @@ -3539,7 +3547,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect View) { for(int Group = m_SelectedGroup - 1; Group >= 0; Group--) { - if(m_Map.m_lGroups[Group]->m_lLayers.size() > 0) + if(!m_Map.m_lGroups[Group]->m_lLayers.empty()) { SelectLayer(m_Map.m_lGroups[Group]->m_lLayers.size() - 1, Group); break; @@ -3580,9 +3588,9 @@ void CEditor::SelectLayerByTile(float &Scroll) if(s_CtrlClick) return; s_CtrlClick = true; - for(int g = 0; g < m_Map.m_lGroups.size(); g++) + for(size_t g = 0; g < m_Map.m_lGroups.size(); g++) { - for(int l = 0; l < m_Map.m_lGroups[g]->m_lLayers.size(); l++) + for(size_t l = 0; l < m_Map.m_lGroups[g]->m_lLayers.size(); l++) { TotalLayers++; if(IsFound) @@ -3660,7 +3668,7 @@ void CEditor::ReplaceImage(const char *pFileName, int StorageType, void *pUser) pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, TextureLoadFlag, pFileName); ImgInfo.m_pData = 0; pEditor->SortImages(); - for(int i = 0; i < pEditor->m_Map.m_lImages.size(); ++i) + for(size_t i = 0; i < pEditor->m_Map.m_lImages.size(); ++i) { if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, pImg->m_aName)) pEditor->m_SelectedImage = i; @@ -3678,9 +3686,9 @@ void CEditor::AddImage(const char *pFileName, int StorageType, void *pUser) // check if we have that image already char aBuf[128]; IStorage::StripPathAndExtension(pFileName, aBuf, sizeof(aBuf)); - for(int i = 0; i < pEditor->m_Map.m_lImages.size(); ++i) + for(const auto &pImage : pEditor->m_Map.m_lImages) { - if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, aBuf)) + if(!str_comp(pImage->m_aName, aBuf)) return; } @@ -3711,9 +3719,9 @@ void CEditor::AddImage(const char *pFileName, int StorageType, void *pUser) ImgInfo.m_pData = 0; str_copy(pImg->m_aName, aBuf, sizeof(pImg->m_aName)); pImg->m_AutoMapper.Load(pImg->m_aName); - pEditor->m_Map.m_lImages.add(pImg); + pEditor->m_Map.m_lImages.push_back(pImg); pEditor->SortImages(); - if(pEditor->m_SelectedImage > -1 && pEditor->m_SelectedImage < pEditor->m_Map.m_lImages.size()) + if(pEditor->m_SelectedImage >= 0 && (size_t)pEditor->m_SelectedImage < pEditor->m_Map.m_lImages.size()) { for(int i = 0; i <= pEditor->m_SelectedImage; ++i) if(!str_comp(pEditor->m_Map.m_lImages[i]->m_aName, aBuf)) @@ -3732,9 +3740,9 @@ void CEditor::AddSound(const char *pFileName, int StorageType, void *pUser) // check if we have that sound already char aBuf[128]; IStorage::StripPathAndExtension(pFileName, aBuf, sizeof(aBuf)); - for(int i = 0; i < pEditor->m_Map.m_lSounds.size(); ++i) + for(const auto &pSound : pEditor->m_Map.m_lSounds) { - if(!str_comp(pEditor->m_Map.m_lSounds[i]->m_aName, aBuf)) + if(!str_comp(pSound->m_aName, aBuf)) return; } @@ -3771,9 +3779,9 @@ void CEditor::AddSound(const char *pFileName, int StorageType, void *pUser) pSound->m_DataSize = (unsigned)DataSize; pSound->m_pData = pData; str_copy(pSound->m_aName, aBuf, sizeof(pSound->m_aName)); - pEditor->m_Map.m_lSounds.add(pSound); + pEditor->m_Map.m_lSounds.push_back(pSound); - if(pEditor->m_SelectedSound > -1 && pEditor->m_SelectedSound < pEditor->m_Map.m_lSounds.size()) + if(pEditor->m_SelectedSound >= 0 && (size_t)pEditor->m_SelectedSound < pEditor->m_Map.m_lSounds.size()) { for(int i = 0; i <= pEditor->m_SelectedSound; ++i) if(!str_comp(pEditor->m_Map.m_lSounds[i]->m_aName, aBuf)) @@ -3880,7 +3888,7 @@ int CEditor::PopupImage(CEditor *pEditor, CUIRect View, void *pContext) if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the image from the map")) { delete pImg; - pEditor->m_Map.m_lImages.remove_index(pEditor->m_SelectedImage); + pEditor->m_Map.m_lImages.erase(pEditor->m_Map.m_lImages.begin() + pEditor->m_SelectedImage); gs_ModifyIndexDeletedIndex = pEditor->m_SelectedImage; pEditor->m_Map.ModifyImageIndex(ModifyIndexDeleted); return 1; @@ -3909,7 +3917,7 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext) if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the sound from the map")) { delete pSound; - pEditor->m_Map.m_lSounds.remove_index(pEditor->m_SelectedSound); + pEditor->m_Map.m_lSounds.erase(pEditor->m_Map.m_lSounds.begin() + pEditor->m_SelectedSound); gs_ModifyIndexDeletedIndex = pEditor->m_SelectedSound; pEditor->m_Map.ModifySoundIndex(ModifyIndexDeleted); return 1; @@ -3920,9 +3928,9 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext) void CEditor::SelectGameLayer() { - for(int g = 0; g < m_Map.m_lGroups.size(); g++) + for(size_t g = 0; g < m_Map.m_lGroups.size(); g++) { - for(int i = 0; i < m_Map.m_lGroups[g]->m_lLayers.size(); i++) + for(size_t i = 0; i < m_Map.m_lGroups[g]->m_lLayers.size(); i++) { if(m_Map.m_lGroups[g]->m_lLayers[i] == m_Map.m_pGameLayer) { @@ -3947,15 +3955,15 @@ static void ModifySortedIndex(int *pIndex) void CEditor::SortImages() { - if(!std::is_sorted(m_Map.m_lImages.base_ptr(), m_Map.m_lImages.base_ptr() + m_Map.m_lImages.size(), ImageNameLess)) + if(!std::is_sorted(m_Map.m_lImages.begin(), m_Map.m_lImages.end(), ImageNameLess)) { - array lTemp = m_Map.m_lImages; + std::vector lTemp = m_Map.m_lImages; gs_pSortedIndex = new int[lTemp.size()]; - std::sort(m_Map.m_lImages.base_ptr(), m_Map.m_lImages.base_ptr() + m_Map.m_lImages.size(), ImageNameLess); - for(int OldIndex = 0; OldIndex < lTemp.size(); OldIndex++) + std::sort(m_Map.m_lImages.begin(), m_Map.m_lImages.end(), ImageNameLess); + for(size_t OldIndex = 0; OldIndex < lTemp.size(); OldIndex++) { - for(int NewIndex = 0; NewIndex < m_Map.m_lImages.size(); NewIndex++) + for(size_t NewIndex = 0; NewIndex < m_Map.m_lImages.size(); NewIndex++) { if(lTemp[OldIndex] == m_Map.m_lImages[NewIndex]) { @@ -4022,7 +4030,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) } ImageCur += 15.0f; - for(int i = 0; i < m_Map.m_lImages.size(); i++) + for(int i = 0; i < (int)m_Map.m_lImages.size(); i++) { if((e && !m_Map.m_lImages[i]->m_External) || (!e && m_Map.m_lImages[i]->m_External)) @@ -4045,23 +4053,37 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) int Selected = m_SelectedImage == i; - for(int x = 0; x < m_Map.m_lGroups.size(); ++x) - for(int j = 0; j < m_Map.m_lGroups[x]->m_lLayers.size(); ++j) - if(m_Map.m_lGroups[x]->m_lLayers[j]->m_Type == LAYERTYPE_QUADS) + bool ImageUsed = false; + for(const auto &pGroup : m_Map.m_lGroups) + { + for(const auto &pLayer : pGroup->m_lLayers) + { + if(pLayer->m_Type == LAYERTYPE_QUADS) { - CLayerQuads *pLayer = static_cast(m_Map.m_lGroups[x]->m_lLayers[j]); - if(pLayer->m_Image == i) - goto done; + CLayerQuads *pQuadsLayer = static_cast(pLayer); + if(pQuadsLayer->m_Image == i) + { + ImageUsed = true; + break; + } } - else if(m_Map.m_lGroups[x]->m_lLayers[j]->m_Type == LAYERTYPE_TILES) + else if(pLayer->m_Type == LAYERTYPE_TILES) { - CLayerTiles *pLayer = static_cast(m_Map.m_lGroups[x]->m_lLayers[j]); - if(pLayer->m_Image == i) - goto done; + CLayerTiles *pTilesLayer = static_cast(pLayer); + if(pTilesLayer->m_Image == i) + { + ImageUsed = true; + break; + } } + } + if(ImageUsed) + break; + } + + if(!ImageUsed) + Selected += 2; // Image is unused - Selected += 2; // Image is unused - done: if(Selected < 2 && e == 1) { if(!IsVanillaImage(m_Map.m_lImages[i]->m_aName)) @@ -4108,8 +4130,8 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) if(Input()->KeyPress(KEY_DOWN) && m_Dialog == DIALOG_NONE) { int OldImage = m_SelectedImage; - m_SelectedImage = clamp(m_SelectedImage, 0, m_Map.m_lImages.size() - 1); - for(int i = m_SelectedImage + 1; i < m_Map.m_lImages.size(); i++) + m_SelectedImage = clamp(m_SelectedImage, 0, (int)m_Map.m_lImages.size() - 1); + for(size_t i = m_SelectedImage + 1; i < m_Map.m_lImages.size(); i++) { if(m_Map.m_lImages[i]->m_External == m_Map.m_lImages[m_SelectedImage]->m_External) { @@ -4119,7 +4141,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) } if(m_SelectedImage == OldImage && !m_Map.m_lImages[m_SelectedImage]->m_External) { - for(int i = 0; i < m_Map.m_lImages.size(); i++) + for(size_t i = 0; i < m_Map.m_lImages.size(); i++) { if(m_Map.m_lImages[i]->m_External) { @@ -4132,7 +4154,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) if(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE) { int OldImage = m_SelectedImage; - m_SelectedImage = clamp(m_SelectedImage, 0, m_Map.m_lImages.size() - 1); + m_SelectedImage = clamp(m_SelectedImage, 0, (int)m_Map.m_lImages.size() - 1); for(int i = m_SelectedImage - 1; i >= 0; i--) { if(m_Map.m_lImages[i]->m_External == m_Map.m_lImages[m_SelectedImage]->m_External) @@ -4143,7 +4165,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) } if(m_SelectedImage == OldImage && m_Map.m_lImages[m_SelectedImage]->m_External) { - for(int i = m_Map.m_lImages.size() - 1; i >= 0; i--) + for(int i = (int)m_Map.m_lImages.size() - 1; i >= 0; i--) { if(!m_Map.m_lImages[i]->m_External) { @@ -4156,7 +4178,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View) // render image int i = m_SelectedImage; - if(i != -1 && i < m_Map.m_lImages.size()) + if(i >= 0 && (size_t)i < m_Map.m_lImages.size()) { CUIRect r; View.Margin(10.0f, &r); @@ -4230,7 +4252,7 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View) UI()->DoLabel(&Slot, "Embedded", 12.0f, TEXTALIGN_CENTER); SoundCur += 15.0f; - for(int i = 0; i < m_Map.m_lSounds.size(); i++) + for(int i = 0; i < (int)m_Map.m_lSounds.size(); i++) { if(SoundCur > SoundStopAt) break; @@ -4246,17 +4268,28 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View) ToolBox.HSplitTop(12.0f, &Slot, &ToolBox); int Selected = m_SelectedSound == i; - for(int x = 0; x < m_Map.m_lGroups.size(); ++x) - for(int j = 0; j < m_Map.m_lGroups[x]->m_lLayers.size(); ++j) - if(m_Map.m_lGroups[x]->m_lLayers[j]->m_Type == LAYERTYPE_SOUNDS) + bool SoundUsed = false; + for(const auto &pGroup : m_Map.m_lGroups) + { + for(const auto &pLayer : pGroup->m_lLayers) + { + if(pLayer->m_Type == LAYERTYPE_SOUNDS) { - CLayerSounds *pLayer = static_cast(m_Map.m_lGroups[x]->m_lLayers[j]); - if(pLayer->m_Sound == i) - goto used; + CLayerSounds *pSoundsLayer = static_cast(pLayer); + if(pSoundsLayer->m_Sound == i) + { + SoundUsed = true; + break; + } } + } + if(SoundUsed) + break; + } + + if(!SoundUsed) + Selected += 2; // Sound is unused - Selected += 2; // Sound is unused - used: float FontSize = 10.0f; while(TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f) > Slot.w) FontSize--; @@ -4284,16 +4317,16 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View) if(Input()->KeyPress(KEY_DOWN) && m_Dialog == DIALOG_NONE) { - m_SelectedSound = clamp(m_SelectedSound, 0, m_Map.m_lSounds.size() - 1); - if(m_SelectedSound == m_Map.m_lSounds.size() - 1) + m_SelectedSound = clamp(m_SelectedSound, 0, (int)m_Map.m_lSounds.size() - 1); + if(m_SelectedSound == (int)m_Map.m_lSounds.size() - 1) m_SelectedSound = 0; else m_SelectedSound += 1; } if(Input()->KeyPress(KEY_UP) && m_Dialog == DIALOG_NONE) { - m_SelectedSound = clamp(m_SelectedSound, 0, m_Map.m_lSounds.size() - 1); - if(m_SelectedSound == 0 && m_Map.m_lSounds.size() != 0) + m_SelectedSound = clamp(m_SelectedSound, 0, (int)m_Map.m_lSounds.size() - 1); + if(m_SelectedSound == 0 && !m_Map.m_lSounds.empty()) m_SelectedSound = m_Map.m_lSounds.size() - 1; else m_SelectedSound -= 1; @@ -4838,36 +4871,36 @@ void CEditor::RenderStatusbar(CUIRect View) bool CEditor::IsEnvelopeUsed(int EnvelopeIndex) const { - for(int i = 0; i < m_Map.m_lGroups.size(); i++) + for(const auto &pGroup : m_Map.m_lGroups) { - for(int j = 0; j < m_Map.m_lGroups[i]->m_lLayers.size(); j++) + for(const auto &pLayer : pGroup->m_lLayers) { - if(m_Map.m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_QUADS) + if(pLayer->m_Type == LAYERTYPE_QUADS) { - CLayerQuads *pQuadLayer = (CLayerQuads *)m_Map.m_lGroups[i]->m_lLayers[j]; - for(int k = 0; k < pQuadLayer->m_lQuads.size(); k++) + CLayerQuads *pLayerQuads = (CLayerQuads *)pLayer; + for(const auto &Quad : pLayerQuads->m_lQuads) { - if(pQuadLayer->m_lQuads[k].m_PosEnv == EnvelopeIndex || pQuadLayer->m_lQuads[k].m_ColorEnv == EnvelopeIndex) + if(Quad.m_PosEnv == EnvelopeIndex || Quad.m_ColorEnv == EnvelopeIndex) { return true; } } } - else if(m_Map.m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_SOUNDS) + else if(pLayer->m_Type == LAYERTYPE_SOUNDS) { - CLayerSounds *pSoundLayer = (CLayerSounds *)m_Map.m_lGroups[i]->m_lLayers[j]; - for(int k = 0; k < pSoundLayer->m_lSources.size(); k++) + CLayerSounds *pLayerSounds = (CLayerSounds *)pLayer; + for(const auto &Source : pLayerSounds->m_lSources) { - if(pSoundLayer->m_lSources[k].m_PosEnv == EnvelopeIndex || pSoundLayer->m_lSources[k].m_SoundEnv == EnvelopeIndex) + if(Source.m_PosEnv == EnvelopeIndex || Source.m_SoundEnv == EnvelopeIndex) { return true; } } } - else if(m_Map.m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_TILES) + else if(pLayer->m_Type == LAYERTYPE_TILES) { - CLayerTiles *pTileLayer = (CLayerTiles *)m_Map.m_lGroups[i]->m_lLayers[j]; - if(pTileLayer->m_ColorEnv == EnvelopeIndex) + CLayerTiles *pLayerTiles = (CLayerTiles *)pLayer; + if(pLayerTiles->m_ColorEnv == EnvelopeIndex) return true; } } @@ -4879,11 +4912,11 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) { if(m_SelectedEnvelope < 0) m_SelectedEnvelope = 0; - if(m_SelectedEnvelope >= m_Map.m_lEnvelopes.size()) + if(m_SelectedEnvelope >= (int)m_Map.m_lEnvelopes.size()) m_SelectedEnvelope = m_Map.m_lEnvelopes.size() - 1; CEnvelope *pEnvelope = 0; - if(m_SelectedEnvelope >= 0 && m_SelectedEnvelope < m_Map.m_lEnvelopes.size()) + if(m_SelectedEnvelope >= 0 && m_SelectedEnvelope < (int)m_Map.m_lEnvelopes.size()) pEnvelope = m_Map.m_lEnvelopes[m_SelectedEnvelope]; CUIRect ToolBar, CurveBar, ColorBar; @@ -4935,7 +4968,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) { m_Map.m_Modified = true; m_Map.DeleteEnvelope(m_SelectedEnvelope); - if(m_SelectedEnvelope >= m_Map.m_lEnvelopes.size()) + if(m_SelectedEnvelope >= (int)m_Map.m_lEnvelopes.size()) m_SelectedEnvelope = m_Map.m_lEnvelopes.size() - 1; pEnvelope = m_SelectedEnvelope >= 0 ? m_Map.m_lEnvelopes[m_SelectedEnvelope] : 0; } @@ -4960,10 +4993,10 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) Shifter.VSplitRight(15.0f, &Shifter, &Inc); Shifter.VSplitLeft(15.0f, &Dec, &Shifter); char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "%d/%d", m_SelectedEnvelope + 1, m_Map.m_lEnvelopes.size()); + str_format(aBuf, sizeof(aBuf), "%d/%d", m_SelectedEnvelope + 1, (int)m_Map.m_lEnvelopes.size()); ColorRGBA EnvColor = ColorRGBA(1, 1, 1, 0.5f); - if(m_Map.m_lEnvelopes.size()) + if(!m_Map.m_lEnvelopes.empty()) { EnvColor = IsEnvelopeUsed(m_SelectedEnvelope) ? ColorRGBA(1, 0.7f, 0.7f, 0.5f) : @@ -4986,7 +5019,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) if(DoButton_ButtonInc(&s_NextButton, 0, 0, &Inc, 0, "Next Envelope")) { m_SelectedEnvelope++; - if(m_SelectedEnvelope >= m_Map.m_lEnvelopes.size()) + if(m_SelectedEnvelope >= (int)m_Map.m_lEnvelopes.size()) m_SelectedEnvelope = 0; CurrentEnvelopeSwitched = true; } @@ -5020,7 +5053,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) if(pEnvelope) { - static array Selection; + static std::vector Selection; static int sEnvelopeEditorID = 0; static int s_ActiveChannels = 0xf; @@ -5152,7 +5185,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) // render curve options { - for(int i = 0; i < pEnvelope->m_lPoints.size() - 1; i++) + for(int i = 0; i < (int)pEnvelope->m_lPoints.size() - 1; i++) { float t0 = pEnvelope->m_lPoints[i].m_Time / 1000.0f / EndTime; float t1 = pEnvelope->m_lPoints[i + 1].m_Time / 1000.0f / EndTime; @@ -5181,7 +5214,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) { Graphics()->TextureClear(); Graphics()->QuadsBegin(); - for(int i = 0; i < pEnvelope->m_lPoints.size() - 1; i++) + for(int i = 0; i < (int)pEnvelope->m_lPoints.size() - 1; i++) { float r0 = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); float g0 = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); @@ -5242,7 +5275,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) if(!(s_ActiveChannels & (1 << c))) continue; - for(int i = 0; i < pEnvelope->m_lPoints.size(); i++) + for(size_t i = 0; i < pEnvelope->m_lPoints.size(); i++) { float x0 = pEnvelope->m_lPoints[i].m_Time / 1000.0f / EndTime; float y0 = (fx2f(pEnvelope->m_lPoints[i].m_aValues[c]) - Bottom) / (Top - Bottom); @@ -5308,7 +5341,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) if(UI()->MouseButton(0)) { Selection.clear(); - Selection.add(i); + Selection.push_back(i); UI()->SetActiveItem(pID); // track it s_pID = pID; @@ -5326,7 +5359,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) str_format(s_aStrCurValue, sizeof(s_aStrCurValue), "0.000"); } - pEnvelope->m_lPoints.remove_index(i); + pEnvelope->m_lPoints.erase(pEnvelope->m_lPoints.begin() + i); m_Map.m_Modified = true; } @@ -5365,7 +5398,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) str_format(s_aStrCurValue, sizeof(s_aStrCurValue), "%.3f", fx2f(CurrentValue)); } - if(m_SelectedQuadEnvelope == m_SelectedEnvelope && m_SelectedEnvelopePoint == i) + if(m_SelectedQuadEnvelope == m_SelectedEnvelope && m_SelectedEnvelopePoint == (int)i) Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); else Graphics()->SetColor(aColors[c].r * ColorMod, aColors[c].g * ColorMod, aColors[c].b * ColorMod, 1.0f); @@ -5434,8 +5467,8 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd if(m_aSettingsCommand[0] != 0 && str_find(m_aSettingsCommand, " ")) { bool Found = false; - for(int i = 0; i < m_Map.m_lSettings.size(); i++) - if(!str_comp(m_Map.m_lSettings[i].m_aCommand, m_aSettingsCommand)) + for(const auto &Setting : m_Map.m_lSettings) + if(!str_comp(Setting.m_aCommand, m_aSettingsCommand)) { Found = true; break; @@ -5445,14 +5478,14 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd { CEditorMap::CSetting Setting; str_copy(Setting.m_aCommand, m_aSettingsCommand, sizeof(Setting.m_aCommand)); - m_Map.m_lSettings.add(Setting); + m_Map.m_lSettings.push_back(Setting); s_CommandSelectedIndex = m_Map.m_lSettings.size() - 1; } } UI()->SetActiveItem(&m_CommandBox); } - if(m_Map.m_lSettings.size() && s_CommandSelectedIndex > -1 && s_CommandSelectedIndex < m_Map.m_lSettings.size()) + if(!m_Map.m_lSettings.empty() && s_CommandSelectedIndex >= 0 && (size_t)s_CommandSelectedIndex < m_Map.m_lSettings.size()) { ToolBar.VSplitRight(50.0f, &ToolBar, &Button); Button.VSplitRight(5.0f, &Button, 0); @@ -5463,7 +5496,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd { bool Found = false; int i; - for(i = 0; i < m_Map.m_lSettings.size(); i++) + for(i = 0; i < (int)m_Map.m_lSettings.size(); i++) if(i != s_CommandSelectedIndex && !str_comp(m_Map.m_lSettings[i].m_aCommand, m_aSettingsCommand)) { Found = true; @@ -5471,7 +5504,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd } if(Found) { - m_Map.m_lSettings.remove_index(s_CommandSelectedIndex); + m_Map.m_lSettings.erase(m_Map.m_lSettings.begin() + s_CommandSelectedIndex); s_CommandSelectedIndex = i > s_CommandSelectedIndex ? i - 1 : i; } else @@ -5487,8 +5520,8 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd static int s_DelButton = 0; if(DoButton_Editor(&s_DelButton, "Del", 0, &Button, 0, "Delete a command from the command list.") || (Input()->KeyPress(KEY_DELETE) && UI()->LastActiveItem() != &m_CommandBox && m_Dialog == DIALOG_NONE)) { - m_Map.m_lSettings.remove_index(s_CommandSelectedIndex); - if(s_CommandSelectedIndex >= m_Map.m_lSettings.size()) + m_Map.m_lSettings.erase(m_Map.m_lSettings.begin() + s_CommandSelectedIndex); + if(s_CommandSelectedIndex >= (int)m_Map.m_lSettings.size()) s_CommandSelectedIndex = m_Map.m_lSettings.size() - 1; if(s_CommandSelectedIndex >= 0) str_copy(m_aSettingsCommand, m_Map.m_lSettings[s_CommandSelectedIndex].m_aCommand, sizeof(m_aSettingsCommand)); @@ -5498,7 +5531,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd ToolBar.VSplitRight(25.0f, &ToolBar, &Button); Button.VSplitRight(5.0f, &Button, 0); static int s_DownButton = 0; - if(s_CommandSelectedIndex < m_Map.m_lSettings.size() - 1 && DoButton_Editor(&s_DownButton, "▼", 0, &Button, 0, "Move command down")) + if(s_CommandSelectedIndex < (int)m_Map.m_lSettings.size() - 1 && DoButton_Editor(&s_DownButton, "▼", 0, &Button, 0, "Move command down")) { std::swap(m_Map.m_lSettings[s_CommandSelectedIndex], m_Map.m_lSettings[s_CommandSelectedIndex + 1]); s_CommandSelectedIndex++; @@ -5553,7 +5586,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd float ListCur = 0; UI()->ClipEnable(&ListBox); - for(int i = 0; i < m_Map.m_lSettings.size(); i++) + for(size_t i = 0; i < m_Map.m_lSettings.size(); i++) { if(ListCur > ListStopAt) break; @@ -5565,7 +5598,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEd ListBox.HSplitTop(2.0f, 0, &ListBox); Button.VSplitLeft(5.0f, 0, &Button); - if(DoButton_MenuItem(&m_Map.m_lSettings[i], m_Map.m_lSettings[i].m_aCommand, s_CommandSelectedIndex == i, &Button, 0, 0)) + if(DoButton_MenuItem(&m_Map.m_lSettings[i], m_Map.m_lSettings[i].m_aCommand, s_CommandSelectedIndex >= 0 && (size_t)s_CommandSelectedIndex == i, &Button, 0, 0)) { s_CommandSelectedIndex = i; str_copy(m_aSettingsCommand, m_Map.m_lSettings[i].m_aCommand, sizeof(m_aSettingsCommand)); @@ -5813,27 +5846,27 @@ void CEditor::Render() if(m_apSavedBrushes[Slot]) { CLayerGroup *pPrev = m_apSavedBrushes[Slot]; - for(int j = 0; j < pPrev->m_lLayers.size(); j++) + for(auto &pLayer : pPrev->m_lLayers) { - if(pPrev->m_lLayers[j]->m_BrushRefCount == 1) - delete pPrev->m_lLayers[j]; + if(pLayer->m_BrushRefCount == 1) + delete pLayer; else - pPrev->m_lLayers[j]->m_BrushRefCount--; + pLayer->m_BrushRefCount--; } } delete m_apSavedBrushes[Slot]; m_apSavedBrushes[Slot] = new CLayerGroup(m_Brush); - for(int j = 0; j < m_apSavedBrushes[Slot]->m_lLayers.size(); j++) - m_apSavedBrushes[Slot]->m_lLayers[j]->m_BrushRefCount++; + for(auto &pLayer : m_apSavedBrushes[Slot]->m_lLayers) + pLayer->m_BrushRefCount++; } else if(m_apSavedBrushes[Slot]) { dbg_msg("editor", "loading brush from slot %d", Slot); CLayerGroup *pNew = m_apSavedBrushes[Slot]; - for(int j = 0; j < pNew->m_lLayers.size(); j++) - pNew->m_lLayers[j]->m_BrushRefCount++; + for(auto &pLayer : pNew->m_lLayers) + pLayer->m_BrushRefCount++; m_Brush = *pNew; } @@ -6174,39 +6207,39 @@ void CEditor::ZoomMouseTarget(float ZoomFactor) void CEditorMap::DeleteEnvelope(int Index) { - if(Index < 0 || Index >= m_lEnvelopes.size()) + if(Index < 0 || Index >= (int)m_lEnvelopes.size()) return; m_Modified = true; // fix links between envelopes and quads - for(int i = 0; i < m_lGroups.size(); ++i) - for(int j = 0; j < m_lGroups[i]->m_lLayers.size(); ++j) - if(m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_QUADS) + for(auto &pGroup : m_lGroups) + for(auto &pLayer : pGroup->m_lLayers) + if(pLayer->m_Type == LAYERTYPE_QUADS) { - CLayerQuads *pLayer = static_cast(m_lGroups[i]->m_lLayers[j]); - for(int k = 0; k < pLayer->m_lQuads.size(); ++k) + CLayerQuads *pLayerQuads = static_cast(pLayer); + for(auto &Quad : pLayerQuads->m_lQuads) { - if(pLayer->m_lQuads[k].m_PosEnv == Index) - pLayer->m_lQuads[k].m_PosEnv = -1; - else if(pLayer->m_lQuads[k].m_PosEnv > Index) - pLayer->m_lQuads[k].m_PosEnv--; - if(pLayer->m_lQuads[k].m_ColorEnv == Index) - pLayer->m_lQuads[k].m_ColorEnv = -1; - else if(pLayer->m_lQuads[k].m_ColorEnv > Index) - pLayer->m_lQuads[k].m_ColorEnv--; + if(Quad.m_PosEnv == Index) + Quad.m_PosEnv = -1; + else if(Quad.m_PosEnv > Index) + Quad.m_PosEnv--; + if(Quad.m_ColorEnv == Index) + Quad.m_ColorEnv = -1; + else if(Quad.m_ColorEnv > Index) + Quad.m_ColorEnv--; } } - else if(m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_TILES) + else if(pLayer->m_Type == LAYERTYPE_TILES) { - CLayerTiles *pLayer = static_cast(m_lGroups[i]->m_lLayers[j]); - if(pLayer->m_ColorEnv == Index) - pLayer->m_ColorEnv = -1; - if(pLayer->m_ColorEnv > Index) - pLayer->m_ColorEnv--; + CLayerTiles *pLayerTiles = static_cast(pLayer); + if(pLayerTiles->m_ColorEnv == Index) + pLayerTiles->m_ColorEnv = -1; + if(pLayerTiles->m_ColorEnv > Index) + pLayerTiles->m_ColorEnv--; } - m_lEnvelopes.remove_index(Index); + m_lEnvelopes.erase(m_lEnvelopes.begin() + Index); } void CEditorMap::MakeGameLayer(CLayer *pLayer) @@ -6225,14 +6258,14 @@ void CEditorMap::MakeGameGroup(CLayerGroup *pGroup) void CEditorMap::Clean() { - for(int i = 0; i < m_lGroups.size(); i++) + for(auto &pGroup : m_lGroups) { - m_lGroups[i]->m_lLayers.delete_all(); + DeleteAll(pGroup->m_lLayers); } - m_lGroups.delete_all(); - m_lEnvelopes.delete_all(); - m_lImages.delete_all(); - m_lSounds.delete_all(); + DeleteAll(m_lGroups); + DeleteAll(m_lEnvelopes); + DeleteAll(m_lImages); + DeleteAll(m_lSounds); m_MapInfo.Reset(); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 187be6337..83612707e 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -10,9 +10,6 @@ #include #include -#include -#include - #include #include #include @@ -50,7 +47,7 @@ class CEnvelope { public: int m_Channels; - array m_lPoints; + std::vector m_lPoints; char m_aName[32]; float m_Bottom, m_Top; bool m_Synchronized; @@ -66,7 +63,7 @@ public: void Resort() { - sort(m_lPoints.all()); + std::sort(m_lPoints.begin(), m_lPoints.end()); FindTopBottom(0xf); } @@ -74,13 +71,13 @@ public: { m_Top = -1000000000.0f; m_Bottom = 1000000000.0f; - for(int i = 0; i < m_lPoints.size(); i++) + for(auto &Point : m_lPoints) { for(int c = 0; c < m_Channels; c++) { if(ChannelMask & (1 << c)) { - float v = fx2f(m_lPoints[i].m_aValues[c]); + float v = fx2f(Point.m_aValues[c]); if(v > m_Top) m_Top = v; if(v < m_Bottom) @@ -92,7 +89,7 @@ public: int Eval(float Time, float *pResult) { - CRenderTools::RenderEvalEnvelope(m_lPoints.base_ptr(), m_lPoints.size(), m_Channels, std::chrono::nanoseconds((int64_t)((double)Time * (double)std::chrono::nanoseconds(1s).count())), pResult); + CRenderTools::RenderEvalEnvelope(&m_lPoints[0], m_lPoints.size(), m_Channels, std::chrono::nanoseconds((int64_t)((double)Time * (double)std::chrono::nanoseconds(1s).count())), pResult); return m_Channels; } @@ -105,13 +102,13 @@ public: p.m_aValues[2] = v2; p.m_aValues[3] = v3; p.m_Curvetype = CURVETYPE_LINEAR; - m_lPoints.add(p); + m_lPoints.push_back(p); Resort(); } float EndTime() const { - if(m_lPoints.size()) + if(!m_lPoints.empty()) return m_lPoints[m_lPoints.size() - 1].m_Time * (1.0f / 1000.0f); return 0; } @@ -180,7 +177,7 @@ class CLayerGroup public: class CEditorMap *m_pMap; - array m_lLayers; + std::vector m_lLayers; int m_OffsetX; int m_OffsetY; @@ -261,20 +258,20 @@ public: void ModifyImageIndex(INDEX_MODIFY_FUNC Func) { - for(int i = 0; i < m_lLayers.size(); i++) - m_lLayers[i]->ModifyImageIndex(Func); + for(auto &pLayer : m_lLayers) + pLayer->ModifyImageIndex(Func); } void ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func) { - for(int i = 0; i < m_lLayers.size(); i++) - m_lLayers[i]->ModifyEnvelopeIndex(Func); + for(auto &pLayer : m_lLayers) + pLayer->ModifyEnvelopeIndex(Func); } void ModifySoundIndex(INDEX_MODIFY_FUNC Func) { - for(int i = 0; i < m_lLayers.size(); i++) - m_lLayers[i]->ModifySoundIndex(Func); + for(auto &pLayer : m_lLayers) + pLayer->ModifySoundIndex(Func); } }; @@ -349,10 +346,10 @@ public: Clean(); } - array m_lGroups; - array m_lImages; - array m_lEnvelopes; - array m_lSounds; + std::vector m_lGroups; + std::vector m_lImages; + std::vector m_lEnvelopes; + std::vector m_lSounds; class CMapInfo { @@ -386,7 +383,7 @@ public: { char m_aCommand[256]; }; - array m_lSettings; + std::vector m_lSettings; class CLayerGame *m_pGameLayer; CLayerGroup *m_pGameGroup; @@ -395,7 +392,7 @@ public: { m_Modified = true; CEnvelope *e = new CEnvelope(Channels); - m_lEnvelopes.add(e); + m_lEnvelopes.push_back(e); return e; } @@ -406,15 +403,15 @@ public: m_Modified = true; CLayerGroup *g = new CLayerGroup; g->m_pMap = this; - m_lGroups.add(g); + m_lGroups.push_back(g); return g; } int SwapGroups(int Index0, int Index1) { - if(Index0 < 0 || Index0 >= m_lGroups.size()) + if(Index0 < 0 || Index0 >= (int)m_lGroups.size()) return Index0; - if(Index1 < 0 || Index1 >= m_lGroups.size()) + if(Index1 < 0 || Index1 >= (int)m_lGroups.size()) return Index0; if(Index0 == Index1) return Index0; @@ -425,32 +422,32 @@ public: void DeleteGroup(int Index) { - if(Index < 0 || Index >= m_lGroups.size()) + if(Index < 0 || Index >= (int)m_lGroups.size()) return; m_Modified = true; delete m_lGroups[Index]; - m_lGroups.remove_index(Index); + m_lGroups.erase(m_lGroups.begin() + Index); } void ModifyImageIndex(INDEX_MODIFY_FUNC pfnFunc) { m_Modified = true; - for(int i = 0; i < m_lGroups.size(); i++) - m_lGroups[i]->ModifyImageIndex(pfnFunc); + for(auto &pGroup : m_lGroups) + pGroup->ModifyImageIndex(pfnFunc); } void ModifyEnvelopeIndex(INDEX_MODIFY_FUNC pfnFunc) { m_Modified = true; - for(int i = 0; i < m_lGroups.size(); i++) - m_lGroups[i]->ModifyEnvelopeIndex(pfnFunc); + for(auto &pGroup : m_lGroups) + pGroup->ModifyEnvelopeIndex(pfnFunc); } void ModifySoundIndex(INDEX_MODIFY_FUNC pfnFunc) { m_Modified = true; - for(int i = 0; i < m_lGroups.size(); i++) - m_lGroups[i]->ModifySoundIndex(pfnFunc); + for(auto &pGroup : m_lGroups) + pGroup->ModifySoundIndex(pfnFunc); } void Clean(); @@ -552,7 +549,7 @@ public: int Height = -1; int Color = 0; }; - static int RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, array &pLayers); + static int RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, std::vector &pLayers); void ModifyImageIndex(INDEX_MODIFY_FUNC pfnFunc) override; void ModifyEnvelopeIndex(INDEX_MODIFY_FUNC pfnFunc) override; @@ -614,7 +611,7 @@ public: void GetSize(float *w, float *h) override; int m_Image; - array m_lQuads; + std::vector m_lQuads; }; class CLayerGame : public CLayerTiles @@ -789,7 +786,7 @@ public: void LoadCurrentMap(); void Render(); - array GetSelectedQuads(); + std::vector GetSelectedQuads(); CLayer *GetSelectedLayerType(int Index, int Type) const; CLayer *GetSelectedLayer(int Index) const; CLayerGroup *GetSelectedGroup() const; @@ -918,8 +915,8 @@ public: bool m_ShowServerSettingsEditor; bool m_ShowPicker; - array m_lSelectedLayers; - array m_lSelectedQuads; + std::vector m_lSelectedLayers; + std::vector m_lSelectedQuads; int m_SelectedQuadPoint; int m_SelectedQuadIndex; int m_SelectedGroup; @@ -990,7 +987,7 @@ public: struct CLayerPopupContext { - array m_aLayers; + std::vector m_aLayers; CLayerTiles::SCommonPropState m_CommonPropState; }; static int PopupLayer(CEditor *pEditor, CUIRect View, void *pContext); @@ -1027,7 +1024,7 @@ public: void PopupSelectSoundInvoke(int Current, float x, float y); int PopupSelectSoundResult(); - void DoQuadEnvelopes(const array &m_lQuads, IGraphics::CTextureHandle Texture = IGraphics::CTextureHandle()); + void DoQuadEnvelopes(const std::vector &m_lQuads, IGraphics::CTextureHandle Texture = IGraphics::CTextureHandle()); void DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int pIndex); void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v); @@ -1287,7 +1284,7 @@ public: void ModifySoundIndex(INDEX_MODIFY_FUNC pfnFunc) override; int m_Sound; - array m_lSources; + std::vector m_lSources; }; #endif diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index 2b07eb43d..f13072b18 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -260,20 +260,20 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) Item.m_License = -1; Item.m_Settings = -1; - if(m_lSettings.size()) + if(!m_lSettings.empty()) { int Size = 0; - for(int i = 0; i < m_lSettings.size(); i++) + for(const auto &Setting : m_lSettings) { - Size += str_length(m_lSettings[i].m_aCommand) + 1; + Size += str_length(Setting.m_aCommand) + 1; } char *pSettings = (char *)malloc(maximum(Size, 1)); char *pNext = pSettings; - for(int i = 0; i < m_lSettings.size(); i++) + for(const auto &Setting : m_lSettings) { - int Length = str_length(m_lSettings[i].m_aCommand) + 1; - mem_copy(pNext, m_lSettings[i].m_aCommand, Length); + int Length = str_length(Setting.m_aCommand) + 1; + mem_copy(pNext, Setting.m_aCommand, Length); pNext += Length; } Item.m_Settings = df.AddData(Size, pSettings); @@ -284,7 +284,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) } // save images - for(int i = 0; i < m_lImages.size(); i++) + for(size_t i = 0; i < m_lImages.size(); i++) { CEditorImage *pImg = m_lImages[i]; @@ -327,7 +327,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) } // save sounds - for(int i = 0; i < m_lSounds.size(); i++) + for(size_t i = 0; i < m_lSounds.size(); i++) { CEditorSound *pSound = m_lSounds[i]; @@ -345,9 +345,8 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) // save layers int LayerCount = 0, GroupCount = 0; int AutomapperCount = 0; - for(int g = 0; g < m_lGroups.size(); g++) + for(const auto &pGroup : m_lGroups) { - CLayerGroup *pGroup = m_lGroups[g]; CMapItemGroup GItem; GItem.m_Version = CMapItemGroup::CURRENT_VERSION; @@ -366,43 +365,43 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) // save group name StrToInts(GItem.m_aName, sizeof(GItem.m_aName) / sizeof(int), pGroup->m_aName); - for(int l = 0; l < pGroup->m_lLayers.size(); l++) + for(const auto &pLayer : pGroup->m_lLayers) { - if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_TILES) + if(pLayer->m_Type == LAYERTYPE_TILES) { m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving tiles layer"); - CLayerTiles *pLayer = (CLayerTiles *)pGroup->m_lLayers[l]; - pLayer->PrepareForSave(); + CLayerTiles *pLayerTiles = (CLayerTiles *)pLayer; + pLayerTiles->PrepareForSave(); CMapItemLayerTilemap Item; Item.m_Version = 3; Item.m_Layer.m_Version = 0; // was previously uninitialized, do not rely on it being 0 - Item.m_Layer.m_Flags = pLayer->m_Flags; - Item.m_Layer.m_Type = pLayer->m_Type; + Item.m_Layer.m_Flags = pLayerTiles->m_Flags; + Item.m_Layer.m_Type = pLayerTiles->m_Type; - Item.m_Color = pLayer->m_Color; - Item.m_ColorEnv = pLayer->m_ColorEnv; - Item.m_ColorEnvOffset = pLayer->m_ColorEnvOffset; + Item.m_Color = pLayerTiles->m_Color; + Item.m_ColorEnv = pLayerTiles->m_ColorEnv; + Item.m_ColorEnvOffset = pLayerTiles->m_ColorEnvOffset; - Item.m_Width = pLayer->m_Width; - Item.m_Height = pLayer->m_Height; - // Item.m_Flags = pLayer->m_Game ? TILESLAYERFLAG_GAME : 0; + Item.m_Width = pLayerTiles->m_Width; + Item.m_Height = pLayerTiles->m_Height; + // Item.m_Flags = pLayerTiles->m_Game ? TILESLAYERFLAG_GAME : 0; - if(pLayer->m_Tele) + if(pLayerTiles->m_Tele) Item.m_Flags = TILESLAYERFLAG_TELE; - else if(pLayer->m_Speedup) + else if(pLayerTiles->m_Speedup) Item.m_Flags = TILESLAYERFLAG_SPEEDUP; - else if(pLayer->m_Front) + else if(pLayerTiles->m_Front) Item.m_Flags = TILESLAYERFLAG_FRONT; - else if(pLayer->m_Switch) + else if(pLayerTiles->m_Switch) Item.m_Flags = TILESLAYERFLAG_SWITCH; - else if(pLayer->m_Tune) + else if(pLayerTiles->m_Tune) Item.m_Flags = TILESLAYERFLAG_TUNE; else - Item.m_Flags = pLayer->m_Game ? TILESLAYERFLAG_GAME : 0; + Item.m_Flags = pLayerTiles->m_Game ? TILESLAYERFLAG_GAME : 0; - Item.m_Image = pLayer->m_Image; + Item.m_Image = pLayerTiles->m_Image; // the following values were previously uninitialized, do not rely on them being -1 when unused Item.m_Tele = -1; @@ -411,29 +410,29 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) Item.m_Switch = -1; Item.m_Tune = -1; - if(Item.m_Flags && !(pLayer->m_Game)) + if(Item.m_Flags && !(pLayerTiles->m_Game)) { - CTile *pEmptyTiles = (CTile *)calloc((size_t)pLayer->m_Width * pLayer->m_Height, sizeof(CTile)); - mem_zero(pEmptyTiles, (size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CTile)); - Item.m_Data = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CTile), pEmptyTiles); + CTile *pEmptyTiles = (CTile *)calloc((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height, sizeof(CTile)); + mem_zero(pEmptyTiles, (size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CTile)); + Item.m_Data = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CTile), pEmptyTiles); free(pEmptyTiles); - if(pLayer->m_Tele) - Item.m_Tele = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CTeleTile), ((CLayerTele *)pLayer)->m_pTeleTile); - else if(pLayer->m_Speedup) - Item.m_Speedup = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile); - else if(pLayer->m_Front) - Item.m_Front = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CTile), pLayer->m_pTiles); - else if(pLayer->m_Switch) - Item.m_Switch = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CSwitchTile), ((CLayerSwitch *)pLayer)->m_pSwitchTile); - else if(pLayer->m_Tune) - Item.m_Tune = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CTuneTile), ((CLayerTune *)pLayer)->m_pTuneTile); + if(pLayerTiles->m_Tele) + Item.m_Tele = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CTeleTile), ((CLayerTele *)pLayerTiles)->m_pTeleTile); + else if(pLayerTiles->m_Speedup) + Item.m_Speedup = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayerTiles)->m_pSpeedupTile); + else if(pLayerTiles->m_Front) + Item.m_Front = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CTile), pLayerTiles->m_pTiles); + else if(pLayerTiles->m_Switch) + Item.m_Switch = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CSwitchTile), ((CLayerSwitch *)pLayerTiles)->m_pSwitchTile); + else if(pLayerTiles->m_Tune) + Item.m_Tune = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CTuneTile), ((CLayerTune *)pLayerTiles)->m_pTuneTile); } else - Item.m_Data = df.AddData((size_t)pLayer->m_Width * pLayer->m_Height * sizeof(CTile), pLayer->m_pTiles); + Item.m_Data = df.AddData((size_t)pLayerTiles->m_Width * pLayerTiles->m_Height * sizeof(CTile), pLayerTiles->m_pTiles); // save layer name - StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayer->m_aName); + StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerTiles->m_aName); df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item); @@ -444,10 +443,10 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) ItemAutomapper.m_Version = CMapItemAutoMapperConfig::CURRENT_VERSION; ItemAutomapper.m_GroupId = GroupCount; ItemAutomapper.m_LayerId = GItem.m_NumLayers; - ItemAutomapper.m_AutomapperConfig = pLayer->m_AutoMapperConfig; - ItemAutomapper.m_AutomapperSeed = pLayer->m_Seed; + ItemAutomapper.m_AutomapperConfig = pLayerTiles->m_AutoMapperConfig; + ItemAutomapper.m_AutomapperSeed = pLayerTiles->m_Seed; ItemAutomapper.m_Flags = 0; - if(pLayer->m_AutoAutoMap) + if(pLayerTiles->m_AutoAutoMap) ItemAutomapper.m_Flags |= CMapItemAutoMapperConfig::FLAG_AUTOMATIC; df.AddItem(MAPITEMTYPE_AUTOMAPPER_CONFIG, AutomapperCount, sizeof(ItemAutomapper), &ItemAutomapper); @@ -457,25 +456,25 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) GItem.m_NumLayers++; LayerCount++; } - else if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_QUADS) + else if(pLayer->m_Type == LAYERTYPE_QUADS) { m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving quads layer"); - CLayerQuads *pLayer = (CLayerQuads *)pGroup->m_lLayers[l]; - if(pLayer->m_lQuads.size()) + CLayerQuads *pLayerQuads = (CLayerQuads *)pLayer; + if(!pLayerQuads->m_lQuads.empty()) { CMapItemLayerQuads Item; Item.m_Version = 2; Item.m_Layer.m_Version = 0; // was previously uninitialized, do not rely on it being 0 - Item.m_Layer.m_Flags = pLayer->m_Flags; - Item.m_Layer.m_Type = pLayer->m_Type; - Item.m_Image = pLayer->m_Image; + Item.m_Layer.m_Flags = pLayerQuads->m_Flags; + Item.m_Layer.m_Type = pLayerQuads->m_Type; + Item.m_Image = pLayerQuads->m_Image; // add the data - Item.m_NumQuads = pLayer->m_lQuads.size(); - Item.m_Data = df.AddDataSwapped(pLayer->m_lQuads.size() * sizeof(CQuad), pLayer->m_lQuads.base_ptr()); + Item.m_NumQuads = pLayerQuads->m_lQuads.size(); + Item.m_Data = df.AddDataSwapped(pLayerQuads->m_lQuads.size() * sizeof(CQuad), &pLayerQuads->m_lQuads[0]); // save layer name - StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayer->m_aName); + StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerQuads->m_aName); df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item); @@ -486,25 +485,25 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) LayerCount++; } } - else if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_SOUNDS) + else if(pLayer->m_Type == LAYERTYPE_SOUNDS) { m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving sounds layer"); - CLayerSounds *pLayer = (CLayerSounds *)pGroup->m_lLayers[l]; - if(pLayer->m_lSources.size()) + CLayerSounds *pLayerSounds = (CLayerSounds *)pLayer; + if(!pLayerSounds->m_lSources.empty()) { CMapItemLayerSounds Item; Item.m_Version = CMapItemLayerSounds::CURRENT_VERSION; Item.m_Layer.m_Version = 0; // was previously uninitialized, do not rely on it being 0 - Item.m_Layer.m_Flags = pLayer->m_Flags; - Item.m_Layer.m_Type = pLayer->m_Type; - Item.m_Sound = pLayer->m_Sound; + Item.m_Layer.m_Flags = pLayerSounds->m_Flags; + Item.m_Layer.m_Type = pLayerSounds->m_Type; + Item.m_Sound = pLayerSounds->m_Sound; // add the data - Item.m_NumSources = pLayer->m_lSources.size(); - Item.m_Data = df.AddDataSwapped(pLayer->m_lSources.size() * sizeof(CSoundSource), pLayer->m_lSources.base_ptr()); + Item.m_NumSources = pLayerSounds->m_lSources.size(); + Item.m_Data = df.AddDataSwapped(pLayerSounds->m_lSources.size() * sizeof(CSoundSource), &pLayerSounds->m_lSources[0]); // save layer name - StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayer->m_aName); + StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerSounds->m_aName); df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item); GItem.m_NumLayers++; @@ -518,7 +517,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) // save envelopes int PointCount = 0; - for(int e = 0; e < m_lEnvelopes.size(); e++) + for(size_t e = 0; e < m_lEnvelopes.size(); e++) { CMapItemEnvelope Item; Item.m_Version = CMapItemEnvelope::CURRENT_VERSION; @@ -537,10 +536,10 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) CEnvPoint *pPoints = (CEnvPoint *)calloc(maximum(PointCount, 1), sizeof(*pPoints)); PointCount = 0; - for(int e = 0; e < m_lEnvelopes.size(); e++) + for(const auto &pEnvelope : m_lEnvelopes) { - int Count = m_lEnvelopes[e]->m_lPoints.size(); - mem_copy(&pPoints[PointCount], m_lEnvelopes[e]->m_lPoints.base_ptr(), sizeof(CEnvPoint) * Count); + int Count = pEnvelope->m_lPoints.size(); + mem_copy(&pPoints[PointCount], &pEnvelope->m_lPoints[0], sizeof(CEnvPoint) * Count); PointCount += Count; } @@ -649,7 +648,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag int StrSize = str_length(pNext) + 1; CSetting Setting; str_copy(Setting.m_aCommand, pNext, sizeof(Setting.m_aCommand)); - m_lSettings.add(Setting); + m_lSettings.push_back(Setting); pNext += StrSize; } } @@ -709,7 +708,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag // load auto mapper file pImg->m_AutoMapper.Load(pImg->m_aName); - m_lImages.add(pImg); + m_lImages.push_back(pImg); // unload image DataFile.UnloadData(pItem->m_ImageData); @@ -768,7 +767,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag if(pName) str_copy(pSound->m_aName, pName, sizeof(pSound->m_aName)); - m_lSounds.add(pSound); + m_lSounds.push_back(pSound); // unload image DataFile.UnloadData(pItem->m_SoundData); @@ -1156,7 +1155,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag pQuads->m_pEditor = m_pEditor; pLayer = pQuads; pQuads->m_Image = pQuadsItem->m_Image; - if(pQuads->m_Image < -1 || pQuads->m_Image >= m_lImages.size()) + if(pQuads->m_Image < -1 || pQuads->m_Image >= (int)m_lImages.size()) pQuads->m_Image = -1; // load layer name @@ -1165,8 +1164,8 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag void *pData = DataFile.GetDataSwapped(pQuadsItem->m_Data); pGroup->AddLayer(pQuads); - pQuads->m_lQuads.set_size(pQuadsItem->m_NumQuads); - mem_copy(pQuads->m_lQuads.base_ptr(), pData, sizeof(CQuad) * pQuadsItem->m_NumQuads); + pQuads->m_lQuads.resize(pQuadsItem->m_NumQuads); + mem_copy(&pQuads->m_lQuads[0], pData, sizeof(CQuad) * pQuadsItem->m_NumQuads); DataFile.UnloadData(pQuadsItem->m_Data); } else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS) @@ -1181,7 +1180,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag pSounds->m_Sound = pSoundsItem->m_Sound; // validate m_Sound - if(pSounds->m_Sound < -1 || pSounds->m_Sound >= m_lSounds.size()) + if(pSounds->m_Sound < -1 || pSounds->m_Sound >= (int)m_lSounds.size()) pSounds->m_Sound = -1; // load layer name @@ -1191,8 +1190,8 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag // load data void *pData = DataFile.GetDataSwapped(pSoundsItem->m_Data); pGroup->AddLayer(pSounds); - pSounds->m_lSources.set_size(pSoundsItem->m_NumSources); - mem_copy(pSounds->m_lSources.base_ptr(), pData, sizeof(CSoundSource) * pSoundsItem->m_NumSources); + pSounds->m_lSources.resize(pSoundsItem->m_NumSources); + mem_copy(&pSounds->m_lSources[0], pData, sizeof(CSoundSource) * pSoundsItem->m_NumSources); DataFile.UnloadData(pSoundsItem->m_Data); } else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS_DEPRECATED) @@ -1208,7 +1207,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag pSounds->m_Sound = pSoundsItem->m_Sound; // validate m_Sound - if(pSounds->m_Sound < -1 || pSounds->m_Sound >= m_lSounds.size()) + if(pSounds->m_Sound < -1 || pSounds->m_Sound >= (int)m_lSounds.size()) pSounds->m_Sound = -1; // load layer name @@ -1218,7 +1217,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag // load data CSoundSource_DEPRECATED *pData = (CSoundSource_DEPRECATED *)DataFile.GetDataSwapped(pSoundsItem->m_Data); pGroup->AddLayer(pSounds); - pSounds->m_lSources.set_size(pSoundsItem->m_NumSources); + pSounds->m_lSources.resize(pSoundsItem->m_NumSources); for(int i = 0; i < pSoundsItem->m_NumSources; i++) { @@ -1266,11 +1265,11 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag { CMapItemEnvelope *pItem = (CMapItemEnvelope *)DataFile.GetItem(Start + e, 0, 0); CEnvelope *pEnv = new CEnvelope(pItem->m_Channels); - pEnv->m_lPoints.set_size(pItem->m_NumPoints); - mem_copy(pEnv->m_lPoints.base_ptr(), &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint) * pItem->m_NumPoints); + pEnv->m_lPoints.resize(pItem->m_NumPoints); + mem_copy(&pEnv->m_lPoints[0], &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint) * pItem->m_NumPoints); if(pItem->m_aName[0] != -1) // compatibility with old maps IntsToStr(pItem->m_aName, sizeof(pItem->m_aName) / sizeof(int), pEnv->m_aName); - m_lEnvelopes.add(pEnv); + m_lEnvelopes.push_back(pEnv); if(pItem->m_Version >= 2) pEnv->m_Synchronized = pItem->m_Synchronized; } @@ -1284,8 +1283,8 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag CMapItemAutoMapperConfig *pItem = (CMapItemAutoMapperConfig *)DataFile.GetItem(Start + i, 0, 0); if(pItem->m_Version == CMapItemAutoMapperConfig::CURRENT_VERSION) { - if(pItem->m_GroupId >= 0 && pItem->m_GroupId < m_lGroups.size() && - pItem->m_LayerId >= 0 && pItem->m_LayerId < m_lGroups[pItem->m_GroupId]->m_lLayers.size()) + if(pItem->m_GroupId >= 0 && (size_t)pItem->m_GroupId < m_lGroups.size() && + pItem->m_LayerId >= 0 && (size_t)pItem->m_LayerId < m_lGroups[pItem->m_GroupId]->m_lLayers.size()) { CLayer *pLayer = m_lGroups[pItem->m_GroupId]->m_lLayers[pItem->m_LayerId]; if(pLayer->m_Type == LAYERTYPE_TILES) @@ -1337,25 +1336,25 @@ int CEditor::Append(const char *pFileName, int StorageType) NewMap.ModifyEnvelopeIndex(ModifyAdd); // transfer images - for(int i = 0; i < NewMap.m_lImages.size(); i++) - m_Map.m_lImages.add(NewMap.m_lImages[i]); + for(const auto &pImage : NewMap.m_lImages) + m_Map.m_lImages.push_back(pImage); NewMap.m_lImages.clear(); // transfer envelopes - for(int i = 0; i < NewMap.m_lEnvelopes.size(); i++) - m_Map.m_lEnvelopes.add(NewMap.m_lEnvelopes[i]); + for(const auto &pEnvelope : NewMap.m_lEnvelopes) + m_Map.m_lEnvelopes.push_back(pEnvelope); NewMap.m_lEnvelopes.clear(); // transfer groups - for(int i = 0; i < NewMap.m_lGroups.size(); i++) + for(const auto &pGroup : NewMap.m_lGroups) { - if(NewMap.m_lGroups[i] == NewMap.m_pGameGroup) - delete NewMap.m_lGroups[i]; + if(pGroup == NewMap.m_pGameGroup) + delete pGroup; else { - NewMap.m_lGroups[i]->m_pMap = &m_Map; - m_Map.m_lGroups.add(NewMap.m_lGroups[i]); + pGroup->m_pMap = &m_Map; + m_Map.m_lGroups.push_back(pGroup); } } NewMap.m_lGroups.clear(); diff --git a/src/game/editor/layer_quads.cpp b/src/game/editor/layer_quads.cpp index ba5d1a951..64735da5e 100644 --- a/src/game/editor/layer_quads.cpp +++ b/src/game/editor/layer_quads.cpp @@ -22,20 +22,21 @@ CLayerQuads::~CLayerQuads() = default; void CLayerQuads::Render(bool QuadPicker) { Graphics()->TextureClear(); - if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size()) + if(m_Image >= 0 && (size_t)m_Image < m_pEditor->m_Map.m_lImages.size()) Graphics()->TextureSet(m_pEditor->m_Map.m_lImages[m_Image]->m_Texture); Graphics()->BlendNone(); - m_pEditor->RenderTools()->ForceRenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor); + m_pEditor->RenderTools()->ForceRenderQuads(&m_lQuads[0], m_lQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor); Graphics()->BlendNormal(); - m_pEditor->RenderTools()->ForceRenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor); + m_pEditor->RenderTools()->ForceRenderQuads(&m_lQuads[0], m_lQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor); } CQuad *CLayerQuads::NewQuad(int x, int y, int Width, int Height) { m_pEditor->m_Map.m_Modified = true; - CQuad *q = &m_lQuads[m_lQuads.add(CQuad())]; + m_lQuads.emplace_back(); + CQuad *q = &m_lQuads[m_lQuads.size() - 1]; q->m_PosEnv = -1; q->m_ColorEnv = -1; @@ -111,16 +112,14 @@ int CLayerQuads::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) pBrush->AddLayer(pGrabbed); //dbg_msg("", "%f %f %f %f", rect.x, rect.y, rect.w, rect.h); - for(int i = 0; i < m_lQuads.size(); i++) + for(const auto &Quad : m_lQuads) { - CQuad *q = &m_lQuads[i]; - float px = fx2f(q->m_aPoints[4].x); - float py = fx2f(q->m_aPoints[4].y); + float px = fx2f(Quad.m_aPoints[4].x); + float py = fx2f(Quad.m_aPoints[4].y); if(px > Rect.x && px < Rect.x + Rect.w && py > Rect.y && py < Rect.y + Rect.h) { - CQuad n; - n = *q; + CQuad n = Quad; for(auto &Point : n.m_aPoints) { @@ -128,19 +127,19 @@ int CLayerQuads::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) Point.y -= f2fx(Rect.y); } - pGrabbed->m_lQuads.add(n); + pGrabbed->m_lQuads.push_back(n); } } - return pGrabbed->m_lQuads.size() ? 1 : 0; + return pGrabbed->m_lQuads.empty() ? 0 : 1; } void CLayerQuads::BrushPlace(CLayer *pBrush, float wx, float wy) { CLayerQuads *l = (CLayerQuads *)pBrush; - for(int i = 0; i < l->m_lQuads.size(); i++) + for(const auto &Quad : l->m_lQuads) { - CQuad n = l->m_lQuads[i]; + CQuad n = Quad; for(auto &Point : n.m_aPoints) { @@ -148,31 +147,27 @@ void CLayerQuads::BrushPlace(CLayer *pBrush, float wx, float wy) Point.y += f2fx(wy); } - m_lQuads.add(n); + m_lQuads.push_back(n); } m_pEditor->m_Map.m_Modified = true; } void CLayerQuads::BrushFlipX() { - for(int i = 0; i < m_lQuads.size(); i++) + for(auto &Quad : m_lQuads) { - CQuad *q = &m_lQuads[i]; - - std::swap(q->m_aPoints[0], q->m_aPoints[1]); - std::swap(q->m_aPoints[2], q->m_aPoints[3]); + std::swap(Quad.m_aPoints[0], Quad.m_aPoints[1]); + std::swap(Quad.m_aPoints[2], Quad.m_aPoints[3]); } m_pEditor->m_Map.m_Modified = true; } void CLayerQuads::BrushFlipY() { - for(int i = 0; i < m_lQuads.size(); i++) + for(auto &Quad : m_lQuads) { - CQuad *q = &m_lQuads[i]; - - std::swap(q->m_aPoints[0], q->m_aPoints[2]); - std::swap(q->m_aPoints[1], q->m_aPoints[3]); + std::swap(Quad.m_aPoints[0], Quad.m_aPoints[2]); + std::swap(Quad.m_aPoints[1], Quad.m_aPoints[3]); } m_pEditor->m_Map.m_Modified = true; } @@ -192,11 +187,9 @@ void CLayerQuads::BrushRotate(float Amount) Center.x /= 2; Center.y /= 2; - for(int i = 0; i < m_lQuads.size(); i++) + for(auto &Quad : m_lQuads) { - CQuad *q = &m_lQuads[i]; - - for(auto &Point : q->m_aPoints) + for(auto &Point : Quad.m_aPoints) { vec2 Pos(fx2f(Point.x), fx2f(Point.y)); Rotate(&Center, &Pos, Amount); @@ -211,9 +204,9 @@ void CLayerQuads::GetSize(float *w, float *h) *w = 0; *h = 0; - for(int i = 0; i < m_lQuads.size(); i++) + for(const auto &Quad : m_lQuads) { - for(auto &Point : m_lQuads[i].m_aPoints) + for(const auto &Point : Quad.m_aPoints) { *w = maximum(*w, fx2f(Point.x)); *h = maximum(*h, fx2f(Point.y)); @@ -259,9 +252,9 @@ void CLayerQuads::ModifyImageIndex(INDEX_MODIFY_FUNC Func) void CLayerQuads::ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func) { - for(int i = 0; i < m_lQuads.size(); i++) + for(auto &Quad : m_lQuads) { - Func(&m_lQuads[i].m_PosEnv); - Func(&m_lQuads[i].m_ColorEnv); + Func(&Quad.m_PosEnv); + Func(&Quad.m_ColorEnv); } } diff --git a/src/game/editor/layer_sounds.cpp b/src/game/editor/layer_sounds.cpp index 4c5316f59..b92622f7c 100644 --- a/src/game/editor/layer_sounds.cpp +++ b/src/game/editor/layer_sounds.cpp @@ -23,44 +23,42 @@ void CLayerSounds::Render(bool Tileset) // draw falloff distance Graphics()->SetColor(0.6f, 0.8f, 1.0f, 0.4f); - for(int i = 0; i < m_lSources.size(); i++) + for(const auto &Source : m_lSources) { - CSoundSource *pSource = &m_lSources[i]; - float OffsetX = 0; float OffsetY = 0; - if(pSource->m_PosEnv >= 0) + if(Source.m_PosEnv >= 0) { float aChannels[4]; - m_pEditor->EnvelopeEval(pSource->m_PosEnvOffset, pSource->m_PosEnv, aChannels, m_pEditor); + m_pEditor->EnvelopeEval(Source.m_PosEnvOffset, Source.m_PosEnv, aChannels, m_pEditor); OffsetX = aChannels[0]; OffsetY = aChannels[1]; } - switch(pSource->m_Shape.m_Type) + switch(Source.m_Shape.m_Type) { case CSoundShape::SHAPE_CIRCLE: { - m_pEditor->RenderTools()->DrawCircle(fx2f(pSource->m_Position.x) + OffsetX, fx2f(pSource->m_Position.y) + OffsetY, - pSource->m_Shape.m_Circle.m_Radius, 32); + m_pEditor->RenderTools()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, + Source.m_Shape.m_Circle.m_Radius, 32); - float Falloff = ((float)pSource->m_Falloff / 255.0f); + float Falloff = ((float)Source.m_Falloff / 255.0f); if(Falloff > 0.0f) - m_pEditor->RenderTools()->DrawCircle(fx2f(pSource->m_Position.x) + OffsetX, fx2f(pSource->m_Position.y) + OffsetY, - pSource->m_Shape.m_Circle.m_Radius * Falloff, 32); + m_pEditor->RenderTools()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, + Source.m_Shape.m_Circle.m_Radius * Falloff, 32); break; } case CSoundShape::SHAPE_RECTANGLE: { - float Width = fx2f(pSource->m_Shape.m_Rectangle.m_Width); - float Height = fx2f(pSource->m_Shape.m_Rectangle.m_Height); - m_pEditor->RenderTools()->DrawRoundRect(fx2f(pSource->m_Position.x) + OffsetX - Width / 2, fx2f(pSource->m_Position.y) + OffsetY - Height / 2, + float Width = fx2f(Source.m_Shape.m_Rectangle.m_Width); + float Height = fx2f(Source.m_Shape.m_Rectangle.m_Height); + m_pEditor->RenderTools()->DrawRoundRect(fx2f(Source.m_Position.x) + OffsetX - Width / 2, fx2f(Source.m_Position.y) + OffsetY - Height / 2, Width, Height, 0.0f); - float Falloff = ((float)pSource->m_Falloff / 255.0f); + float Falloff = ((float)Source.m_Falloff / 255.0f); if(Falloff > 0.0f) - m_pEditor->RenderTools()->DrawRoundRect(fx2f(pSource->m_Position.x) + OffsetX - Falloff * Width / 2, fx2f(pSource->m_Position.y) + OffsetY - Falloff * Height / 2, + m_pEditor->RenderTools()->DrawRoundRect(fx2f(Source.m_Position.x) + OffsetX - Falloff * Width / 2, fx2f(Source.m_Position.y) + OffsetY - Falloff * Height / 2, Width * Falloff, Height * Falloff, 0.0f); break; } @@ -75,22 +73,20 @@ void CLayerSounds::Render(bool Tileset) Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); m_pEditor->RenderTools()->SelectSprite(SPRITE_AUDIO_SOURCE); - for(int i = 0; i < m_lSources.size(); i++) + for(const auto &Source : m_lSources) { - CSoundSource *pSource = &m_lSources[i]; - float OffsetX = 0; float OffsetY = 0; - if(pSource->m_PosEnv >= 0) + if(Source.m_PosEnv >= 0) { float aChannels[4]; - m_pEditor->EnvelopeEval(pSource->m_PosEnvOffset, pSource->m_PosEnv, aChannels, m_pEditor); + m_pEditor->EnvelopeEval(Source.m_PosEnvOffset, Source.m_PosEnv, aChannels, m_pEditor); OffsetX = aChannels[0]; OffsetY = aChannels[1]; } - m_pEditor->RenderTools()->DrawSprite(fx2f(pSource->m_Position.x) + OffsetX, fx2f(pSource->m_Position.y) + OffsetY, s_SourceVisualSize * m_pEditor->m_WorldZoom); + m_pEditor->RenderTools()->DrawSprite(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY, s_SourceVisualSize * m_pEditor->m_WorldZoom); } Graphics()->QuadsEnd(); @@ -100,7 +96,8 @@ CSoundSource *CLayerSounds::NewSource(int x, int y) { m_pEditor->m_Map.m_Modified = true; - CSoundSource *pSource = &m_lSources[m_lSources.add(CSoundSource())]; + m_lSources.emplace_back(); + CSoundSource *pSource = &m_lSources[m_lSources.size() - 1]; pSource->m_Position.x = f2fx(x); pSource->m_Position.y = f2fx(y); @@ -150,38 +147,36 @@ int CLayerSounds::BrushGrab(CLayerGroup *pBrush, CUIRect Rect) pGrabbed->m_Sound = m_Sound; pBrush->AddLayer(pGrabbed); - for(int i = 0; i < m_lSources.size(); i++) + for(const auto &Source : m_lSources) { - CSoundSource *pSource = &m_lSources[i]; - float px = fx2f(pSource->m_Position.x); - float py = fx2f(pSource->m_Position.y); + float px = fx2f(Source.m_Position.x); + float py = fx2f(Source.m_Position.y); if(px > Rect.x && px < Rect.x + Rect.w && py > Rect.y && py < Rect.y + Rect.h) { - CSoundSource n; - n = *pSource; + CSoundSource n = Source; n.m_Position.x -= f2fx(Rect.x); n.m_Position.y -= f2fx(Rect.y); - pGrabbed->m_lSources.add(n); + pGrabbed->m_lSources.push_back(n); } } - return pGrabbed->m_lSources.size() ? 1 : 0; + return pGrabbed->m_lSources.empty() ? 0 : 1; } void CLayerSounds::BrushPlace(CLayer *pBrush, float wx, float wy) { CLayerSounds *l = (CLayerSounds *)pBrush; - for(int i = 0; i < l->m_lSources.size(); i++) + for(const auto &Source : l->m_lSources) { - CSoundSource n = l->m_lSources[i]; + CSoundSource n = Source; n.m_Position.x += f2fx(wx); n.m_Position.y += f2fx(wy); - m_lSources.add(n); + m_lSources.push_back(n); } m_pEditor->m_Map.m_Modified = true; } @@ -224,9 +219,9 @@ void CLayerSounds::ModifySoundIndex(INDEX_MODIFY_FUNC Func) void CLayerSounds::ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func) { - for(int i = 0; i < m_lSources.size(); i++) + for(auto &Source : m_lSources) { - Func(&m_lSources[i].m_SoundEnv); - Func(&m_lSources[i].m_PosEnv); + Func(&Source.m_SoundEnv); + Func(&Source.m_PosEnv); } } diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index c7d52d5a2..65f834c70 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -1,7 +1,6 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include #include #include @@ -82,7 +81,7 @@ void CLayerTiles::MakePalette() void CLayerTiles::Render(bool Tileset) { - if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size()) + if(m_Image >= 0 && (size_t)m_Image < m_pEditor->m_Map.m_lImages.size()) m_Texture = m_pEditor->m_Map.m_lImages[m_Image]->m_Texture; Graphics()->TextureSet(m_Texture); ColorRGBA Color = ColorRGBA(m_Color.r / 255.0f, m_Color.g / 255.0f, m_Color.b / 255.0f, m_Color.a / 255.0f); @@ -793,7 +792,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox) if(m_pEditor->m_Map.m_pGameLayer != this) { - if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size() && m_pEditor->m_Map.m_lImages[m_Image]->m_AutoMapper.IsLoaded() && + if(m_Image >= 0 && (size_t)m_Image < m_pEditor->m_Map.m_lImages.size() && m_pEditor->m_Map.m_lImages[m_Image]->m_AutoMapper.IsLoaded() && m_AutoMapperConfig != -1) { static int s_AutoMapperButton = 0; @@ -926,11 +925,11 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox) } if(Prop == PROP_COLOR_ENV) { - int Index = clamp(NewVal - 1, -1, m_pEditor->m_Map.m_lEnvelopes.size() - 1); + int Index = clamp(NewVal - 1, -1, (int)m_pEditor->m_Map.m_lEnvelopes.size() - 1); int Step = (Index - m_ColorEnv) % 2; if(Step != 0) { - for(; Index >= -1 && Index < m_pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + for(; Index >= -1 && Index < (int)m_pEditor->m_Map.m_lEnvelopes.size(); Index += Step) if(Index == -1 || m_pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 4) { m_ColorEnv = Index; @@ -957,7 +956,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox) return 0; } -int CLayerTiles::RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, array &pLayers) +int CLayerTiles::RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, std::vector &pLayers) { if(State.Modified) { @@ -967,7 +966,8 @@ int CLayerTiles::RenderCommonProperties(SCommonPropState &State, CEditor *pEdito if(pEditor->DoButton_Editor(&s_CommitButton, "Commit", 0, &Commit, 0, "Applies the changes")) { dbg_msg("editor", "applying changes"); - for_each(pLayers.all(), [&State](CLayerTiles *pLayer) { + for(auto &pLayer : pLayers) + { pLayer->Resize(State.Width, State.Height); pLayer->m_Color.r = (State.Color >> 24) & 0xff; @@ -976,18 +976,19 @@ int CLayerTiles::RenderCommonProperties(SCommonPropState &State, CEditor *pEdito pLayer->m_Color.a = State.Color & 0xff; pLayer->FlagModified(0, 0, pLayer->m_Width, pLayer->m_Height); - }); + } State.Modified = false; } } else { - for_each(pLayers.all(), [&State](CLayerTiles *pLayer) { + for(auto &pLayer : pLayers) + { if(pLayer->m_Width > State.Width) State.Width = pLayer->m_Width; if(pLayer->m_Height > State.Height) State.Height = pLayer->m_Height; - }); + } } { @@ -1048,9 +1049,8 @@ int CLayerTiles::RenderCommonProperties(SCommonPropState &State, CEditor *pEdito } else if(Prop == PROP_SHIFT) { - for_each(pLayers.all(), [NewVal](CLayerTiles *pLayer) { + for(auto &pLayer : pLayers) pLayer->Shift(NewVal); - }); } else if(Prop == PROP_SHIFT_BY) pEditor->m_ShiftBy = NewVal; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 371af92ea..f82b23178 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -2,7 +2,6 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include #include #include @@ -138,11 +137,11 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View, void *pContext) if(pEditor->DoButton_Editor(&s_DeleteButton, "Clean up game tiles", 0, &Button, 0, "Removes game tiles that aren't based on a layer")) { // gather all tile layers - array Layers; - for(int i = 0; i < pEditor->m_Map.m_pGameGroup->m_lLayers.size(); ++i) + std::vector Layers; + for(auto &pLayer : pEditor->m_Map.m_pGameGroup->m_lLayers) { - if(pEditor->m_Map.m_pGameGroup->m_lLayers[i] != pEditor->m_Map.m_pGameLayer && pEditor->m_Map.m_pGameGroup->m_lLayers[i]->m_Type == LAYERTYPE_TILES) - Layers.add(static_cast(pEditor->m_Map.m_pGameGroup->m_lLayers[i])); + if(pLayer != pEditor->m_Map.m_pGameLayer && pLayer->m_Type == LAYERTYPE_TILES) + Layers.push_back(static_cast(pLayer)); } // search for unneeded game tiles @@ -154,9 +153,9 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View, void *pContext) continue; bool Found = false; - for(int i = 0; i < Layers.size(); ++i) + for(const auto &pLayer : Layers) { - if(x < Layers[i]->m_Width && y < Layers[i]->m_Height && Layers[i]->m_pTiles[y * Layers[i]->m_Width + x].m_Index) + if(x < pLayer->m_Width && y < pLayer->m_Height && pLayer->m_pTiles[y * pLayer->m_Width + x].m_Index) { Found = true; break; @@ -329,7 +328,7 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View, void *pContext) }; CProperty aProps[] = { - {"Order", pEditor->m_SelectedGroup, PROPTYPE_INT_STEP, 0, pEditor->m_Map.m_lGroups.size() - 1}, + {"Order", pEditor->m_SelectedGroup, PROPTYPE_INT_STEP, 0, (int)pEditor->m_Map.m_lGroups.size() - 1}, {"Pos X", -pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_OffsetX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {"Pos Y", -pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_OffsetY, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {"Para X", pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_ParallaxX, PROPTYPE_INT_SCROLL, -1000000, 1000000}, @@ -442,8 +441,8 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View, void *pContext) }; CProperty aProps[] = { - {"Group", pEditor->m_SelectedGroup, PROPTYPE_INT_STEP, 0, pEditor->m_Map.m_lGroups.size() - 1}, - {"Order", pEditor->m_lSelectedLayers[0], PROPTYPE_INT_STEP, 0, pCurrentGroup->m_lLayers.size()}, + {"Group", pEditor->m_SelectedGroup, PROPTYPE_INT_STEP, 0, (int)pEditor->m_Map.m_lGroups.size() - 1}, + {"Order", pEditor->m_lSelectedLayers[0], PROPTYPE_INT_STEP, 0, (int)pCurrentGroup->m_lLayers.size()}, {"Detail", pCurrentLayer && pCurrentLayer->m_Flags & LAYERFLAG_DETAIL, PROPTYPE_BOOL, 0, 1}, {0}, }; @@ -465,10 +464,12 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View, void *pContext) pEditor->SelectLayer(pCurrentGroup->SwapLayers(pEditor->m_lSelectedLayers[0], NewVal)); else if(Prop == PROP_GROUP && pCurrentLayer && pCurrentLayer->m_Type != LAYERTYPE_GAME) { - if(NewVal >= 0 && NewVal < pEditor->m_Map.m_lGroups.size()) + if(NewVal >= 0 && (size_t)NewVal < pEditor->m_Map.m_lGroups.size()) { - pCurrentGroup->m_lLayers.remove(pCurrentLayer); - pEditor->m_Map.m_lGroups[NewVal]->m_lLayers.add(pCurrentLayer); + auto Position = std::find(pCurrentGroup->m_lLayers.begin(), pCurrentGroup->m_lLayers.end(), pCurrentLayer); + if(Position != pCurrentGroup->m_lLayers.end()) + pCurrentGroup->m_lLayers.erase(Position); + pEditor->m_Map.m_lGroups[NewVal]->m_lLayers.push_back(pCurrentLayer); pEditor->m_SelectedGroup = NewVal; pEditor->SelectLayer(pEditor->m_Map.m_lGroups[NewVal]->m_lLayers.size() - 1); } @@ -487,7 +488,7 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext) { - array lQuads = pEditor->GetSelectedQuads(); + std::vector lQuads = pEditor->GetSelectedQuads(); CQuad *pCurrentQuad = lQuads[pEditor->m_SelectedQuadIndex]; CUIRect Button; @@ -510,37 +511,37 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext) View.HSplitBottom(10.0f, &View, &Button); View.HSplitBottom(12.0f, &View, &Button); CLayerQuads *pLayer = (CLayerQuads *)pEditor->GetSelectedLayerType(0, LAYERTYPE_QUADS); - if(pLayer && pLayer->m_Image >= 0 && pLayer->m_Image < pEditor->m_Map.m_lImages.size()) + if(pLayer && pLayer->m_Image >= 0 && (size_t)pLayer->m_Image < pEditor->m_Map.m_lImages.size()) { static int s_AspectRatioButton = 0; if(pEditor->DoButton_Editor(&s_AspectRatioButton, "Aspect ratio", 0, &Button, 0, "Resizes the current Quad based on the aspect ratio of the image")) { - for(int i = 0; i < lQuads.size(); ++i) + for(auto &pQuad : lQuads) { - int Top = lQuads[i]->m_aPoints[0].y; - int Left = lQuads[i]->m_aPoints[0].x; - int Right = lQuads[i]->m_aPoints[0].x; + int Top = pQuad->m_aPoints[0].y; + int Left = pQuad->m_aPoints[0].x; + int Right = pQuad->m_aPoints[0].x; for(int k = 1; k < 4; k++) { - if(lQuads[i]->m_aPoints[k].y < Top) - Top = lQuads[i]->m_aPoints[k].y; - if(lQuads[i]->m_aPoints[k].x < Left) - Left = lQuads[i]->m_aPoints[k].x; - if(lQuads[i]->m_aPoints[k].x > Right) - Right = lQuads[i]->m_aPoints[k].x; + if(pQuad->m_aPoints[k].y < Top) + Top = pQuad->m_aPoints[k].y; + if(pQuad->m_aPoints[k].x < Left) + Left = pQuad->m_aPoints[k].x; + if(pQuad->m_aPoints[k].x > Right) + Right = pQuad->m_aPoints[k].x; } int Height = (Right - Left) * pEditor->m_Map.m_lImages[pLayer->m_Image]->m_Height / pEditor->m_Map.m_lImages[pLayer->m_Image]->m_Width; - lQuads[i]->m_aPoints[0].x = Left; - lQuads[i]->m_aPoints[0].y = Top; - lQuads[i]->m_aPoints[1].x = Right; - lQuads[i]->m_aPoints[1].y = Top; - lQuads[i]->m_aPoints[2].x = Left; - lQuads[i]->m_aPoints[2].y = Top + Height; - lQuads[i]->m_aPoints[3].x = Right; - lQuads[i]->m_aPoints[3].y = Top + Height; + pQuad->m_aPoints[0].x = Left; + pQuad->m_aPoints[0].y = Top; + pQuad->m_aPoints[1].x = Right; + pQuad->m_aPoints[1].y = Top; + pQuad->m_aPoints[2].x = Left; + pQuad->m_aPoints[2].y = Top + Height; + pQuad->m_aPoints[3].x = Right; + pQuad->m_aPoints[3].y = Top + Height; pEditor->m_Map.m_Modified = true; } return 1; @@ -553,12 +554,12 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext) static int s_AlignButton = 0; if(pEditor->DoButton_Editor(&s_AlignButton, "Align", 0, &Button, 0, "Aligns coordinates of the quad points")) { - for(int i = 0; i < lQuads.size(); ++i) + for(auto &pQuad : lQuads) { for(int k = 1; k < 4; k++) { - lQuads[i]->m_aPoints[k].x = 1000.0f * (lQuads[i]->m_aPoints[k].x / 1000); - lQuads[i]->m_aPoints[k].y = 1000.0f * (lQuads[i]->m_aPoints[k].y / 1000); + pQuad->m_aPoints[k].x = 1000.0f * (pQuad->m_aPoints[k].x / 1000); + pQuad->m_aPoints[k].y = 1000.0f * (pQuad->m_aPoints[k].y / 1000); } pEditor->m_Map.m_Modified = true; } @@ -571,33 +572,33 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext) static int s_Button = 0; if(pEditor->DoButton_Editor(&s_Button, "Square", 0, &Button, 0, "Squares the current quad")) { - for(int i = 0; i < lQuads.size(); ++i) + for(auto &pQuad : lQuads) { - int Top = lQuads[i]->m_aPoints[0].y; - int Left = lQuads[i]->m_aPoints[0].x; - int Bottom = lQuads[i]->m_aPoints[0].y; - int Right = lQuads[i]->m_aPoints[0].x; + int Top = pQuad->m_aPoints[0].y; + int Left = pQuad->m_aPoints[0].x; + int Bottom = pQuad->m_aPoints[0].y; + int Right = pQuad->m_aPoints[0].x; for(int k = 1; k < 4; k++) { - if(lQuads[i]->m_aPoints[k].y < Top) - Top = lQuads[i]->m_aPoints[k].y; - if(lQuads[i]->m_aPoints[k].x < Left) - Left = lQuads[i]->m_aPoints[k].x; - if(lQuads[i]->m_aPoints[k].y > Bottom) - Bottom = lQuads[i]->m_aPoints[k].y; - if(lQuads[i]->m_aPoints[k].x > Right) - Right = lQuads[i]->m_aPoints[k].x; + if(pQuad->m_aPoints[k].y < Top) + Top = pQuad->m_aPoints[k].y; + if(pQuad->m_aPoints[k].x < Left) + Left = pQuad->m_aPoints[k].x; + if(pQuad->m_aPoints[k].y > Bottom) + Bottom = pQuad->m_aPoints[k].y; + if(pQuad->m_aPoints[k].x > Right) + Right = pQuad->m_aPoints[k].x; } - lQuads[i]->m_aPoints[0].x = Left; - lQuads[i]->m_aPoints[0].y = Top; - lQuads[i]->m_aPoints[1].x = Right; - lQuads[i]->m_aPoints[1].y = Top; - lQuads[i]->m_aPoints[2].x = Left; - lQuads[i]->m_aPoints[2].y = Bottom; - lQuads[i]->m_aPoints[3].x = Right; - lQuads[i]->m_aPoints[3].y = Bottom; + pQuad->m_aPoints[0].x = Left; + pQuad->m_aPoints[0].y = Top; + pQuad->m_aPoints[1].x = Right; + pQuad->m_aPoints[1].y = Top; + pQuad->m_aPoints[2].x = Left; + pQuad->m_aPoints[2].y = Bottom; + pQuad->m_aPoints[3].x = Right; + pQuad->m_aPoints[3].y = Bottom; pEditor->m_Map.m_Modified = true; } return 1; @@ -645,50 +646,50 @@ int CEditor::PopupQuad(CEditor *pEditor, CUIRect View, void *pContext) float OffsetX = i2fx(NewVal) - pCurrentQuad->m_aPoints[4].x; float OffsetY = i2fx(NewVal) - pCurrentQuad->m_aPoints[4].y; - for(int i = 0; i < lQuads.size(); ++i) + for(auto &pQuad : lQuads) { if(Prop == PROP_POS_X) { - for(auto &Point : lQuads[i]->m_aPoints) + for(auto &Point : pQuad->m_aPoints) Point.x += OffsetX; } if(Prop == PROP_POS_Y) { - for(auto &Point : lQuads[i]->m_aPoints) + for(auto &Point : pQuad->m_aPoints) Point.y += OffsetY; } if(Prop == PROP_POS_ENV) { - int Index = clamp(NewVal - 1, -1, pEditor->m_Map.m_lEnvelopes.size() - 1); - int Step = (Index - lQuads[i]->m_PosEnv) % 2; + int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_lEnvelopes.size() - 1); + int Step = (Index - pQuad->m_PosEnv) % 2; if(Step != 0) { - for(; Index >= -1 && Index < pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + for(; Index >= -1 && Index < (int)pEditor->m_Map.m_lEnvelopes.size(); Index += Step) if(Index == -1 || pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 3) { - lQuads[i]->m_PosEnv = Index; + pQuad->m_PosEnv = Index; break; } } } if(Prop == PROP_POS_ENV_OFFSET) - lQuads[i]->m_PosEnvOffset = NewVal; + pQuad->m_PosEnvOffset = NewVal; if(Prop == PROP_COLOR_ENV) { - int Index = clamp(NewVal - 1, -1, pEditor->m_Map.m_lEnvelopes.size() - 1); - int Step = (Index - lQuads[i]->m_ColorEnv) % 2; + int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_lEnvelopes.size() - 1); + int Step = (Index - pQuad->m_ColorEnv) % 2; if(Step != 0) { - for(; Index >= -1 && Index < pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + for(; Index >= -1 && Index < (int)pEditor->m_Map.m_lEnvelopes.size(); Index += Step) if(Index == -1 || pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 4) { - lQuads[i]->m_ColorEnv = Index; + pQuad->m_ColorEnv = Index; break; } } } if(Prop == PROP_COLOR_ENV_OFFSET) - lQuads[i]->m_ColorEnvOffset = NewVal; + pQuad->m_ColorEnvOffset = NewVal; } return 0; @@ -709,7 +710,7 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View, void *pContext) if(pLayer) { pEditor->m_Map.m_Modified = true; - pLayer->m_lSources.remove_index(pEditor->m_SelectedSource); + pLayer->m_lSources.erase(pLayer->m_lSources.begin() + pEditor->m_SelectedSource); pEditor->m_SelectedSource--; } return 1; @@ -798,11 +799,11 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View, void *pContext) pSource->m_Falloff = NewVal; if(Prop == PROP_POS_ENV) { - int Index = clamp(NewVal - 1, -1, pEditor->m_Map.m_lEnvelopes.size() - 1); + int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_lEnvelopes.size() - 1); int Step = (Index - pSource->m_PosEnv) % 2; if(Step != 0) { - for(; Index >= -1 && Index < pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + for(; Index >= -1 && Index < (int)pEditor->m_Map.m_lEnvelopes.size(); Index += Step) if(Index == -1 || pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 3) { pSource->m_PosEnv = Index; @@ -814,11 +815,11 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View, void *pContext) pSource->m_PosEnvOffset = NewVal; if(Prop == PROP_SOUND_ENV) { - int Index = clamp(NewVal - 1, -1, pEditor->m_Map.m_lEnvelopes.size() - 1); + int Index = clamp(NewVal - 1, -1, (int)pEditor->m_Map.m_lEnvelopes.size() - 1); int Step = (Index - pSource->m_SoundEnv) % 2; if(Step != 0) { - for(; Index >= -1 && Index < pEditor->m_Map.m_lEnvelopes.size(); Index += Step) + for(; Index >= -1 && Index < (int)pEditor->m_Map.m_lEnvelopes.size(); Index += Step) if(Index == -1 || pEditor->m_Map.m_lEnvelopes[Index]->m_Channels == 1) { pSource->m_SoundEnv = Index; @@ -896,7 +897,7 @@ int CEditor::PopupSource(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupPoint(CEditor *pEditor, CUIRect View, void *pContext) { - array lQuads = pEditor->GetSelectedQuads(); + std::vector lQuads = pEditor->GetSelectedQuads(); CQuad *pCurrentQuad = lQuads[pEditor->m_SelectedQuadIndex]; enum @@ -923,7 +924,7 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View, void *pContext) CProperty aProps[] = { {"Pos X", x, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {"Pos Y", y, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Color", Color, PROPTYPE_COLOR, -1, pEditor->m_Map.m_lEnvelopes.size()}, + {"Color", Color, PROPTYPE_COLOR, -1, (int)pEditor->m_Map.m_lEnvelopes.size()}, {"Tex U", tu, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {"Tex V", tv, PROPTYPE_INT_SCROLL, -1000000, 1000000}, {0}, @@ -935,19 +936,19 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View, void *pContext) if(Prop != -1) pEditor->m_Map.m_Modified = true; - for(int i = 0; i < lQuads.size(); ++i) + for(auto &pQuad : lQuads) { if(Prop == PROP_POS_X) { for(int v = 0; v < 4; v++) if(pEditor->m_SelectedPoints & (1 << v)) - lQuads[i]->m_aPoints[v].x = i2fx(NewVal); + pQuad->m_aPoints[v].x = i2fx(NewVal); } if(Prop == PROP_POS_Y) { for(int v = 0; v < 4; v++) if(pEditor->m_SelectedPoints & (1 << v)) - lQuads[i]->m_aPoints[v].y = i2fx(NewVal); + pQuad->m_aPoints[v].y = i2fx(NewVal); } if(Prop == PROP_COLOR) { @@ -955,10 +956,10 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View, void *pContext) { if(pEditor->m_SelectedPoints & (1 << v)) { - lQuads[i]->m_aColors[v].r = (NewVal >> 24) & 0xff; - lQuads[i]->m_aColors[v].g = (NewVal >> 16) & 0xff; - lQuads[i]->m_aColors[v].b = (NewVal >> 8) & 0xff; - lQuads[i]->m_aColors[v].a = NewVal & 0xff; + pQuad->m_aColors[v].r = (NewVal >> 24) & 0xff; + pQuad->m_aColors[v].g = (NewVal >> 16) & 0xff; + pQuad->m_aColors[v].b = (NewVal >> 8) & 0xff; + pQuad->m_aColors[v].a = NewVal & 0xff; } } } @@ -966,13 +967,13 @@ int CEditor::PopupPoint(CEditor *pEditor, CUIRect View, void *pContext) { for(int v = 0; v < 4; v++) if(pEditor->m_SelectedPoints & (1 << v)) - lQuads[i]->m_aTexcoords[v].x = f2fx(NewVal / 1024.0f); + pQuad->m_aTexcoords[v].x = f2fx(NewVal / 1024.0f); } if(Prop == PROP_TEX_V) { for(int v = 0; v < 4; v++) if(pEditor->m_SelectedPoints & (1 << v)) - lQuads[i]->m_aTexcoords[v].y = f2fx(NewVal / 1024.0f); + pQuad->m_aTexcoords[v].y = f2fx(NewVal / 1024.0f); } } @@ -1251,7 +1252,7 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View, void *pContext) float ImageStopAt = ImagesHeight - ScrollDifference * (1 - s_ScrollValue); float ImageCur = 0.0f; - for(int i = -1; i < pEditor->m_Map.m_lImages.size(); i++) + for(int i = -1; i < (int)pEditor->m_Map.m_lImages.size(); i++) { if(ImageCur > ImageStopAt) break; @@ -1280,7 +1281,7 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View, void *pContext) } } - if(ShowImage >= 0 && ShowImage < pEditor->m_Map.m_lImages.size()) + if(ShowImage >= 0 && (size_t)ShowImage < pEditor->m_Map.m_lImages.size()) { if(ImageView.h < ImageView.w) ImageView.w = ImageView.h; @@ -1358,7 +1359,7 @@ int CEditor::PopupSelectSound(CEditor *pEditor, CUIRect View, void *pContext) float SoundStopAt = SoundsHeight - ScrollDifference * (1 - s_ScrollValue); float SoundCur = 0.0f; - for(int i = -1; i < pEditor->m_Map.m_lSounds.size(); i++) + for(int i = -1; i < (int)pEditor->m_Map.m_lSounds.size(); i++) { if(SoundCur > SoundStopAt) break;