Skip to content

Commit fe061a5

Browse files
committed
Store edge-activated hats by target
1 parent 53bec00 commit fe061a5

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/engine/internal/engine.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,21 +526,30 @@ void Engine::step()
526526
assert(fieldValueId != -1);
527527
}
528528

529+
Target *target = hatBlock->target();
530+
assert(target);
529531
auto it = m_edgeActivatedHatValues.find(hatType);
530532

531533
if (it == m_edgeActivatedHatValues.cend()) {
532-
m_edgeActivatedHatValues[hatType] = {};
534+
m_edgeActivatedHatValues[hatType] = { { target, {} } };
533535
} else {
534-
const std::unordered_map<int, bool> &values = it->second;
535-
auto fieldIt = values.find(fieldValueId);
536+
auto &map = it->second;
537+
auto it = map.find(target);
536538

537-
if (fieldIt != values.cend())
538-
oldValue = fieldIt->second;
539+
if (it == map.cend())
540+
map[target] = {};
541+
else {
542+
const std::unordered_map<int, bool> &values = it->second;
543+
auto fieldIt = values.find(fieldValueId);
544+
545+
if (fieldIt != values.cend())
546+
oldValue = fieldIt->second;
547+
}
539548
}
540549

541550
bool newValue = thread->script()->runHatPredicate(hatBlock->target());
542551
bool edgeWasActivated = !oldValue && newValue; // changed from false true
543-
m_edgeActivatedHatValues[hatType][fieldValueId] = newValue;
552+
m_edgeActivatedHatValues[hatType][target][fieldValueId] = newValue;
544553

545554
if (!edgeWasActivated)
546555
stopThread(thread.get());

src/engine/internal/engine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ class Engine : public IEngine
252252

253253
std::unordered_map<Script *, std::unordered_map<HatField, int>> m_scriptHatFields; // HatField, field ID from the block implementation
254254

255-
std::unordered_map<HatType, std::unordered_map<int, bool>> m_edgeActivatedHatValues; // (field value, last value) edge-activated hats only run after the value changes from false to true
255+
std::unordered_map<HatType, std::unordered_map<Target *, std::unordered_map<int, bool>>> m_edgeActivatedHatValues; // (target, field value ID, last value) edge-activated hats only run after
256+
// the value changes from false to true
256257

257258
std::unique_ptr<ITimer> m_defaultTimer;
258259
ITimer *m_timer = nullptr;

0 commit comments

Comments
 (0)