Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit e0f35c6

Browse files
committed
Replace a bunch of iterators with range loops
1 parent 422c41b commit e0f35c6

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

Managers/FrameMan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ namespace RTE {
788788
if (IsInMultiplayerMode()) {
789789
unsigned short layerCount = 0;
790790

791-
for (std::list<SceneLayer *>::reverse_iterator itr = g_SceneMan.GetScene()->GetBackLayers().rbegin(); itr != g_SceneMan.GetScene()->GetBackLayers().rend(); ++itr) {
792-
SLOffset[playerScreen][layerCount] = (*itr)->GetOffset();
791+
for (const SceneLayer *sceneLayer : g_SceneMan.GetScene()->GetBackLayers()) {
792+
SLOffset[playerScreen][layerCount] = sceneLayer->GetOffset();
793793
layerCount++;
794794

795795
if (layerCount >= c_MaxLayersStoredForNetwork) {

Managers/PerformanceMan.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ namespace RTE {
6767

6868
// Calculate the average milliseconds per frame over the last sampleSize frames
6969
m_MSPFAverage = 0;
70-
for (std::deque<unsigned int>::iterator fItr = m_MSPFs.begin(); fItr != m_MSPFs.end(); ++fItr) {
71-
m_MSPFAverage += *fItr;
70+
for (const unsigned int &mspf : m_MSPFs) {
71+
m_MSPFAverage += mspf;
7272
}
7373
m_MSPFAverage /= m_MSPFs.size();
7474

@@ -149,8 +149,8 @@ namespace RTE {
149149
m_MSPFs.pop_front();
150150
}
151151
// Calculate the average milliseconds per frame over the last sampleSize frames
152-
for (deque<unsigned int>::iterator fItr = m_MSPFs.begin(); fItr != m_MSPFs.end(); ++fItr) {
153-
m_MSPFAverage += *fItr;
152+
for(const unsigned int &mspf : m_MSPFs){
153+
m_MSPFAverage += mspf;
154154
}
155155
m_MSPFAverage /= m_MSPFs.size();
156156

Managers/PostProcessMan.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ namespace RTE {
7575
if (g_FrameMan.GetDrawNetworkBackBuffer()) { g_PostProcessMan.GetNetworkPostEffectsList(0, screenRelativeEffectsList); }
7676

7777
// Adjust for the player screen's position on the final buffer
78-
for (list<PostEffect>::iterator eItr = screenRelativeEffectsList.begin(); eItr != screenRelativeEffectsList.end(); ++eItr) {
78+
for (const PostEffect &postEffect : screenRelativeEffectsList) {
7979
// Make sure we won't be adding any effects to a part of the screen that is occluded by menus and such
80-
if ((*eItr).m_Pos.m_X > screenOcclusionOffsetX && (*eItr).m_Pos.m_Y > screenOcclusionOffsetY && (*eItr).m_Pos.m_X < occludedOffsetX && (*eItr).m_Pos.m_Y < occludedOffsetY) {
81-
g_PostProcessMan.GetPostScreenEffectsList()->push_back(PostEffect((*eItr).m_Pos + targetBitmapOffset, (*eItr).m_Bitmap, (*eItr).m_BitmapHash, (*eItr).m_Strength, (*eItr).m_Angle));
80+
if (postEffect.m_Pos.m_X > screenOcclusionOffsetX && postEffect.m_Pos.m_Y > screenOcclusionOffsetY && postEffect.m_Pos.m_X < occludedOffsetX && postEffect.m_Pos.m_Y < occludedOffsetY) {
81+
g_PostProcessMan.GetPostScreenEffectsList()->push_back(PostEffect(postEffect.m_Pos + targetBitmapOffset, postEffect.m_Bitmap, postEffect.m_BitmapHash, postEffect.m_Strength, postEffect.m_Angle));
8282
}
8383
}
8484
// Adjust glow areas for the player screen's position on the final buffer
85-
for (list<Box>::iterator bItr = screenRelativeGlowBoxesList.begin(); bItr != screenRelativeGlowBoxesList.end(); ++bItr) {
86-
g_PostProcessMan.GetPostScreenGlowBoxesList()->push_back(*bItr);
85+
for (const Box &glowBox : screenRelativeGlowBoxesList) {
86+
g_PostProcessMan.GetPostScreenGlowBoxesList()->push_back(glowBox);
8787
// Adjust each added glow area for the player screen's position on the final buffer
8888
g_PostProcessMan.GetPostScreenGlowBoxesList()->back().m_Corner += targetBitmapOffset;
8989
}
@@ -153,15 +153,16 @@ namespace RTE {
153153

154154
// Account for wrapping in any registered glow IntRects, as well as on the box we're testing against
155155
std::list<IntRect> wrappedGlowRects;
156-
for (std::list<IntRect>::iterator grItr = m_GlowAreas.begin(); grItr != m_GlowAreas.end(); ++grItr) {
157-
g_SceneMan.WrapRect((*grItr), wrappedGlowRects);
156+
157+
for(const IntRect &glowArea : m_GlowAreas) {
158+
g_SceneMan.WrapRect(glowArea, wrappedGlowRects);
158159
}
159160
std::list<IntRect> wrappedTestRects;
160161
g_SceneMan.WrapRect(IntRect(boxPos.m_X, boxPos.m_Y, boxPos.m_X + boxWidth, boxPos.m_Y + boxHeight), wrappedTestRects);
161162

162163
// Check for intersections. If any are found, cut down the intersecting IntRect to the bounds of the IntRect we're testing against, then make and store a Box out of it
163-
for (IntRect wrappedTestRect : wrappedTestRects) {
164-
for (IntRect wrappedGlowRect : wrappedGlowRects) {
164+
for (IntRect &wrappedTestRect : wrappedTestRects) {
165+
for (IntRect &wrappedGlowRect : wrappedGlowRects) {
165166
if (wrappedTestRect.Intersects(wrappedGlowRect)) {
166167
IntRect cutRect(wrappedGlowRect);
167168
cutRect.IntersectionCut(wrappedTestRect);
@@ -179,8 +180,8 @@ namespace RTE {
179180
void PostProcessMan::GetNetworkPostEffectsList(short whichScreen, std::list<PostEffect> & outputList) {
180181
ScreenRelativeEffectsMutex[whichScreen].lock();
181182
outputList.clear();
182-
for (std::list<PostEffect>::iterator eItr = m_ScreenRelativeEffects[whichScreen].begin(); eItr != m_ScreenRelativeEffects[whichScreen].end(); ++eItr) {
183-
outputList.push_back(PostEffect((*eItr).m_Pos, (*eItr).m_Bitmap, (*eItr).m_BitmapHash, (*eItr).m_Strength, (*eItr).m_Angle));
183+
for (const PostEffect &postEffect : m_ScreenRelativeEffects[whichScreen]) {
184+
outputList.push_back(PostEffect(postEffect.m_Pos, postEffect.m_Bitmap, postEffect.m_BitmapHash, postEffect.m_Strength, postEffect.m_Angle));
184185
}
185186
ScreenRelativeEffectsMutex[whichScreen].unlock();
186187
}
@@ -190,8 +191,8 @@ namespace RTE {
190191
void PostProcessMan::SetNetworkPostEffectsList(short whichScreen, std::list<PostEffect> & inputList) {
191192
ScreenRelativeEffectsMutex[whichScreen].lock();
192193
m_ScreenRelativeEffects[whichScreen].clear();
193-
for (std::list<PostEffect>::iterator eItr = inputList.begin(); eItr != inputList.end(); ++eItr) {
194-
m_ScreenRelativeEffects[whichScreen].push_back(PostEffect((*eItr).m_Pos, (*eItr).m_Bitmap, (*eItr).m_BitmapHash, (*eItr).m_Strength, (*eItr).m_Angle));
194+
for (const PostEffect &postEffect : inputList) {
195+
m_ScreenRelativeEffects[whichScreen].push_back(PostEffect(postEffect.m_Pos, postEffect.m_Bitmap, postEffect.m_BitmapHash, postEffect.m_Strength, postEffect.m_Angle));
195196
}
196197
ScreenRelativeEffectsMutex[whichScreen].unlock();
197198
}
@@ -203,13 +204,13 @@ namespace RTE {
203204
bool unseen = false;
204205
Vector postEffectPosRelativeToBox;
205206

206-
for (std::list<PostEffect>::iterator itr = m_PostSceneEffects.begin(); itr != m_PostSceneEffects.end(); ++itr) {
207-
if (team != Activity::NOTEAM) { unseen = g_SceneMan.IsUnseen((*itr).m_Pos.m_X, (*itr).m_Pos.m_Y, team); }
207+
for (PostEffect &scenePostEffect : m_PostSceneEffects) {
208+
if (team != Activity::NOTEAM) { unseen = g_SceneMan.IsUnseen(scenePostEffect.m_Pos.m_X, scenePostEffect.m_Pos.m_Y, team); }
208209

209-
if (WithinBox((*itr).m_Pos, boxPos, boxWidth, boxHeight) && !unseen) {
210+
if (WithinBox(scenePostEffect.m_Pos, boxPos, boxWidth, boxHeight) && !unseen) {
210211
found = true;
211-
postEffectPosRelativeToBox = (*itr).m_Pos - boxPos;
212-
effectsList.push_back(PostEffect(postEffectPosRelativeToBox, (*itr).m_Bitmap, (*itr).m_BitmapHash, (*itr).m_Strength, (*itr).m_Angle));
212+
postEffectPosRelativeToBox = scenePostEffect.m_Pos - boxPos;
213+
effectsList.push_back(PostEffect(postEffectPosRelativeToBox, scenePostEffect.m_Bitmap, scenePostEffect.m_BitmapHash, scenePostEffect.m_Strength, scenePostEffect.m_Angle));
213214
}
214215
}
215216
return found;
@@ -222,13 +223,13 @@ namespace RTE {
222223
bool unseen = false;
223224
Vector postEffectPosRelativeToBox;
224225

225-
for (std::list<PostEffect>::iterator itr = m_PostSceneEffects.begin(); itr != m_PostSceneEffects.end(); ++itr) {
226-
if (team != Activity::NOTEAM) { unseen = g_SceneMan.IsUnseen((*itr).m_Pos.m_X, (*itr).m_Pos.m_Y, team); }
226+
for (PostEffect &scenePostEffect : m_PostSceneEffects) {
227+
if (team != Activity::NOTEAM) { unseen = g_SceneMan.IsUnseen(scenePostEffect.m_Pos.m_X, scenePostEffect.m_Pos.m_Y, team); }
227228

228-
if (WithinBox((*itr).m_Pos, left, top, right, bottom) && !unseen) {
229+
if (WithinBox(scenePostEffect.m_Pos, left, top, right, bottom) && !unseen) {
229230
found = true;
230-
postEffectPosRelativeToBox = Vector((*itr).m_Pos.m_X - left, (*itr).m_Pos.m_Y - top);
231-
effectsList.push_back(PostEffect(postEffectPosRelativeToBox, (*itr).m_Bitmap, (*itr).m_BitmapHash, (*itr).m_Strength, (*itr).m_Angle));
231+
postEffectPosRelativeToBox = Vector(scenePostEffect.m_Pos.m_X - left, scenePostEffect.m_Pos.m_Y - top);
232+
effectsList.push_back(PostEffect(postEffectPosRelativeToBox, scenePostEffect.m_Bitmap, scenePostEffect.m_BitmapHash, scenePostEffect.m_Strength, scenePostEffect.m_Angle));
232233
}
233234
}
234235
return found;
@@ -309,12 +310,11 @@ namespace RTE {
309310

310311
// Randomly sample the entire backbuffer, looking for pixels to put a glow on.
311312
// NOTE THIS IS SLOW, especially on higher resolutions!
312-
for (std::list<Box>::iterator bItr = m_PostScreenGlowBoxes.begin(); bItr != m_PostScreenGlowBoxes.end(); ++bItr) {
313-
startX = (*bItr).m_Corner.m_X;
314-
startY = (*bItr).m_Corner.m_Y;
315-
endX = startX + (*bItr).m_Width;
316-
endY = startY + (*bItr).m_Height;
317-
testpixel = 0;
313+
for (const Box &glowBox : m_PostScreenGlowBoxes) {
314+
startX = glowBox.m_Corner.m_X;
315+
startY = glowBox.m_Corner.m_Y;
316+
endX = startX + glowBox.m_Width;
317+
endY = startY + glowBox.m_Height;
318318

319319
// Sanity check a little at least
320320
if (startX < 0 || startX >= g_FrameMan.GetBackBuffer8()->w || startY < 0 || startY >= g_FrameMan.GetBackBuffer8()->h ||

Managers/PrimitiveMan.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ namespace RTE {
2929
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3030

3131
void PrimitiveMan::ClearPrimitivesList() {
32-
for (std::list<GraphicalPrimitive *>::const_iterator it = m_Primitives.begin(); it != m_Primitives.end(); ++it) {
33-
delete (*it);
32+
for (const GraphicalPrimitive *primitive : m_Primitives) {
33+
delete primitive;
3434
}
3535
m_Primitives.clear();
3636
}
3737

3838
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3939

4040
void PrimitiveMan::DrawPrimitives(short player, BITMAP *pTargetBitmap, const Vector &targetPos) {
41-
for (std::list<GraphicalPrimitive *>::const_iterator it = m_Primitives.begin(); it != m_Primitives.end(); ++it) {
42-
if (player == (*it)->m_Player || (*it)->m_Player == -1) { (*it)->Draw(pTargetBitmap, targetPos); }
41+
for (GraphicalPrimitive *primitive : m_Primitives) {
42+
if (player == primitive->m_Player || primitive->m_Player == -1) { primitive->Draw(pTargetBitmap, targetPos); }
4343
}
4444
}
4545
}

0 commit comments

Comments
 (0)