13
0

triggerbox: implement (?) JumpTrigger follow action

This commit is contained in:
Paul Davis 2022-01-20 11:01:00 -07:00
parent b6e0332148
commit 413f2e9d1b
3 changed files with 24 additions and 1 deletions

View File

@ -836,12 +836,13 @@ struct FollowAction {
LastTrigger,
AnyTrigger,
OtherTrigger,
JumpTrigger,
};
/* We could theoretically limit this to default_triggers_per_box but
* doing it this way makes it likely that this will not change. Could
* be worth a constexpr-style compile time assert to check
* default_triggers_per_box < 64.
* default_triggers_per_box < 64
*/
typedef std::bitset<64> Targets;
@ -854,6 +855,13 @@ struct FollowAction {
FollowAction (Type t, std::string const & bitstring) : type (t), targets (bitstring) {}
FollowAction (std::string const &);
static Targets target_any () { Targets t; t.set(); return t; }
static Targets target_other (uint8_t skip) { Targets t; t.set (); t.reset (skip); return t; }
static Targets target_next_wrap (uint8_t from) { Targets t; if (from < t.size() - 1) { t.set (from + 1); } else { t.set (0); } return t; }
static Targets target_prev_wrap (uint8_t from) { Targets t; if (from) { t.set (from - 1); } else { t.set (t.size() - 1); } return t; }
static Targets target_next_nowrap (uint8_t from) { Targets t; if (from < t.size() - 1) { t.set (from + 1); } return t; }
static Targets target_prev_nowrap (uint8_t from) { Targets t; if (from) { t.set (from - 1); } return t; }
bool operator!= (FollowAction const & other) const {
return other.type != type || other.targets != targets;
}

View File

@ -871,6 +871,7 @@ setup_enum_writer ()
REGISTER_CLASS_ENUM (FollowAction, LastTrigger);
REGISTER_CLASS_ENUM (FollowAction, AnyTrigger);
REGISTER_CLASS_ENUM (FollowAction, OtherTrigger);
REGISTER_CLASS_ENUM (FollowAction, JumpTrigger);
REGISTER (_FollowAction);
REGISTER_CLASS_ENUM (Trigger, OneShot);

View File

@ -2995,6 +2995,9 @@ TriggerBox::determine_next_trigger (uint32_t current)
{
uint32_t n;
uint32_t runnable = 0;
std::vector<int32_t> possible_targets;
possible_targets.reserve (default_triggers_per_box);
/* count number of triggers that can actually be run (i.e. they have a region) */
@ -3157,6 +3160,17 @@ TriggerBox::determine_next_trigger (uint32_t current)
}
return n;
case FollowAction::JumpTrigger:
for (std::size_t n = 0; n < default_triggers_per_box; ++n) {
if (fa.targets.test (n) && all_triggers[n]->region()) {
possible_targets.push_back (n);
}
}
if (possible_targets.empty()) {
return 1;
}
return possible_targets[_pcg.rand (possible_targets.size())];
/* NOTREACHED */
case FollowAction::Stop: