1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Optimization for CGameInfoCallback:getPlayer function. It also seems to be called more often than needed.

This commit is contained in:
DjWarmonger 2015-08-30 20:51:22 +02:00
parent cdad9f88b7
commit 70801309bd

View File

@ -61,17 +61,26 @@ bool CGameInfoCallback::isAllowed( int type, int id )
const PlayerState * CGameInfoCallback::getPlayer(PlayerColor color, bool verbose) const
{
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!hasAccess(color), verbose, "Cannot access player " << color << "info!", nullptr);
//if (!vstd::contains(gs->players, color))
//{
// logGlobal->errorStream() << "Cannot access player " << color << "info!";
// return nullptr; //macros are not really useful when debugging :?
//}
//else
//{
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!vstd::contains(gs->players,color), verbose, "Cannot find player " << color << "info!", nullptr);
return &gs->players[color];
//}
//funtion written from scratch since it's accessed A LOT by AI
auto player = gs->players.find(color);
if (player != gs->players.end())
{
if (hasAccess(color))
return &player->second;
else
{
if (verbose)
logGlobal->errorStream() << boost::format("Cannot access player %d info!") % color;
return nullptr;
}
}
else
{
if (verbose)
logGlobal->errorStream() << boost::format("Cannot find player %d info!") % color;
return nullptr;
}
}
const CTown * CGameInfoCallback::getNativeTown(PlayerColor color) const