Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/TurbulenceGridTests.h

Source at documentation-generation time. See Test catalog for fixture associations.

1#pragma once
2
3static void CheckGridTurbulence(Viewscreen& view, grid& terrain, Receiver& receiver, Network& network)
4{
5 auto& weather=view.weather;
9 auto full=Packet(true,{1019,1019},0,1000,0,7);
10 for(int i=0;i<4096;++i) full[17+i*12+1]=51;
11 const unsigned char values[]{0,64,128,255};
12 for(int q=0;q<2;++q)for(int r=0;r<2;++r)
13 full[17+((31+q)*64+31+r)*12+1]=values[q*2+r];
14 Accept(weather.plotWeather,full);
16 Check(weather.plotWeather.Interpolate(0,1019.25,1019.75,7,local)
17 && Near(local.turbulence,91.8125f/255.f,.000001f),
18 "turbulence byte normalization or unequal bilinear weights changed");
19 Check(weather.plotWeather.Interpolate(0,1019,1019,7,local) && local.turbulence==0.f
20 && weather.plotWeather.Interpolate(0,1020,1020,7,local) && local.turbulence==1.f,
21 "zero/full turbulence endpoints are not preserved");
22 auto position=[&](float u,float v,float altitude) {
23 playerships[0].position=RiseMath::Vector3((u-1019)/1019,-1,(v-1019)/1019)*(radiusC+altitude);
24 playerships[0].mslKm=altitude;
25 };
26 position(1019.25f,1019.75f,.4f);
27 const float expected=91.8125f/255.f;
28 Check(Near(weather.GetTurbulence(),expected,.00001f),"vehicle did not sample local turbulence");
29 terrain.ClearGrid();
30 Check(Near(weather.GetTurbulence(),expected,.00001f),"turbulence incorrectly requires loaded terrain");
31 view.matrixLook._41=100;view.matrixLook._43=-100;
32 Check(Near(weather.GetTurbulence(),expected,.00001f),"camera displaced flight turbulence");
34 // No low-speed or flight-mode gate: ground, VTOL/hover and fast flight
35 // sample the same weather. The existing dynamics supplies speed response.
36 const auto oldReference=playerships[0].reference;
37 const auto oldVelocity=playerships[0].velocity;
38 for(auto reference:{REF_ONGROUND,REF_APNMODE,REF_ACLMODE})
39 for(float speed:{0.f,.25f,4.5f}) {
40 playerships[0].reference=reference;
41 playerships[0].velocity={speed,0,0};
42 Check(Near(weather.GetTurbulence(),expected,.00001f),"speed/reference suppressed weather sampling");
43 }
44 playerships[0].reference=oldReference;playerships[0].velocity=oldVelocity;
45 receiver.Receive(Weather1Packet(0,0));receiver.Receive(Weather1Packet(252));
46 Check(Near(weather.GetTurbulence(),expected,.00001f),"deprecated Weather1 f_y replaced grid turbulence");
47 position(1020,1019,.4f);
48 Check(Near(weather.GetTurbulence(),128.f/255,.00001f),"vehicle movement retained old turbulence");
49
50 auto global=std::make_shared<CloudWeather::Map>();
51 global->mips.push_back({8,4,std::vector<uint8_t>(32,204)});
52 network.cloudWeather.latest=global;
53 position(1019.25f,1019.75f,.4f);
54 Check(Near(weather.GetTurbulence(),expected,.00001f),"global fallback displaced valid local weather");
55 // The source changes at 9.5 km on ascent and descent, before the visual
56 // above-cloud flag changes. A valid local grid must not mask this boundary.
57 for(bool above:{false,true}) {
58 g_bAboveClouds=above;
59 for(float altitude:{9.499f,9.5f,9.501f,10.f,16.f,22.f,9.501f,9.5f,9.499f}) {
60 position(1019.25f,1019.75f,altitude);
61 Check(Near(weather.GetTurbulence(),altitude<9.5f?expected:.8f,.00001f),
62 "turbulence source ignored the 9.5 km MSL boundary");
63 }
64 }
65 g_bAboveClouds=false;position(1019.25f,1019.75f,.4f);
66 auto missing=full;missing[17+(31*64+32)*12]=0;
68 Check(weather.GetTurbulence()==0.f,"missing local corner substituted coarse global weather");
71 Check(weather.GetTurbulence()==0.f,"stale local token supplied turbulence");
73 position(1200,1019,.4f);
74 Check(weather.GetTurbulence()==0.f,"out-of-footprint weather substituted global turbulence");
75
76 position(1019.25f,1019.75f,10.1f);g_bAboveClouds=true;
79 "ascent lost turbulence with suspended local grid");
80 for(float altitude:{10.1f,30.f,62.999f,63.f,80.f,150.f,62.999f,30.f,9.7f}) {
81 position(1019.25f,1019.75f,altitude);
82 view.turbEnergy=.6f;view.turbLow=.4f;
83 weather.FrameTurbulenceReset();
84 Check(Near(weather.GetTurbulence(),altitude>=63?0.f:.8f),
85 "atmospheric/suborbital/orbital/re-entry turbulence envelope changed");
86 Check(altitude<63 || (view.turbEnergy==0 && view.turbLow==0),
87 "space retained gust energy for re-entry");
88 }
89 position(1019.25f,1019.75f,9.49f);g_bAboveClouds=false;
91 Check(weather.GetTurbulence()==0.f,"descent wait substituted global weather below 9.5 km");
92 auto descent=full;Put16(descent.data()+7,weather.weatherRequestToken);
94 "fresh descent fixture rejected current request token");
95 Check(Near(weather.GetTurbulence(),expected,.00001f),"fresh descent grid did not restore local turbulence");
96 playerships[0].isSimulator=true;view.turbEnergy=.9f;view.turbLow=.7f;
97 weather.FrameTurbulenceReset();receiver.Receive(Weather1Packet(0,0));receiver.Receive(Weather1Packet(252));
98 Check(weather.GetTurbulence()==0 && view.turbEnergy==0 && view.turbLow==0,
99 "simulator retained turbulence or gust memory");
100 playerships[0].isSimulator=false;
101 Check(Near(weather.GetTurbulence(),expected,.00001f) && view.turbEnergy==0,
102 "simulator exit replayed gust memory or failed to resume current weather");
104 Check(view.turbEnergy==0 && view.turbLow==0 && weather.GetTurbulence()==0.f,
105 "reposition retained gust memory or old local generation");
106
107 // Global orientation: physical +X is rendered -X (east); rows run north
108 // to south in render coordinates. Probe exact texel centers independently.
109 for(int i=0;i<32;++i)global->mips[0].pixels[i]=static_cast<uint8_t>(i*7);
111 for(int x=0;x<8;++x)for(int y=0;y<4;++y) {
112 const float lon=((x+.5f)/8-.5f)*RiseMath::Tau;
113 const float lat=(.5f-(y+.5f)/4)*RiseMath::Pi;
114 playerships[0].position=RiseMath::Vector3(sinf(lon)*cosf(lat),-cosf(lon)*cosf(lat),-sinf(lat))*(radiusC+30);
115 playerships[0].mslKm=30;
116 Check(Near(weather.GetTurbulence(),(y*8+x)*7.f/255,.00001f),"global turbulence has wrong hemisphere or orientation");
117 }
118 playerships[0].position.x=std::numeric_limits<float>::quiet_NaN();
119 Check(weather.GetTurbulence()==0,"invalid position reached global sampler");
120 position(1019,1019,.4f);playerships[0].mslKm=std::numeric_limits<float>::quiet_NaN();
121 Check(weather.GetTurbulence()==0,"invalid altitude enabled turbulence");
122 position(1019,1019,.4f);network.cloudWeather.latest.reset();
123 Check(weather.GetTurbulence()==0,"missing grids manufactured turbulence");
125}
@ REF_ACLMODE
Definition ServerTypes.h:44
@ REF_APNMODE
Definition ServerTypes.h:42
@ REF_ONGROUND
Definition ServerTypes.h:43
bool Interpolate(unsigned cube, double u, double v, uint16_t token, LocalSample &result) const
float turbLow
Definition Viewscreen.h:97
RiseMath::Matrix matrixLook
Definition Viewscreen.h:346
float turbEnergy
Definition Viewscreen.h:98
Definition grid.h:14
void ClearGrid()
Definition grid.cpp:78
float GetTurbulence() const
Definition weather.cpp:1436
void QueuePlotWeatherReset()
Definition weather.cpp:1060
uint16_t weatherRequestToken
Definition weather.h:85
void ResetPlotWeatherConnection()
Definition weather.cpp:1008
void UpdatePlotWeatherConditions()
Definition weather.cpp:1085
PlotWeather::Store plotWeather
Definition weather.h:86
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
bool g_bAboveClouds
Definition globals.cpp:16
#define radiusC
Definition globals.h:87
bool Near(const Body &b, const Triangle &t, double extra)
Definition RigidProp.h:141
constexpr float Pi
Definition ClientMath.h:12
constexpr float Tau
Definition ClientMath.h:12
RiseMath::Vector3 position
Definition globals.h:511
RiseMath::Vector3 velocity
Definition globals.h:500