1#include "../Modules/ModuleScheduler.h"
2
3static void ModuleSchedulingRegressions()
4{
5 for (size_t count : {size_t(1),size_t(7),size_t(50)})
6 for (int fps : {15,30,60,144,240})
7 {
9 std::vector<double> previous(count), longest(count);
10 std::vector<int> calls(count);
11 double now=0; bool ordered=true, timing=true, gaps=true, one=true;
12 int dispatched=0;
13 for (size_t frame=0;frame<count*5;++frame)
14 {
15 const float dt=float(1./fps*(frame%3==0 ? 1.7 : frame%3==1 ? .3 : 1.));
16 now+=dt;
17 for(auto& gap:longest) gap=(std::max)(gap,double(dt));
18 int thisFrame=0;
19 scheduler.
Advance(dt,count,[&](
size_t index,
float elapsed,
float maxFrame) {
20 ++thisFrame; ordered&=index==size_t(dispatched)%count; ++dispatched;
21 timing&=std::fabs(elapsed-(now-previous[index]))<1e-6;
22 gaps&=std::fabs(maxFrame-longest[index])<1e-7;
23 previous[index]=now; longest[index]=0; ++calls[index];
24 });
25 one&=thisFrame==1;
26 }
27 Check(one&&ordered,"scheduler dispatches exactly one module per frame in registration order");
28 Check(std::all_of(calls.begin(),calls.end(),[](int n){return n==5;}),"every module gets one turn per cycle, including 50-module loads");
29 Check(timing&&gaps,"variable FPS preserves accumulated elapsed and largest actual frame gap independently");
30 }
31 {
32 ModuleScheduler scheduler;
int calls=0;
float elapsed=0, gap=0;
size_t selected=99;
33 const auto run=[&](size_t i,float dt,float frame){++calls;selected=i;elapsed=dt;gap=frame;};
35 Check(calls==1,"zero-time frame does not consume a module turn");
37 Check(selected==1&&std::fabs(elapsed-1.1f)<1e-6&&gap==1,"a real stalled frame reaches its scheduled module without a catch-up burst");
38 for(
int i=0;i<7;++i) scheduler.
Advance(.1f,7,run);
39 Check(selected==1&&std::fabs(elapsed-.7f)<1e-6&&gap==.1f,"gap history clears after each module consumes it");
41 Check(selected==0&&elapsed==.1f,"module-count change restarts without carrying old timing debt");
42 for(float invalid:{-1.f,std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::infinity()})
43 {
44 const int before=calls; scheduler.
Advance(invalid,2,run);
45 Check(calls==before,"invalid time never reaches a module");
46 scheduler.
Advance(.1f,2,run); Check(selected==0&&elapsed==.1f,
"invalid-time recovery starts fresh");
47 }
48 const int before=calls; scheduler.
Advance(.1f,0,run); scheduler.
Reset();
49 Check(calls==before,"empty or disabled dispatcher runs no modules");
50 }
51 {
54 Command queued; queued.
name=
"GPWSMode6Fifty"; f.bus->commandStream.push_back(queued);
55 f.vmu.FrameMove(2.5f);
57 "VMU warm-up starts a full phrase even with a long accumulated turn");
58 f.vmu.FrameMove(.5f); Check(played.size()==1,"scheduled VMU does not overlap its warm-up recording");
59 f.vmu.FrameMove(.5f); Check(played.back()==
SOUND_GPWSFIFTY,
"queued callout follows the completed warm-up phrase");
60 }
61
62
63 for(size_t count:{size_t(7),size_t(50)}) for(int fps:{30,60,144})
64 {
67 bool warned=false;
68 for(int frame=0;frame<fps*10;++frame)
69 {
70 const float dt=1.f/fps; now+=dt;
71 auto& wind=f.bus->WindshearWind;
72 wind.valid=true; wind.sequence=frame+1; wind.seconds=now;
74 wind.up={0,0,1}; wind.forward={0,1,0};
75 wind.windToMs={0,float(2*(std::min)(now,5.)),0};
76 scheduler.
Advance(dt,count,[&](
size_t index,
float elapsed,
float maxFrame) {
78 if(index==5) { f.vmu.maxFrameSeconds=maxFrame; f.vmu.FrameMove(elapsed); }
79 });
80 }
81 Check(warned,"scheduled GPWS detects sustained signed headwind loss");
83 "scheduled VMU plays complete windshear phrases without restarting speech");
85 "scheduled recovery clears warning and stale queued audio");
86 }
87}
@ SOUND_GPWSWINDSHEARWARNING
void Advance(float frameSeconds, size_t count, Dispatch dispatch)
s_network_objects playerships[MAX_SCAN]
@ Mode7_Windshear_Warning