1#pragma once
2
3static void CheckSpatialFogTransport()
4{
6 const auto field=[](int face,uint64_t revision,float offset=0) {
9 for(int y=0;y<64;++y)for(int x=0;x<64;++x)
10 g->cells[y*64+x]={8+offset+.3f*x+.1f*y,2+.1f*x};
11 return g;
12 };
13 for(int face=0;face<6;++face)
14 {
15 auto g=field(face,1);
18 const auto expected=g->Sample(p);
21 const auto moved=
Add(
Scale(p,std::cos(angle)),
Scale(wind,-std::sin(angle)/.01));
23 "fog must move downwind by 600 meters in 60 seconds at 10 m/s on every face");
25 "spatial fog stayed fixed between packets");
26 for(int fps:{30,60,144})
27 {
29 for(
int i=0;i<60*fps;++i)frames.
Advance(1.0/fps,position,wind);
31 "fog drift depends on frame rate");
32 }
36 one.
Advance(std::numeric_limits<double>::infinity(),position,wind);
37 one.
Advance(1,position,{std::numeric_limits<double>::quiet_NaN(),0,0});
39 "calm or invalid time/wind changed fog displacement");
40
42 Check(std::abs(one.
Sample(p).
visibility-expected.visibility)<.00001,
"reversed wind has wrong sign");
43
45 const auto before=corrected.
Sample(p);
46 auto next=field(face,2,4);corrected.
Accept(next,
true);
47 Check(corrected.
Sample(p).
visibility==before.visibility,
"full snapshot snapped fog");
48 corrected.
Advance(5,position,{});
49 Check(std::abs(corrected.
Sample(p).
visibility-(before.visibility+next->Sample(p).visibility)*.5f)<.00001,
50 "full snapshot correction midpoint");
51 const auto halfway=corrected.
Sample(p);
52 corrected.
Accept(field(face,3,8),
true);
54 "frequent full snapshots restarted from an invisible endpoint");
55 corrected.
Advance(10,position,{});
57 "full snapshot correction did not converge");
58
59
61 const auto beforeStrip=strips.
Sample(p);
62 auto shifted=std::make_shared<Grid>(*g);++shifted->u;shifted->revision=2;
63 for(int y=0;y<64;++y)for(int x=0;x<63;++x)shifted->cells[y*64+x]=g->cells[y*64+x+1];
64 strips.
Accept(shifted,
false);
66 "strip update reset weather age or shifted geography");
67 strips.
Advance(60,position,wind);
70 "drift did not continue across a strip update");
71 Check(strips.
Sample(
Scale(p,-1)).visibility==42.16f,
"opposite hemisphere reused local fog");
72 strips.
Reset();Check(!strips.
Ready(),
"fog reset retained a prediction");
73 }
74
75 auto seam=field(0,1);seam->u=2037;
76 const auto raw=
Direction(0,seam->u,seam->v),p=
Scale(raw,1/std::sqrt(
Dot(raw,raw)));
77 const Point tangent{p.y,-p.x,0},wind=
Scale(tangent,-.06);
80 const auto moved=
Add(
Scale(p,std::cos(angle)),
Scale(wind,-std::sin(angle)/.06));
81 cross.
Advance(60,position,wind);
82 Check(std::abs(cross.
Sample(moved).
visibility-seam->Sample(p).visibility)<.0001,
83 "cube seam disrupted fog transport");
84
85 Check(seam->Sample(
Direction(0,seam->u+40,seam->v)).visibility==42.16f,
86 "uncovered upwind weather was extrapolated");
87}
88
89static void CheckSpatialFogLifecycle(
Viewscreen& view,
grid& terrain,Receiver& receiver)
90{
97 LoadTerrain(view,{1019,1019},0,450);
98 auto packet=StormGrid({1019,1019},0,2000,7,false);
99 for(int q=0;q<64;++q)for(int r=0;r<64;++r)
100 {
102 const uint16_t visibility=uint16_t(5000+q*500);
103 packet[offset+8]=uint8_t(visibility);packet[offset+9]=uint8_t(visibility>>8);
104
105 packet[offset+10]=80;packet[offset+11]=255;
106 }
109 const auto before=rain.latest.cells[31*64+31];const auto snapshot=TerrainSnapshot();
110 const auto uploads=rain.uploads;
112 const auto after=rain.latest.cells[31*64+31];
113
114 const float expected=20.5f-float(std::tan(.6/(
radiusC+.4))*1019)*.5f;
115 Check(std::abs(after.z-expected)<.0001f && after.z!=before.z,
116 "production fog packing did not use Weather1 direction/speed at 1x");
117 Check(after.x==before.x && after.y==before.y,
118 "fog advection moved terrain or cloud-base heights");
119 TerrainUnchanged(snapshot);
120 Check(rain.uploads==uploads+1,"fog drift did not refresh GPU grid");
122
123 auto replacement=packet;Put32(replacement.data()+9,2001);
124 for(int q=0;q<64;++q)for(int r=0;r<64;++r)
125 {
const size_t at=17+(q*64+r)*
sizeof(
SRenderWeather)+8;replacement[at]=0x10;replacement[at+1]=0x27;}
127 Check(std::abs(rain.latest.cells[31*64+31].z-after.z)<.0001f,"packet receiver snapped rendered fog");
129 Check(std::abs(rain.latest.cells[31*64+31].z-(after.z+10)*.5f)<.0001f,"rendered fog reconciliation midpoint");
131 Check(std::abs(rain.latest.cells[31*64+31].z-10)<.0001f,"rendered fog reconciliation completion");
132
135 Put32(replacement.data()+9,2002);receiver.Receive(replacement);
138 Check(rain.active &&
Near(rain.latest.cells[31*64+31].z,10),
"simulator exit replayed old fog");
149 Check(rain.active &&
Near(rain.latest.cells[31*64+31].z,10),
"fresh descent failed to restore spatial fog");
153}
Rendering::CloudRenderer11 renderer
void Advance(double elapsed, Point physicalPosition, Point physicalWindKms)
void Accept(GridPtr next, bool full)
uint64_t Generation() const
Cell Sample(Point renderPosition) const
CloudVolumeRenderer cloudVolume
RiseMath::Vector3 compassnorth
RiseMath::Vector3 posnorml
void ElevationChanged() const
void QueuePlotWeatherReset()
void SetWindDirectionRadians(float prmWinddir)
void PrepareRainCurtains(bool exteriorView)
void SetWindspeedKms(float prmWindspeed)
uint16_t weatherRequestToken
float visibilityOverrideKm
SpatialFogWeather::Store spatialFogWeather
void AdvanceSpatialFog(float elapsed)
void ResetPlotWeatherConnection()
void UpdatePlotWeatherConditions()
s_network_objects playerships[MAX_SCAN]
SRenderWeather Sample(const unsigned char *p)
bool Near(const Body &b, const Triangle &t, double extra)
double Dot(Point a, Point b)
Point Direction(int cube, double u, double v)
Point Add(Point a, Point b)
Point Scale(Point a, double b)
RiseMath::Vector3 position