1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-07 00:58:39 +02:00

int3 dist2d microoptimization

This commit is contained in:
karol57
2014-05-25 20:42:25 +02:00
parent df8cce0d61
commit dd33fd51a8
5 changed files with 18 additions and 17 deletions

View File

@ -744,23 +744,26 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
if (h->getSpellSchoolLevel(CGI->spellh->objects[spell]) < 2) //not advanced or expert - teleport to nearest available city
{
int nearest = -1; //nearest town's ID
double dist = -1;
for (int g=0; g<Towns.size(); ++g)
auto nearest = Towns.cbegin(); //nearest town's iterator
si32 dist = LOCPLINT->cb->getTown((*nearest)->id)->pos.dist2dSQ(h->pos);
for (auto i = nearest + 1; i != Towns.cend(); ++i)
{
const CGTownInstance * dest = LOCPLINT->cb->getTown(Towns[g]->id);
double curDist = dest->pos.dist2d(h->pos);
if (nearest == -1 || curDist < dist)
const CGTownInstance * dest = LOCPLINT->cb->getTown((*i)->id);
si32 curDist = dest->pos.dist2dSQ(h->pos);
if (curDist < dist)
{
nearest = g;
nearest = i;
dist = curDist;
}
}
if ( Towns[nearest]->visitingHero )
if ((*nearest)->visitingHero)
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[123]);
else
{
const CGTownInstance * town = LOCPLINT->cb->getTown(Towns[nearest]->id);
const CGTownInstance * town = LOCPLINT->cb->getTown((*nearest)->id);
LOCPLINT->cb->castSpell(h, spell, town->visitablePos());// - town->getVisitableOffset());
}
}