1#include "../Viewscreen/globals.h"
2#include "../Protocol/TerrainWeather.h"
3#include "../Viewscreen/GridLightning.h"
4#include "../Viewscreen/TerrainSnow.h"
5#include "../Viewscreen/WeatherOverrides.h"
6#include "../Viewscreen/CloudVolume.h"
7#include "../Viewscreen/SpatialFogWeather.h"
8#include "../Logger.h"
9#include <cfloat>
10#include <iostream>
11#include <memory>
12#include <limits>
13#include <stdexcept>
14#include <vector>
15#include <unordered_map>
16#include <chrono>
17
23{
if (level >=
Error)
throw std::runtime_error(text); }
30static int checks = 0;
31static void Check(bool condition, const char* message)
32{ ++checks; if (!condition) throw std::runtime_error(message); }
33
34
38 RainGrid latest;
bool active=
false;
unsigned uploads=0;
39 bool HasRainGrid(uint64_t revision,
int cube,
int u,
int v)
const
40 {return active && latest.revision==revision && latest.cube==cube && latest.u==u && latest.v==v;}
41 void SetRainGrid(
const RainGrid* grid){active=grid!=
nullptr;
if(grid){latest=*grid;++uploads;}}
42};
43}
44struct RainRendererSink {
45 Rendering::CloudRenderer11 renderer;unsigned historyResets=0;
46 bool lightningDiagnostic=false;
47 auto* Effect(){return &renderer;}
48 void ResetHistory(){++historyResets;}
49 bool SetLightningDiagnostic(bool enabled){lightningDiagnostic=enabled;return true;}
50};
53struct Weather
54{
55 Viewscreen* viewscreen = nullptr; Logger* logger = nullptr;
56 int resets = 0;
57 bool weatherPending = true, weatherRequestQueued = true;
58 bool plotWeatherSuspended = false,spatialFogRendering=false;
59 void PrepareRainCurtains(bool);
60 bool UpdatePlotWeatherAltitude();
61 uint16_t weatherRequestToken = 1;
62 PlotWeather::Store plotWeather;
63 SpatialFogWeather::Store spatialFogWeather;
64 CloudVolume::Point ObservedWindKms() const;
65 void UpdateSpatialFogSnapshot(bool full);
66 void AdvanceSpatialFog(float elapsed);
67 CloudBaseWeather::Store cloudBaseWeather;
68 uint32_t cloudBaseWeatherRevision=0;
69 uint16_t cloudBaseRequestToken=0;
70 uint64_t cloudBaseTerrainRevision=0;
71 void UpdateCloudBaseWeather(float elapsed);
72 void ResetCloudBaseWeather();
73 CloudVolume::Parameters cloudParameters;
74 TerrainSnow::Store terrainSnow;
75 uint32_t snowWeatherRevision=0;uint16_t snowRequestToken=0;uint64_t snowTerrainRevision=0;
76 float orbitSunLatitude=0;
77 void UpdateTerrainSnow(float);
78 RiseMath::Vector4 TerrainSnowTint(int,int) const;
79 GridLightning::System gridLightning{};
80 uint32_t lightningWeatherRevision=0;
81 uint64_t lightningTerrainRevision=0,rainTerrainRevision=0;
82 float snowBlend=0,precipOverride=-1;
83 bool RefreshLightningGrid();
84 void UpdateLightningSpawns(float);
85 void ReceiveGridLightning(short,short,int,int);
86 bool TriggerForwardLightning();
87 float cloudCeilingOverrideKm=-1;
88 float GetCloudCeilingKm() const {return cloudCeilingSmoothAglKm;}
89 float GetPrecip() const;
90 float GetRainPrecip() const;
91 float GetVisibilityKm() const;
92 float visibilityOverrideKm=-1;
93 void SetPrecipOverride(float);
94 float GetTurbulence() const;
95 void ResetTurbulence();
96 void FrameTurbulenceReset();
97 ULONGLONG weatherDiagnosticUntil = 0, weatherNextDiagnostic = 0;
98 float cloudSurfaceTargetKm = 0, cloudCeilingTargetKm = 1.8f, visibility = 42.16f;
99 float precip=2, smoothPrecip=-1, winddir=0, temperature=0, windspeed=0;
100 void SetPrecip(float);
101 void SetWindDirectionRadians(float value) { winddir=value; }
102 void SetTemperatureCelsius(float value) { temperature=value; }
103 void SetWindspeedKms(float value) { windspeed=value; }
105 float GetWindDirectionRadians() const {return winddir;}
106 float cloudSurfaceSmoothKm = -1, cloudCeilingSmoothAglKm = -1, smoothVisibility = -1;
107 void SetCloudSurfaceTargetKm(float v) { cloudSurfaceTargetKm=v; if(cloudSurfaceSmoothKm==-1) cloudSurfaceSmoothKm=v; }
108 void SetCloudCeilingTargetKm(float v) { cloudCeilingTargetKm=v; if(cloudCeilingSmoothAglKm==-1) cloudCeilingSmoothAglKm=v; }
109 void SetVisibility(float v) { visibility=v; if(smoothVisibility==-1) smoothVisibility=v; }
110 void ForceSmoothValues() { ++resets; smoothPrecip=precip; cloudSurfaceSmoothKm=cloudSurfaceTargetKm; cloudCeilingSmoothAglKm=cloudCeilingTargetKm; smoothVisibility=visibility; }
111 void ResetPlotWeatherConnection();
112 void RequestPlotWeather(bool);
113 void QueuePlotWeatherReset();
114 void ReceivePlotWeather(const unsigned char*, size_t);
115 void UpdatePlotWeatherConditions();
116};
118{
119 struct CloudWeatherSource {
122 } cloudWeather;
123 std::vector<SClientPacket> requests, weatherRequests, lightningRequests;
125 {
126 Check(size == sizeof(SClientPacket) && reliable, "request framing/reliability changed");
127 const auto packet = *static_cast<const SClientPacket*>(data);
128 if(packet.type == 42) {
129 Check(ordering==
ORDERING_NONE && packet.f_z>=0 && packet.f_z<=2
130 && packet.f_w>=0 && packet.f_w<=32767,"lightning wire fields/order changed");
131 lightningRequests.push_back(packet);
132 } else if(packet.type == 45) {
133 Check(ordering ==
ORDERING_WEATHER && ordering == 9 && packet.f_x >= 0 && packet.f_x <= 65535
134 && packet.f_x == floorf(packet.f_x) && packet.f_y == 0 && packet.f_z == 0 && packet.f_w == 0,
135 "weather request token/channel/padding changed");
136 weatherRequests.push_back(packet);
137 } else {
139 requests.push_back(packet);
140 }
141 }
142};
143struct FixtureBus { VECTOR2SHORT DebugApn; };
144struct Game { FixtureBus* bus;
Network* networking; };
146{
147public:
155 bool testStrike=false; int strikeChains=-1;
158 RiseMath::Vector3 strikeGround{},strikeCloud{}; float strikeDistance=0;
159 void TriggerBCLLightningAt(
const RiseMath::Vector3& ground,
const RiseMath::Vector3& cloud,
float distance,
int,
int chains,
bool test=
false) {
160 ++strikes; strikeGround=ground;strikeCloud=cloud;strikeDistance=distance;testStrike=test;strikeChains=chains;
161 }
165 VECTOR2SHORT
CalculateCGC(RiseMath::Vector3,
char)
const;
168 LOCALGRID2
CalculateSRV(
short,
short, VECTOR2SHORT,
char, SRenderVertex);
169};
171{
172public:
176 bool TryRadarSurface(
char face,
short u,
short v,
short& meters,
bool& water)
const;
178
179 bool TryElevation(
char face,
short u,
short v,
short& meters)
const;
194 void RemoveBuildZone(
short)
const {
throw std::runtime_error(
"weather touched a terrain building"); }
195};
196#include "TerrainGeometry.generated.h"
197#include "TerrainGrid.generated.h"
198#include "TerrainWeatherSource.generated.h"
199
200struct Receiver
201{
202 struct HandlerGame { Viewscreen* viewscreen; } owner;
203 HandlerGame* game = &owner; char msg[999]{};
204 int commands = 0, buildings = 0, menus = 0;
206 void Receive(const std::vector<unsigned char>& wire)
207 {
208 struct Packet { const unsigned char* data; unsigned length; } storage{wire.data(), static_cast<unsigned>(wire.size())};
209 auto* packet = &storage;
210 if (!packet->length || packet->data[0] != ID_USER_PACKET_ENUM) return;
211 switch (packet->length - 1)
212 {
213 case sizeof SServerPacket: {
214 SServerPacket datapacket;
215 memcpy(&datapacket,packet->data+1,sizeof datapacket);
216 switch(datapacket.
type) {
217#include "Weather1Receiver.generated.h"
218#include "LightningReceiver.generated.h"
219 default: ++commands; break;
220 }
221 break;
222 }
223 case sizeof SRenderBuilding: ++buildings; break;
224 case sizeof SPacketMenu: ++menus; break;
225#include "TerrainReceiver.generated.h"
226 }
227 }
228};
229
230static void Put16(unsigned char* p, int value)
231{ p[0]=static_cast<unsigned char>(value); p[1]=static_cast<unsigned char>(value >> 8); }
232static void Put32(unsigned char* p, uint32_t value)
233{ Put16(p,value & 65535); Put16(p+2,value >> 16); }
234static void PutSample(unsigned char* p, int i)
235{
236 p[0]=static_cast<unsigned char>(20+i%141); p[1]=static_cast<unsigned char>((i/7)%256);
237 p[4]=static_cast<unsigned char>(i%256);p[5]=static_cast<unsigned char>((i/5)%256);
238 p[6]=static_cast<unsigned char>((i/3)%256);p[7]=0;
239 Put16(p+2,300+i); Put16(p+8,42160-i);
240 p[10]=static_cast<unsigned char>(i%158);p[11]=static_cast<unsigned char>((i/11)%256);
241}
242static std::vector<unsigned char> Packet(
bool full,
VECTOR2SHORT center,
unsigned cube,
243 uint32_t revision, uint32_t base, uint16_t token, unsigned side=0, int first=0)
244{
245 std::vector<unsigned char> bytes(1+(full?49168:784));
246 bytes[0]=ID_USER_PACKET_ENUM;
247 auto* p=bytes.data()+1;
248 Put16(p,center.
u); Put16(p+2,center.
v); p[4]=
static_cast<unsigned char>(cube);
249 p[5]=static_cast<unsigned char>(side); Put16(p+6,token); Put32(p+8,revision); Put32(p+12,base);
250 for(int i=0;i<(full?4096:64);++i) PutSample(p+16+i*12,first+i);
251 return bytes;
252}
254{
return store.
Accept(p.data()+1,p.size()-1,token); }
256{
257 Check(sample && sample->
HasVisibility(),
"expected a valid located weather sample");
262 && sample->
snowAgeHours==(index/3)%256 && sample->
turbulence==(index/7)%256,
"weather shifted onto the wrong plot");
263}
264static std::vector<unsigned char> Weather1Packet(unsigned char encoded,float unusedTurbulence=.3f)
265{
267 data.
f_x=1.2f; data.
f_y=unusedTurbulence; data.
f_z=15.f; data.
f_w=.02f;
268 std::vector<unsigned char> wire(1+sizeof data); wire[0]=ID_USER_PACKET_ENUM;
269 memcpy(wire.data()+1,&data,sizeof data); return wire;
270}
271static std::vector<unsigned char> Weather2Packet()
272{
275 std::vector<unsigned char> wire(1+sizeof data);wire[0]=ID_USER_PACKET_ENUM;
276 memcpy(wire.data()+1,&data,sizeof data);return wire;
277}
278static void CheckStore()
279{
280
281 const unsigned char goldenHeader[16]{0x34,0x12,0xfe,0xff,0x04,0x01,0xcd,0xab,
282 0x78,0x56,0x34,0x12,0x77,0x56,0x34,0x12};
283 std::vector<unsigned char> goldenRow(784);
284 memcpy(goldenRow.data(),goldenHeader,sizeof goldenHeader);
287 && golden.
tcp.
u==0x1234 && golden.
tcp.
v==-2 && golden.
cube==4 && golden.
side==1
289 "managed server header golden bytes changed");
291 auto full=Packet(true,center,0,100,0,7);
293 for(size_t length:{size_t(0),size_t(20),size_t(28),size_t(32),size_t(528),size_t(656),size_t(32784),size_t(40976),size_t(783),size_t(785),size_t(49167),size_t(49169),size_t(400),size_t(24592)})
296 for(unsigned cube:{6u,255u}) {
297 auto invalid=full; invalid[5]=static_cast<unsigned char>(cube);
299 }
300 auto invalid=full; invalid[6]=1;
302 invalid=full; Put32(invalid.data()+9,0);
304 invalid=full; Put32(invalid.data()+13,1);
306
307 for(int side=1;side<=4;++side)
308 {
311 for(int q=0;q<64;++q) for(int r=0;r<64;++r)
312 CheckSample(store.
At(0,
VECTOR2SHORT(center.
u+q-31,center.
v+r-31),7),q*64+r);
313 Check(!store.
At(1,center,7) && !store.
At(0,center,8)
314 && !store.
At(0,
VECTOR2SHORT(center.
u+33,center.
v),7),
"weather sampling escaped face/token/bounds");
315 const int du=side==3?1:side==4?-1:0, dv=side==2?1:side==1?-1:0;
317 auto row=Packet(false,next,0,117,100,7,side,6000);
319 for(int q=0;q<64;++q) for(int r=0;r<64;++r)
320 {
321 const int oldQ=q+du, oldR=r+dv;
322 const bool retained=oldQ>=0 && oldQ<64 && oldR>=0 && oldR<64;
323 const int expected=retained?oldQ*64+oldR:6000+(du?r:q);
324 CheckSample(store.
At(0,
VECTOR2SHORT(next.u+q-31,next.v+r-31),7),expected);
325 }
327 "duplicate/delayed packet overwrote a newer grid");
328 auto gap=Packet(
false,
VECTOR2SHORT(next.u+du,next.v+dv),0,120,116,7,side);
330 "missing strip base failed to request repair or mutated storage");
331 auto wrongStep=Packet(false,next,0,120,117,7,side);
333 auto wrongFace=Packet(
false,
VECTOR2SHORT(next.u+du,next.v+dv),1,120,117,7,side);
337 }
338
345 Check(Accept(store,Packet(
true,center,0,1,0,7))==
PlotWeather::Result::Full,
"connection reset retained revision watermark");
346 auto unavailable=full; unavailable[17]=19;
348 && !store.
At(0,
VECTOR2SHORT(469,1069),7)->Available(),
"invalid sample was treated as valid weather");
349 unsigned char sample[12]{0x49,0x7b,0xd2,0x04,0x19,0x7b,0xf0,0x00,0xb0,0xa4,0x1f,0x0d};
351 Check(decoded.ceiling==1234 && decoded.visibility==42160
352 && decoded.precipitation==73 && decoded.turbulence==123
353 && decoded.snowDepthMm==25 && decoded.surfaceWaterTenthsMm==123 && decoded.snowAgeHours==240
354 && decoded.unused==0 && decoded.windDirectionRadians==31 && decoded.windSpeedMs==13
355 && memcmp(&decoded,sample,sizeof sample)==0,
356 "twelve-byte server golden cell or little-endian units changed");
357
358 for(int snow=0;snow<=255;++snow) for(int water:{0,1,123,255}) for(int age:{0,1,127,240,255}) {
359 sample[4]=static_cast<unsigned char>(snow);sample[5]=static_cast<unsigned char>(water);
360 sample[6]=static_cast<unsigned char>(age);sample[7]=0xa5;
362 Check(cell.HasVisibility() && cell.turbulence==123 && cell.snowDepthMm==snow
363 && cell.surfaceWaterTenthsMm==water && cell.snowAgeHours==age
364 && cell.windDirectionRadians==31 && cell.windSpeedMs==13,
365 "independent surface fields or reserved byte affected another quantity");
366 }
367 for(int value:{0,1,127,255}) {
368 sample[1]=sample[10]=sample[11]=static_cast<unsigned char>(value);
370 Check(cell.turbulence==value && cell.windDirectionRadians==value && cell.windSpeedMs==value
371 && cell.snowDepthMm==255 && cell.surfaceWaterTenthsMm==255,"byte endpoints lost independent fields");
372 }
373 for(int meters:{0,1,10,42160,42161,65535}) {
374 Put16(sample+8,meters);
375 Check(
PlotWeather::Sample(sample).HasVisibility()==(meters>0 && meters<=42160),
"visibility limits changed");
376 }
377 Put16(sample+8,42160);
378 for(int meters:{-32768,-1,0,32767}) {
379 Put16(sample+2,meters);
380 Check(
PlotWeather::Sample(sample).HasVisibility()==(meters>=0),
"ceiling validity changed");
381 }
382 const unsigned char absent[12]{};
384 Check(!decoded.HasVisibility() && memcmp(&decoded,absent,sizeof absent)==0,"missing weather invented surface values");
385
386}
387
388
389static bool Near(
float a,
float b,
float tolerance=.001f) {
return fabsf(a-b)<=tolerance; }
390static void CheckInterpolation()
391{
393 const auto full=Packet(true,center,0,100,0,7);
395 Accept(store,full);
397 const double u=500.25, v=1100.75, index=31.25*64+31.75;
400 "fractional bilinear targets do not match the four control samples");
401 for(int axis=0;axis<2;++axis) {
403 const double a=axis?500.25:500.999999, b=axis?1100.999999:1100.75;
405 && store.
Interpolate(0,a+(axis?0:.000002),b+(axis?.000002:0),7,right)
408 "local weather target jumped across a control-point boundary");
409 }
410 for(int side=1;side<=4;++side) {
412 const int du=side==3?1:side==4?-1:0, dv=side==2?1:side==1?-1:0;
413 const auto row=Packet(
false,
VECTOR2SHORT(center.
u+du,center.
v+dv),0,117,100,7,side,6000);
414 Accept(shifted,row);
415 for(int q=1;q<62;++q) for(int r=1;r<62;++r) {
416 const double x=center.
u+q-31+.25, y=center.
v+r-31+.75;
425 "shifting the grid changed local interpolation in the retained footprint");
426 }
427 }
430 "exact edge samples needed a nonexistent neighbor");
432 && !store.
Interpolate(0,u,v,8,local),
"interpolation crossed coverage, face or token");
433
434 auto mixed=full;
435 const int depths[4]{40,123,255,255}, waters[4]{100,123,255,0}, ages[4]{1,0,255,0};
436 for(int dq=0;dq<2;++dq)for(int dr=0;dr<2;++dr) {
437 auto* cell=mixed.data()+17+((31+dq)*64+31+dr)*12;
438 cell[4]=static_cast<unsigned char>(depths[dq*2+dr]);
439 cell[5]=static_cast<unsigned char>(waters[dq*2+dr]);
440 cell[6]=static_cast<unsigned char>(ages[dq*2+dr]);
441 }
445 "snow/water interpolation lost independent depth units");
448 "age-zero snow and surface water must coexist");
451 "aged snow lost simultaneous surface water");
452 auto missing=full;
453 missing[17+(31*64+32)*12]=0;
455 local={123,456,2};
456 Check(!partial.Interpolate(0,u,v,7,local) && local.
ceilingMeters==123
457 && partial.Interpolate(0,500,1100,7,local),
458 "missing neighbor blended zeroes, changed the output, or invalidated an exact good point");
459 const double nan=std::numeric_limits<double>::quiet_NaN();
461 "nonfinite interpolation coordinates accepted");
462}
463static void CheckSurfaceWind()
464{
465 const unsigned char golden[12]{0x49,0x7b,0xd2,0x04,0x19,0x7b,0xf0,0,0xb0,0xa4,0x1f,0x0d};
466 auto wire=Packet(true,{500,1100},0,100,0,7);
467 for(int i=0;i<4096;++i) memcpy(wire.data()+17+i*12,golden,12);
473 &&
Near(local.
snowDepthMm,25),
"server golden wind/surface units differ");
474
475 auto blend=[&](unsigned char direction0,unsigned char speed0,unsigned char direction1,unsigned char speed1) {
476 auto packet=wire;
477 for(int q=0;q<64;++q)for(int r=0;r<64;++r) {
478 auto* cell=packet.data()+17+(q*64+r)*12;
479 cell[10]=q<=31?direction0:direction1;cell[11]=q<=31?speed0:speed1;
480 }
481 store.
Reset();Accept(store,packet);
482 Check(store.
Interpolate(0,500.5,1100.25,7,local),
"wind blend fixture unavailable");
483 };
484 blend(0,10,157,10);
487 blend(0,10,79,10);
489 "opposing surface winds did not cancel as vectors");
490 blend(78,0,31,20);
492 "calm cell bearing rotated the active surface wind");
493 blend(0,0,157,0);
495 "calm wind has nonfinite or stale direction/speed");
496 blend(31,255,31,255);
498 "surface wind upper byte endpoint changed units");
499
500 auto unequal=wire;
501 const unsigned char speeds[]{0,10,100,200};
502 for(int q=0;q<2;++q)for(int r=0;r<2;++r)
503 unequal[17+((31+q)*64+31+r)*12+11]=speeds[q*2+r];
504 store.
Reset();Accept(store,unequal);
507 "surface wind used different bilinear weights");
508 const auto previous=local;
509 unequal[17+(31*64+32)*12]=0;
510 store.
Reset();Accept(store,unequal);
513 && local.
surfaceWindSpeedMs==previous.surfaceWindSpeedMs,
"missing weather changed retained surface wind");
514}
516{
517 const VECTOR2SHORT centers[6]{{1019,1019},{3057,1019},{-1019,1019},{5095,1019},{1019,-1019},{1019,3057}};
518 for(unsigned face=0;face<6;++face) for(int offset=-900;offset<=900;offset+=300) {
519 const auto center=centers[face];
520
521 auto point=[&](short u,short v) {
523 const float dominant=(face==0||face==3)?fabsf(p.y):(face==1||face==2)?fabsf(p.x):fabsf(p.z);
524 return p/dominant;
525 };
526 const short x=center.
u+offset,y=center.
v-offset;
527 auto position=(point(x,y)*.1875f+point(x+1,y)*.0625f+point(x,y+1)*.5625f+point(x+1,y+1)*.1875f)*6000.f;
528 double u,v;
530 && fabs(u-(x+.25))<.001 && fabs(v-(y+.75))<.001,
531 "fractional weather projection differs from production ground geometry");
532 const auto integral=view.
CalculateCGC(position,
static_cast<char>(face));
533 Check(integral.u==x && integral.v==y,"fractional projection lost negative-face alignment");
534 position=position*1.1f;
536 "altitude changed fractional weather coordinates");
537 }
538 double u,v;
541}
542
543static void LoadTerrain(
Viewscreen& view,
VECTOR2SHORT center,
char cube,
short elevation=200,
bool slope=
false)
544{
546 terrain.requestedCube=cube;terrain.requestedTcp=center;terrain.wholeGridPending=true;
547 auto data=std::make_unique<SRenderGrid>();data->tcp=center;
548 for(int q=0;q<64;++q)for(int r=0;r<64;++r) {
549 auto& sample=data->gridarray[q][r];sample.pri_landform=2;
550 sample.elevation=slope?short(100+(center.
u+q-31)*2+(center.
v+r-31)*3):elevation;
551 }
552 terrain.ReceiveWholeGrid(*data);
553 terrain.geometryReady=true;terrain.wholeGridReceived=false;
554}
555
556static void InitialTerrain(
Viewscreen& view,
grid& terrain, Receiver& receiver)
557{
562 auto data=std::make_unique<SRenderGrid>(); data->tcp=terrain.
requestedTcp;
563 for(auto& column:data->gridarray) for(auto& v:column) { v.pri_landform=2; v.elevation=300; v.color=0xff445566; }
564 std::vector<unsigned char> wire(1+sizeof *data); wire[0]=ID_USER_PACKET_ENUM;
565 memcpy(wire.data()+1,data.get(),sizeof *data); receiver.Receive(wire);
568}
569static std::vector<LOCALGRID2> TerrainSnapshot()
570{
571 std::vector<LOCALGRID2> result(4096); memcpy(result.data(),
gridarray,
sizeof gridarray);
return result;
572}
573static void TerrainUnchanged(const std::vector<LOCALGRID2>& before)
574{ Check(memcmp(before.data(),
gridarray,
sizeof gridarray)==0,
"weather packet mutated ground/building storage"); }
575
576static void CheckIntegration(
Viewscreen& view,
grid& terrain, Receiver& receiver, Network& network)
577{
578 InitialTerrain(view,terrain,receiver);
580 const auto center=terrain.
tcp;
const unsigned cube=terrain.
cube;
582 const auto ground=TerrainSnapshot();
584 receiver.Receive(Weather1Packet(72));
585 Check(
weather.
precip==initialPrecip,
"deprecated Weather1 array changed precipitation before grid detection");
586 receiver.Receive(Weather2Packet());
588 "retired Weather2 initialized weather before grid arrival");
589 const int before=
weather.resets;
591 Check(network.weatherRequests.size()==1 && network.weatherRequests.back().f_x==1,
592 "startup did not request grid weather before receiving any weather packet");
593 receiver.Receive(Packet(true,center,cube,10,0,0));
596 Check(network.weatherRequests.size()==1 && network.weatherRequests.back().f_x==1,"initial weather request missing");
597 receiver.Receive(Packet(true,center,cube,11,0,0));
599 receiver.Receive(Packet(true,center,cube,12,0,1));
600 double localU,localV;
602 const float localIndex=float((31+localU-center.
u)*64+31+localV-center.
v);
605 && fabsf(
weather.
smoothVisibility-(42160-localIndex)*.001f)<.00001f,
"independent full did not initialize local weather");
606 TerrainUnchanged(ground);
610 "grid precipitation did not feed/snap the local target");
612 "surface wind replaced altitude-specific Weather1 values during grid application");
614 receiver.Receive(Weather1Packet(0,0)); receiver.Receive(Weather1Packet(252));
617 "modern Weather1 changed precipitation or lost wind/temperature fields");
618 receiver.Receive(Weather2Packet());
620
621
622 receiver.Receive(Packet(
false,
VECTOR2SHORT(center.
u+1,center.
v),cube,13,12,1,3,6000));
623 TerrainUnchanged(ground);
624 Check(terrain.
geometryReady &&
weather.resets==before+1,
"weather strip rebuilt mesh or reset smoothers");
625 receiver.Receive(std::vector<unsigned char>(21,ID_USER_PACKET_ENUM));
626 receiver.Receive(std::vector<unsigned char>(25,ID_USER_PACKET_ENUM));
627 receiver.Receive(std::vector<unsigned char>(533,ID_USER_PACKET_ENUM));
628 Check(receiver.commands==1 && receiver.buildings==1 && receiver.menus==1,"weather envelope collided with existing messages");
629
631 Check(
weather.
weatherPending && network.weatherRequests.back().f_x==2,
"W0 did not request a new weather token");
632 receiver.Receive(Packet(true,center,cube,14,0,1));
634 receiver.Receive(Packet(
true,
VECTOR2SHORT(center.
u+100,center.
v),cube,15,0,2));
636 auto missing=Packet(true,center,cube,16,0,2); missing[17+(31*64+31)*12]=0;
637 receiver.Receive(missing);
639 receiver.Receive(Packet(true,center,cube,17,0,2));
641 TerrainUnchanged(ground);
642 receiver.Receive(Packet(
false,
VECTOR2SHORT(center.
u+1,center.
v),cube,20,18,2,3));
645 Check(network.weatherRequests.back().f_x==3,"missing base did not request repair");
646 receiver.Receive(Packet(true,center,cube,21,0,3));
647 Check(
weather.resets==before+2,
"transport repair reset weather smoothers");
648
649
651 const auto requestCount=network.weatherRequests.size();
655 && network.weatherRequests.size()==requestCount,"ascent retained grid or sent a request");
657 receiver.Receive(Packet(true,center,cube,22,0,4));
660 && network.weatherRequests.size()==requestCount,"above-cloud packet applied weather/W0");
662 Check(network.weatherRequests.size()==requestCount+1 && network.weatherRequests.back().f_x==5,
663 "descent did not replace the deferred W0 token");
664 receiver.Receive(Packet(true,center,cube,23,0,4));
666 receiver.Receive(Packet(true,center,cube,24,0,5));
670 const auto aboveCenter=center;
671
673 Check(network.weatherRequests.back().f_x==0,"request token did not wrap as ushort");
674 receiver.Receive(Packet(true,aboveCenter,cube,25,0,0));
677 auto refresh=Packet(true,aboveCenter,cube,26,0,0);
678 for(int i=0;i<4096;++i) { Put16(refresh.data()+17+i*12+8,1000); refresh[17+i*12]=140; }
679 receiver.Receive(refresh);
682 "ordinary full weather advance bypassed temporal smoothing");
685 "connection reset failed to queue a fresh modern grid");
687 receiver.Receive(Weather2Packet());
689 "retired Weather2 consumed a reconnect reset");
691 receiver.Receive(Weather1Packet(72));
692 Check(
weather.
precip==reconnectPrecip,
"connection reset restored deprecated Weather1 precipitation decoding");
693}
694
695
696static std::vector<unsigned char> LightningPacket(float u,float v,float seed=77,float chains=1)
697{
699 std::vector<unsigned char> wire(1+sizeof data);wire[0]=ID_USER_PACKET_ENUM;
700 memcpy(wire.data()+1,&data,sizeof data);return wire;
701}
702static std::vector<unsigned char> StormGrid(
VECTOR2SHORT center,
unsigned cube,uint32_t revision,uint16_t token,
bool eastOnly)
703{
704 auto packet=Packet(true,center,cube,revision,0,token);
705 for(int q=0;q<64;++q) for(int r=0;r<64;++r) {
706 auto* p=packet.data()+17+(q*64+r)*12;
707 p[0]=eastOnly && q<33?20:160;
708 Put16(p+2,900+q*30);Put16(p+8,15000);
709 }
710 return packet;
711}
712static void CheckLightningIntegration(
Viewscreen& view,Receiver& receiver,Network& network)
713{
719 LoadTerrain(view,center,static_cast<char>(cube));
722 receiver.Receive(StormGrid(center,cube,101,1,true));
725 network.lightningRequests.clear();
727 Check(network.lightningRequests.size()>250 && network.lightningRequests.size()<550,
728 "regional storm rate multiplied by wet-sector count or depended on local rain");
729 for(const auto& packet:network.lightningRequests)
730 Check(packet.f_x>=center.
u+2,
"lightning spawned in the dry/wrong direction");
731 const auto sent=network.lightningRequests.front();
732 const int before=view.strikes;
733 receiver.Receive(LightningPacket(sent.f_x,sent.f_y,sent.f_w,sent.f_z));
734 const float cellCeiling=(900+(sent.f_x-center.
u+31)*30)*.001f;
735 Check(view.strikes==before+1 && view.legacyStrikes==0
739 "strike did not use selected cell elevation, ceiling and actual observer distance");
740 const auto count=network.lightningRequests.size();
742 receiver.Receive(LightningPacket(sent.f_x,sent.f_y));
743 Check(network.lightningRequests.size()==count && view.strikes==before+1,"lightning generated/rendered at or above 10 km");
745 receiver.Receive(LightningPacket(sent.f_x,sent.f_y));
746 Check(network.lightningRequests.size()==count && view.strikes==before+1,"simulator generated lightning");
749 receiver.Receive(LightningPacket(sent.f_x,sent.f_y));
751 "pending W0 used the old storm footprint");
752 receiver.Receive(LightningPacket(std::numeric_limits<float>::quiet_NaN(),sent.f_y));
753 receiver.Receive(LightningPacket(sent.f_x+.5f,sent.f_y));
754 receiver.Receive(LightningPacket(sent.f_x,sent.f_y,77,100));
755 Check(view.strikes==before+1,"malformed lightning packet reached renderer");
756
757
758
762 Check(seamCube==1,"seam fixture left EP");
763 LoadTerrain(view,seamCenter,static_cast<char>(seamCube));
766 receiver.Receive(StormGrid(seamCenter,seamCube,201,1,false));
767 char rotation;
768 const auto canonical=view.
CalculateWrap(3057,-1,seamCube,&rotation);
769 const int seamBefore=view.strikes;
770 receiver.Receive(LightningPacket(canonical.u,canonical.v));
771 Check(rotation!=0 && view.strikes==seamBefore+1 && view.strikeDistance<20,
772 "rotated cube-seam lightning lost its geographic position");
775 Check(strike!=nullptr && savedRevision==201,"lightning geometry cache did not use the accepted weather revision");
779 "disconnect retained lightning or accepted a strike without current weather");
780
781
782 const int legacyBefore=view.legacyStrikes, modernBefore=view.strikes;
783 receiver.Receive(LightningPacket(seamCenter.u,seamCenter.v));
784 Check(view.legacyStrikes==legacyBefore && view.strikes==modernBefore,
785 "retired terrain-only lightning path accepted a strike without weather");
787 const auto sentBefore=network.lightningRequests.size();
789 receiver.Receive(LightningPacket(seamCenter.u,seamCenter.v));
790 Check(view.legacyStrikes==legacyBefore && view.strikes==modernBefore
791 && network.lightningRequests.size()==sentBefore,
792 "legacy-server lightning escaped simulator suppression");
795 Check(view.legacyStrikes==legacyBefore && view.strikes==modernBefore,
796 "leaving simulator replayed a discarded strike");
797 receiver.Receive(LightningPacket(seamCenter.u,seamCenter.v));
798 Check(view.legacyStrikes==legacyBefore && view.strikes==modernBefore,
799 "simulator exit restored retired lightning fallback");
800}
801
802static void CheckWeatherCommands(
Viewscreen& view,Receiver& receiver,Network& network)
803{
810 LoadTerrain(view,center,cube);
812 auto dry=StormGrid(center,cube,300,0,false);
813 for(int i=0;i<4096;++i) dry[17+i*12]=20;
815 Put16(dry.data()+7,1);
816 receiver.Receive(dry);
820 "RAIN changed live weather or contaminated its smoother");
821 network.lightningRequests.clear();
823 Check(network.lightningRequests.empty(),"RAIN manufactured a regional storm");
829 for(float yaw:{0.f,1.5f,3.f,4.5f})for(float pitch:{-.5f,0.f,.5f})
830 {
831 const auto bearing=right*cosf(yaw)+ahead*sinf(yaw);
832 const auto look=bearing*cosf(pitch)+up*sinf(pitch);
833 const auto cameraEye=-right*.03f-up*.02f,at=cameraEye-look,renderUp=-up;
835 const int before=view.strikes;
837 "BOLT failed to trigger its local diagnostic in dry weather at the cube seam");
839 "BOLT requested an unsupported chain count");
843 "BOLT was not 1 km along the camera bearing");
846 Check(std::abs(projected.x)<.002f && projected.z<0,"BOLT was behind/beside the active camera");
848 &&
GridLightning::Distance(view.strikeGround,view.strikeCloud)>.8f,
"BOLT did not attach to terrain/cloud base");
849 Check(network.lightningRequests.empty(),"BOLT broadcast a random replacement/echo");
851 }
861 "RAIN reset did not resume current live rain");
865 "live weather initialization inherited RAIN");
866 const int beforeReset=view.strikes;
867 const auto historyBefore=view.
cloudVolume.historyResets;
869 Check(view.
cloudVolume.historyResets==historyBefore+1,
"reposition retained cloud image history");
872
873
874
876 "connection-reset fixture did not arm its orbital lightning diagnostic");
878 Check(view.
cloudVolume.historyResets==historyBefore+2,
"connection reset retained cloud image history");
879 Check(!view.
cloudVolume.lightningDiagnostic,
"connection reset retained orbital lightning diagnostic");
887}
888
889static void CheckAltitudeLifecycle(
Viewscreen& view,Receiver& receiver,Network& network)
890{
896 LoadTerrain(view,center,cube);
899 receiver.Receive(StormGrid(center,cube,401,1,false));
902 const int resets=
weather.resets;
905 const auto requests=network.weatherRequests.size();
912 "ascent failed to discard weather/lightning/unsent request state");
913 for(int i=0;i<5;++i) {
914 receiver.Receive(StormGrid(center,cube,402+i,preAscentToken,false));
916 }
917 receiver.Receive(Packet(
false,
VECTOR2SHORT(center.
u+1,center.
v),cube,408,407,preAscentToken,3));
920 "above-cloud grid traffic changed weather or produced a request");
922 "volume atmosphere retained ground fog above cloud tops");
923 receiver.Receive(Weather1Packet(252));
931 "legacy renderer lost above-cloud clear-air visibility");
937 "9.5-to-10 km hysteresis band resumed local grid/lightning too early");
938
939
941 receiver.Receive(StormGrid(center,cube,410,preAscentToken,false));
946 Check(network.weatherRequests.size()==requests+1 && network.weatherRequests.back().f_x==descentToken,
947 "descent did not send exactly one causal full-grid request");
948 auto fresh=StormGrid(center,cube,411,descentToken,false);
949 for(int i=0;i<4096;++i) {
950 auto* cell=fresh.data()+17+i*12;cell[0]=80;
951 Put16(cell+2,3000);Put16(cell+8,5000);
952 }
953 LoadTerrain(view,center,cube,1000);
954 receiver.Receive(fresh);
957 "fresh descent full did not replace local targets");
960 "ordinary descent snapped local smoothers");
962 Check(network.weatherRequests.size()==requests+1,"descent repeatedly requested full grids");
963
964
968 const auto startupRequests=network.weatherRequests.size();
972 "above-cloud simulator startup sent/applied local grid");
975 "first descent failed to request its initial full");
976 receiver.Receive(StormGrid(center,cube,501,0,false));
978 receiver.Receive(StormGrid(center,cube,502,2,false));
981}
982
983
984template<class T> static void ReceiveTerrainPacket(Receiver& receiver, const T& packet)
985{
986 std::vector<unsigned char> wire(1+sizeof packet);wire[0]=ID_USER_PACKET_ENUM;
987 memcpy(wire.data()+1,&packet,sizeof packet);receiver.Receive(wire);
988}
989static void CheckTerrainAlignment(
Viewscreen& view,
grid& terrain,Receiver& receiver)
990{
991 const VECTOR2SHORT centers[6]{{2037,1019},{3057,1},{-1019,1},{5095,1},{2037,-1019},{2037,3057}};
992 for(char face=0;face<6;++face) {
993 const auto center=centers[face];
995 LoadTerrain(view,shifted,face,0,true);
996 for(int q=0;q<64;++q)for(int r=0;r<64;++r) {
997 const short u=center.
u+q-31,v=center.
v+r-31;
998 char rotation;
const auto canonical=view.
CalculateWrap(u,v,face,&rotation);
999 const bool overlap=q>=5 && r<61 && canonical.
u!=30000 && canonical.v!=30000;
1000 short height=-12345;
1001 const bool found=terrain.
TryElevation(face,u,v,height);
1002 Check(found==overlap,"terrain/weather centers or cube wrapping misaligned elevation");
1003 if(found) Check(height==100+u*2+v*3,"terrain elevation came from matching array indices");
1004 else Check(height==-12345,"missing terrain published a replacement elevation");
1005 }
1006 }
1007
1008
1009 LoadTerrain(view,{3057,1},1,650);
1010 short height=0;
1011 Check(terrain.
TryElevation(4,2037,-1019,height) && height==650,
1012 "cross-face overlap could not resolve a wrapped terrain control point");
1013 Check(!terrain.
TryElevation(4,1019,-1019,height),
"unrelated old face supplied elevation");
1014
1015 const VECTOR2SHORT center(500,1100), weatherCenter(505,1100);
1018 LoadTerrain(view,center,0,200);
1022 receiver.Receive(StormGrid(weatherCenter,0,1001,1,false));
1026 const auto rainIndex=[&](int u,int v){return (v-weatherCenter.v+31)*64+u-weatherCenter.u+31;};
1027 const auto uploads=rain.uploads;
const auto terrainRevision=terrain.
ElevationRevision();
1029 ReceiveTerrainPacket(receiver,point);
1035 &&
Near(rain.latest.cells[rainIndex(center.
u,center.
v)].x,.9f)
1037 "terrain-only point failed to refresh local weather, rain or lightning");
1038
1039
1040
1043 a=a/fabsf(a.y);b=b/fabsf(b.y);c=c/fabsf(c.y);d=d/fabsf(d.y);
1046 float interpolated;
1048 &&
Near(interpolated,331.25f,.15f),
"terrain bilinear interpolation lost fractional continuity");
1055 Check(terrain.
TryElevation(0,501,1101,height) && height==-200,
"valid negative terrain elevation was rejected");
1057 Check(terrain.
TryElevation(0,501,1101,height) && height==0,
"valid sea-level terrain was mistaken for missing data");
1058
1059
1060
1065 "terrain strip fixture did not shift east");
1066 Check(!terrain.
TryElevation(0,533,1100,height),
"cleared strip retained its former location's elevation");
1068 Check(rain.active && rain.latest.cells[rainIndex(533,1100)].w==2
1071 for(
auto& cell:row.
gridarray){cell.pri_landform=2;cell.elevation=777;}
1072 const auto beforeRow=rain.uploads;ReceiveTerrainPacket(receiver,row);
1075 Check(rain.uploads==beforeRow+1 && strike &&
Near(rain.latest.cells[rainIndex(533,1100)].x,.777f)
1078 Check(terrain.
TryElevation(0,500,1100,height) && height==900,
"terrain shift changed retained plot elevation");
1079
1080
1081 LoadTerrain(view,{501,1100},0,1200);
1082 const auto beforeFull=rain.uploads;
1087 "terrain-only full retained old weather heights");
1088
1089
1090
1096 "weather first used a fabricated terrain surface");
1099 "wrong-location terrain consumed weather reset");
1102 "unchanged weather did not initialize after matching terrain arrived");
1103
1104
1105 LoadTerrain(view,{500,1100},0,0,true);
1106 float before,after;
1107 for(int axis=0;axis<2;++axis) {
1108 const double x=axis?500.25:500.999999,y=axis?1100.999999:1100.75;
1111 &&
Near(before,after),
"terrain-driven local base jumped across a plot boundary");
1112 }
1114 LoadTerrain(view,{505,1097},0,0,true);
1116 "terrain recenter changed the same geographical surface");
1120}
1121
1123{
1124 LoadTerrain(view,{500,1100},0,175);
1125 float height=0,water=0;
1127 "radar surface preserves elevation and land classification");
1130 "radar coastline interpolates supplied water vertices above MSL");
1134 "inactive secondary water landform does not turn land into water");
1137 "active coastal landform refreshes cached radar material");
1140 "missing terrain corner cannot be filled with invented water or land");
1141}
1142
1143static void BenchmarkTerrainJoin(
Viewscreen& view,
grid& terrain,Receiver& receiver)
1144{
1145 using Clock=std::chrono::steady_clock;
1152 receiver.Receive(StormGrid({505,1097},0,1001,1,false));
1154 const auto measure=[](int count,auto run) {
1155 const auto start=Clock::now();
1156 for(int i=0;i<count;++i)run();
1157 return std::chrono::duration<double,std::milli>(Clock::now()-start).count()/count;
1158 };
1159 short surface=0;
1160 const auto rebuild=measure(500,[&]{
1162 });
1165 const auto cached=measure(20000,[&]{
1167 });
1168 Check(surface==200,"benchmark terrain lookup");
1169 std::cout<<"CPU-only ms/operation: terrain index rebuild="<<rebuild
1170 <<" full 4096-cell rain join="<<rain<<" lightning join="<<lightning
1171 <<" cached local/rain/lightning frame="<<cached
1172 <<"; offline logger and rendering sink, no GPU upload/draw timing\n";
1173}
1174
1176{
1179 const VECTOR2SHORT centers[6]{{2037,1019},{3057,1},{-1019,1},{5095,1},{2037,-1019},{2037,3057}};
1180 uint32_t revision=10000;
1181 for(char face=0;face<6;++face) {
1183 const auto center=centers[face];
1184 LoadTerrain(view,{short(center.
u+5),short(center.
v-3)},face,500);
1185 const auto base=TerrainSnapshot();
1186 auto packet=Packet(true,center,face,++revision,0,7);
1189 size_t overlap=0;
1190 for(int q=5;q<64;++q)for(int r=0;r<61;++r) {
1191 char rotation;
1192 const auto canonical=view.
CalculateWrap(center.
u+q-31,center.
v+r-31,face,&rotation);
1193 if(canonical.u==30000 || canonical.v==30000)continue;
1195 const int index=q*64+r;
1196 const int age=(index/3)%256;
1197 Check(surface &&
Near(surface->depthMm,
float(index%256))
1198 &&
Near(surface->ageHours,
float(age))
1199 &&
Near(surface->waterMm,((index/5)%256)*.1f),
"canonical snow/water alignment failed");
1200 ++overlap;
1201 }
1202 Check(overlap>3000,"snow seam fixture lacks overlap");
1205 auto changed=Packet(
true,{short(center.
u+1),center.
v},face,++revision,0,7);
1206 for(int i=0;i<4096;++i){auto* cell=changed.data()+17+i*12;cell[1]=123;cell[4]=40;cell[5]=123;cell[6]=240;}
1210 Check(
Near(after.depthMm,before.depthMm) &&
Near(after.waterMm,before.waterMm),
1211 "weather recenter snapped retained snow");
1214 const float f=1-expf(-1);
1215 Check(
Near(smoothed.depthMm,before.depthMm+(40-before.depthMm)*f)
1216 &&
Near(smoothed.waterMm,before.waterMm+(12.3f-before.waterMm)*f),
"three-second surface smoothing incorrect");
1220 Check(color1==color2 &&
Near(color1.w,1) &&
Near(color1.x,200.f/255),
"aged full snow tint");
1221 Check(memcmp(base.data(),
gridarray,
sizeof(
gridarray))==0,
"snow cumulatively modified terrain storage");
1226 "surface properties missing from weather interpolation");
1227
1228 std::fill(changed.begin()+17,changed.end(),0);Put32(changed.data()+9,++revision);
1232
1233 const int transitionDepths[3]{0,40,0}, transitionWater[3]{123,255,0}, transitionAges[3]{0,0,0};
1234 for(int step=0;step<3;++step) {
1235 changed=Packet(
true,{short(center.
u+1),center.
v},face,++revision,0,7);
1236 const int depth=transitionDepths[step], water=transitionWater[step], age=transitionAges[step];
1237 for(int i=0;i<4096;++i){auto* cell=changed.data()+17+i*12;cell[4]=static_cast<unsigned char>(depth);cell[5]=static_cast<unsigned char>(water);cell[6]=static_cast<unsigned char>(age);}
1245 Check(
Near(transitioned->depthMm,
float(depth)) &&
Near(transitioned->ageHours,
float(age))
1246 &&
Near(transitioned->waterMm,water*.1f),
"surface transition retained the inactive quantity");
1247 }
1248 }
1254 Check(dry.
depthMm==0 && dry.
waterMm==0,
"polar policy changed physical amounts");
1257 "legacy/reconnect snow lifecycle");
1258}
1259
1260#include "LightningThunderTests.h"
1261#include "PrecipitationAudioTests.h"
1262#include "LocalCloudBaseLifecycleTests.h"
1263
1264#include "TurbulenceGridTests.h"
1265#include "SpatialFogWeatherTests.h"
1266
1267int main(
int argc,
char** argv)
1268{
1269 try {
1270 CheckStore();
1271 CheckSpatialFogTransport();
1274 view.weather.viewscreen=&view; view.weather.
logger=&logger;
1275 Receiver receiver; receiver.owner.viewscreen=&view;
1276 if(argc==2 && !strcmp(argv[1],"--terrain-benchmark")) {BenchmarkTerrainJoin(view,terrain,receiver);return 0;}
1277 CheckInterpolation(); CheckSurfaceWind(); CheckCoordinates(view);
1278 CheckIntegration(view,terrain,receiver,network);
1279 CheckLightningIntegration(view,receiver,network);
1280 CheckWeatherCommands(view,receiver,network);
1281 LightningThunderTests(view);
1282 PrecipitationAudioTests();
1283 CheckAltitudeLifecycle(view,receiver,network);
1284 CheckTerrainAlignment(view,terrain,receiver);
1285 CheckRadarSurface(view,terrain);
1286 CheckSpatialFogLifecycle(view,terrain,receiver);
1287 CheckSnow(view,terrain);
1288 const int beforeCloudBase=checks;
1289 CheckLocalCloudBaseLifecycle(view,terrain);
1290 std::cout<<"PASS "<<checks-beforeCloudBase<<" local cloud-base lifecycle checks\n";
1291 const int beforeTurbulence=checks;
1292 CheckGridTurbulence(view,terrain,receiver,network);
1293 std::cout<<"PASS "<<checks-beforeTurbulence<<" vehicle turbulence grid checks\n";
1298 LoadTerrain(view,{1024,1016},0,450);
1300 const auto full=Packet(true,{1019,1019},0,1000,0,7);
1304 const auto& cell=rain.latest.cells[5*64+9];const int sample=9*64+5;
1305 Check(
Near(cell.x,.45f) &&
Near(cell.y,(750+sample)*.001f)
1306 &&
Near(cell.z,(42160-sample)*.001f) &&
Near(cell.w,(20+sample%141)*.1f),
1307 "rain grid is transposed or has incorrect units/surface plus ceiling");
1309 Check(rain.uploads==1 &&
Near(rain.latest.cells[5*64+9].w,(20+sample%141)*.1f),
1310 "RAIN command changed spatial weather or unchanged grid uploaded again");
1314 "simulator weather update fixture");
1316 Check(!rain.active && rain.uploads==1,"valid weather grid reactivated simulator fog");
1319 "simulator exit must republish current weather instead of retaining a GPU fog generation");
1323 Check(!rain.active,"enclosed/windowless view enabled spatial fog");
1327 Check(!rain.active,"stale generation enabled rain");
1329 Check(!rain.active,"unavailable grid enabled rain");
1331 Check(rain.active,"reconnect fixture active");
1335 std::cout<<"PASS "<<checks<<" independent weather grid/decoder/request/reset checks\n";
1336 return 0;
1337 } catch(const std::exception& error) { std::cerr<<"FAIL: "<<error.what()<<'\n'; return 1; }
1338}
Rendering::CloudRenderer11 renderer
bool SetLightningDiagnostic(bool enabled)
void Observe(const Vector3 &ground)
const Cell * Find(short u, short v) const
void Log(const char *msg, Level level=Info, int errorCode=0)
void AddToCallStack(const char *msg)
Result Accept(const unsigned char *p, size_t length, uint16_t expectedToken)
bool Interpolate(unsigned cube, double u, double v, uint16_t token, LocalSample &result) const
const SRenderWeather * At(unsigned cube, VECTOR2SHORT tcp, uint16_t token) const
const SPlotWeatherHeader & Header() const
bool HasRainGrid(uint64_t revision, int cube, int u, int v) const
void SetRainGrid(const RainGrid *grid)
const Surface * At(VECTOR2SHORT p) const
CloudVolumeRenderer cloudVolume
bool VolumeCloudsEnabled() const
RiseMath::Vector3 compassnorth
RiseMath::Matrix matrixLook
std::unique_ptr< weather > ptrWeather
RiseMath::Vector3 posnorml
std::unique_ptr< grid > ptrGrid
bool IsRepositionSettling() const
VECTOR2SHORT CalculateCGC(RiseMath::Vector3 position, char cube) const
VECTOR2SHORT CalculateWrap(short u, short v, char cube, char *rotate) const
LOCALGRID2 CalculateSRV(short t, short s, VECTOR2SHORT tcp, char cube, SRenderVertex sourcedata)
RiseMath::Vector3 CalculatePlanar(short u, short v)
void TriggerBCLLightningAt(const RiseMath::Vector3 &ground, const RiseMath::Vector3 &cloud, float distanceKm, int seed, int chainedBolts, bool testStrike=false) const
float onlinePlayersInVicinity
char CalculateCube(RiseMath::Vector3 position) const
void TriggerBCLLightning(int u, int v, float distanceKm, int seed, int chainedBolts) const
VECTOR2SHORT requestedTcp
uint64_t ElevationRevision() const
bool InterpolateElevation(char face, double u, double v, float &meters) const
grid(Viewscreen *ptrGame)
std::unordered_map< uint32_t, SurfacePoint > elevationByPlot
void ElevationChanged() const
void ReceiveWholeGrid(const SRenderGrid &datapacket)
void CalculateInsideArray(short t, short s) const
void CalculateCubeAndTcp()
uint64_t elevationRevision
void Trace(const char *msg, Logger::Level severity=Logger::Level::Info) const
bool TryElevation(char face, short u, short v, short &meters) const
bool TryRadarSurface(char face, short u, short v, short &meters, bool &water) const
void RemoveBuildZone(short ordinal) const
void PrepareForReposition()
bool resetWeatherOnNextGrid
bool InterpolateRadarSurface(char face, double u, double v, float &meters, float &waterFraction) const
uint64_t elevationIndexRevision
float cloudCeilingOverrideKm
void UpdateLightningSpawns(float elapsed)
void ReceiveGridLightning(short u, short v, int seed, int chainedBolts)
uint64_t lightningTerrainRevision
uint32_t lightningWeatherRevision
float cloudSurfaceTargetKm
float GetTurbulence() const
bool RefreshLightningGrid()
float cloudCeilingSmoothAglKm
float GetRainPrecip() const
void UpdateTerrainSnow(float elapsed)
void SetPrecip(float prmPrecip)
RiseMath::Vector4 TerrainSnowTint(int u, int v) const
void RequestPlotWeather(bool reset)
TerrainSnow::Store terrainSnow
void QueuePlotWeatherReset()
GridLightning::System gridLightning
void PrepareRainCurtains(bool exteriorView)
bool TriggerForwardLightning()
bool plotWeatherSuspended
uint16_t weatherRequestToken
float cloudCeilingTargetKm
bool weatherRequestQueued
uint32_t snowWeatherRevision
float visibilityOverrideKm
float cloudSurfaceSmoothKm
void SetPrecipOverride(float value)
void ResetPlotWeatherConnection()
float GetVisibilityKm() const
void UpdatePlotWeatherConditions()
uint64_t rainTerrainRevision
PlotWeather::Store plotWeather
s_network_objects playerships[MAX_SCAN]
RiseMath::Vector3 insidearray[63][63][3]
LOCALGRID2 gridarray[64][64]
constexpr float ClearVisibilityKm
std::shared_ptr< const Map > MapPtr
float Distance(const Vector3 &a, const Vector3 &b)
constexpr int MaxChainedBolts
std::wstring Clock(double seconds)
bool ParseHeader(const unsigned char *p, size_t length, SPlotWeatherHeader &result)
SRenderWeather Sample(const unsigned char *p)
bool Coordinates(const RiseMath::Vector3 &position, unsigned cube, double &u, double &v)
bool Near(const Body &b, const Triangle &t, double extra)
float Vec3Length(const Vector3 *a)
Vector3 * Vec3Cross(Vector3 *out, const Vector3 *a, const Vector3 *b)
Matrix * MatrixLookAtRH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
RiseMath::Vector4 Tint(const Surface &surface, float latitude, float sunLatitude)
std::vector< Segment > Network(float width, float height, uint32_t seed)
@ Game
Use the game audio system.
unsigned char sec_landform
unsigned char pri_landform
unsigned char pri_transition
float surfaceWindDirectionRadians
std::array< Color, 4096 > cells
SRenderVertex gridarray[64]
unsigned char pri_landform
unsigned char windDirectionRadians
bool HasVisibility() const
unsigned char precipitation
unsigned char snowDepthMm
unsigned char snowAgeHours
unsigned char surfaceWaterTenthsMm
unsigned char windSpeedMs
RiseMath::Vector3 position