Skip to content

Commit 4a876bd

Browse files
committed
Store edge-activated hat values by block and target
1 parent 8ab338c commit 4a876bd

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

src/engine/internal/engine.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -518,39 +518,23 @@ void Engine::step()
518518
auto hatBlock = thread->script()->topBlock();
519519
assert(hatBlock);
520520

521-
// TODO: Edge-activated hats currently support only one field
522-
// If there isn't any field, -1 is used as the field value ID
523-
int fieldValueId = -1;
524-
525-
if (hatBlock->fieldAt(0)) {
526-
fieldValueId = hatBlock->fieldAt(0)->specialValueId();
527-
assert(fieldValueId != -1);
528-
}
529-
530521
Target *target = hatBlock->target();
531522
assert(target);
532-
auto it = m_edgeActivatedHatValues.find(hatType);
523+
auto it = m_edgeActivatedHatValues.find(hatBlock.get());
533524

534525
if (it == m_edgeActivatedHatValues.cend()) {
535-
m_edgeActivatedHatValues[hatType] = { { target, {} } };
526+
m_edgeActivatedHatValues[hatBlock.get()] = {};
536527
} else {
537528
auto &map = it->second;
538529
auto it = map.find(target);
539530

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

551535
bool newValue = thread->script()->runHatPredicate(hatBlock->target());
552536
bool edgeWasActivated = !oldValue && newValue; // changed from false true
553-
m_edgeActivatedHatValues[hatType][target][fieldValueId] = newValue;
537+
m_edgeActivatedHatValues[hatBlock.get()][target] = newValue;
554538

555539
if (!edgeWasActivated)
556540
stopThread(thread.get());

src/engine/internal/engine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ class Engine : public IEngine
255255

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

258-
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
259-
// the value changes from false to true
258+
std::unordered_map<Block *, std::unordered_map<Target *, bool>> m_edgeActivatedHatValues; // (block, target, last value) edge-activated hats only run after the value changes from false to true
260259

261260
std::unique_ptr<ITimer> m_defaultTimer;
262261
ITimer *m_timer = nullptr;

0 commit comments

Comments
 (0)