Performance optimization: when processing for reactions to a card click, instead of looping through all the stored objects a second time, only call reactToClick() on objects that already indicated true to isReactingToClick().
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
#include "SimpleMenu.h"
|
#include "SimpleMenu.h"
|
||||||
#include "MTGAbility.h"
|
#include "MTGAbility.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
class GuiLayer;
|
class GuiLayer;
|
||||||
class Targetable;
|
class Targetable;
|
||||||
class WEvent;
|
class WEvent;
|
||||||
@@ -49,6 +51,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
ActionElement * currentWaitingAction;
|
ActionElement * currentWaitingAction;
|
||||||
int cantCancel;
|
int cantCancel;
|
||||||
|
std::set<ActionElement*> mReactions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -242,7 +242,11 @@ int ActionLayer::isReactingToClick(MTGCardInstance * card)
|
|||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
{
|
{
|
||||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
||||||
result += currentAction->isReactingToClick(card);
|
if (currentAction->isReactingToClick(card))
|
||||||
|
{
|
||||||
|
++result;
|
||||||
|
mReactions.insert(currentAction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -256,13 +260,22 @@ int ActionLayer::reactToClick(MTGCardInstance * card)
|
|||||||
if (ae)
|
if (ae)
|
||||||
return reactToClick(ae, card);
|
return reactToClick(ae, card);
|
||||||
|
|
||||||
for (int i = 0; i < mCount; i++)
|
std::set<ActionElement*>::const_iterator iter = mReactions.begin();
|
||||||
|
std::set<ActionElement*>::const_iterator end = mReactions.end();
|
||||||
|
for (; iter !=end; ++iter)
|
||||||
{
|
{
|
||||||
ActionElement * currentAction = (ActionElement *) mObjects[i];
|
result += reactToClick(*iter, card);
|
||||||
result += reactToClick(currentAction, card);
|
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
// if we hit this, then something strange has happened with the click logic - reactToClick()
|
||||||
|
// should never be called if isReactingToClick() previously didn't have an object return true
|
||||||
|
assert(!mReactions.empty());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mReactions.clear();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user