Rise
The Vieneo Province
Loading...
Searching...
No Matches
weather.h
Go to the documentation of this file.
1#pragma once
2
3#include <WinSock2.h>
4#include <WS2tcpip.h>
5#include <Windows.h>
7#include "../Logger.h"
8#include "CloudVolume.h"
9#include "NightVisionGain.h"
10#include "SpatialFogWeather.h"
12#include "GridLightning.h"
13#include "TerrainSnow.h"
14
15class Viewscreen;
16
17// Highest peak wind Thule Air Base, Greenland 333 kph/207 mph
18// Highest average wind speed in 24 hours Port Martin, Antarctica 174 kph/108 mph
19// Highest peak wind gust Mt. Washington (NH) 372 kph/231 mph
20// Highest monthly average wind speed Port Martin, Antarctica 105 kph/65 mph
21
22// Gusts/turbulence, turbulence variable is 0-1
23
24struct ColorStop { float stop; unsigned char r, g, b; };
25static constexpr ColorStop aStops[] = {
26 {-0.25881904510252076234889883762405f,122,0,48 }, // Deep crimson of early civil twilight
27 {-0.08715574274765817355806427083747f,200,16,90 }, // Magenta - red of sunrise’s first rays
28 {0 ,224,96,128 }, // Soft rose just as the sun breaks the horizon
29 {0.17364817766693034885171662676931f,160,76,160 }, // Violet - pink transition
30 {0.5f,88,88,255 }, // Rich indigo of lower sky
31 { 0.86602540378443864676372317075294f,124,146,255 }, // Soft violet - blue midday glow
32 { 1,192,192,255 },
33};
34static constexpr ColorStop zStops[] = {
35 { -1.00f, 0, 0, 0 }, // true night
36 { -0.09f, 60, 0, 80 }, // deep night (~–5.4°)
37 { -0.06f, 112, 48, 140 }, // civil twilight (~–3.6°)
38 { -0.02f, 160, 96, 200 }, // dawn lavender (~–1.2°)
39 { 0.02f, 112, 88, 224 }, // morning indigo (~+1.2°)
40 { 1.00f, 154, 160, 255 } // midday pale violet-blue (+60°)
41};
42
44{
46 Logger* logger = nullptr;
47
48
49 char msg[199] = { 0 };
50 short r = 0, s = 0, t = 0;
51
52 bool hullIonization = false;
53
54
55 float windspeed = 0.0f; // kms
56 float smoothwindspeed = -1.0f;
57
58 // based on old Linke Turbidity Factor
59 float precip = 2.0f; // precip scale 1 is practical lowest clear (above clouds), 16 is limit (extreme rain)
60 float smoothPrecip = -1.0f; // init
61 float precipOverride = -1.0f;
62
63 float visibility = 42.16f; // based on old turbidity scale of 2
64 float smoothVisibility = -1.0f; // init
65 float visibilityOverrideKm = -1.0f;
66
67 float winddir = 0.0f; // radians 0-6.282
68 float smoothwinddir = -1.0f; // radians 0-6.282
69
70 float temperature = 20.0f;
71 float smoothTemperature = -1.0f;
72
76
78 float cloudSurfaceSmoothKm = -1.0f;
79
80 float cloudVisTarget1 = 0.0f;
81 float cloudVisSmooth1 = 0.0f;
84 bool spatialFogRendering = false;
85 uint16_t weatherRequestToken = 1;
89 void UpdateSpatialFogSnapshot(bool full);
90 void AdvanceSpatialFog(float elapsed);
95 void UpdateCloudBaseWeather(float elapsed);
98 uint32_t snowWeatherRevision = 0;
99 uint16_t snowRequestToken = 0;
101 void UpdateTerrainSnow(float elapsed);
106 void UpdateLightningSpawns(float elapsed);
108 void RequestPlotWeather(bool reset);
110 void ResetTurbulence();
113
114public:
115 weather(Viewscreen* ptr);
117 float orbitSunLatitude = 0; // astronomical sun before the SUN visual override
118 RiseMath::Vector4 TerrainSnowTint(int u, int v) const;
119
120 static float SunAttenuation();
122
123 template<size_t N>
124 RiseMath::Color SampleColorGradient(float step, const ColorStop(&stops)[N]) {
125 // clamp below first
126 if (step <= stops[0].stop) {
127 return RiseMath::Color(stops[0].r, stops[0].g, stops[0].b, 1.0f) / 255.0f;
128 }
129 // clamp above last
130 if (step >= stops[N - 1].stop) {
131 return RiseMath::Color(stops[N - 1].r, stops[N - 1].g, stops[N - 1].b, 1.0f) / 255.0f;
132 }
133 // find segment
134 size_t i = 0;
135 for (; i + 1 < N; ++i) {
136 if (step < stops[i + 1].stop) break;
137 }
138 // interpolate
139 float t = (step - stops[i].stop) / (stops[i + 1].stop - stops[i].stop);
140 float r = stops[i].r + (stops[i + 1].r - stops[i].r) * t;
141 float g = stops[i].g + (stops[i + 1].g - stops[i].g) * t;
142 float b = stops[i].b + (stops[i + 1].b - stops[i].b) * t;
143 return RiseMath::Color(r, g, b, 1.0f) / 255.0f;
144 }
145
146 void FrameMove(float fElapsedTime);
147 void SetWindDirectionRadians(float prmWinddir);
148 void SetTemperatureCelsius(float prmTemperature);
149 void SetWindspeedKms(float prmWindspeed);
150 void SetPrecip(float prmPrecip);
151 void SetPrecipOverride(float value);
152 void SetCloudCeilingOverrideKm(float value);
153 void SetVisibility(float prmVisibility);
154 void SetVisibilityOverrideKm(float value);
155 void SetCloudSurfaceTargetKm(float prmCloudSurfaceTargetKm);
156 void SetCloudCeilingTargetKm(float prmCloudCeilingTargetKm);
159 void ReceivePlotWeather(const unsigned char* bytes, size_t length);
160 // Read-only surface feed for weather radar and GPWS look-ahead; unavailable during reset/ascent.
166 bool TriggerForwardLightning(); // local BOLT diagnostic, 1 km along the camera ground bearing
167 void ReceiveGridLightning(short u, short v, int seed, int chainedBolts);
168 void ForceSmoothValues();
169 float GetWindspeedKms() const;
170 float GetPrecip() const; // live weather, unaffected by RAIN
171 float GetRainPrecip() const; // local exterior/glass particle override
172 float GetVisibilityKm() const;
173 void PrepareRainCurtains(bool exteriorView);
175 // Opaque geometry is fogged once by the depth-aware spatial pass.
177 float GetWindDirectionRadians() const;
178 float GetTurbulence() const;
179 float GetTemperatureCelsius() const;
180 float GetCloudCeilingMslKm() const;
181 float GetCloudCeilingKm() const;
182 float GetNormalizedPrecip();
183
184 // Ambient before lightning, fireworks, or optical equipment gain.
186
187 // Shared sky/cloud fill for exterior hull, cockpit and glass.
189 NightVisionGain::Response cockpitVision; // Recomputed with equipment/camera/simulator state.
190 RiseMath::Color cockpitAmbient = 0UL; // NVG-adjusted glass fill; instrument emission is separate.
191 RiseMath::Color cockpitRawCloudLight = 0UL; // Before exterior NVG gain/clipping.
192 RiseMath::Color cockpitRawAmbient = 0UL; // Mixed with cabin lamps before surface gain.
197 float elevation = 0.0f;
199 RiseMath::Color solarHorizon = 0UL; // Before observer eclipse; clouds shade each sample.
201 float shearRate = 0.0f;
202 float snowBlend = 0.0f;
203
205
206 //Needed in render cities
207 float fFogEndHorizon = 0.0f;
208
209 //Needed for radar
210 //unsigned char weathergrid[64][64] = {};
211
212 // Direct solar transmission through Vieneo, Iomere, and local clouds.
213 float shadow = 0.0f;
214 float solarVisibility = 1.0f; // Iomere disk coverage, recomputed every frame.
215 float cloudThickness = 0.0f;
217 float cloudDensity = 0.0f;
218 float cloudPocket = .5f;
220 float cloudRainDensity = 0.0f;
222
223 float daylightOverride = -1.0f; // admin sun position: -1 orbit; 0..1 = -90..+90 degrees, .5 horizon
224 float alphascreenOverride = -1.0f; // admin override
225 float gammascreenOverride = -1.0f; // admin override
226 bool elmoOverride = false;
227};
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
const SPlotWeatherHeader & Header() const
RiseMath::Color cockpitRawAmbient
Definition weather.h:192
float cloudCeilingOverrideKm
Definition weather.h:75
float GetPrecip() const
Definition weather.cpp:1365
void UpdateLightningSpawns(float elapsed)
Definition weather.cpp:1225
RiseMath::Color dwFogFactorZenith
Definition weather.h:194
RiseMath::Color vehicleAmbient
Definition weather.h:188
float smoothVisibility
Definition weather.h:64
float smoothTemperature
Definition weather.h:71
void ReceiveGridLightning(short u, short v, int seed, int chainedBolts)
Definition weather.cpp:1214
float alphascreenOverride
Definition weather.h:224
void SetCloudCeilingTargetKm(float prmCloudCeilingTargetKm)
Definition weather.cpp:950
uint64_t lightningTerrainRevision
Definition weather.h:104
uint32_t lightningWeatherRevision
Definition weather.h:103
float cloudSurfaceTargetKm
Definition weather.h:77
CloudBaseWeather::Store cloudBaseWeather
Definition weather.h:91
CloudVolume::Point ObservedWindKms() const
Definition weather.cpp:967
uint64_t cloudBaseTerrainRevision
Definition weather.h:94
float cloudHorizonAngle
Definition weather.h:196
float GetTurbulence() const
Definition weather.cpp:1436
bool RefreshLightningGrid()
Definition weather.cpp:1120
void SetCloudSurfaceTargetKm(float prmCloudSurfaceTargetKm)
Definition weather.cpp:938
float GetRenderVisibilityKm() const
Definition weather.h:176
RiseMath::Color solarHorizon
Definition weather.h:199
float cloudCeilingSmoothAglKm
Definition weather.h:74
float GetRainPrecip() const
Definition weather.cpp:1360
Logger * logger
Definition weather.h:46
RiseMath::Color dwFogColorZenith
Definition weather.h:193
bool IsSpatialFogRendering() const
Definition weather.h:174
weather(Viewscreen *ptr)
Definition weather.cpp:11
void UpdateTerrainSnow(float elapsed)
Definition weather.cpp:1296
void SetPrecip(float prmPrecip)
Definition weather.cpp:893
float daylightOverride
Definition weather.h:223
float shadow
Definition weather.h:213
bool hullIonization
Definition weather.h:52
float smoothPrecip
Definition weather.h:60
float GetWindspeedKms() const
Definition weather.cpp:1352
void SetTemperatureCelsius(float prmTemperature)
Definition weather.cpp:869
float shearRate
Definition weather.h:201
static float SunAttenuation()
Definition weather.cpp:22
RiseMath::Vector4 TerrainSnowTint(int u, int v) const
Definition weather.cpp:1324
float temperature
Definition weather.h:70
void FrameMove(float fElapsedTime)
Definition weather.cpp:32
float winddir
Definition weather.h:67
uint16_t cloudBaseRequestToken
Definition weather.h:93
void ForceSmoothValues()
Definition weather.cpp:1338
void RequestPlotWeather(bool reset)
Definition weather.cpp:1053
RiseMath::Color cockpitAmbient
Definition weather.h:190
float orbitSunLatitude
Definition weather.h:117
void ResetCloudBaseWeather()
Definition weather.cpp:1243
char msg[199]
Definition weather.h:49
float cloudHorizonDistance
Definition weather.h:196
uint16_t snowRequestToken
Definition weather.h:99
TerrainSnow::Store terrainSnow
Definition weather.h:97
short r
Definition weather.h:50
NightVisionGain::Response cockpitVision
Definition weather.h:189
bool weatherPending
Definition weather.h:82
float GetNormalizedPrecip()
Definition weather.cpp:1496
void QueuePlotWeatherReset()
Definition weather.cpp:1060
GridLightning::System gridLightning
Definition weather.h:102
RiseMath::Color sunAppearance
Definition weather.h:121
void SetWindDirectionRadians(float prmWinddir)
Definition weather.cpp:856
float GetWindDirectionRadians() const
Definition weather.cpp:1428
RiseMath::Color betascreen
Definition weather.h:200
float GetCloudCeilingKm() const
Definition weather.cpp:1491
uint64_t snowTerrainRevision
Definition weather.h:100
bool resetLocalCloudWeather
Definition weather.h:111
float windspeed
Definition weather.h:55
float visibility
Definition weather.h:63
void PrepareRainCurtains(bool exteriorView)
Definition weather.cpp:1375
float cloudPocket
Definition weather.h:218
void SetCloudCeilingOverrideKm(float value)
Definition weather.cpp:911
float precipOverride
Definition weather.h:61
void SetWindspeedKms(float prmWindspeed)
Definition weather.cpp:881
bool TriggerForwardLightning()
Definition weather.cpp:1161
float elevation
Definition weather.h:197
float cloudVisSmooth1
Definition weather.h:81
bool plotWeatherSuspended
Definition weather.h:83
DWORD m_dwSunViz
Definition weather.h:204
RiseMath::Color cockpitRawCloudLight
Definition weather.h:191
RiseMath::Vector4 nightVisionCloudGain
Definition weather.h:116
RiseMath::Color colorhorizon
Definition weather.h:198
float snowBlend
Definition weather.h:202
ULONGLONG weatherDiagnosticUntil
Definition weather.h:112
CloudVolume::Point cloudSurfaceWind
Definition weather.h:221
float cloudRainDensity
Definition weather.h:220
uint16_t weatherRequestToken
Definition weather.h:85
ULONGLONG weatherNextDiagnostic
Definition weather.h:112
float cloudCeilingTargetKm
Definition weather.h:73
float cloudThickness
Definition weather.h:215
bool elmoOverride
Definition weather.h:226
bool weatherRequestQueued
Definition weather.h:82
uint32_t snowWeatherRevision
Definition weather.h:98
float smoothwinddir
Definition weather.h:68
Viewscreen * viewscreen
Definition weather.h:45
void ReceivePlotWeather(const unsigned char *bytes, size_t length)
Definition weather.cpp:1069
void UpdateSpatialFogSnapshot(bool full)
Definition weather.cpp:978
float visibilityOverrideKm
Definition weather.h:65
CloudVolume::Parameters cloudParameters
Definition weather.h:216
SpatialFogWeather::Store spatialFogWeather
Definition weather.h:87
short s
Definition weather.h:50
float cloudVisTarget1
Definition weather.h:80
float cloudSurfaceSmoothKm
Definition weather.h:78
void SetVisibility(float prmVisibility)
Definition weather.cpp:926
void SetPrecipOverride(float value)
Definition weather.cpp:905
void SetVisibilityOverrideKm(float value)
Definition weather.cpp:918
RiseMath::Color SampleColorGradient(float step, const ColorStop(&stops)[N])
Definition weather.h:124
float precip
Definition weather.h:59
float GetCloudCeilingMslKm() const
Definition weather.cpp:1483
void UpdateCloudBaseWeather(float elapsed)
Definition weather.cpp:1249
float solarVisibility
Definition weather.h:214
void ResetTurbulence()
Definition weather.cpp:962
uint32_t cloudBaseWeatherRevision
Definition weather.h:92
float cloudTurbulenceBlend
Definition weather.h:219
RiseMath::Color dwFogColorHorizon
Definition weather.h:195
short t
Definition weather.h:50
void AdvanceSpatialFog(float elapsed)
Definition weather.cpp:998
void ResetPlotWeatherConnection()
Definition weather.cpp:1008
float GetVisibilityKm() const
Definition weather.cpp:1411
float GetTemperatureCelsius() const
Definition weather.cpp:1470
float lightningAfterimageAmbient
Definition weather.h:185
const PlotWeather::Store * RadarWeatherData() const
Definition weather.h:161
float cloudDensity
Definition weather.h:217
void UpdatePlotWeatherConditions()
Definition weather.cpp:1085
float gammascreenOverride
Definition weather.h:225
float smoothwindspeed
Definition weather.h:56
bool UpdatePlotWeatherAltitude()
Definition weather.cpp:1028
bool spatialFogRendering
Definition weather.h:84
uint64_t rainTerrainRevision
Definition weather.h:104
float fFogEndHorizon
Definition weather.h:207
PlotWeather::Store plotWeather
Definition weather.h:86
unsigned char r
Definition weather.h:24
unsigned char g
Definition weather.h:24
unsigned char b
Definition weather.h:24
float stop
Definition weather.h:24
static constexpr ColorStop aStops[]
Definition weather.h:25
static constexpr ColorStop zStops[]
Definition weather.h:34