Skip to content

Commit e9364c5

Browse files
committed
Store edge-activated hat values by block and target
1 parent 7aadd10 commit e9364c5

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
@@ -506,39 +506,23 @@ void Engine::step()
506506
auto hatBlock = thread->script()->topBlock();
507507
assert(hatBlock);
508508

509-
// TODO: Edge-activated hats currently support only one field
510-
// If there isn't any field, -1 is used as the field value ID
511-
int fieldValueId = -1;
512-
513-
if (hatBlock->fieldAt(0)) {
514-
fieldValueId = hatBlock->fieldAt(0)->specialValueId();
515-
assert(fieldValueId != -1);
516-
}
517-
518509
Target *target = hatBlock->target();
519510
assert(target);
520-
auto it = m_edgeActivatedHatValues.find(hatType);
511+
auto it = m_edgeActivatedHatValues.find(hatBlock.get());
521512

522513
if (it == m_edgeActivatedHatValues.cend()) {
523-
m_edgeActivatedHatValues[hatType] = { { target, {} } };
514+
m_edgeActivatedHatValues[hatBlock.get()] = {};
524515
} else {
525516
auto &map = it->second;
526517
auto it = map.find(target);
527518

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-
}
519+
if (it != map.cend())
520+
oldValue = it->second;
537521
}
538522

539523
bool newValue = thread->script()->runHatPredicate();
540524
bool edgeWasActivated = !oldValue && newValue; // changed from false true
541-
m_edgeActivatedHatValues[hatType][target][fieldValueId] = newValue;
525+
m_edgeActivatedHatValues[hatBlock.get()][target] = newValue;
542526

543527
if (!edgeWasActivated)
544528
stopThread(thread.get());

src/engine/internal/engine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ 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<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
249+
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
251250

252251
std::unique_ptr<ITimer> m_defaultTimer;
253252
ITimer *m_timer = nullptr;

0 commit comments

Comments
 (0)