Skip to content

Commit 6082b82

Browse files
committed
Store edge-activated hats by target
1 parent 8039bf5 commit 6082b82

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
@@ -515,21 +515,30 @@ void Engine::step()
515515
assert(fieldValueId != -1);
516516
}
517517

518+
Target *target = hatBlock->target();
519+
assert(target);
518520
auto it = m_edgeActivatedHatValues.find(hatType);
519521

520522
if (it == m_edgeActivatedHatValues.cend()) {
521-
m_edgeActivatedHatValues[hatType] = {};
523+
m_edgeActivatedHatValues[hatType] = { { target, {} } };
522524
} else {
523-
const std::unordered_map<int, bool> &values = it->second;
524-
auto fieldIt = values.find(fieldValueId);
525+
auto &map = it->second;
526+
auto it = map.find(target);
525527

526-
if (fieldIt != values.cend())
527-
oldValue = fieldIt->second;
528+
if (it == map.cend())
529+
map[target] = {};
530+
else {
531+
const std::unordered_map<int, bool> &values = it->second;
532+
auto fieldIt = values.find(fieldValueId);
533+
534+
if (fieldIt != values.cend())
535+
oldValue = fieldIt->second;
536+
}
528537
}
529538

530539
bool newValue = thread->script()->runHatPredicate();
531540
bool edgeWasActivated = !oldValue && newValue; // changed from false true
532-
m_edgeActivatedHatValues[hatType][fieldValueId] = newValue;
541+
m_edgeActivatedHatValues[hatType][target][fieldValueId] = newValue;
533542

534543
if (!edgeWasActivated)
535544
stopThread(thread.get());

src/engine/internal/engine.h

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

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

249-
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
249+
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
250+
// the value changes from false to true
250251

251252
std::unique_ptr<ITimer> m_defaultTimer;
252253
ITimer *m_timer = nullptr;

0 commit comments

Comments
 (0)