JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
Loading...
Searching...
No Matches
inputSet.hpp
Go to the documentation of this file.
1#pragma once
2
9#include "condition.hpp"
10#include "property.hpp"
11#include <jaffarCommon/json.hpp>
12#include <unordered_set>
13#include <vector>
14
15namespace jaffarPlus
16{
17
25class InputSet final
26{
27public:
29 typedef size_t inputIndex_t;
30
31 InputSet() = default;
32 ~InputSet() = default;
33
38 // The input set is activated only if all conditions are met
39 __INLINE__ bool evaluate() const
40 {
41 for (const auto& c : _conditions)
42 if (c->evaluate() == false) return false;
43 return true;
44 }
45
47 void addInput(const inputIndex_t inputIdx) { _inputIndexes.insert(inputIdx); }
49 void addCondition(std::unique_ptr<Condition> condition) { _conditions.insert(std::move(condition)); }
51 const std::unordered_set<inputIndex_t>& getInputIndexes() const { return _inputIndexes; }
55 void setStopInputEvaluationFlag(const bool stopInputEvaluation) { _stopInputEvaluation = stopInputEvaluation; }
56
57private:
59 // Conditions are evaluated frequently, so this optimized for performance
60 // Operands are pre-parsed as pointers/immediates and the evaluation function
61 // is a template that is created at compilation time.
62 std::unordered_set<std::unique_ptr<Condition>> _conditions;
63
65 // Storage for game-specific actions
66 std::unordered_set<inputIndex_t> _inputIndexes;
67
69 // If this flag is true, then the other input sets after this will not be evaluated
71};
72
73} // namespace jaffarPlus
A collection of input indexes whose availability is gated by a set of conditions.
Definition inputSet.hpp:26
const std::unordered_set< inputIndex_t > & getInputIndexes() const
Returns the input indexes contained in this set.
Definition inputSet.hpp:51
bool getStopInputEvaluationFlag() const
Returns whether this set stops evaluation of subsequent input sets.
Definition inputSet.hpp:53
bool _stopInputEvaluation
If true, input sets after this one are not evaluated.
Definition inputSet.hpp:70
size_t inputIndex_t
Type used to index an input.
Definition inputSet.hpp:29
std::unordered_set< inputIndex_t > _inputIndexes
Input indexes belonging to this set.
Definition inputSet.hpp:66
void addCondition(std::unique_ptr< Condition > condition)
Adds a condition that must hold for this set to be active.
Definition inputSet.hpp:49
void setStopInputEvaluationFlag(const bool stopInputEvaluation)
Sets whether this set stops evaluation of subsequent input sets.
Definition inputSet.hpp:55
std::unordered_set< std::unique_ptr< Condition > > _conditions
Conditions that must all hold for this input set to be active.
Definition inputSet.hpp:62
void addInput(const inputIndex_t inputIdx)
Adds an input index to this set.
Definition inputSet.hpp:47
bool evaluate() const
Evaluates the input set by checking all of its conditions.
Definition inputSet.hpp:39
Boolean comparisons between game properties (or immediate values) used by rules and input sets to dec...
A named, typed view into a region of game memory, with datatype and endianness handling and a templat...