fix(meta): SecondsInStateP survives re-entering the state

As RynthScript documents the persistent timer (2026-09-30 audit, question 16):
PSecsInStateGE no longer restarts on a SetState to the current state, and pauses
while the state has Called another (CallMetaState or the watchdog), resuming on the
Return. It restarts on a move to a different state or a meta load. The plain
SecondsInState timer is unchanged. The host test is no longer a known failure;
new test for the pause / self-SetState / move / meta-load rules.
This commit is contained in:
BlankenshipG 2026-10-08 22:58:38 -04:00
commit cdaf824676
3 changed files with 137 additions and 13 deletions

View file

@ -54,9 +54,8 @@ internal static class MetaTests
r.Add("meta: state snapshot", Snapshot);
r.Add("meta: VendorClosed fires after a vendor closes", VendorClosedFires); // was a known failure; fixed by ef68455
r.Add("meta: InventoryItemCount counts stack sizes", InventoryCountsStacks); // was a known failure; fixed by 716f16d
r.KnownFailure("meta: SecondsInStateP keeps counting across a call and return",
"SecondsInStateP_GE survives a macro stop/start since 1ee6145, but still restarts whenever the state is re-entered (SetState, Call, Return), as VTank documents it; RynthScript says it survives re-entry. Open compatibility call (2026-09-30 audit, question 16)",
SecondsInStatePPersists);
r.Add("meta: SecondsInStateP keeps counting across a call and return", SecondsInStatePPersists); // was a known failure (2026-09-30 audit, question 16: RynthScript's re-entry rule)
r.Add("meta: SecondsInStateP pauses in a call, survives SetState to itself, restarts on a new state or meta", SecondsInStatePRules);
r.Add("meta: MainHealthPHE / MainManaPHE mean 'percent >='", PercentConditionsAreGE); // was a known failure; fixed by a7c4618
r.Add("meta: a negative vital threshold never holds", NegativeVitalThreshold); // was a known failure; fixed by 6f72b67
r.Add("meta edit: saving a rule keeps the running meta's state, clocks and latch", EditKeepsRunningMeta);
@ -1105,6 +1104,78 @@ internal static class MetaTests
Check.Eq(rig.Var("p"), "1", "SecondsInStateP_GE 25 after 25 s spent in Default around a 1 s call");
}
private static void SecondsInStatePRules()
{
// Paused while Default has Called Sub: 25 s of wall time is only 15 s in Default.
var call = new Rig(rules: new[]
{
Mark("Default", C.SecondsInStateP_GE, "20", "p"),
Rule("Default", C.SecondsInState_GE, "10", A.CallMetaState, "Sub"),
Rule("Sub", C.SecondsInState_GE, "10", A.ReturnFromCall, ""),
});
call.Tick(); // T0: Default
call.Tick(10); // T0+10: call Sub
call.Tick();
call.Tick(10); // T0+20: return
call.Tick();
call.Tick(5); // T0+25: 15 s in Default
Check.False(call.Has("p"), "15 s in Default (10 s in Sub not counted)");
call.Tick(5); // T0+30: 20 s in Default
Check.Eq(call.Var("p"), "1", "20 s in Default");
// In the called state the P clock is that state's own, from its entry.
var inSub = new Rig(rules: new[]
{
Rule("Default", C.SecondsInState_GE, "30", A.CallMetaState, "Sub"),
Mark("Sub", C.SecondsInStateP_GE, "5", "sub"),
});
inSub.Tick();
inSub.Tick(30); // call Sub after 30 s in Default
inSub.Tick();
inSub.Tick(4);
Check.False(inSub.Has("sub"), "4 s into Sub");
inSub.Tick(1);
Check.Eq(inSub.Var("sub"), "1", "5 s into Sub");
// SetState to the state it is already in: the plain clock restarts, the P clock does not.
var self = new Rig(rules: new[]
{
Mark("Default", C.SecondsInStateP_GE, "15", "p"),
Rule("Default", C.SecondsInState_GE, "10", A.SetMetaState, "Default"),
});
self.Tick();
self.Tick(10); // SetState Default
self.Tick();
self.Tick(5); // 15 s since Default was entered
Check.Eq(self.Var("p"), "1", "SetState to the same state keeps the P clock");
// A move to another state restarts it.
var move = new Rig(rules: new[]
{
Rule("Default", C.SecondsInState_GE, "10", A.SetMetaState, "Hunt"),
Mark("Hunt", C.SecondsInStateP_GE, "3", "h"),
});
move.Tick();
move.Tick(10);
move.Tick();
move.Tick(2.9);
Check.False(move.Has("h"), "2.9 s into Hunt (restarted on the move)");
move.Tick(0.1);
Check.Eq(move.Var("h"), "1", "3 s into Hunt");
// Loading a meta restarts it, even when the start state has the same name.
var load = new Rig(rules: Mark("Default", C.SecondsInStateP_GE, "15", "p"));
load.Tick();
load.Tick(10);
load.S.ForceStateReset = true;
load.S.MetaCallStackReset = true; // what a meta load sets
load.Tick();
load.Tick(10); // 20 s in Default, 10 s since the load
Check.False(load.Has("p"), "10 s since the meta load");
load.Tick(5);
Check.Eq(load.Var("p"), "1", "15 s since the meta load");
}
private static void PercentConditionsAreGE()
{
var rig = new Rig();