mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-15 22:16:37 +02:00
Fixed high CPU usage by mapHandler::hideObject
This commit is contained in:
parent
fe2a72f543
commit
32f3f9d76d
@ -1329,22 +1329,26 @@ bool CMapHandler::printObject(const CGObjectInstance *obj, bool fadein /* = fals
|
|||||||
|
|
||||||
bool CMapHandler::hideObject(const CGObjectInstance *obj, bool fadeout /* = false */)
|
bool CMapHandler::hideObject(const CGObjectInstance *obj, bool fadeout /* = false */)
|
||||||
{
|
{
|
||||||
// do we actually need to search through the whole map for this?
|
auto pos = obj->pos;
|
||||||
for (size_t i=0; i<map->width; i++)
|
|
||||||
|
for (size_t i = pos.x; i > pos.x - obj->getWidth(); i--)
|
||||||
{
|
{
|
||||||
for (size_t j=0; j<map->height; j++)
|
for (size_t j = pos.y; j > pos.y - obj->getHeight(); j--)
|
||||||
{
|
{
|
||||||
for (size_t k=0; k<(map->twoLevel ? 2 : 1); k++)
|
int3 t(i, j, pos.z);
|
||||||
{
|
if (!map->isInTheMap(t))
|
||||||
auto &objs = ttiles[i][j][k].objects;
|
continue;
|
||||||
|
|
||||||
|
auto &objs = ttiles[i][j][pos.z].objects;
|
||||||
for (size_t x = 0; x < objs.size(); x++)
|
for (size_t x = 0; x < objs.size(); x++)
|
||||||
{
|
{
|
||||||
if (objs[x].obj && objs[x].obj->id == obj->id)
|
auto ourObj = objs[x].obj;
|
||||||
|
if (ourObj && ourObj->id == obj->id)
|
||||||
{
|
{
|
||||||
if (fadeout && ADVOPT.objectFading) // object should be faded == erase is delayed until the end of fadeout
|
if (fadeout && ADVOPT.objectFading) // object should be faded == erase is delayed until the end of fadeout
|
||||||
{
|
{
|
||||||
if (startObjectFade(objs[x], false, int3(i, j, k)))
|
if (startObjectFade(objs[x], false, t))
|
||||||
objs[x].obj = nullptr;
|
objs[x].obj = nullptr; //set original pointer to null
|
||||||
else
|
else
|
||||||
objs.erase(objs.begin() + x);
|
objs.erase(objs.begin() + x);
|
||||||
}
|
}
|
||||||
@ -1354,8 +1358,9 @@ bool CMapHandler::hideObject(const CGObjectInstance *obj, bool fadeout /* = fals
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool CMapHandler::removeObject(CGObjectInstance *obj, bool fadeout /* = false */)
|
bool CMapHandler::removeObject(CGObjectInstance *obj, bool fadeout /* = false */)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user