我有一些包含对象的向量,并且我有一系列嵌套的循环来获取我想要的对象
if (_dir->Instance()->isDebug())
{
Utils::LogTextWithInt("growing timers size: ", _glo->Instance()->getGrowingTimers().size());
for (int i=0; i < _glo->Instance()->getGrowingTimers().size(); i++)
{
GrowingTimer _growingTimer = _glo->Instance()->getGrowingTimers().at(i);
std::cout << "growing timer Field id and plant id: " << _growingTimer.getFieldID() << " - "
<< _growingTimer.getPlantID() << std::endl;
}
}
std::vector<GrowingTimer>::iterator _gtIterB = _glo->Instance()->getGrowingTimers().begin();
for (_gtIterB; _gtIterB != _glo->Instance()->getGrowingTimers().end(); ++_gtIterB)
{
for (std::vector<Field>::iterator _fIterB = _glo->Instance()->getFields().begin();
_fIterB != _glo->Instance()->getFields().end(); ++_fIterB)
{
if (_gtIterB->getFieldID() == _fIterB->getFieldNumber())
{
for (std::vector<Plant>::iterator _pIterB = _fIterB->getPlants().begin();
_pIterB != _fIterB->getPlants().end(); )
{
if (_gtIterB->getPlantID() == _pIterB->getPlantID())
{
Utils::LogText("gt and plant ID's match");
Utils::LogTextWithInt("Plant ID after matching: ", _pIterB->getPlantID());
// Wiggle our plant.
Utils::wiggleNode(_pIterB->getPlantSprite(), 10.0f, 5.0f);
_pIterB->setPlantStoppedGrowing(true);
_gtIterB = _glo->Instance()->getGrowingTimers().erase(_gtIterB);
++_pIterB;
}
else
{
++_pIterB;
}
}
}
}
}
输出是:
growing timers size: 2
growing timer Field id and plant id: 7620 - -2130819608
growing timer Field id and plant id: 7620 - -2130802800
gt field id: 7620
gt plant id: -2130819608
gt and plant ID's match
Plant ID after matching: -2130819608
deleted
gt and plant ID's match
Plant ID after matching: -2130802800
deleted
gt field id: 7620
gt plant id: -2130802800
gt and plant ID's match
Plant ID after matching: -2130802800
在这一切之后我崩溃了:
0x209eff0: addb %ah, %gs:115(%ecx,%ebp,2)
0x209eff5: jo 0x209f063 ; "nitWithCondition:"
0x209eff7: popal
0x209eff8: jns 0x209f048 ; "'v'"
0x209effa: popal
0x209effb: insl
0x209effc: incl %esi
0x209effe: outsl
0x209efff: jb 0x209f04c ; "ckBeforeDate:"
0x209f001: jns 0x209f03e ; "Name:"
0x209f004: jbe 0x209f067 ; "ithCondition:"
0x209f006: insb
0x209f007: jne 0x209f06e ; "ition:"
0x209f009: cmpb (%eax), %al
0x209f00b: popl %edi
0x209f00c: jo 0x209f080 ; "lSinceNow"
基本上现在我有一个匹配并且我对它采取行动我想删除_gIterB
不再需要的位置。如果您愿意运行正在运行的定时事件,则此向量会不断添加为“跟踪器”,以便在计时器完成时我们知道计时器用于什么对象,并且可以返回到它以执行后续步骤。
编辑:GrowingTimer 的向量存储 fieldID 和“正在生长”的 PlantID,因此我们可以返回它。
字段向量存储用户拥有的所有字段,并且作为成员,每个字段对象都有一个字段中植物的向量。8 株植物到 1 块田地。
用户创建的每个字段都有一个唯一的 ID,下面的输出是一个字段中有 2 个植物。