Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove loop* and loopv* macros from menus.cpp #175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions src/engine/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ bool pop_ui(bool skip = true)

bool remove_ui(menu *m)
{
loopv(menustack) if(menustack[i] == m)
for (int i = 0; i < menustack.length(); i++)
{
if (menustack[i] != m)
{
continue;
}
menustack.remove(i);
m->passes = 0;
if(m->keep) *m->keep = false;
Expand Down Expand Up @@ -164,7 +168,10 @@ bool push_ui(menu *m, int pos = -1, int tab = 0, bool *keep = NULL)
bool restore_ui(int pos, int tab = 0, bool *keep = NULL)
{
int clear = menustack.length()-pos-1;
loopi(clear) pop_ui();
for (int i = 0; i < clear; i++)
{
pop_ui();
}
menu *m = menustack.last();
if(m)
{
Expand Down Expand Up @@ -198,7 +205,13 @@ int cleargui(int n, bool skip)
if(closetexgui()) n--;
int clear = menustack.length();
if(n>0) clear = min(clear, n);
loopi(clear) if(!pop_ui(skip)) break;
for (int i = 0; i < clear; i++)
{
if (!pop_ui(skip))
{
break;
}
}
if(!menustack.empty()) restore_ui(menustack.length() - 1);
return clear;
}
Expand Down Expand Up @@ -850,7 +863,10 @@ static struct applymenu : menu
g.start(menu_start, NULL, true);
g.text("the following settings have changed:");
g.pushfont("little");
loopv(needsapply) g.text(needsapply[i].desc, 0xFFFFFF, "point");
for (int i = 0; i < needsapply.length(); i++)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest not to just stubbornly replace all occurrences of the macro, but just go for the more modern iterator-based loops where applicable. How about

Suggested change
for (int i = 0; i < needsapply.length(); i++)
for (const auto& i : needsapply)

If you can not use this approach, please don't use the deprecated length() but the STL-compatible size().

Applies to pretty much all loops you modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll do that

{
g.text(needsapply[i].desc, 0xFFFFFF, "point");
}
g.popfont();
g.separator();
g.text("apply changes now?");
Expand All @@ -859,7 +875,10 @@ static struct applymenu : menu
if(g.button("\fgOK")&GUI_UP)
{
int changetypes = 0;
loopv(needsapply) changetypes |= needsapply[i].type;
for (int i = 0; i < needsapply.length(); i++)
{
changetypes |= needsapply[i].type;
}
if(changetypes&CHANGE_GFX) updatelater.add().schedule("resetgl");
if(changetypes&CHANGE_SOUND) updatelater.add().schedule("resetsound");
clearlater = true;
Expand All @@ -886,15 +905,24 @@ void addchange(const char *desc, int type, bool force)
int changetypes = type;
if(menustack.find(&applymenu) >= 0)
{
loopv(needsapply) changetypes |= needsapply[i].type;
for (int i = 0; i < needsapply.length(); i++)
{
changetypes |= needsapply[i].type;
}
clearlater = true;
}
if(changetypes&CHANGE_GFX) updatelater.add().schedule("resetgl");
if(changetypes&CHANGE_SOUND) updatelater.add().schedule("resetsound");
}
else
{
loopv(needsapply) if(!strcmp(needsapply[i].desc, desc)) return;
for (int i = 0; i < needsapply.length(); i++)
{
if (!strcmp(needsapply[i].desc, desc))
{
return;
}
}
needsapply.add(change(type, desc));
if(needsapply.length() && menustack.find(&applymenu) < 0)
push_ui(&applymenu, max(menustack.length() - 1, 0));
Expand All @@ -903,7 +931,7 @@ void addchange(const char *desc, int type, bool force)

void clearchanges(int type)
{
loopv(needsapply)
for (int i = 0; i < needsapply.length(); i++)
{
if(needsapply[i].type&type)
{
Expand All @@ -918,12 +946,21 @@ void menuprocess()
{
int level = menustack.length();
interactive = true;
loopv(updatelater) updatelater[i].run();
for (int i = 0; i < updatelater.length(); i++)
{
updatelater[i].run();
}
updatelater.shrink(0);
interactive = false;
if(clearlater)
{
if(level==menustack.length()) loopi(level) pop_ui();
if (level==menustack.length())
{
for (int i = 0; i < level; i++)
{
pop_ui();
}
}
clearlater = false;
}
}
Expand Down