1
0
Fork 0

Merge branch 'master' of git://gitorious.org/fg/fgdata

This commit is contained in:
Alexis Bory 2010-10-28 21:29:37 +02:00
commit 3c18fc1e1c
21 changed files with 2268 additions and 1022 deletions

View file

@ -7,7 +7,7 @@
<body>
<h1>Local Weather Package - v0.85</h1>
<h1>Local Weather Package - v0.9</h1>
<h2>1. Introduction</h2>
@ -15,7 +15,7 @@ The aim of a local weather system is to simulate weather phenomena tied to speci
This is in contrast to the current (v.2.0.0) weather system of Flightgear where weather changes affect the weather everywhere in the simulated world and are (with few exceptions) not tied to specific locations. In such a system, it is impossible to observe e.g. the approach of a rainfront while flying in sunshine.<p>
The local weather package ultimately aims to provide the functionality to simulate such local phenomena. In version 0.85, the package supplies various cloud placement algorithms, as well as local control over most major weather parameters (wind, visibility, pressure, temperature, rain, snow, thermal lift, turbulence...) through interpolation routines and event volumes. The dynamics of the different systems is tied together - clouds and weather effects drift in the specified wind field. The package also contains a fairly detailed algorithm to generate convective clouds and thermals with a realistic distribution. Unfortunately, as of v0.85, there is no interaction yet between the windfield and the cloud-generating algorithms, i.e. while the placement algorithms create a realistic configuration of thermals and convective clouds, the wind will simply move this configuration, not create, destroy or move clouds in altitude dynamically (which would be realistic). <p>
The local weather package ultimately aims to provide the functionality to simulate such local phenomena. In version 0.9, the package supplies various cloud placement algorithms, as well as local control over most major weather parameters (wind, visibility, pressure, temperature, rain, snow, thermal lift, turbulence...) through interpolation routines and effect volumes. The dynamics of the different systems is tied together - clouds and weather effects drift in the specified wind field. The package also contains a fairly detailed algorithm to generate convective clouds and thermals with a realistic distribution. In addition, there is a simulation of realistic interaction of the convective cloud system with the terrain as a function of time. Clouds drifting in the wind flow over obstacles, i.e. they change their altitude dynamically. Convection is implemented with a life cycle model of clouds - they are generated, evolve for a given lifetime dependent on the underlying terrain and decay at the end of their life cycle. Thermals associated with the clouds follow the same pattern. In particular, in the presence of wind favourable spots for convection generate 'alleys' of dense cloud cover downwind, or thermals and clouds generated over land decay rapidly once they reach open water.<p>
For long-range flights, the system automatically provides transitions between different weather patterns like fronts and low and high pressure areas. However, basically all features currently present can and will eventually be improved.<p>
@ -24,13 +24,18 @@ For long-range flights, the system automatically provides transitions between di
The package needs to be unpacked in the Flightgear root directory. It writes content into the <i>Nasal/, gui/, gui/dialogs/, Shaders, Effects/, Docs/</i>, and <i>Models/Weather/</i> subdirectories. The installation does not overwrite any of the default Flightgear files, but to be accessible from the menu, one must copy <i>gui/menubar.xml.alt</i> to the default <i>menubar.xml</i> or copy the last two lines of the environemnt menu calling <i>local_weather</i> and <i>local_weather_tiles</i> into the default file.<p>
This adds the items <i>Local Weather</i>, <i>Local Weather Tiles</i> and <i>Local Weather Settings</i> to the <i>Environment</i> menu when Flightgear is up. Most of the basic functionality is contained in <i>local_weather.nas</i> which is loaded at startup and identifies itself with a message, but does not start any functions unless called from the GUI.<p>
This adds the items <i>Local Weather</i>, <i>Local Weather Tiles</i> and <i>Local Weather Settings</i> to the <i>Environment</i> menu when Flightgear is up. Most of the basic functionality is contained in <i>local_weather.nas</i> which is loaded at startup and identifies itself with a message.<p>
Unless asked to do so from the menu, local weather does <b>not</b> run any process in the background. Upon loading, the package does not set any properties already existing, but only generates properties necessary for the menu entries in its own subdirectory <i>/local-weather/</i> in the tree. The package also does a features check on startup if particular functions are available in hard-coded form. If the features are not present, the package will still function properly using slower Nasal fallbacks.<p>
<h2>3. Functionality</h2>
The general rule is that the gui is not hardened against problematic user input, for example it will not reject meaningless input like negative windspeeds or unphysical windshear. It is recommended to watch the console, because some level of warnings and errors are passed to the console. Placement calls may sometimes take a significant time to execute especially for large numbers of clouds tied in a complicated way to the terrain. Placing 500 barrier clouds against a small barrier may take a minute to compute. During this time, a reduced framerate is to be expected<p>
The general rule is that the gui is not hardened against problematic user input, for example it will not reject meaningless input like negative windspeeds or unphysical windshear. It is recommended to watch the console, because some level of warnings and errors are passed to the console if the log options is on. Crucial warnings are also printed on-screen.<p>
The first menu contains the low level cloud placement functions. Its purpose is mainly for developing cloud patterns without having to resort to re-type the underlying Nasal code every time. Currently five options are supported: <i>Place a single cloud</i>, <i>Place a cloud streak</i>, <i>Start the convective system</i>, <i>Create barrier clouds</i> and <i>Place a cloud layer</i>.<p>
Placement calls may sometimes take a significant time to execute especially for large numbers of clouds tied in a complicated way to the terrain. Placing 500 barrier clouds against a small barrier may take a minute to compute. During this time, a reduced framerate is to be expected<p>
The first menu <b>Local Weather</b> contains the low level cloud placement functions. Its purpose is mainly for developing cloud patterns without having to resort to re-type the underlying Nasal code every time. Currently five options are supported: <i>Place a single cloud</i>, <i>Place a cloud streak</i>, <i>Start the convective system</i>, <i>Create barrier clouds</i> , <i>Place a cloud layer</i> and <i>Make a cloudbox</i>.<p>
<center>
<img src="menu1.jpg">
@ -93,26 +98,45 @@ The second menu is used to place complete weather tiles based on low-level calls
<img src="menu2.jpg">
</center><p>
Weather is created in a series of 40x40 km squares, called tiles. Tiles are classified by airmass, such that the sequence of tiles can describe for example the transition from a high pressure area to a low pressure area. The dropdown menu is used to select the type of weather tile to build initially. The menu contains two groups of tiles - the first are classified by airmass, whereas the last two are scenarios intended for soaring. <p>
Weather is created in a series of 40x40 km squares, called tiles. Tiles are classified by airmass, such that the sequence of tiles can describe for example the transition from a high pressure area to a low pressure area. The dropdown menu is used to select the type of weather tile to build initially. <p>
Below are entries for three parameters. The first two are the simplified version of wind direction and speed for the user who is not interested in specifying many different wind interpolation points.
The third parameter, the altitude offset, is to manually adjust the altitude level of clouds in the absence of terrain presampling. Cloud layer placement calls are then specified for absolute altitudes and calibrated at sea level. As a result, layers are placed too low in mountainous terrain, hence the need for an offset. The offset may at present also be useful for dynamical weather, as convective clouds with terrain presampling follow terrain altitude, which looks strange when the clouds are allowed to drift in the wind without altitude correction. <p>
The third parameter, the altitude offset, is to manually adjust the altitude level of clouds in the absence of terrain presampling. Cloud layer placement calls are then specified for absolute altitudes and calibrated at sea level. As a result, layers are placed too low in mountainous terrain, hence the need for an offset. <p>
The dropdown menu for the wind contains various models for how the windfield is specified which require a different amount of user-specified input. The options are described further down when the windfield modelling is described in more detail.<p>
The dropdown menu for the tile selection mode controls the long-range behaviour of weather. It specifies according to what rules tiles are automatically generated once the aircraft reaches the border of the original tile. The option 'single tile' creates a single weather tile as specified without automatic generation of further tiles. The option 'repeat tile' creates new tiles of the same type as the originally selected tile. This does not mean that weather will be unchanged during flight, as both parameters like pressure, temperature and visibility as well as the positioning of cloud banks are randomized to some degree. In addition, each tile typically contains 2-5 different cloud scenarios, so five repeated generations of 'low-pressure-border' tiles may never result in the same arrangement of cloud layers. Necertheless, the option will keep weather conditions roughly the same. This is different with the (somewhat optimistically named) 'realistic weather'. This option allows transitions between different airmasses, thus one may select 'low-pressure-core' initially, but as the flight goes on, eventually a region of high pressure and clear skies may be reached. Currently this change between airmasses does not include transitions across fronts. Moreover, it does not cover transitions to arctic or tropical weather conditions - those will be covered in a future release. Note that 'realistic weather' does not work for the two soaring scenarios, 'repeat tile' does not work for any tile which is part of a front.<p>
The dropdown menu for the tile selection mode controls the long-range behaviour of weather. It specifies according to what rules tiles are automatically generated once the aircraft reaches the border of the original tile. The option 'single tile' creates a single weather tile as specified without automatic generation of further tiles. The option 'repeat tile' creates new tiles of the same type as the originally selected tile. This does not mean that weather will be unchanged during flight, as both parameters like pressure, temperature and visibility as well as the positioning of cloud banks are randomized to some degree. In addition, each tile typically contains 2-5 different cloud scenarios, so five repeated generations of 'low-pressure-border' tiles may never result in the same arrangement of cloud layers. Necertheless, the option will keep weather conditions roughly the same. This is different with the (somewhat optimistically named) 'realistic weather'. This option allows transitions between different airmasses, thus one may select 'low-pressure-core' initially, but as the flight goes on, eventually a region of high pressure and clear skies may be reached. Moreover, it does not cover transitions to arctic or tropical weather conditions - those will be covered in a future release. 'repeat tile' does not work for any tile which is part of a front.<p>
The final option, 'METAR', generates weather according to parsed METAR information. This information must be made available in the property tree. Currently this is <b>not</b> done automatically and the METAR system does <b>not</b> work with real-weather-fetch, this needs some work on the Flightgear core.<p>
The final option, 'METAR', generates weather according to parsed METAR information. This information must be made available in the property tree. Currently this is <b>not</b> done automatically and the METAR system does <b>not</b> work with real-weather-fetch, this needs some work on the Flightgear core. Future versions will be able to use parsed METAR to generate weather tiles.<p>
Below the menu are five tickboxes. 'Terrain presampling' finds the distribution of altitude in the terrain before placing a cloud layer. As a result, the layers or clouds are automatically placed at the correct altitude above ground in level terrain. In mountain regions, cloud placement is fairly tricky, and the algorithm analyzes quantities like the median altitude to determine what to do. The appendix contains a detailed description of the algorithm. If the box is ticked, the altitude offset specified above is not parsed.<p>
Below the menu are six tickboxes. 'Terrain presampling' finds the distribution of altitude in the terrain before placing a cloud layer. As a result, the layers or clouds are automatically placed at the correct altitude above ground in level terrain. In mountain regions, cloud placement is fairly tricky, and the algorithm analyzes quantities like the median altitude to determine what to do. The appendix contains a detailed description of the algorithm. If the box is ticked, the altitude offset specified above is not parsed.<p>
'generate thermals' is an option intended primarily for soaring. It determines if thermals will be placed whenever a convective clouds is generated. Since managing a large number of thermals costs some amount of resources, it is recommended to generate thermals only if they are needed, i.e. definitely for soaring, possibly for added realism in small aircraft.<p>
'Worker threads' is an option to distribute the work flow. Usually, the local weather package will compute a task till it is done before starting the next. Thus, creating a new weather tile may lead to a few seconds freeze, before Flightgear continues normally. With 'worker threads' selected, computations will be split across several frames. The advantage is that Flightgear stays responsive during loading and unloading of weather tiles, and in general the flight continues smoothly, albeit with reduced framerate. However, selecting this option does not guarantee that an operation is finished by the time another is beginning - thus there may be situations in which the loading of a new tile blocks unloading of an old one and so on, in essence leading to processes competing for access to the weather array, resulting in an extended period of very low framerates. Dependent on system performance, this may or may not be acceptable to the user. 'asymmetric range' is an experimental performance-improving option (see below). Finally, 'detailed clouds' will change the technique for generating Cumulus clouds from a multilayer model to multiple cloudlets filling a box. This improves the visual appearance of the clouds significantly, albeit at the expense of a (significant) loss of framerate. Rendering multiple tiles of dense Cumulus development with detailed clouds will quite possibly freeze even a powerful system. <p>
'debug output' determines if the system writes status messages to the console. Unselecting the option suppresses normal status messages (warnings and errors will still be written). However, in many cases the log of status messages is needed to trace bugs, so if you switch it off and experience a problem, it is likely that the problem cannot be traced.<p>
The option 'dynamical weather' ties all clouds and weather effects to the windfield. If that option is not chosen, the wind is still generated according to the chosen model, but only felt by the aircraft. This makes e.g. soaring unrealistic, as the aircraft continuously drifts out of a static thermal below a static cap cloud. When 'dynamical weather' is selected, aircraft, cloud and thermal are all displaced by the wind.<p>
'detailed clouds' will change the technique for generating Cumulus clouds from a multilayer model to multiple cloudlets filling a box. This improves the visual appearance of the clouds significantly, albeit at the expense of some loss of framerate. Rendering multiple tiles of dense Cumulus development with detailed clouds will quite possibly slow down even a powerful system. <p>
The option 'dynamical weather' ties all clouds and weather effects to the windfield. If that option is not chosen, the wind is still generated according to the chosen model, but only felt by the aircraft. This makes e.g. soaring unrealistic, as the aircraft continuously drifts out of a static thermal below a static cap cloud. When 'dynamical weather' is selected, aircraft, cloud and thermal are all displaced by the wind and follow elevation changes to some degree.<p>
The final option 'dynamical convection' requires both 'terrain presamling' and 'dynamical weather' to be on (if not, a warning is given and the system aborts). If this option is chosen, all convective clouds and thermals have a life cycle - clouds are continually spawned and decay after a while. This preserves realistic cloud configurations over islands even with wind drift on and improves the realism of the soaring experience as the thermals change over time, but again uses somewhat more performance - switch it on if you need it, for fast planes the visual gain is almost non-existent.<p>
The slider 'Thermal properties' is mainly relevant for soaring scenarios. It governs the rato of maximum lift to radius of a thermal. A setting close to 'low convection' creates large thermals with relatively small lift and virtually no turbulence, a setting close to 'rough day' creates very narrow, turbulent thermals with large lift. However, it also affects the Cumulus textures to be used. 'low convection' creates well-formed, smooth Cumuli whereas 'rough day' biases the texture selection towards more rugged and diffuse clouds.<p>
The difference is apparent from the following pictures: Smooth and well-formed clouds characteristic of a calm day:<p>
<center>
<img src="detailed_clouds04.jpg">
</center><p>
Rough clouds characteristic of windshear and more turbulent conditions:<p>
<center>
<img src="detailed_clouds05.jpg">
</center><p>
As for the buttons, 'Ok' starts the local weather system with the selected options (note that all options in this menu are startup-time options, they are read once and changing them without restarting the system will not affect the behaviour of the system). 'Clear/End' clears all clouds and ends all local weather functionality - the button brings the system back into the state before it was started. No loops or other subroutines are executed after the button is pressed. 'Close' closes the dialog without starting the system.<p>
The button 'Show winds' brings up the detailed wind menu which is needed for the wind models 'aloft interpolated' and 'aloft waypoints':<p>
<center>
@ -125,14 +149,14 @@ In principle, the waypoint information inserted so far can be seen using the pro
The following pictures show the results of tile setups 'Low-pressure-border' and 'High-pressure-border':<p>
The following pictures show possible results of tile setups 'High-pressure-border' and 'Low-pressure':<p>
<center>
<img src="carrier-ops08.jpg">
<img src="high_pressure_border.jpg">
</center><p>
<center>
<img src="clouds-lpb01.jpg">
<img src="low_pressure.jpg">
</center><p>
<h3>Performance settings</h3>
@ -162,11 +186,20 @@ All performance setting menu-options work at runtime, but are processed over tim
The package contains a number of different cloud models, both static ones for Cirrus and Cirrocumulus clouds as well as rotated ones for Altocumulus, Cirrostratus, Cumulus, Cumulonimbus, Stratus and Nimbostratus cloudlet models. Neither the cloud textures, nor the models nor the transformations are perfected, and any aspect can be improved.<p>
Static clouds project textures onto curved sheets into the sky. The advantage of the technique is that cloud layers consisting of thousands of cloudlets with different sizes can be modelled. However, the sheets do not look equally well from all perspectives and somewhat unrealistic from close up.<p>
<center>
<img src="clouds-static.jpg">
</center><p>
Rotated cloud models have the advantage that they look much better from close up and hardly unrealistic from any perspective, but the size distribution of cloudlets is somewhat restricted and they use a lot more performance than static clouds.<p>
<center>
<img src="clouds-detailed01.jpg">
</center><p>
These are rendered by a different technique: While the default Cumulus models consist of multiple layers rotated around the center of the model, the detailed Cumulus clouds consist of multiple (up to 24) individual cloudlets, rotating each around its own center, randomly distributed into a box. This not only improves the visual appearance, but also leads to a more realistic distribution of cloud sizes and shapes in the sky. In addition, when circling below the cloud (as done when soaring) the effect of the cloudlet rotation is less pronounced. The price to pay is that rendering detailed clouds costs about a factor 4 more performance, so they may not be suitable for all systems.<p>
These are rendered by different techniques. While the default Cumulus models consist of multiple layers rotated around the center of the model, the detailed Cumulus clouds consist of multiple (up to 24) individual cloudlets, rotating each around its own center, randomly distributed into a box with different texture types used for the cloud bottom. This not only improves the visual appearance, but also leads to a more realistic distribution of cloud sizes and shapes in the sky. In addition, when circling below the cloud (as done when soaring) the effect of the cloudlet rotation is less pronounced. The price to pay is that rendering detailed clouds costs more performance, so they may not be suitable for all systems.<p>
More complex clouds are rendered in sandwitched layers of several different textures. An example are Cumulonimbus towers, which use diffuse textures on the bottom, changing to more structured textures in the upper part of the cloud. With up to 2000 cloudlets, skies with multiple thunderstorms may not render with sufficient framerates on every system.<p>
@ -178,7 +211,7 @@ The general problem is finding a good balance between spending a lot of CPU time
Currently all clouds which need to be rotated are treated in the Shaders using a view-axis based rotation by two angles. This generally looks okay from a normal flight position, but rapid change of the view axis (looking around), especially straight up or down, causes unrealistic cloud movement. Any static picture of clouds however is (almost) guaranteed to look fine. This means that shader effects need to be 'on' in order to see most of the clouds.<p>
Currently all clouds which need to be rotated are treated in the shaders using a view-axis based rotation by two angles. This generally looks okay from a normal flight position, but rapid change of the view axis (looking around), especially straight up or down, causes unrealistic cloud movement. Any static picture of clouds however is (almost) guaranteed to look fine. This means that shader effects need to be 'on' in order to see most of the clouds.<p>
<h2>5. Local weather parameters</h2>
@ -208,11 +241,11 @@ Volumes 2 and 3 are nested inside volume 1, therefore all settings of 2 overwrit
Effect volumes are always specified between a minimum and a maximum altitude, and they can have a circular, elliptical and rectangular share (the last two rotated by an angle phi). Since it is quite difficult to set up event volumes without visual reference and also not realistic to use them without the context of a cloud or precipitation model, there is no low-level setup call available in the menu. Effect volumes can be created with a Nasal call <p>
<i>create_effect_volume(geometry, lat, lon, r1, r2, phi, alt_low, alt_high, vis, rain, snow, turb, lift, lift_flag);</i><p>
<i>create_effect_volume(geometry, lat, lon, r1, r2, phi, alt_low, alt_high, vis, rain, snow, turb, lift, lift_flag, sat);</i><p>
where <i>geometry</i> is a flag (1: circular, 2: elliptical and 3: rectangular), <i>lat</i> and <i>lon</i> are the latitude and longitude, <i>r1</i> and <i>r2</i> are the two size parameters for the elliptic or rectangular shape (for the circular shape, only the first is used), <i>phi</i> is the rotation angle of the shape (not used for circular shape), <i>alt_low</i> and <i>alt_high</i> are the altitude boundaries, <i>vis, rain, snow, turb</i> and <i>lift</i> are weather parameters which are either set to the value they should assume, or to -1 if they are not to be used, or to -2 if a function instead of a parameter is to be used. Since thermal lift can be set to negative values in a sink, a separate flag is provided in this case.<p>
where <i>geometry</i> is a flag (1: circular, 2: elliptical and 3: rectangular), <i>lat</i> and <i>lon</i> are the latitude and longitude, <i>r1</i> and <i>r2</i> are the two size parameters for the elliptic or rectangular shape (for the circular shape, only the first is used), <i>phi</i> is the rotation angle of the shape (not used for circular shape), <i>alt_low</i> and <i>alt_high</i> are the altitude boundaries, <i>vis, rain, snow, turb</i> and <i>lift</i> are weather parameters which are either set to the value they should assume, or to -1 if they are not to be used, or to -2 if a function instead of a parameter is to be used and -3 if a function for wave lift is used. Since thermal lift can be set to negative values in a sink, a separate flag is provided in this case. <i>sat</i> finally determines the light saturation - it can be used to dim the light beneath cloud layers (which is not done automatically as objects don't cast shades in Flightgear, and given that most cloud models are rotated, their shade would look rather odd on any case).<p>
In version 0.85, thermal lift is implemented by function. There is no easy way to implement any weather parameter by function in an effect volume, as this requires some amount of Nasal coding.
In version 0.9, thermal lift and wave lift are implemented by function (wave lift is not yet automatically placed, but can be easily from Nasal). There is no easy way to implement any weather parameter by function in an effect volume, as this requires some amount of Nasal coding.
<h2>6. Wind models and dynamical weather</h2>
@ -245,9 +278,9 @@ The internal state of the local weather system is found in the property tree und
The <i>local-weather</i> folder contains various subdirectories. <i>clouds/</i> contains the record of all visible weather phenomena (clouds, precipitation layers, lightning...) in a subdirectory <i>tile[j]/cloud[i]/</i>. The total number of all models placed is accessible as <i>local-weather/clouds/cloud-number</i>. Inside each <i>cloud/</i> subdirectory, there is a string <i>type</i> specifying the type of object and subdirectories <i>position/</i> and <i>orientation</i> which contain the position and spatial orientation of the model inside the scenery. Note that the orientation property is obsolete for clouds which are rotated by the shader.<p>
The <i>local-weather/effect-volumes/</i> subfolder contains the management of the effect volumes. It has the total count of specified effect volumes, along with the count of currently active volumes for each property. If volumes are defined, their properties are stored under <i>local-weather/effect-volumes/effect-volume[i]/</i>. In each folder, there are <i>position/</i> and <i>volume/</i> storing the spatial position and extent of the volume, as well as the <i>active-flag</i> which is set to 1 if the airplane is in the volume and the <i>geometry</i> flag which determines if the volume has circular, elliptical or rectangular shape. Finally, the <i>effects/</i> subfolder holds flags determining of a property is to be set when the volume is active and the corresponding values. On entry, the effect volumes also create a subfolder <i>restore/</i> in which the conditions as they were when the volume was entered are saved.<p>
The <i>local-weather/effect-volumes/</i> subfolder contains the management of the effect volumes. It has the total count of specified effect volumes, along with the count of currently active volumes for each property.<p>
<i>local-weather/interpolation/</i> holds all properties which are set by the interpolation system, as well as subfolders <i>station[i]/</i> in which the weather station information for the interpolation are found and subfolders <i>wind[i]</i> where wind information in the case of 'aloft interpolated' or 'aloft waypoints' is stored. Basically, here is the state of the weather as it is outside of effect volumes. Since parameters may be set to different values in effect volumes, the folder <i>local-weather/current/</i> contains the weather as the local weather system currently thinks it should be. Currently, weather is actually passed to the Flightgear environment system through several workarounds. In a clean C++ supported version, the parameters should be read from here.<p>
<i>local-weather/interpolation/</i> holds all properties which are set by the interpolation system. Basically, here is the state of the weather as it is outside of effect volumes. Since parameters may be set to different values in effect volumes, the folder <i>local-weather/current/</i> contains the weather as the local weather system currently thinks it should be. Currently, weather may be passed to the Flightgear environment system through several workarounds, dependent on the Flightgear core version.<p>
<i>local-weather/tiles</i> stores the information of the 9 managed weather tiles (the one the airplane is currently in, and the 8 surrounding it). By default each directory contains the tile center coordinates and a flag if it has been generated. Tiles are not generated unless a minimum distance to the tile center has been reached. Once this happens, the tile type is written as a code, and the cloud, interpolation and effect volume information corresponding to the tile is generated. <p>
@ -261,7 +294,7 @@ The first important call sets up the conditions to be interpolated:<p>
<i>set_weather_station(latitude, longitude, visibility-m, temperature-degc, dewpoint-degc, pressure-sea-level-inhg);</i><p>
The cloud placement calls should be reasonably familiar, as they closely resemble the structure by which they are accessible from the menu. Note that for (rather stupid reasons) currently a <i>randomize_pos</i> call <b>must</b> follow a <i>create_streak</i> call.<p>
The cloud placement calls should be reasonably familiar, as they closely resemble the structure by which they are accessible from the 'Local Weather' menu.<p>
If the cloud layer has an orientation, then all placement coordinates should be rotated accordingly. Similarly, each placement call should include the altitude offset. Take care to nest effect volumes properly where possible, otherwise undesired effects might occur...<p>
@ -281,7 +314,8 @@ With default settings, the local weather package generates a 40x40 km weather ti
<li> if this does not help, try avoiding scenarios with large cloud count. As a rule, low pressure areas have high cloud count, high pressure areas have a low cloud count. Do not use 'detailed clouds', which tend to generate large cloud counts.<p>
<li> a different issue is a characteristic small pause every second. This is caused by the interpolation loop resetting the weather parameters. Currently, a computationally expensive workaround is needed to do so, causing the problem. Work on a better environment controller is on the way, however until that modification to the core Flightgear code is implemented, the best solution is to set the loop time in <i>Nasal/local-weather.nas</i> to a larger value. <p>
<li> a different issue is a characteristic small pause every second. This may be caused by the interpolation loop resetting the weather parameters or by the altitude correction of convective clouds when cloud count is high and wind drift is on. The first issue only occurs when the system did not find hard coded support. There is no easy fix for the second problem, except to avoid dynamical weather in situations with large cloud counts.
<p>
<li> dynamical weather uses a lot of performance. If framerate is low and you don't need it, don't use it! From fast planes, cloud drift is almost impossible to see against the relative motion of cloud and airplane anyway.<p>
@ -297,7 +331,7 @@ With default settings, the local weather package generates a 40x40 km weather ti
<li> Rain and snow may not start properly. For me, rain is only generated when I switch 'Shader effects' on and off in the menu on startup, otherwise neither moving the menu slider nor entering an effect volume generate rain. This seems to be a bug of some Flightgear versions, not of the local weather system.<p>
<li> Especially with multiple overcast layers and weather fronts, loading and unloading weather tiles may take a long time / cause severe drops in framerate. Please refer to performance tuning to solve such problems. In general, overcast layers and tropical weather tiles do require a system on the high end of the performance scale to render properly.<p>
<li> Especially with multiple overcast layers and weather fronts, loading and unloading weather tiles may take a long time / cause severe drops in framerate. The problem is much worse in GIT than in 2.0.0. Please refer to performance tuning to solve such problems. In general, overcast layers and tropical weather tiles do require a system on the high end of the performance scale to render properly.<p>
<li> The local weather package is able to occasionally trigger errors like 'Warning:: Picked up error in TriangleIntersect'. These seem to be a problem in the core Flightgear code - the package does nothing but placing normal (rather simple) AC3D models into the scenery.<p>
@ -307,6 +341,8 @@ With default settings, the local weather package generates a 40x40 km weather ti
<li> Large tile creation distances can cause problems in low visibility weather, because Flightgear loads terrain only if it is within visual range. Thus, trying to sample the terrain for a tile 55 km away in 8 km visibility doesn't work because the terrain elevation and altitude is not known. This may cause improper placement of clouds - chiefly convective clouds, but also layered clouds may not appear on the proper altitude. Currently, there is a limit which restricts tile loading range to 3 times the visibility, but presumably a better solution can be found.<p>
<li> Using the 'aloft interpolated' wind option, it is possible to turn the wind direction sharply over a small distance (for example, one may turn the wind by 90 degrees from one tile to the next). Such sharp wind changes are (in most situations) unphysical, and they may cause problems for local weather because they rotate the coordinate system to a degree that the neighbouring tile may not be identified correctly. In essence, the system may not generate new tiles because the nearest tile is still the last generated one. There will be a future fix to address the problem, for the moment just avoid rotating the wind strongly.<p>
<li> The thermals in the soaring scenarios need GIT to work.<p>
</ul>
@ -314,9 +350,9 @@ With default settings, the local weather package generates a 40x40 km weather ti
This section describes the more complicated cloud placement algorithms in some detail. It is intended for readers who are interested in understanding (and possibly modifying) what creates the weather they get to see.
<h3>The convective algorithm and the properties of thermals</h3>
<h3>The convective startup algorithm and the properties of thermals</h3>
The convective algorithm is used to place Cumulus clouds as well as thermals. Thermals are by default not placed to save CPU time unless a tile designed for soaring is selected, but they can be generated for any weather tile by setting <i>local-weather/tmp/generate-thermal-lift-flag</i> to either 1 (constant-strength thermals) or 2 (detailed thermal model).<p>
The convective startup algorithm is used to place Cumulus clouds as well as thermals. Thermals are by default not placed to save CPU time unless the flag is set in the menu.<p>
At the core of the convective algorithm is the concept of locally available thermal energy. The source of this energy is solar radiation. The flux of solar energy depends on the angle of incident sunlight with the terrain surface. It is possibly (though computationally very expensive) to compute this quantity, but the algorithm uses a proxy instead. The daily angle of the sun at the equator assuming flat terrain is modelled as <i>0.5 * (1.0-cos(t/24.0*2pi))</i> with t expressed in hours, a function that varies between zero at midnight and 1 at noon. There is a geographical correction to this formula which goes with <i>cos(latitude)</i>, taking care of the fact that the sun does not reach the zenith at higher latitudes. Both the yearly summer/winter variation of the solar position in the sky and the terrain slope are neglected.<p>
@ -368,6 +404,32 @@ At sunset around 19:00 pm, the number of clouds decreases quickly, but there is
While not accurate in every respect, the model works fairly well to reproduce the actual time dependence of convective clouds and thermal lift during the day.<p>
<h3>The convective dynamics algorithm</h3>
The convective dynamics algorithm is responsible for modelling the life cycle of convective clouds, dependent on the terrain type underneath. It meshes well with the convective startup algorithm, and its long-term zero wind limit is just the situation set up by the initial convective placement.<p>
At its heart is the idea of fractional cloud lifetime. A cloud is born with fractional lifetime zero, and it decays once its fractional lifetime reaces 1. The translation of real time to fractional lifetime is given by <i>sqrt(p)</i> where <i>p</i> is the landcover dependent probability defined above. A cloud over landcover with maximum <i>p</i> of 0.35 has a lifetime of 30 minutes, so if a cloud spends 10 minutes over this terrain type, its fractional lifetime is increased by 1/3. If the landcover is different, the lifetime is reduced according to <i>sqrt(p_1/p_max)</i>.<p>
A cloud field is initialized with fractional lifetimes randomly distributed between zero and 1. To compensate for the decay of clouds, clouds are periodically respawned as in the startup algorithm, but with placement probability <i>sqrt(p)</i> instead of <i>p</i>. In the limit of no wind, the cloud density over a terrain type is then given by placement probability times lifetime, i.e. <i>sqrt(p) * sqrt(p) = p</i> as it should be. The presence of a windfield distorts the cloud distribution, dense clouds are then found preferably downwind of suitable convection sources.<p>
<h3>The thermal lift model</h3>
The model of the distribution of lift inside a thermal is quite complex. <p>
<center>
<img src="thermal_lift.gif">
</center><p>
Vertically, is is characterized in addition to height and radius by two parameters, 'coning' and 'shaping', which make it cone-shaped and wasp-waisted. From zero to 200 m above ground, the lift is smoothly fading in, above the cloudbase it is smoothly faded out to zero at 10% above the nominal altitude. Horizontally, there is an outer ring where the air becomes turbulent, followed by a region of sink which in turn is followed by the inner core of lift.<p>
The distribution of lift and sink is time dependent.
<center>
<img src="thermal_lift_time.gif">
</center><p>
In a young thermal, lift starts to develop from the ground, sink is initially absent. When the lift reaches the cloudbase, sink starts to develop from the ground and rises up as well. Only in a mature thermal are sink and lift in equilibrium. When the thermal starts to decay, lift initially decays from the ground upward, till it reaches the cloudbase. At this time the cap cloud dissolves. For a time there is a residual distribution of sink decaying from bottom to top till the thermal evolution is over and the thermal (and the associate turbulence field) is removed.<p>
<h3>The terrain presampling and cloud altitude determination algorithm</h3>
While the meaning of a cloud layer altitude is rather obvious in level terrain, this quickly becomes a highly non-trivial question in mountaineous terrain where the elevation of the terrain is more difficult to define. Observation of weather patterns in mountain regions suggests that clouds follow changes in terrain elevation to some degree, but not all cloud types do to the same degree. While convective clouds follow a change in elevation more readily even on small distance scales, layered clouds don't do so. The purpose of the terrain presampling and cloud altitude determination algorithm is to capture this behaviour as closely as possible.<p>
@ -434,10 +496,10 @@ Realistically, the boundary layer should also depend on terrain coverage. Due to
<h2>Credits</h2>
The model of a thermal has been developed by Patrice Poly. The shader code used to transform clouds is heavily based on prior work by Stuart Buchanan.<p>
The model of a thermal has been developed by Patrice Poly. The shader code used to transform clouds is heavily based on prior work by Stuart Buchanan. Hard-coding of some features by Torsten Dreyer is greatly appreciated.<p>
Thorsten Renk, June 2010
Thorsten Renk, October 2010
</body>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 58 KiB

BIN
Docs/clouds-static.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
Docs/detailed_clouds04.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
Docs/detailed_clouds05.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
Docs/low_pressure.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 26 KiB

BIN
Docs/thermal_lift.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
Docs/thermal_lift_time.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

@ -7,6 +7,7 @@
<depth-factor type="float">0.008</depth-factor>
<night-color type="vec3d">0.75 0.59 0.05</night-color>
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
<max-lod-level>10</max-lod-level>
</parameters>
<generate>
<normal type="int">15</normal>
@ -68,12 +69,24 @@
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format>
<use>texture[2]/internal-format</use>
</internal-format>
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<image><use>texture[2]/image</use></image>
<filter>nearest-mipmap-nearest</filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format><use>texture[2]/internal-format</use></internal-format>
<mipmap-control>
<function-r>average</function-r>
<function-g>average</function-g>
<function-b>average</function-b>
<function-a>min</function-a>
</mipmap-control>
</texture-unit>
<texture-unit>
<unit>3</unit>
<type>noise</type>
</texture-unit>
<program>
@ -102,10 +115,15 @@
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>QDMTex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>NoiseTex</name>
<type>sampler-3d</type>
<value type="int">2</value>
<value type="int">3</value>
</uniform>
<uniform>
<name>depth_factor</name>
@ -132,6 +150,11 @@
<type>float</type>
<value><use>snow-level</use></value>
</uniform>
<uniform>
<name>max_lod_level</name>
<type>float</type>
<value><use>max-lod-level</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -7,21 +7,19 @@
# function purpose
#
# setVisibility to set the visibility to a given value
# setLift to set lift to given value
# setRain to set rain to a given value
# setSnow to set snow to a given value
# setTurbulence to set turbulence to a given value
# setTemperature to set temperature to a given value
# setPressure to set pressure to a given value
# setDewpoint to set the dewpoint to a given value
# setLight to set light saturation to given value
# setWind to set wind
# setWindSmoothly to set the wind gradually across a second
# smooth_wind_loop helper function for setWindSmoothly
# smooth_wind_loop (helper function for setWindSmoothly)
# create_cloud to place a single cloud into the scenery
# create_cloud_array to place clouds from storage arrays into the scenery
# move_cloud to move the cloud position
# remove_clouds to remove clouds by tile index
# waiting_loop to ensure tile removal calls do not overlap
# remove_tile_loop to remove a fixed number of clouds per frame
# get_elevation to get the terrain elevation at given coordinates
# get_elevation_vector to get terrain elevation at given coordinate vector
@ -68,72 +66,35 @@
# The compatibility layer is currently work in progress and will be extended as new Nasal
# APIs are being added to FlightGear.
###########################################
# header checking availability of functions
###########################################
var has_symbol = func(s) contains(globals,s);
var is_function = func(s) typeof(globals[s])=='func';
var has_function = func(f) has_symbol(f) and is_function(f);
# try to call a function with given parameters
# save exceptions to err vector
# returns 0 for no exceptions (exceptions vector is empty)
# returns >=1 for exception occurred (i.e. unsupported API call)
var try_call = func(f, params) {
var err=[];
call(globals[f], params, nil,nil,err); # see http://plausible.org/nasal/lib.html
return size(err);
};
var query = func(api,params) {
if ( has_function(api) ) {
return try_call(api, params );
}
return 1; # fail
}
var patches = { geodinfo: "http://flightgear.org/forums/viewtopic.php?f=5&t=7358&st=0&sk=t&sd=a&start=90#p82805", };
# query fgfs binary for required APIs and set values in this hash
var features = {};
#fixme: compare results from new and old API
var check_geodinfo_vec = func {
var err=[];
if ( query('geodinfo',[ [37.618,-122.374],1000])==0 ) {
printf("geodinfo found"); # now try to use it
var ksfo=[37.618, -122.374];
var alt=10000;
# see if it returns a vector or not
call( func { print (alt); (typeof(geodinfo(ksfo,alt))=='vector')?return:die(); }, [], caller()[0],nil,err);
print('-','geodinfo:', (size(err) >=1) ? "Vector support unavailable" : "Vector support available");
if(size(err) and contains(patches,'geodinfo')) print('---> A patch is available at ', patches['geodinfo']);
return size(err)?0:1;
}
return 0;
}
_setlistener("/sim/signals/nasal-dir-initialized", func {
print ("Compatibility layer: Checking available Nasal APIs:");
print ("(this may cause harmless error messages when hard-coded support is lacking)");
print ("##########################################");
features.geodinfo_supports_vectors= check_geodinfo_vec ();
print("features.geodinfo_supports_vectors=", features.geodinfo_supports_vectors);
print ("##########################################");
print("Compatibility checks done.");
var result = "yes";
print("Compatibility layer: testing for hard coded support");
if (props.globals.getNode("/rendering/scene/saturation", 0) == nil)
{result = "no"; features.can_set_light = 0;}
else
{result = "yes"; features.can_set_light = 1;}
print("* can set light saturation: "~result);
if (props.globals.getNode("/environment/terrain", 0) == nil)
{result = "no"; features.terrain_presampling = 0;}
else
{result = "yes"; features.terrain_presampling = 1;}
print("* hard coded terrain presampling: "~result);
if (props.globals.getNode("/environment/config/enabled", 0) == nil)
{result = "no"; features.can_disable_environment = 0;}
else
{result = "yes"; features.can_disable_environment = 1;}
print("* can disable global weather: "~result);
print("Compatibility layer: tests done.");
});
# this is now where we can simply refer to features.geodinfo_supports_vectors
# for checking if vector support is available or not - to use the most appropriate
# APIs
@ -143,20 +104,38 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
var setVisibility = func (vis) {
# this is a rather dirty workaround till a better solution becomes available
# essentially we update all entries in config and reinit environment
if (features.can_disable_environment == 1)
{
setprop("/environment/visibility-m",vis);
}
else
{
# this is a workaround for systems which lack hard-coded support
# essentially we update all entries in config and reinit environment
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
foreach (var e; entries_aloft) {
e.getNode("visibility-m",1).setValue(vis);
}
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
foreach (var e; entries_aloft) {
e.getNode("visibility-m",1).setValue(vis);
}
var entries_boundary = props.globals.getNode("environment/config/boundary", 1).getChildren("entry");
foreach (var e; entries_boundary) {
e.getNode("visibility-m",1).setValue(vis);
}
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var entries_boundary = props.globals.getNode("environment/config/boundary", 1).getChildren("entry");
foreach (var e; entries_boundary) {
e.getNode("visibility-m",1).setValue(vis);
}
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
}
}
####################################
# set thermal lift to given value
####################################
var setLift = func (lift) {
if (features.can_disable_environment == 1)
{
setprop("/environment/wind-from-down-fps",lift);
}
}
####################################
@ -193,24 +172,36 @@ setprop("environment/metar/snow-norm",snow);
var setTurbulence = func (turbulence) {
# this is a rather dirty workaround till a better solution becomes available
# essentially we update all entries in config and reinit environment
if (features.can_disable_environment == 1)
{
setprop("/environment/turbulence/magnitude-norm",turbulence);
setprop("/environment/turbulence/rate-hz",3.0);
}
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
foreach (var e; entries_aloft) {
e.getNode("turbulence/magnitude-norm",1).setValue(turbulence);
}
else
{
# this is a workaround for systems which lack hard-coded support
# essentially we update all entries in config and reinit environment
# turbulence is slightly reduced in boundary layers
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
foreach (var e; entries_aloft) {
e.getNode("turbulence/magnitude-norm",1).setValue(turbulence);
e.getNode("turbulence/rate-hz",1).setValue(3.0);
e.getNode("turbulence/factor",1).setValue(1.0);
}
var entries_boundary = props.globals.getNode("environment/config/boundary", 1).getChildren("entry");
var i = 1;
foreach (var e; entries_boundary) {
e.getNode("turbulence/magnitude-norm",1).setValue(turbulence * 0.25*i);
i = i + 1;
}
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
# turbulence is slightly reduced in boundary layers
var entries_boundary = props.globals.getNode("environment/config/boundary", 1).getChildren("entry");
var i = 1;
foreach (var e; entries_boundary) {
e.getNode("turbulence/magnitude-norm",1).setValue(turbulence * 0.25*i);
e.getNode("turbulence/rate-hz",1).setValue(5.0);
e.getNode("turbulence/factor",1).setValue(1.0);
i = i + 1;
}
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
}
}
@ -220,11 +211,18 @@ fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var setTemperature = func (T) {
# this is a rather dirty workaround till a better solution becomes available
# essentially we update the entry in config and reinit environment
setprop(ec~"boundary/entry[0]/temperature-degc",T);
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
if (features.can_disable_environment == 1)
{
setprop("/environment/temperature-sea-level-degc",T);
}
else
{
# this is a workaround for systems which lack hard-coded support
# essentially we update the entry in config and reinit environment
setprop(ec~"boundary/entry[0]/temperature-degc",T);
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
}
}
####################################
@ -233,12 +231,19 @@ fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var setPressure = func (p) {
# this is a rather dirty workaround till a better solution becomes available
# essentially we update the entry in config and reinit environment
if (features.can_disable_environment == 1)
{
setprop("/environment/pressure-sea-level-inhg",p);
}
else
{
# this is a workaround for systems which lack hard-coded support
# essentially we update the entry in config and reinit environment
setprop(ec~"boundary/entry[0]/pressure-sea-level-inhg",p);
setprop(ec~"aloft/entry[0]/pressure-sea-level-inhg",p);
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
setprop(ec~"boundary/entry[0]/pressure-sea-level-inhg",p);
setprop(ec~"aloft/entry[0]/pressure-sea-level-inhg",p);
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
}
}
####################################
@ -247,11 +252,30 @@ fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var setDewpoint = func (D) {
# this is a rather dirty workaround till a better solution becomes available
# essentially we update the entry in config and reinit environment
if (features.can_disable_environment == 1)
{
setprop("/environment/dewpoint-sea-level-degc",D);
}
else
{
# this is a workaround for systems which lack hard-coded support
# essentially we update the entry in config and reinit environment
setprop(ec~"boundary/entry[0]/dewpoint-degc",D);
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
setprop(ec~"boundary/entry[0]/dewpoint-degc",D);
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
}
}
####################################
# set light saturation to given value
####################################
var setLight = func (s) {
if (features.can_set_light == 1)
{
setprop("/rendering/scene/saturation",s);
}
}
###########################################################
@ -261,23 +285,30 @@ fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var setWind = func (dir, speed) {
# this is a rather dirty workaround till a better solution becomes available
# essentially we update all entries in config and reinit environment
if (features.can_disable_environment == 1)
{
setprop("/environment/wind-from-heading-deg",dir);
setprop("/environment/wind-speed-kt",speed);
}
else
{
# this is a workaround for systems which lack hard-coded support
# essentially we update all entries in config and reinit environment
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
foreach (var e; entries_aloft) {
e.getNode("wind-from-heading-deg",1).setValue(dir);
e.getNode("wind-speed-kt",1).setValue(speed);
}
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
foreach (var e; entries_aloft) {
e.getNode("wind-from-heading-deg",1).setValue(dir);
e.getNode("wind-speed-kt",1).setValue(speed);
}
var entries_boundary = props.globals.getNode("environment/config/boundary", 1).getChildren("entry");
foreach (var e; entries_boundary) {
e.getNode("wind-from-heading-deg",1).setValue(dir);
e.getNode("wind-speed-kt",1).setValue(speed);
}
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var entries_boundary = props.globals.getNode("environment/config/boundary", 1).getChildren("entry");
foreach (var e; entries_boundary) {
e.getNode("wind-from-heading-deg",1).setValue(dir);
e.getNode("wind-speed-kt",1).setValue(speed);
}
fgcommand("reinit", props.Node.new({subsystem:"environment"}));
}
}
###########################################################
@ -288,21 +319,29 @@ fgcommand("reinit", props.Node.new({subsystem:"environment"}));
var setWindSmoothly = func (dir, speed) {
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
if (features.can_disable_environment == 1)
{
setWind(dir, speed);
}
else
{
var dir_old = entries_aloft[0].getNode("wind-from-heading-deg",1).getValue();
var speed_old = entries_aloft[0].getNode("wind-speed-kt",1).getValue();
var entries_aloft = props.globals.getNode("environment/config/aloft", 1).getChildren("entry");
var dir = dir * math.pi/180.0;
var dir_old = dir_old * math.pi/180.0;
var dir_old = entries_aloft[0].getNode("wind-from-heading-deg",1).getValue();
var speed_old = entries_aloft[0].getNode("wind-speed-kt",1).getValue();
var vx = speed * math.sin(dir);
var vx_old = speed_old * math.sin(dir_old);
var dir = dir * math.pi/180.0;
var dir_old = dir_old * math.pi/180.0;
var vy = speed * math.cos(dir);
var vy_old = speed_old * math.cos(dir_old);
var vx = speed * math.sin(dir);
var vx_old = speed_old * math.sin(dir_old);
smooth_wind_loop(vx,vy,vx_old, vy_old, 4, 4);
var vy = speed * math.cos(dir);
var vy_old = speed_old * math.cos(dir_old);
smooth_wind_loop(vx,vy,vx_old, vy_old, 4, 4);
}
}
@ -335,10 +374,35 @@ var create_cloud = func(path, lat, long, alt, heading) {
var tile_counter = getprop(lw~"tiles/tile-counter");
var buffer_flag = getprop(lw~"config/buffer-flag");
var dynamics_flag = getprop(lw~"config/dynamics-flag");
var d_max = weather_tile_management.cloud_view_distance + 1000.0;
# check if we deal with a convective cloud
var convective_flag = 0;
if (find("cumulus",path) != -1)
{
if ((find("alto",path) != -1) or (find("cirro", path) != -1) or (find("strato", path) != -1))
{convective_flag = 0;}
else if ((find("small",path) != -1) or (find("whisp",path) != -1))
{convective_flag = 1;}
else if (find("bottom",path) != -1)
{convective_flag = 4;}
else
{convective_flag = 2;}
}
else if (find("congestus",path) != -1)
{
if (find("bottom",path) != -1)
{convective_flag = 5;}
else
{convective_flag = 3;}
}
#print("path: ", path, " flag: ", convective_flag);
# first check if the cloud should be stored in the buffer
# we keep it if it is in visual range or at high altitude (where visual range is different)
@ -352,8 +416,17 @@ if (buffer_flag == 1)
if ((d > d_max) and (alt < 20000.0)) # we buffer the cloud
{
var b = weather_tile_management.cloudBuffer.new(lat, long, alt, path, heading, tile_counter);
if (dynamics_flag ==1) {b.timestamp = weather_dynamics.time_lw;}
var b = weather_tile_management.cloudBuffer.new(lat, long, alt, path, heading, tile_counter, convective_flag);
if (local_weather.dynamics_flag ==1)
{
b.timestamp = weather_dynamics.time_lw;
if (convective_flag !=0) # Cumulus clouds get some extra info
{
b.evolution_timestamp = cloud_evolution_timestamp;
b.flt = cloud_flt;
b.rel_alt = alt - cloud_mean_altitude;
}
}
append(weather_tile_management.cloudBufferArray,b);
return;
}
@ -364,10 +437,12 @@ if (buffer_flag == 1)
if (getprop(lw~"tmp/buffer-status") == "placing")
{
tile_counter = getprop(lw~"tmp/buffer-tile-index");
#tile_counter = getprop(lw~"tmp/buffer-tile-index");
tile_counter = buffered_tile_index;
}
# if the cloud is not buffered, get property tree nodes and write it
# into the scenery
@ -382,6 +457,7 @@ var cloud_number = n.getNode("placement-index").getValue();
cl = c.getChild("cloud", i, 1);
n.getNode("placement-index").setValue(i);
var placement_index = i;
var model_number = n.getNode("model-placement-index").getValue();
var m = props.globals.getNode("models", 1);
@ -397,8 +473,6 @@ var latN = cl.getNode("position/latitude-deg", 1); latN.setValue(lat);
var lonN = cl.getNode("position/longitude-deg", 1); lonN.setValue(long);
var altN = cl.getNode("position/altitude-ft", 1); altN.setValue(alt);
var hdgN = cl.getNode("orientation/true-heading-deg", 1); hdgN.setValue(heading);
#var pitchN = cl.getNode("orientation/pitch-deg", 1); pitchN.setValue(0.0);
#var rollN = cl.getNode("orientation/roll-deg", 1);rollN.setValue(0.0);
cl.getNode("tile-index",1).setValue(tile_counter);
@ -407,35 +481,57 @@ model.getNode("latitude-deg-prop", 1).setValue(latN.getPath());
model.getNode("longitude-deg-prop", 1).setValue(lonN.getPath());
model.getNode("elevation-ft-prop", 1).setValue(altN.getPath());
model.getNode("heading-deg-prop", 1).setValue(hdgN.getPath());
#model.getNode("pitch-deg-prop", 1).setValue(pitchN.getPath());
#model.getNode("roll-deg-prop", 1).setValue(rollN.getPath());
model.getNode("tile-index",1).setValue(tile_counter);
model.getNode("load", 1).remove();
n.getNode("cloud-number").setValue(n.getNode("cloud-number").getValue()+1);
# sort the model node into a vector for easy deletion
# append(weather_tile_management.modelArrays[tile_counter-1],model);
# sort the cloud into the cloud hash array
if ((buffer_flag == 1) and (getprop(lw~"tmp/tile-management") != "single tile"))
if (buffer_flag == 1)
{
var cs = weather_tile_management.cloudScenery.new(tile_counter, cl, model);
var cs = weather_tile_management.cloudScenery.new(tile_counter, convective_flag, cl, model);
append(weather_tile_management.cloudSceneryArray,cs);
}
# if weather dynamics is on, also create a timestamp property and sort the cloud node into quadtree
# if weather dynamics is on, also create a timestamp property and sort the cloud hash into quadtree
#if (getprop(lw~"config/dynamics-flag") == 1)
if (dynamics_flag == 1)
if (local_weather.dynamics_flag == 1)
{
cl.getNode("timestamp-sec",1).setValue(weather_dynamics.time_lw);
var blat = getprop(lw~"tiles/tmp/latitude-deg");
var blon = getprop(lw~"tiles/tmp/longitude-deg");
var alpha = getprop(lw~"tmp/tile-orientation-deg");
weather_dynamics.sort_into_quadtree(blat, blon, alpha, lat, long, weather_dynamics.cloudQuadtrees[tile_counter-1], cl);
cs.timestamp = weather_dynamics.time_lw;
cs.write_index = placement_index;
if (convective_flag !=0) # Cumulus clouds get some extra info
{
cs.evolution_timestamp = cloud_evolution_timestamp;
cs.flt = cloud_flt;
cs.rel_alt = alt - cloud_mean_altitude;
cs.target_alt = alt;
}
if (getprop(lw~"tmp/buffer-status") == "placing")
{
var blat = buffered_tile_latitude;
var blon = buffered_tile_longitude;
var alpha = buffered_tile_alpha;
#var blat1 = getprop(lw~"tiles/tmp/latitude-deg");
#var blon1 = getprop(lw~"tiles/tmp/longitude-deg");
#var alpha1 = getprop(lw~"tmp/tile-orientation-deg");
#print("Lat: ", blat1, " ", blat);
#print("Lon: ", blon1, " ", blon);
#print("Alp: ", alpha1, " ", alpha);
}
else
{
var blat = getprop(lw~"tiles/tmp/latitude-deg");
var blon = getprop(lw~"tiles/tmp/longitude-deg");
var alpha = getprop(lw~"tmp/tile-orientation-deg");
}
weather_dynamics.sort_into_quadtree(blat, blon, alpha, lat, long, weather_dynamics.cloudQuadtrees[tile_counter-1], cs);
}
}
@ -451,12 +547,13 @@ if (getprop(lw~"tmp/thread-status") != "placing") {return;}
if (getprop(lw~"tmp/convective-status") != "idle") {return;}
if ((i < 0) or (i==0))
{
print("Cloud placement from array finished!");
if (local_weather.debug_output_flag == 1)
{print("Cloud placement from array finished!"); }
setprop(lw~"tmp/thread-status", "idle");
# now set flag that tile has been completely processed
var dir_index = props.globals.getNode(lw~"tiles/tmp/dir-index").getValue();
# print("dir_index: ",dir_index);
props.globals.getNode(lw~"tiles").getChild("tile",dir_index).getNode("generated-flag").setValue(2);
return;
@ -470,6 +567,12 @@ if (s < k_max) {k_max = s;}
for (var k = 0; k < k_max; k = k+1)
{
if (getprop(lw~"config/dynamics-flag") ==1)
{
cloud_mean_altitude = local_weather.clouds_mean_alt[s-k-1];
cloud_flt = local_weather.clouds_flt[s-k-1];
cloud_evolution_timestamp = local_weather.clouds_evolution_timestamp[s-k-1];
}
create_cloud(clouds_path[s-k-1], clouds_lat[s-k-1], clouds_lon[s-k-1], clouds_alt[s-k-1], clouds_orientation[s-k-1]);
}
@ -479,144 +582,19 @@ setsize(clouds_lon,s-k_max);
setsize(clouds_alt,s-k_max);
setsize(clouds_orientation,s-k_max);
if (getprop(lw~"config/dynamics-flag") ==1)
{
setsize(local_weather.clouds_mean_alt,s-k_max);
setsize(local_weather.clouds_flt,s-k_max);
setsize(local_weather.clouds_evolution_timestamp,s-k_max);
}
settimer( func {create_cloud_array(i - k, clouds_path, clouds_lat, clouds_lon, clouds_alt, clouds_orientation ) }, 0 );
};
####################################################
# move a cloud
####################################################
var move_cloud = func (c, tile_index) {
# get the old spacetime position of the cloud
var lat_old = c.getNode("position/latitude-deg").getValue();
var lon_old = c.getNode("position/longitude-deg").getValue();
var alt = c.getNode("position/altitude-ft").getValue();
var timestamp = c.getNode("timestamp-sec").getValue();
# get windfield and time since last update
var windfield = weather_dynamics.get_windfield(tile_index);
var dt = weather_dynamics.time_lw - timestamp;
#print(dt * windfield[1]);
# update the spacetime position of the cloud
c.getNode("position/latitude-deg",1).setValue(lat_old + windfield[1] * dt * local_weather.m_to_lat);
c.getNode("position/longitude-deg",1).setValue(lon_old + windfield[0] * dt * local_weather.m_to_lon);
c.getNode("timestamp-sec",1).setValue(weather_dynamics.time_lw);
}
####################################################
# remove clouds by tile index
####################################################
var remove_clouds = func (index) {
var n = size(props.globals.getNode("local-weather/clouds").getChild("tile",index,1).getChildren("cloud"));
props.globals.getNode("local-weather/clouds", 1).removeChild("tile",index);
setprop(lw~"clouds/cloud-number",getprop(lw~"clouds/cloud-number")-n);
if (getprop(lw~"tmp/thread-flag") == 1)
{settimer( func {waiting_loop(index); },0);}
else
{
var modelNode = props.globals.getNode("models", 1).getChildren("model");
foreach (var m; modelNode)
{
if (m.getNode("tile-index",1).getValue() == index) {m.remove();}
}
}
}
# this is to avoid two tile removal loops starting at the same time
var waiting_loop = func (index) {
var status = getprop(lw~"tmp/thread-status");
if (status == "idle") {remove_tile_loop(index);}
else {
print("Removal of ",index, " waiting for idle thread...");
settimer( func {waiting_loop(index); },1.0);
}
}
var remove_tile_loop = func (index) {
var n = 100;
var flag_mod = 0;
var status = getprop(lw~"tmp/thread-status");
if ((status == "computing") or (status == "placing")) # the array is blocked
{
settimer( func {remove_tile_loop(index); },0); # try again next frame
return;
}
else if (status == "idle") # we initialize the loop
{
mvec = weather_tile_management.modelArrays[index-1];
msize = size(mvec);
if (msize == 0)
{
print("Tile deletion loop finished!");
setprop(lw~"tmp/thread-status", "idle");
setprop(lw~"clouds/placement-index",0);
setprop(lw~"clouds/model-placement-index",0);
setsize(weather_tile_management.modelArrays[index-1],0);
return;
}
setprop(lw~"tmp/last-reading-pos-mod", msize);
setprop(lw~"tmp/thread-status", "removing");
}
var lastpos = getprop(lw~"tmp/last-reading-pos-mod");
if (lastpos < (msize-1)) {var istart = lastpos;} else {var istart = (msize-1);}
if (istart<0) {istart=0;}
var i_min = istart - n;
if (i_min < -1) {i_min =-1;}
for (var i = istart; i > i_min; i = i- 1)
{
m = mvec[i];
m.remove();
}
if (i<0) {flag_mod = 1;}
if (flag_mod == 0) {setprop(lw~"tmp/last-reading-pos-mod",i); }
if (flag_mod == 0) # we still have work to do
{settimer( func {remove_tile_loop(index); },0);}
else
{
print("Tile deletion loop finished!");
setprop(lw~"tmp/thread-status", "idle");
setprop(lw~"clouds/placement-index",0);
setprop(lw~"clouds/model-placement-index",0);
setsize(weather_tile_management.modelArrays[index-1],0);
}
}
@ -629,7 +607,8 @@ var get_elevation = func (lat, lon) {
var info = geodinfo(lat, lon);
if (info != nil) {var elevation = info[0] * local_weather.m_to_ft;}
else {var elevation = -1.0;}
else {var elevation = -1.0; }
return elevation;
}
@ -643,17 +622,12 @@ var get_elevation_array = func (lat, lon) {
var elevation = [];
var n = size(lat);
if (features.geodinfo_supports_vectors == 0)
for(var i = 0; i < n; i=i+1)
{
for(var i = 0; i < n; i=i+1)
{
append(elevation, get_elevation(lat[i], lon[i]));
}
}
else
{
elevation = geodinfo(lat,10000);
append(elevation, get_elevation(lat[i], lon[i]));
}
return elevation;
}
@ -673,3 +647,20 @@ var ec = "/environment/config/";
var mvec = [];
var msize = 0;
# available hard-coded support
var features = {};
# globals to transmit info if clouds are written from buffer
var buffered_tile_latitude = 0.0;
var buffered_tile_longitude = 0.0;
var buffered_tile_alpha = 0.0;
var buffered_tile_index = 0;
# globals to handle additional info for Cumulus cloud dynamics
var cloud_mean_altitude = 0.0;
var cloud_flt = 0.0;
var cloud_evolution_timestamp = 0.0;

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
########################################################
# routines to simulate cloud wind drift and evolution
# Thorsten Renk, July 2010
# Thorsten Renk, October 2010
########################################################
# function purpose
@ -9,18 +9,18 @@
# timing_loop to provide accurate timing information for wind drift calculations
# quadtree_loop to manage drift of clouds in the field of view
# weather_dynamics_loop to manage drift of weather effects, tile centers and interpolation points
# convective_loop to regularly recreate convective clouds
# generate_quadtree_structure to generate a quadtree data structure used for managing the visual field
# sort_into_quadtree to sort objects into a quadtree structure
# sorting_recursion to recursively sort into a quadree (helper)
# quadtree_recursion to search the quadtree for objects in the visual field
# check_visibility to check if a quadrant is currently visible
# move_tile to move tile coordinates in the wind
# move_effect_volume to move an effect volume in the wind
# move_weather_station to move a weather station in the wind
# get_cartesian to get local Cartesian coordinates out of coordinates
####################################################
# get the windfield for a given locatio and altitude
# get the windfield for a given location and altitude
# (currently constant, but supposed to be local later)
####################################################
@ -63,7 +63,8 @@ return windfield;
var timing_loop = func {
time_lw = time_lw + getprop("/sim/time/delta-sec");
dt_lw = getprop("/sim/time/delta-sec");
time_lw = time_lw + dt_lw;
if (getprop(lw~"timing-loop-flag") ==1) {settimer(timing_loop, 0);}
@ -116,6 +117,8 @@ foreach (t; tiles)
cos_beta = math.cos(beta * math.pi/180.0);
sin_beta = math.sin(beta * math.pi/180.0);
plane_x = xy_vec[0]; plane_y = xy_vec[1];
windfield = get_windfield(index);
quadtree_recursion(cloudQuadtrees[index-1],0,1,0.0,0.0);
}
@ -156,34 +159,172 @@ if (getprop(lw~"dynamics-loop-flag") ==1) {settimer(quadtree_loop, 0);}
var weather_dynamics_loop = func (index) {
var weather_dynamics_loop = func (index, cindex) {
var n = 20;
var nc = 1;
var csize = weather_tile_management.n_cloudSceneryArray;
var i_max = index + n;
if (i_max > local_weather.n_effectVolumeArray) {i_max = local_weather.n_effectVolumeArray;}
var ecount = 0;
for (var i = index; i < i_max; i = i+1)
{
move_effect_volume(local_weather.effectVolumeArray[i]);
var ev = local_weather.effectVolumeArray[i];
if (ev.index !=0)
{ev.move();}
if ((ev.lift_flag == 2) and (rand() < 0.05) and (local_weather.presampling_flag == 1))
{
if (local_weather.dynamical_convection_flag ==1)
{
ev.correct_altitude_and_age();
if (ev.flt > 1.2) # beyond 1.0, sink is still active
{
local_weather.effectVolumeArray = weather_tile_management.delete_from_vector(local_weather.effectVolumeArray,i);
local_weather.n_effectVolumeArray = local_weather.n_effectVolumeArray - 1;
i = i-1; i_max = i_max -1; ecount = ecount + 1;
}
}
else
{ev.correct_altitude();}
}
}
setprop(lw~"effect-volumes/number",getprop(lw~"effect-volumes/number")- ecount);
index = index + n;
if (i >= local_weather.n_effectVolumeArray) {index = 0;}
var stations = props.globals.getNode(lw~"interpolation").getChildren("station");
foreach (s; stations)
var ccount = 0;
if (csize > 0)
{
move_weather_station(s);
var j_max = cindex + nc;
if (j_max > csize -1) {j_max = csize-1;}
for (var j = cindex; j < j_max; j = j+1)
{
var cs = weather_tile_management.cloudSceneryArray[j];
#cs.move();
if (cs.type !=0)
{
if ((rand() < 0.1) and (local_weather.presampling_flag == 1))
{
if (local_weather.dynamical_convection_flag ==1)
{
cs.correct_altitude_and_age();
if (cs.flt > 1.0) # the cloud has reached its maximum age and decays
{
cs.removeNodes();
weather_tile_management.cloudSceneryArray = weather_tile_management.delete_from_vector(weather_tile_management.cloudSceneryArray,j);
ccount = ccount + 1;
}
}
else
{
cs.correct_altitude();
}
}
}
}
cindex = cindex + nc;
if (j >= csize) {cindex = 0;}
}
if (getprop(lw~"dynamics-loop-flag") ==1) {settimer( func {weather_dynamics_loop(index); },0);}
foreach (s; local_weather.weatherStationArray)
{
s.move();
}
if (getprop(lw~"dynamics-loop-flag") ==1) {settimer( func {weather_dynamics_loop(index, cindex); },0);}
}
###########################################################
# convective evolution loop
###########################################################
var convective_loop = func {
# a 30 second loop needs a different strategy to end, otherwise there is trouble if it is restarted while still running
if (convective_loop_kill_flag == 1)
{convective_loop_kill_flag = 0; return;}
var cloud_respawning_interval_s = 30.0;
if (getprop(lw~"tmp/thread-status") == "placing")
{if (getprop(lw~"convective-loop-flag") ==1) {settimer( func {convective_loop()}, 5.0);} return;}
# open the system for write status
setprop(lw~"tmp/buffer-status","placing");
if (local_weather.debug_output_flag == 1)
{print("Respawning convective clouds...");}
for(var i = 0; i < 9; i = i + 1)
{
var index = getprop(lw~"tiles/tile["~i~"]/tile-index");
if ((index == -1) or (index == 0)) {continue;}
if (getprop(lw~"tiles/tile["~i~"]/generated-flag") != 2)
{continue;}
var strength = tile_convective_strength[index-1];
var alt = tile_convective_altitude[index-1];
var n = weather_tiles.get_n(strength);
if (local_weather.detailed_clouds_flag == 1)
{n = int(0.7 * n);}
n = n/cloud_convective_lifetime_s * cloud_respawning_interval_s * math.sqrt(0.35);
n_res = n - int(n);
n = int(n);
if (rand() < n_res) {n=n+1;}
if (local_weather.debug_output_flag == 1)
{print("Tile: ", index, " n: ", n);}
var lat = getprop(lw~"tiles/tile["~i~"]/latitude-deg");
var lon = getprop(lw~"tiles/tile["~i~"]/longitude-deg");
var alpha = getprop(lw~"tiles/tile["~i~"]/orientation-deg");
compat_layer.buffered_tile_latitude = lat;
compat_layer.buffered_tile_longitude = lon;
compat_layer.buffered_tile_alpha = alpha;
compat_layer.buffered_tile_index = index;
setprop(lw~"tmp/buffer-tile-index", index);
if (local_weather.presampling_flag == 1)
{var alt_offset = local_weather.alt_20_array[index -1];}
else
{var alt_offset = getprop(lw~"tmp/tile-alt-offset-ft");}
local_weather.recreate_cumulus(lat,lon, alt + alt_offset, alpha, n, 20000.0, index);
}
# close the write process
setprop(lw~"tmp/buffer-status","idle");
if (getprop(lw~"convective-loop-flag") ==1) {settimer(convective_loop, cloud_respawning_interval_s);}
}
###########################################################
# generate quadtree structure
###########################################################
@ -266,7 +407,8 @@ if (depth == quadtree_depth +1)
{
foreach (var c; tree)
{
compat_layer.move_cloud(c, current_tile_index_wd);
c.move();
c.to_target_alt();
cloud_counter = cloud_counter + 1;
}
return;
@ -396,59 +538,6 @@ t.getNode("timestamp-sec",1).setValue(weather_dynamics.time_lw);
}
####################################################
# move an effect volume
####################################################
var move_effect_volume = func (e) {
# get the old spacetime position of the effect
var lat_old = e.getNode("position/latitude-deg").getValue();
var lon_old = e.getNode("position/longitude-deg").getValue();
var tile_index = e.getNode("tile-index").getValue();
var timestamp = e.getNode("timestamp-sec").getValue();
# get windfield and time since last update
var windfield = weather_dynamics.get_windfield(tile_index);
var dt = weather_dynamics.time_lw - timestamp;
# update the spacetime position of the effect
e.getNode("position/latitude-deg",1).setValue(lat_old + windfield[1] * dt * local_weather.m_to_lat);
e.getNode("position/longitude-deg",1).setValue(lon_old + windfield[0] * dt * local_weather.m_to_lon);
e.getNode("timestamp-sec",1).setValue(weather_dynamics.time_lw);
}
####################################################
# move a weather station
####################################################
var move_weather_station = func (s) {
# get the old spacetime position of the station
var lat_old = s.getNode("latitude-deg").getValue();
var lon_old = s.getNode("longitude-deg").getValue();
var tile_index = s.getNode("tile-index").getValue();
var timestamp = s.getNode("timestamp-sec").getValue();
# get windfield and time since last update
var windfield = weather_dynamics.get_windfield(tile_index);
var dt = weather_dynamics.time_lw - timestamp;
# update the spacetime position of the effect
s.getNode("latitude-deg",1).setValue(lat_old + windfield[1] * dt * local_weather.m_to_lat);
s.getNode("longitude-deg",1).setValue(lon_old + windfield[0] * dt * local_weather.m_to_lon);
s.getNode("timestamp-sec",1).setValue(weather_dynamics.time_lw);
}
###########################################################
# get local Cartesian coordinates
@ -504,7 +593,12 @@ var lw = "/local-weather/";
# globals
var time_lw = 0.0;
var dt_lw = 0.0;
var max_clouds_in_loop = 250;
var cloud_max_vertical_speed_fts = 30.0;
var cloud_convective_lifetime_s = 1800.0; # max. lifetime of convective clouds
var convective_loop_kill_flag = 0;
# the quadtree structure
@ -516,6 +610,8 @@ var quadtree_depth = 3;
var tile_wind_direction = [];
var tile_wind_speed = [];
var tile_convective_altitude = [];
var tile_convective_strength = [];
# define these as global, as we need to evaluate them only once per frame
# but use them over and over
@ -525,6 +621,7 @@ var cos_beta = 0;
var sin_beta = 0;
var plane_x = 0;
var plane_y = 0;
var windfield = [];
var current_tile_index_wd = 0;

View file

@ -1,6 +1,6 @@
########################################################
# routines to set up, transform and manage weather tiles
# Thorsten Renk, July 2010
# Thorsten Renk, October 2010
########################################################
# function purpose
@ -13,9 +13,17 @@
# create_neighbour to set up information for a new neighbouring tile
# create_neighbours to initialize the 8 neighbours of the initial tile
# buffer_loop to manage the buffering of faraway clouds in an array
# housekeeping_loop to shift clouds from the scenery into the buffer
# wathcdog loop (debug helping structure)
# calc_geo to get local Cartesian geometry for latitude conversion
# get_lat to get latitude from Cartesian coordinates
# get_lon to get longitude from Cartesian coordinates
# delete_from_vector to delete an element 'n' from a vector
# object purpose
#
# cloudBuffer to store a cloud in a Nasal buffer, to provide methods to move it
# cloudScenery to store info for clouds in scenery, to provide methods to move and evolve them
###################################
@ -38,11 +46,12 @@ var loading_flag = getprop(lw~"tmp/asymmetric-tile-loading-flag");
var this_frame_action_flag = 0; # use this flag to avoid overlapping tile operations
setsize(active_tile_list,0);
#append(active_tile_list,0); # tile zero formally containing static objects is always active
if (distance_to_load > 3.0 * current_visibility)
{distance_to_load = 3.0 * current_visibility;}
if (distance_to_load < 25000.0)
{distance_to_load = 25000.0;}
if (distance_to_load < 29000.0)
{distance_to_load = 29000.0;}
foreach (var t; tNode) {
@ -77,10 +86,11 @@ foreach (var t; tNode) {
{
this_frame_action_flag = 1;
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
print("Building tile unique index ",getprop(lw~"tiles/tile-counter"), " in direction ",i);
if (local_weather.debug_output_flag == 1)
{print("Building tile unique index ",getprop(lw~"tiles/tile-counter"), " in direction ",i);}
append(active_tile_list,getprop(lw~"tiles/tile-counter"));
if (getprop(lw~"config/dynamics-flag") == 1)
if (local_weather.dynamics_flag == 1)
{
var quadtree = [];
weather_dynamics.generate_quadtree_structure(0, quadtree);
@ -97,7 +107,8 @@ foreach (var t; tNode) {
if ((d > d_remove) and (flag == 2) and (this_frame_action_flag == 0)) # the tile needs to be deleted if it exists
{
print("Removing tile, unique index ", t.getNode("tile-index").getValue()," direction ",i);
if (local_weather.debug_output_flag == 1)
{print("Removing tile, unique index ", t.getNode("tile-index").getValue()," direction ",i);}
remove_tile(t.getNode("tile-index").getValue());
t.getNode("generated-flag").setValue(0);
this_frame_action_flag = 1;
@ -132,7 +143,8 @@ foreach (var t; tNode) {
print("Flag: ",gen_flag);
}
print("Changing active tile to direction ", i_min);
if (local_weather.debug_output_flag == 1)
{print("Changing active tile to direction ", i_min);}
change_active_tile(i_min);
}
@ -169,28 +181,30 @@ setprop(lw~"tiles/tmp/dir-index",dir_index);
# do windspeed and orientation before presampling check, but test not to do it again
if (((getprop(lw~"tmp/presampling-flag") == 1) and (getprop(lw~"tmp/presampling-status") == "idle")) or (getprop(lw~"tmp/presampling-flag") == 0))
if (((local_weather.presampling_flag == 1) and (getprop(lw~"tmp/presampling-status") == "idle")) or (local_weather.presampling_flag == 0))
{
var alpha = getprop(lw~"tmp/tile-orientation-deg");
if ((local_weather.wind_model_flag == 2) or (local_weather.wind_model_flag ==4))
{
alpha = alpha + 2.0 * (rand()-0.5) * 10.0;
# account for the systematic spin of weather systems around a low pressure
# core dependent on hemisphere
if (lat >0.0) {alpha = alpha -3.0;}
else {alpha = alpha +3.0;}
setprop(lw~"tmp/tile-orientation-deg",alpha);
# compute the new windspeed
var windspeed = getprop(lw~"tmp/windspeed-kt");
windspeed = windspeed + 2.0 * (rand()-0.5) * 2.0;
if (windspeed < 0) {windspeed = rand();}
setprop(lw~"tmp/windspeed-kt", windspeed);
setprop(lw~"tmp/windspeed-kt",windspeed);
# store the tile orientation and wind strength in an array for fast processing
@ -204,7 +218,6 @@ if (((getprop(lw~"tmp/presampling-flag") == 1) and (getprop(lw~"tmp/presampling-
alpha = res[0];
setprop(lw~"tmp/tile-orientation-deg",alpha);
var windspeed = res[1];
setprop(lw~"tmp/windspeed-kt",windspeed);
@ -219,16 +232,17 @@ if (((getprop(lw~"tmp/presampling-flag") == 1) and (getprop(lw~"tmp/presampling-
# now see if we need to presample the terrain
if ((getprop(lw~"tmp/presampling-flag") == 1) and (getprop(lw~"tmp/presampling-status") == "idle"))
if ((local_weather.presampling_flag == 1) and (getprop(lw~"tmp/presampling-status") == "idle"))
{
local_weather.terrain_presampling_start(lat, lon, 1000, 40000, getprop(lw~"tmp/tile-orientation-deg"));
return;
}
print("Current tile type: ", code);
if (local_weather.debug_output_flag == 1)
{print("Current tile type: ", code);}
if (getprop(lw~"tmp/tile-management") == "repeat tile")
{
@ -248,7 +262,11 @@ if (getprop(lw~"tmp/tile-management") == "repeat tile")
else if (code == "cold_sector") {weather_tiles.set_cold_sector_tile();}
else if (code == "warm_sector") {weather_tiles.set_warm_sector_tile();}
else if (code == "tropical_weather") {weather_tiles.set_tropical_weather_tile();}
else {print("Repeat tile not implemented with this tile type!");}
else
{
print("Repeat tile not implemented with this tile type!");
setprop("/sim/messages/pilot", "Local weather: Repeat tile not implemented with this tile type!");
}
}
else if (getprop(lw~"tmp/tile-management") == "realistic weather")
{
@ -370,6 +388,7 @@ else if (getprop(lw~"tmp/tile-management") == "realistic weather")
else
{
print("Realistic weather not implemented with this tile type!");
setprop("/sim/messages/pilot", "Local weather: Realistic weather not implemented with this tile type!");
}
} # end if mode == realistic weather
@ -397,21 +416,34 @@ for (var j = 0; j < s; j=j+1)
settimer( func { props.globals.getNode("local-weather/clouds", 1).removeChild("tile",index) },100);
#compat_layer.remove_clouds(index);
var effectNode = props.globals.getNode("local-weather/effect-volumes").getChildren("effect-volume");
var ecount = 0;
foreach (var e; effectNode)
for (var i = 0; i < local_weather.n_effectVolumeArray; i = i + 1)
{
if (e.getNode("tile-index").getValue() == index)
{
e.remove();
ev = local_weather.effectVolumeArray[i];
if (ev.index == index)
{
local_weather.effectVolumeArray = delete_from_vector(local_weather.effectVolumeArray,i);
local_weather.n_effectVolumeArray = local_weather.n_effectVolumeArray - 1;
i = i - 1;
ecount = ecount + 1;
}
else if (ev.index == 0) # use the opportunity to check if static effects should also be removed
{
if (ev.get_distance() > 80000.0)
{
local_weather.effectVolumeArray = delete_from_vector(local_weather.effectVolumeArray,i);
local_weather.n_effectVolumeArray = local_weather.n_effectVolumeArray - 1;
i = i - 1;
ecount = ecount + 1;
}
}
}
setprop(lw~"effect-volumes/number",getprop(lw~"effect-volumes/number")- ecount);
# set placement indices to zero to reinitiate search for free positions
@ -422,7 +454,7 @@ setprop(lw~"effect-volumes/effect-placement-index",0);
# remove quadtree structures
if (getprop(lw~"config/dynamics-flag") ==1)
if (local_weather.dynamics_flag ==1)
{
settimer( func {setsize(weather_dynamics.cloudQuadtrees[index-1],0);},1.0);
}
@ -568,11 +600,6 @@ t.getNode("timestamp-sec").setValue(f.getNode("timestamp-sec").getValue());
t.getNode("orientation-deg").setValue(f.getNode("orientation-deg").getValue());
t.getNode("code").setValue(f.getNode("code").getValue());
#if (f.getNode("code").getValue() == "")
# {print("Empty tile code copying from ", from_index," to ", to_index, "!");}
#if (f.getNode("code").getValue() != "") # we don't copy an empty code, that can trigger errors
# {t.getNode("code").setValue(f.getNode("code").getValue());}
}
@ -630,7 +657,7 @@ setprop(lw~"tiles/tile[0]/generated-flag",0);
setprop(lw~"tiles/tile[0]/tile-index",-1);
setprop(lw~"tiles/tile[0]/code","");
setprop(lw~"tiles/tile[0]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[0]/orientation-deg",0.0);
setprop(lw~"tiles/tile[0]/orientation-deg",alpha);
x = 0.0; y = 40000.0;
setprop(lw~"tiles/tile[1]/latitude-deg",blat + get_lat(x,y,phi));
@ -639,7 +666,7 @@ setprop(lw~"tiles/tile[1]/generated-flag",0);
setprop(lw~"tiles/tile[1]/tile-index",-1);
setprop(lw~"tiles/tile[1]/code","");
setprop(lw~"tiles/tile[1]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[1]/orientation-deg",0.0);
setprop(lw~"tiles/tile[1]/orientation-deg",alpha);
x = 40000.0; y = 40000.0;
setprop(lw~"tiles/tile[2]/latitude-deg",blat + get_lat(x,y,phi));
@ -648,7 +675,7 @@ setprop(lw~"tiles/tile[2]/generated-flag",0);
setprop(lw~"tiles/tile[2]/tile-index",-1);
setprop(lw~"tiles/tile[2]/code","");
setprop(lw~"tiles/tile[2]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[2]/orientation-deg",0.0);
setprop(lw~"tiles/tile[2]/orientation-deg",alpha);
x = -40000.0; y = 0.0;
setprop(lw~"tiles/tile[3]/latitude-deg",blat + get_lat(x,y,phi));
@ -657,7 +684,7 @@ setprop(lw~"tiles/tile[3]/generated-flag",0);
setprop(lw~"tiles/tile[3]/tile-index",-1);
setprop(lw~"tiles/tile[3]/code","");
setprop(lw~"tiles/tile[3]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[3]/orientation-deg",0.0);
setprop(lw~"tiles/tile[3]/orientation-deg",alpha);
# this is the current tile
x = 0.0; y = 0.0;
@ -677,7 +704,7 @@ setprop(lw~"tiles/tile[5]/generated-flag",0);
setprop(lw~"tiles/tile[5]/tile-index",-1);
setprop(lw~"tiles/tile[5]/code","");
setprop(lw~"tiles/tile[5]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[5]/orientation-deg",0.0);
setprop(lw~"tiles/tile[5]/orientation-deg",alpha);
x = -40000.0; y = -40000.0;
setprop(lw~"tiles/tile[6]/latitude-deg",blat + get_lat(x,y,phi));
@ -686,7 +713,7 @@ setprop(lw~"tiles/tile[6]/generated-flag",0);
setprop(lw~"tiles/tile[6]/tile-index",-1);
setprop(lw~"tiles/tile[6]/code","");
setprop(lw~"tiles/tile[6]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[6]/orientation-deg",0.0);
setprop(lw~"tiles/tile[6]/orientation-deg",alpha);
x = 0.0; y = -40000.0;
setprop(lw~"tiles/tile[7]/latitude-deg",blat + get_lat(x,y,phi));
@ -695,7 +722,7 @@ setprop(lw~"tiles/tile[7]/generated-flag",0);
setprop(lw~"tiles/tile[7]/tile-index",-1);
setprop(lw~"tiles/tile[7]/code","");
setprop(lw~"tiles/tile[7]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[7]/orientation-deg",0.0);
setprop(lw~"tiles/tile[7]/orientation-deg",alpha);
x = 40000.0; y = -40000.0;
setprop(lw~"tiles/tile[8]/latitude-deg",blat + get_lat(x,y,phi));
@ -704,7 +731,7 @@ setprop(lw~"tiles/tile[8]/generated-flag",0);
setprop(lw~"tiles/tile[8]/tile-index",-1);
setprop(lw~"tiles/tile[8]/code","");
setprop(lw~"tiles/tile[8]/timestamp-sec",weather_dynamics.time_lw);
setprop(lw~"tiles/tile[8]/orientation-deg",0.0);
setprop(lw~"tiles/tile[8]/orientation-deg",alpha);
}
@ -772,7 +799,7 @@ for (var i = index; i < i_max; i = i+1)
# if wind drift is on, move the cloud
if (getprop(lw~"config/dynamics-flag") == 1)
if (local_weather.dynamics_flag == 1)
{
c.move();
}
@ -797,8 +824,30 @@ for (var i = index; i < i_max; i = i+1)
if (d < d_comp) # insert the cloud into scenery and delete from buffer
{
setprop(lw~"tmp/buffer-tile-index",c.index);
compat_layer.buffered_tile_index = c.index;
if (local_weather.dynamics_flag == 1) # assemble the current tile coordinates for insertion into quadtree
{
for (var j = 0; j < 9; j=j+1)
{
if (getprop(lw~"tiles/tile["~j~"]/tile-index") == c.index)
{
compat_layer.buffered_tile_latitude = getprop(lw~"tiles/tile["~j~"]/latitude-deg");
compat_layer.buffered_tile_longitude = getprop(lw~"tiles/tile["~j~"]/longitude-deg");
compat_layer.buffered_tile_alpha=getprop(lw~"tiles/tile["~j~"]/orientation-deg");
break;
}
}
}
if ((c.type !=0) and (local_weather.dynamics_flag == 1)) # set additional info for Cumulus clouds
{
compat_layer.cloud_mean_altitude = c.alt - c.rel_alt;
compat_layer.cloud_flt = c.flt;
compat_layer.cloud_evolution_timestamp = c.evolution_timestamp;
}
compat_layer.create_cloud(c.path, c.lat, c.lon, c.alt, c.orientation);
n_cloudSceneryArray = n_cloudSceneryArray +1;
cloudBufferArray = delete_from_vector(cloudBufferArray,i);
i = i -1; i_max = i_max - 1; n_max = n_max - 1;
deleted_flag = 1;
@ -826,6 +875,7 @@ var housekeeping_loop = func (index) {
var n = 5;
var n_max = size(cloudSceneryArray);
n_cloudSceneryArray = n_max;
var s = size(active_tile_list);
setprop(lw~"clouds/cloud-scenery-count",n_max);
@ -869,6 +919,7 @@ for (var i = index; i < i_max; i = i+1)
c.removeNodes();
cloudSceneryArray = delete_from_vector(cloudSceneryArray,i);
i = i -1; i_max = i_max - 1; n_max = n_max - 1;
n_cloudSceneryArray = n_cloudSceneryArray -1;
continue;
}
@ -893,6 +944,7 @@ for (var i = index; i < i_max; i = i+1)
append(cloudBufferArray,c.to_buffer());
cloudSceneryArray = delete_from_vector(cloudSceneryArray,i);
i = i -1; i_max = i_max - 1; n_max = n_max - 1;
n_cloudSceneryArray = n_cloudSceneryArray -1;
continue;
}
@ -921,11 +973,13 @@ foreach(t; tNode)
var code = t.getNode("code").getValue();
var index = t.getNode("tile-index").getValue();
var flag = t.getNode("generated-flag").getValue();
var alpha = t.getNode("orientation-deg").getValue();
print(i,": code: ", code, " unique id: ", index, " flag: ", flag);
print(i,": code: ", code, " unique id: ", index, " flag: ", flag, " alpha: ",alpha);
i = i + 1;
}
print("alpha: ",getprop(lw~"tmp/tile-orientation-deg"));
print("====================");
@ -963,8 +1017,9 @@ var active_tile_list = [];
var cloudBufferArray = [];
var cloudBuffer = {
new: func(lat, lon, alt, path, orientation, index) {
new: func(lat, lon, alt, path, orientation, index, type) {
var c = { parents: [cloudBuffer] };
c.lat = lat;
c.lon = lon;
@ -972,6 +1027,7 @@ var cloudBuffer = {
c.path = path;
c.orientation = orientation;
c.index = index;
c.type = type;
return c;
},
get_distance: func {
@ -1003,13 +1059,21 @@ var cloudBuffer = {
var cloudSceneryArray = [];
var n_cloudSceneryArray = 0;
var cloudScenery = {
new: func(index, cloudNode, modelNode) {
new: func(index, type, cloudNode, modelNode) {
var c = { parents: [cloudScenery] };
c.index = index;
c.type = type;
c.cloudNode = cloudNode;
c.modelNode = modelNode;
c.calt = cloudNode.getNode("position/altitude-ft");
c.clat = cloudNode.getNode("position/latitude-deg");
c.clon = cloudNode.getNode("position/longitude-deg");
c.alt = c.calt.getValue();
c.lat = c.clat.getValue();
c.lon = c.clon.getValue();
return c;
},
removeNodes: func {
@ -1017,17 +1081,20 @@ var cloudScenery = {
me.cloudNode.remove();
},
to_buffer: func {
var lat = me.cloudNode.getNode("position/latitude-deg").getValue();
var lon = me.cloudNode.getNode("position/longitude-deg").getValue();
var alt = me.cloudNode.getNode("position/altitude-ft").getValue();
var path = me.modelNode.getNode("path").getValue();
var orientation = me.cloudNode.getNode("orientation/true-heading-deg").getValue();
var b = cloudBuffer.new(lat, lon, alt, path, orientation, me.index);
var b = cloudBuffer.new(me.lat, me.lon, me.alt, path, orientation, me.index, me.type);
if (getprop(lw~"config/dynamics-flag") == 1)
if (local_weather.dynamics_flag == 1)
{
var timestamp = me.cloudNode.getNode("timestamp-sec").getValue();
b.timestamp = timestamp;
b.timestamp = me.timestamp;
if (me.type !=0) # Cumulus clouds get some extra info
{
b.flt = me.flt;
b.rel_alt = me.rel_alt;
b.evolution_timestamp = me.evolution_timestamp;
}
}
me.removeNodes();
@ -1036,21 +1103,106 @@ var cloudScenery = {
get_distance: func {
var pos = geo.aircraft_position();
var cpos = geo.Coord.new();
var lat = me.cloudNode.getNode("position/latitude-deg").getValue();
var lon = me.cloudNode.getNode("position/longitude-deg").getValue();
var lat = me.clat.getValue();
var lon = me.clon.getValue();
cpos.set_latlon(lat,lon,0.0);
return pos.distance_to(cpos);
},
get_course: func {
var pos = geo.aircraft_position();
var cpos = geo.Coord.new();
var lat = me.cloudNode.getNode("position/latitude-deg").getValue();
var lon = me.cloudNode.getNode("position/longitude-deg").getValue();
var lat = me.clat.getValue();
var lon = me.clon.getValue();
cpos.set_latlon(lat,lon,0.0);
return pos.course_to(cpos);
},
get_altitude: func {
return me.cloudNode.getNode("position/altitude-ft").getValue();
return me.calt.getValue();
},
correct_altitude: func {
var lat = me.clat.getValue();
var lon = me.clon.getValue();
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + local_weather.alt_20_array[me.index-1];
var elevation = compat_layer.get_elevation(lat, lon);
var alt_new = local_weather.get_convective_altitude(convective_alt, elevation, me.index);
me.target_alt = alt_new + me.rel_alt;
},
correct_altitude_and_age: func {
var lat = me.lat;
var lon = me.lon;
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + local_weather.alt_20_array[me.index-1];
# get terrain elevation and landcover
var elevation = -1.0; var p_cover = 0.2;# defaults if there is no info
var info = geodinfo(lat, lon);
if (info != nil)
{
elevation = info[0] * local_weather.m_to_ft;
if (info[1] != nil)
{
var landcover = info[1].names[0];
if (contains(local_weather.landcover_map,landcover)) {p_cover = local_weather.landcover_map[landcover];}
else {p_cover = 0.2;}
}
}
# correct the altitude
var alt_new = local_weather.get_convective_altitude(convective_alt, elevation, me.index);
me.target_alt = alt_new + me.rel_alt;
# correct fractional lifetime based on terrain below
var current_lifetime = math.sqrt(p_cover)/math.sqrt(0.35) * weather_dynamics.cloud_convective_lifetime_s;
var fractional_increase = (weather_dynamics.time_lw - me.evolution_timestamp)/current_lifetime;
me.flt = me.flt + fractional_increase;
me.evolution_timestamp = weather_dynamics.time_lw;
},
to_target_alt: func {
if (me.type ==0) {return;}
var alt_diff = me.target_alt - me.alt;
if (alt_diff == 0.0) {return;}
var max_vertical_movement_ft = weather_dynamics.dt_lw * weather_dynamics.cloud_max_vertical_speed_fts;
if (abs(alt_diff) < max_vertical_movement_ft)
{
me.alt = me.target_alt;
}
else if (alt_diff < 0)
{
me.alt = me.alt -max_vertical_movement_ft;
}
else
{
me.alt = me.alt + max_vertical_movement_ft;
}
setprop(lw~"clouds/tile["~me.index~"]/cloud["~me.write_index~"]/position/altitude-ft", me.alt);
},
move: func {
var windfield = weather_dynamics.windfield;
var dt = weather_dynamics.time_lw - me.timestamp;
me.lat = me.lat + windfield[1] * dt * local_weather.m_to_lat;
me.lon = me.lon + windfield[0] * dt * local_weather.m_to_lon;
setprop(lw~"clouds/tile["~me.index~"]/cloud["~me.write_index~"]/position/latitude-deg", me.lat);
setprop(lw~"clouds/tile["~me.index~"]/cloud["~me.write_index~"]/position/longitude-deg", me.lon);
me.timestamp = weather_dynamics.time_lw;
},
show: func {
var lat = me.clat.getValue();
var lon = me.clon.getValue();
var alt = me.calt.getValue();
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + local_weather.alt_20_array[me.index-1];
var elevation = compat_layer.get_elevation(lat, lon);
print("lat :", lat, " lon: ", lon, " alt: ", alt);
print("path: ", me.modelNode.getNode("path").getValue());
print("elevation: ", compat_layer.get_elevation(lat, lon), " cloudbase: ", convective_alt);
if (me.type !=0) {print("relative: ", me.rel_alt, "target: ", me.target_alt);}
},
};

View file

@ -1,7 +1,7 @@
########################################################
# routines to set up weather tiles
# Thorsten Renk, July 2010
# Thorsten Renk, October 2010
########################################################
# function purpose
@ -22,7 +22,7 @@
var tile_start = func {
# set thread lock
if (getprop(lw~"tmp/thread-flag") == 1){setprop(lw~"tmp/thread-status","computing");}
if (local_weather.thread_flag == 1){setprop(lw~"tmp/thread-status","computing");}
# set the tile code
var current_code = getprop(lw~"tiles/code");
@ -51,9 +51,10 @@ var dir_index = getprop(lw~"tiles/tmp/dir-index");
local_weather.assemble_effect_array();
print("Finished setting up tile type ",current_code, " in direction ",dir_index);
if (local_weather.debug_output_flag == 1)
{print("Finished setting up tile type ",current_code, " in direction ",dir_index);}
if (getprop(lw~"tmp/thread-flag") == 1)
if (local_weather.thread_flag == 1)
{setprop(lw~"tmp/thread-status","placing");}
else # without worker threads, tile generation is complete at this point
{props.globals.getNode(lw~"tiles").getChild("tile",dir_index).getNode("generated-flag").setValue(2);}
@ -97,10 +98,17 @@ local_weather.set_weather_station(blat, blon, 20000.0, 14.0, 12.0, 29.78);
#create_2_8_sstratus_streak(blat, blon,5000.0,0.0);
create_4_8_cirrocumulus_bank(blat, blon, 6000.0, 0.0);
#create_4_8_cirrocumulus_bank(blat, blon, 6000.0, 0.0);
#create_4_8_cirrocumulus_streaks(blat, blon, 6000.0, 0.0);
# create_2_8_cirrocumulus(blat, blon, 6000.0, 0.0);
#create_detailed_stratocumulus_bank(blat, blon,5000.0+alt_offset,0.0);
create_4_8_altocumulus_perlucidus(blat, blon, 10000.0, 0.0);
local_weather.create_effect_volume(3, blat, blon, 20000.0, 7000.0, alpha, 0.0, 80000.0, -1, -1, -1, -1, 15.0, -3,-1);
tile_finished();
@ -143,12 +151,43 @@ var p = 1025.0 + rand() * 6.0; p = adjust_p(p);
# and set them at the tile center
local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# weak cumulus development
var alt = spread * 1000;
var strength = rand() * 0.05;
var strength = 0.0;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
var rn = rand();
if (rn > 0.5)
{
# cloud scenario 1: weak cumulus development and blue thermals
strength = rand() * 0.05;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
# generate a few blue thermals
if (local_weather.generate_thermal_lift_flag !=0)
{
local_weather.generate_thermal_lift_flag = 3;
strength = rand() * 0.4;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
local_weather.generate_thermal_lift_flag = 2;
}
}
else if (rn > 0.0)
{
# cloud scenario 2: some Cirrocumulus patches
create_2_8_cirrocumulus(blat, blon, alt + alt_offset + 5000.0, alpha);
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -192,36 +231,35 @@ var p = 1019.0 + rand() * 6.0; p = adjust_p(p);
# and set them at the tile center
local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# moderate cumulus development
var alt = spread * 1000;
var strength = 0.0;
var rn = rand();
if (rn > 0.66)
{
# cloud scenario 1: possible Cirrus over Cumulus
var strength = 0.2 + rand() * 0.4;
strength = 0.2 + rand() * 0.4;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
# one or two Cirrus clouds
x = 2000.0 + rand() * 16000.0;
y = 2.0 * (rand()-0.5) * 18000;
alt = 25000.0 + rand() * 5000.0;
var path = local_weather.select_cloud_model("Cirrus", "small");
compat_layer.create_cloud(path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset,alpha);
compat_layer.create_cloud(path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset + 25000.0 + rand() * 5000.0,alpha);
if (rand() > 0.5)
{
x = -2000.0 - rand() * 16000.0;
y = 2.0 * (rand()-0.5) * 18000;
alt = 25000.0 + rand() * 5000.0;
var path = local_weather.select_cloud_model("Cirrus", "small");
compat_layer.create_cloud(path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset,alpha);
compat_layer.create_cloud(path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset +25000.0 + rand() * 5000.0,alpha);
}
}
@ -229,7 +267,7 @@ else if (rn > 0.33)
{
# cloud scenario 2: Cirrostratus over weak Cumulus
var strength = 0.2 + rand() * 0.2;
strength = 0.2 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
create_2_8_cirrostratus(blat, blon, alt+alt_offset+25000.0, alpha);
@ -239,7 +277,7 @@ else if (rn > 0.0)
{
# cloud scenario 3: Cirrocumulus sheet over Cumulus
var strength = 0.2 + rand() * 0.2;
strength = 0.2 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
x = 2.0 * (rand()-0.5) * 5000;
@ -251,6 +289,12 @@ else if (rn > 0.0)
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
}
@ -296,25 +340,26 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# now a random selection of different possible cloud configuration scenarios
var alt = spread * 1000;
var strength = 0.0;
var rn = rand();
if (rn > 0.833)
if (rn > 0.875)
{
# cloud scenario 1: Altocumulus patch over weak Cumulus
var strength = 0.1 + rand() * 0.1;
strength = 0.1 + rand() * 0.1;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
x = 2.0 * (rand()-0.5) * 5000;
y = 2.0 * (rand()-0.5) * 5000;
local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,1500.0,30,1000.0,0.2,800.0,30,1000.0,0.2,800.0,alpha ,1.0);
local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,1500.0,30,1000.0,0.2,1200.0,30,1000.0,0.2,1200.0,alpha ,1.0);
}
else if (rn > 0.666)
else if (rn > 0.750)
{
# cloud scenario 2: Altocumulus streaks
var strength = 0.15 + rand() * 0.2;
strength = 0.15 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
x = 2.0 * (rand()-0.5) * 10000;
@ -322,14 +367,14 @@ else if (rn > 0.666)
local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,1500.0,25,700.0,0.2,800.0,10,700.0,0.2,800.0,alpha ,1.4);
x = 2.0 * (rand()-0.5) * 10000;
y = 2.0 * (rand()-0.5) * 10000;
local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,1500.0,22,750.0,0.2,800.0,8,750.0,0.2,800.0,alpha ,1.1);
local_weather.create_streak("Altocumulus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 12000.0+alt+alt_offset,1500.0,22,750.0,0.2,1000.0,8,750.0,0.2,1000.0,alpha ,1.1);
}
else if (rn > 0.5)
else if (rn > 0.625)
{
# cloud scenario 3: Cirrus
var strength = 0.1 + rand() * 0.1;
strength = 0.1 + rand() * 0.1;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
x = 2.0 * (rand()-0.5) * 3000;
@ -337,11 +382,11 @@ else if (rn > 0.5)
local_weather.create_streak("Cirrus",blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 22000.0+alt+alt_offset,1500.0,3,9000.0,0.0, 800.0, 1,8000.0,0.0,800,0,alpha ,1.0);
}
else if (rn > 0.333)
else if (rn > 0.5)
{
# cloud scenario 4: Cumulonimbus banks
var strength = 0.7 + rand() * 0.3;
strength = 0.7 + rand() * 0.3;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
for (var i = 0; i < 3; i = i + 1)
@ -352,11 +397,11 @@ else if (rn > 0.333)
create_cloud_bank("Cumulonimbus", blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset, 1600.0, 800.0, 3000.0, 9, alpha);
}
}
else if (rn > 0.166)
else if (rn > 0.375)
{
# cloud scenario 5: scattered Stratus
var strength = 0.4 + rand() * 0.2;
strength = 0.4 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Stratus_structured"];
@ -364,11 +409,11 @@ else if (rn > 0.166)
local_weather.create_streak("Stratus (structured)",blat, blon, alt+6000.0+alt_offset+size_offset,1000.0,18,0.0,0.3,20000.0,18,0.0,0.3,20000.0,0.0,1.0);
}
else if (rn > 0.0)
else if (rn > 0.250)
{
# cloud scenario 6: Cirrocumulus sheets
var strength = 0.2 + rand() * 0.2;
strength = 0.2 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
@ -383,10 +428,31 @@ else if (rn > 0.0)
var path = local_weather.select_cloud_model("Cirrocumulus", "large");
compat_layer.create_cloud(path, blat + get_lat(x,y,phi), blon+get_lon(x,y,phi), alt + alt_offset +20000+ alt_variation,alpha+ beta);
}
}
else if (rn > 0.125)
{
# cloud scenario 7: Thin Cirrocumulus sheets over weak Cumulus
strength = 0.05 + rand() * 0.1;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
create_4_8_cirrocumulus_streaks(blat, blon, alt + 6000.0 + alt_offset, alpha);
}
else if (rn > 0.0)
{
# cloud scenario 8: Altocumulus perlucidus
create_4_8_altocumulus_perlucidus(blat, blon, alt + 10000.0 + alt_offset, alpha);
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -435,6 +501,7 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
# now a random selection of different possible cloud configuration scenarios
@ -484,6 +551,11 @@ else if (rn > 0.0)
create_4_8_cirrocumulus_bank(blat, blon, alt+alt_offset + 12000.0, alpha);
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
}
@ -531,6 +603,7 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
var rn = rand();
@ -547,16 +620,16 @@ if (rn > 0.75)
var beta = rand() * 360.0;
local_weather.create_layer("Nimbus", blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset, 500.0, 12000.0, 7000.0, beta, 1.0, 0.2, 1, 1.0);
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 10000.0, 6000.0, beta, 0.0, alt + alt_offset, 5000.0, 0.3, -1, -1, -1,0 );
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 9000.0, 5000.0, beta, 0.0, alt+alt_offset-300.0, 1500.0, 0.5, -1, -1, -1,0 );
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 10000.0, 6000.0, beta, 0.0, alt + alt_offset, 5000.0, 0.3, -1, -1, -1,0,-1 );
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 9000.0, 5000.0, beta, 0.0, alt+alt_offset-300.0, 1500.0, 0.5, -1, -1, -1,0,-1 );
x = 2.0 * (rand()-0.5) * 11000.0;
y = 2.0 * (rand()-0.5) * 11000.0;
var beta = rand() * 360.0;
local_weather.create_layer("Nimbus", blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset, 500.0, 10000.0, 6000.0, beta, 1.0, 0.2, 1, 1.0);
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 9000.0, 5000.0, beta, 0.0, alt + alt_offset, 5000.0, 0.3, -1, -1, -1,0 );
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 8000.0, 4000.0, beta, 0.0, alt+alt_offset-300.0, 1500.0, 0.5, -1, -1, -1,0 );
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 9000.0, 5000.0, beta, 0.0, alt + alt_offset, 5000.0, 0.3, -1, -1, -1,0 ,-1);
local_weather.create_effect_volume(2, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 8000.0, 4000.0, beta, 0.0, alt+alt_offset-300.0, 1500.0, 0.5, -1, -1, -1,0,-1 );
create_4_8_sstratus_undulatus(blat, blon, alt+alt_offset +3000.0, alpha);
create_2_8_tstratus(blat, blon, alt+alt_offset +6000.0, alpha);
@ -569,8 +642,8 @@ else if (rn >0.5)
alt = alt + local_weather.cloud_vertical_size_map["Stratus"] * 0.5 * m_to_ft;
create_8_8_stratus(blat, blon, alt+alt_offset,alpha);
local_weather.create_effect_volume(3, blat, blon, 18000.0, 18000.0, 0.0, 0.0, 1800.0, 8000.0, -1, -1, -1, -1, 0);
local_weather.create_effect_volume(3, blat, blon, 14000.0, 14000.0, 0.0, 0.0, 1500.0, 6000.0, 0.1, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat, blon, 18000.0, 18000.0, 0.0, 0.0, 1800.0, 8000.0, -1, -1, -1, -1, 0,-1);
local_weather.create_effect_volume(3, blat, blon, 14000.0, 14000.0, 0.0, 0.0, 1500.0, 6000.0, 0.1, -1, -1, -1,0,-1 );
create_2_8_sstratus(blat, blon, alt+alt_offset+3000,alpha);
}
else if (rn >0.25)
@ -594,6 +667,11 @@ else if (rn >0.0)
create_2_8_sstratus(blat, blon, alt+alt_offset+6000,alpha);
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
}
@ -643,15 +721,15 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# set a closed Nimbostratus layer
var alt = spread * 1000.0 + local_weather.cloud_vertical_size_map["Nimbus"] * 0.5 * m_to_ft;
var strength = 0.0;
#print("alt: ",spread*1000);
create_8_8_nimbus(blat, blon, alt+alt_offset, alpha);
# and a precipitation layer below, more rain in the center of the tile
local_weather.create_effect_volume(3, blat, blon, 20000.0, 20000.0, alpha, 0.0, alt + alt_offset, 3000.0, 0.3, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat , blon, 16000.0, 16000.0, alpha, 0.0, alt + alt_offset - 300.0, 1500.0, 0.5, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat, blon, 20000.0, 20000.0, alpha, 0.0, alt + alt_offset, 3000.0, 0.3, -1, -1, -1,0 ,0.95);
local_weather.create_effect_volume(3, blat , blon, 16000.0, 16000.0, alpha, 0.0, alt + alt_offset - 300.0, 1500.0, 0.5, -1, -1, -1,0 ,0.8);
# and some broken Stratus cover above
@ -661,6 +739,10 @@ var rn = rand();
if (rn > 0.5){create_4_8_stratus_patches(blat, blon, alt+alt_offset+3000.0, alpha);}
else {create_4_8_stratus(blat, blon, alt+alt_offset+3000.0, alpha);}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -705,6 +787,7 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
var rn = rand();
@ -713,7 +796,7 @@ var rn = rand();
if (rn > 0.5)
{
# cloud scenario 1: strong Cumulus development
var strength = 0.8 + rand() * 0.2;
strength = 0.8 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
}
@ -721,7 +804,7 @@ else if (rn > 0.0)
{
# cloud scenario 2: Cirrocumulus sheets over Cumulus
var strength = 0.6 + rand() * 0.2;
strength = 0.6 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
for (var i = 0; i < 2; i = i + 1)
@ -738,6 +821,12 @@ else if (rn > 0.0)
}
#local_weather.create_effect_volume(3, blat, blon, 20000.0, 7000.0, alpha, 0.0, 80000.0, -1, -1, -1, -1, 15.0, -3,-1);
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -782,6 +871,7 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
var rn = rand();
@ -789,14 +879,14 @@ var rn = rand();
if (rn > 0.8)
{
# cloud scenario 1: weak Cumulus development, some Cirrostratus
var strength = 0.3 + rand() * 0.2;
strength = 0.3 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
create_4_8_cirrostratus_patches(blat, blon, alt+alt_offset+25000.0, alpha);
}
else if (rn > 0.6)
{
# cloud scenario 2: weak Cumulus development under Altostratus streaks
var strength = 0.1 + rand() * 0.1;
strength = 0.1 + rand() * 0.1;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Stratus_structured"];
@ -807,7 +897,7 @@ else if (rn > 0.6)
else if (rn > 0.4)
{
# cloud scenario 3: Cirrocumulus bank
var strength = 0.05 + rand() * 0.05;
strength = 0.05 + rand() * 0.05;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Cirrocumulus"];
@ -818,7 +908,7 @@ else if (rn > 0.4)
else if (rn > 0.2)
{
# cloud scenario 4: Cirrocumulus undulatus
var strength = 0.05 + rand() * 0.05;
strength = 0.05 + rand() * 0.05;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Cirrocumulus"];
@ -830,7 +920,7 @@ else if (rn > 0.0)
{
# cloud scenario 5: weak Cumulus development under scattered Altostratus
var strength = 0.15 + rand() * 0.15;
strength = 0.15 + rand() * 0.15;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
var size_offset = 0.5 * m_to_ft * local_weather.cloud_vertical_size_map["Stratus_structured"];
@ -839,6 +929,10 @@ else if (rn > 0.0)
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -892,6 +986,7 @@ local_weather.set_weather_station(blat, blon, vis, T, D, p * hp_to_inhg);
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
# tropical weather has a strong daily variation, call thunderstorm only in the correct afternoon time window
@ -901,7 +996,7 @@ var rn = rand();
if (rn > (t_factor * t_factor * t_factor * t_factor)) # call a normal convective cloud system
{
var strength = 1.0 + rand() * 0.2;
strength = 1.0 + rand() * 0.2;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
}
@ -954,10 +1049,15 @@ local_weather.cumulus_exclusion_layer(blat, blon, alt+alt_offset, n, 20000.0, 20
# some turbulence in the convection layer
local_weather.create_effect_volume(3, blat, blon, 20000.0, 20000.0, alpha, 0.0, alt+3000.0+alt_offset, -1, -1, -1, 0.4, -1,0 );
local_weather.create_effect_volume(3, blat, blon, 20000.0, 20000.0, alpha, 0.0, alt+3000.0+alt_offset, -1, -1, -1, 0.4, -1,0 ,-1);
} # end thundercloud placement
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
}
@ -1019,6 +1119,7 @@ local_weather.set_weather_station(blat +get_lat(x,y,phi), blon + get_lon(x,y,phi
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
# thunderstorms first
@ -1072,12 +1173,17 @@ local_weather.create_streak("Stratus (thin)",blat+get_lat(x,y,phi), blon+get_lon
# some turbulence in the convection layer
x=0.0; y = 5000.0;
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 11000.0, alpha, 0.0, alt+3000.0+alt_offset, -1, -1, -1, 0.4, -1,0 );
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 11000.0, alpha, 0.0, alt+3000.0+alt_offset, -1, -1, -1, 0.4, -1,0 ,-1);
# some rain and reduced visibility in its core
x=0.0; y = 5000.0;
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 8000.0, alpha, 0.0, alt+alt_offset, 10000.0, 0.1, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 8000.0, alpha, 0.0, alt+alt_offset, 10000.0, 0.1, -1, -1, -1,0,-1 );
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -1145,6 +1251,12 @@ local_weather.set_weather_station(blat +get_lat(x,y,phi), blon + get_lon(x,y,phi
# altitude for the lowest layer
var alt = spread * 1000.0;
# some weak Cumulus development
var strength = 0.1 + rand() * 0.1;
local_weather.create_cumosys(blat,blon, alt + alt_offset, get_n(strength), 20000.0);
# high Cirrus leading
x = 2.0 * (rand()-0.5) * 1000;
@ -1165,6 +1277,11 @@ for (var i=0; i<6; i=i+1)
}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
}
@ -1230,7 +1347,7 @@ local_weather.set_weather_station(blat +get_lat(x,y,phi), blon + get_lon(x,y,phi
# altitude for the lowest layer
var alt = spread * 1000.0;
var strength = 0.0;
# followed by random patches of Cirrostratus
@ -1273,6 +1390,10 @@ var y = 8000.0;
local_weather.create_streak("Stratus",blat +get_lat(x,y,phi), blon+get_lon(x,y,phi), alt+alt_offset +5000.0,1000.0,30,0.0,0.2,20000.0,10,0.0,0.2,12000.0,alpha,1.0);
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -1339,7 +1460,7 @@ local_weather.set_weather_station(blat +get_lat(x,y,phi), blon + get_lon(x,y,phi
# altitude for the lowest layer
var alt = spread * 1000.0 + local_weather.cloud_vertical_size_map["Nimbus"] * 0.5 * m_to_ft;
var strength = 0.0;
# closed Stratus layer
@ -1364,12 +1485,18 @@ local_weather.create_streak("Nimbus",blat +get_lat(x,y,phi), blon+get_lon(x,y,ph
# some rain beneath the stratus
x=0.0; y = -10000.0;
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 10000.0, alpha, 0.0, alt+alt_offset+1000, vis * 0.7, 0.1, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 10000.0, alpha, 0.0, alt+alt_offset+1000, vis * 0.7, 0.1, -1, -1, -1,0 ,-1);
# heavier rain beneath the Nimbostratus
x=0.0; y = 10000.0;
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 10000.0, alpha, 0.0, alt+alt_offset, vis * 0.5, 0.3, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 10000.0, alpha, 0.0, alt+alt_offset, vis * 0.5, 0.3, -1, -1, -1,0,-1 );
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -1436,6 +1563,7 @@ local_weather.set_weather_station(blat +get_lat(x,y,phi), blon + get_lon(x,y,phi
# altitude for the lowest layer
var alt = spread * 1000.0 + local_weather.cloud_vertical_size_map["Nimbus"] * 0.5 * m_to_ft;
var strength = 0.0;
# low Nimbostratus layer
@ -1461,7 +1589,13 @@ local_weather.create_streak("Nimbus",blat +get_lat(x,y,phi), blon+get_lon(x,y,ph
# rain beneath the Nimbostratus
x=0.0; y = -5000.0;
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 15000.0, alpha, 0.0, alt+alt_offset, vis * 0.5, 0.3, -1, -1, -1,0 );
local_weather.create_effect_volume(3, blat+get_lat(x,y,phi), blon+get_lon(x,y,phi), 20000.0, 15000.0, alpha, 0.0, alt+alt_offset, vis * 0.5, 0.3, -1, -1, -1,0 ,-1);
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -1481,7 +1615,7 @@ tile_finished();
var set_gliders_sky_tile = func {
setprop(lw~"tiles/code","glides_sky");
setprop(lw~"tiles/code","gliders_sky");
tile_start();
@ -1503,16 +1637,20 @@ calc_geo(blat);
# first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure)
local_weather.set_weather_station(blat, blon, 35000.0, 20.0, 16.0, 1018 * hp_to_inhg);
# switch the placement of thermal effect volumes on: 1: constant lift 2: by function
setprop(lw~"tmp/generate-thermal-lift-flag",2);
var alt = 3000.0;
# add convective clouds
var strength = 0.5;
var n = int(4000 * strength); # calculate the number of placement tries from tile size 20x20km and strength
local_weather.create_cumosys(blat,blon, 3000.0+alt_offset,n, 20000.0);
local_weather.create_cumosys(blat,blon, alt+alt_offset,n, 20000.0);
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -1547,16 +1685,28 @@ calc_geo(blat);
# first weather info for tile center (lat, lon, visibility, temperature, dew point, pressure)
local_weather.set_weather_station(blat, blon, 45000.0, 20.0, 15.0, 1018 * hp_to_inhg);
# switch the placement of thermal effect volumes on: 1: constant lift 2: by function 3: blue
setprop(lw~"tmp/generate-thermal-lift-flag",3);
local_weather.generate_thermal_lift_flag = 3;
var alt = 5000.0;
# add convective clouds
# set flag to blue thermal generation
if (local_weather.generate_thermal_lift_flag !=0)
{local_weather.generate_thermal_lift_flag = 3;}
var strength = 0.9;
var n = int(4000 * strength); # calculate the number of placement tries from tile size 20x20km and strength
local_weather.create_cumosys(blat,blon, 5000.0+alt_offset,n, 20000.0);
# set flag back to normal thermal generation
if (local_weather.generate_thermal_lift_flag !=0)
{local_weather.generate_thermal_lift_flag = 0;}
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
@ -1723,6 +1873,10 @@ for (var i = n; i <n_layers; i=i+1)
setprop(lw~"METAR/available-flag",0);
# store convective altitude and strength
append(weather_dynamics.tile_convective_altitude,alt_low);
append(weather_dynamics.tile_convective_strength,strength);
tile_finished();
}
@ -1909,6 +2063,41 @@ local_weather.create_streak("Cirrocumulus (cloudlet)",lat+get_lat(x,y,phi), lon+
}
var create_4_8_cirrocumulus_streaks = func (lat, lon, alt, alpha) {
var phi = alpha * math.pi/180.0;
var beta = 90.0 + (rand() -0.5) * 30.0;
for (var i=0; i<2; i=i+1)
{
var x = 2.0 * (rand()-0.5) * 12000;
var y = 2.0 * (rand()-0.5) * 12000;
var tri = 1.5 + rand() * 1.5;
local_weather.create_streak("Cirrocumulus (cloudlet)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,300.0,10,700.0,0.1,400.0,30,700.0,0.1,400.0,alpha+beta,tri);
}
}
var create_4_8_altocumulus_perlucidus = func (lat, lon, alt, alpha) {
var phi = alpha * math.pi/180.0;
for (var i=0; i<20; i=i+1)
{
var x = 2.0 * (rand()-0.5) * 18000;
var y = 2.0 * (rand()-0.5) * 18000;
var beta = (rand() -0.5) * 180.0;
local_weather.create_streak("Altocumulus perlucidus",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,300.0,4,1400.0,0.1,900.0,4,1400.0,0.1,900.0,alpha+beta,1.0);
}
}
var create_2_8_stratus = func (lat, lon, alt, alpha) {
var phi = alpha * math.pi/180.0;
@ -1992,12 +2181,12 @@ var create_2_8_cirrocumulus = func (lat, lon, alt, alpha) {
var phi = alpha * math.pi/180.0;
for (var i=0; i<3; i=i+1)
for (var i=0; i<25; i=i+1)
{
var x = 2.0 * (rand()-0.5) * 12000;
var y = 2.0 * (rand()-0.5) * 12000;
var x = 2.0 * (rand()-0.5) * 18000;
var y = 2.0 * (rand()-0.5) * 18000;
var beta = (rand() -0.5) * 180.0;
local_weather.create_streak("Cirrocumulus (cloudlet)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,300.0,3,4000.0,0.2,1000.0,3,4000.0,0.2,1000.0,alpha+beta,1.0);
local_weather.create_streak("Cirrocumulus (cloudlet)",lat+get_lat(x,y,phi), lon+get_lon(x,y,phi), alt,300.0,3,600.0,0.1,500.0,3,600.0,0.1,500.0,alpha+beta,1.0);
}
@ -2028,14 +2217,14 @@ var beta = (rand() -0.5) * 60.0;
var alt_offset = 0.5 * local_weather.cloud_vertical_size_map["Cumulus"] * ft_to_m;
local_weather.create_streak("Congestus",lat+get_lat(x,y+7500,phi), lon+get_lon(x,y+7500,phi), alt + alt_offset,500.0,12,1000.0,0.1,400.0,15,1000.0,0.1,400.0,alpha+90.0+beta,tri);
local_weather.create_streak("Stratocumulus",lat+get_lat(x,y+7500,phi), lon+get_lon(x,y+7500,phi), alt + alt_offset,500.0,12,1000.0,0.1,400.0,15,1000.0,0.1,400.0,alpha+90.0+beta,tri);
local_weather.create_streak("Congestus",lat+get_lat(x,y-7500,phi), lon+get_lon(x,y-7500,phi), alt + alt_offset,500.0,12,1000.0,0.1,400.0,15,1000.0,0.1,400.0,alpha+270.0+beta,tri);
local_weather.create_streak("Stratocumulus",lat+get_lat(x,y-7500,phi), lon+get_lon(x,y-7500,phi), alt + alt_offset,500.0,12,1000.0,0.1,400.0,15,1000.0,0.1,400.0,alpha+270.0+beta,tri);
local_weather.create_streak("Congestus bottom",lat+get_lat(x,y+5250,phi), lon+get_lon(x,y+5250,phi), alt,0.0,10,700.0,0.2,400.0,15,700.0,0.0,400.0,alpha+90.0+beta,tri);
local_weather.create_streak("Stratocumulus bottom",lat+get_lat(x,y+5250,phi), lon+get_lon(x,y+5250,phi), alt,0.0,10,700.0,0.2,400.0,15,700.0,0.0,400.0,alpha+90.0+beta,tri);
local_weather.create_streak("Congestus bottom",lat+get_lat(x,y-5250,phi), lon+get_lon(x,y-5250,phi), alt,0.0,10,700.0,0.2,400.0,15,700.0,0.0,400.0,alpha+270.0+beta,tri);
local_weather.create_streak("Stratocumulus bottom",lat+get_lat(x,y-5250,phi), lon+get_lon(x,y-5250,phi), alt,0.0,10,700.0,0.2,400.0,15,700.0,0.0,400.0,alpha+270.0+beta,tri);
}
@ -2060,7 +2249,7 @@ append(elat, lat); append(elon, lon); append(erad, 4000.0 * scale * 1.2);
# set precipitation, visibility, updraft and turbulence in the cloud
local_weather.create_effect_volume(1, lat, lon, 4000.0 * 0.7 * scale, 4000.0 * 0.7 * scale , 0.0, 0.0, 20000.0, 600.0, 0.8, -1, 0.6, 15.0,1 );
local_weather.create_effect_volume(1, lat, lon, 4000.0 * 0.7 * scale, 4000.0 * 0.7 * scale , 0.0, 0.0, 20000.0, 600.0, 0.8, -1, 0.6, 15.0,1 ,-1);
}
@ -2083,7 +2272,7 @@ append(elat, lat); append(elon, lon); append(erad, 6000.0 * scale * 1.2);
# set precipitation, visibility, updraft and turbulence in the cloud
local_weather.create_effect_volume(1, lat, lon, 6000.0 * 0.7 * scale, 6000.0 * 0.7 * scale , 0.0, 0.0, 20000.0, 500.0, 1.0, -1, 0.8, 20.0,1 );
local_weather.create_effect_volume(1, lat, lon, 6000.0 * 0.7 * scale, 6000.0 * 0.7 * scale , 0.0, 0.0, 20000.0, 500.0, 1.0, -1, 0.8, 20.0,1,-1 );
}
@ -2114,7 +2303,7 @@ local_weather.create_layer("Stratus (thin)", lat+get_lat(0,-4000,phi), lon+get_l
# set the exclusion region for the Cumulus layer
append(elat, lat); append(elon, lon); append(erad, 7500.0 * scale * 1.2);
local_weather.create_effect_volume(1, lat, lon, 7500.0 * 0.7 * scale, 7500.0 * 0.7 * scale , 0.0, 0.0, 20000.0, 500.0, 1.0, -1, 1.0, 25.0,1 );
local_weather.create_effect_volume(1, lat, lon, 7500.0 * 0.7 * scale, 7500.0 * 0.7 * scale , 0.0, 0.0, 20000.0, 500.0, 1.0, -1, 1.0, 25.0,1,-1 );
}

View file

@ -16,7 +16,7 @@ varying float fogFactor;
void main(void)
{
float shade = 0.9;
float shade = 0.8;
float cloud_height = 1000.0;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
@ -35,8 +35,8 @@ void main(void)
// scaling in the homogeneous component of pos.
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_Position.xyz = gl_Vertex.x * u;
gl_Position.xyz += gl_Vertex.y * r * 0.25;
gl_Position.xyz += gl_Vertex.z * w * 0.25;
gl_Position.xyz += gl_Vertex.y * r * 0.35;
gl_Position.xyz += gl_Vertex.z * w * 0.35;
//gl_Position.xyz += gl_Vertex.y * r * wScale;
//gl_Position.xyz += gl_Vertex.z * w * hScale;
gl_Position.xyz += gl_Color.xyz;

View file

@ -2,9 +2,15 @@
// Licence: GPL v2
// Author: Frederic Bouvier.
// Adapted from the paper by F. Policarpo et al. : Real-time Relief Mapping on Arbitrary Polygonal Surfaces
// Adapted from the paper and sources by M. Drobot in GPU Pro : Quadtree Displacement Mapping with Height Blending
#version 120
#define TEXTURE_MIP_LEVELS 10
#define TEXTURE_PIX_COUNT 1024 //pow(2,TEXTURE_MIP_LEVELS)
#define BINARY_SEARCH_COUNT 10
#define BILINEAR_SMOOTH_FACTOR 2.0
varying vec4 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal;
@ -16,6 +22,7 @@ varying vec4 constantColor;
uniform sampler3D NoiseTex;
uniform sampler2D BaseTex;
uniform sampler2D NormalTex;
uniform sampler2D QDMTex;
uniform float depth_factor;
uniform float tile_size;
uniform float quality_level; // From /sim/rendering/quality-level
@ -23,52 +30,103 @@ uniform float snowlevel; // From /sim/rendering/snow-level-m
uniform vec3 night_color;
const float scale = 1.0;
int linear_search_steps = 10;
int GlobalIterationCount = 0;
int gIterationCap = 64;
float ray_intersect(sampler2D reliefMap, vec2 dp, vec2 ds)
void QDM(inout vec3 p, inout vec3 v)
{
float size = 1.0 / float(linear_search_steps);
float depth = 0.0;
float best_depth = 1.0;
const int MAX_LEVEL = TEXTURE_MIP_LEVELS;
const float NODE_COUNT = TEXTURE_PIX_COUNT;
const float TEXEL_SPAN_HALF = 1.0 / NODE_COUNT / 2.0;
for(int i = 0; i < linear_search_steps - 1; ++i)
float fDeltaNC = TEXEL_SPAN_HALF * depth_factor;
vec3 p2 = p;
float level = MAX_LEVEL;
vec2 dirSign = (sign(v.xy) + 1.0) * 0.5;
GlobalIterationCount = 0;
float d = 0.0;
while (level >= 0.0 && GlobalIterationCount < gIterationCap)
{
depth += size;
float t = step(0.95, texture2D(reliefMap, dp + ds * depth).a);
if(best_depth > 0.996)
if(depth >= t)
best_depth = depth;
}
depth = best_depth;
vec4 uv = vec4(p2.xyz, level);
d = texture2DLod(QDMTex, uv.xy, uv.w).w;
const int binary_search_steps = 5;
for(int i = 0; i < binary_search_steps; ++i)
{
size *= 0.5;
float t = step(0.95, texture2D(reliefMap, dp + ds * depth).a);
if(depth >= t)
if (d > p2.z)
{
best_depth = depth;
depth -= 2.0 * size;
//predictive point of ray traversal
vec3 tmpP2 = p + v * d;
//current node count
float nodeCount = pow(2.0, (MAX_LEVEL - level));
//current and predictive node ID
vec4 nodeID = floor(vec4(p2.xy, tmpP2.xy)*nodeCount);
//check if we are crossing the current cell
if (nodeID.x != nodeID.z || nodeID.y != nodeID.w)
{
//calculate distance to nearest bound
vec2 a = p2.xy - p.xy;
vec2 p3 = (nodeID.xy + dirSign) / nodeCount;
vec2 b = p3.xy - p.xy;
vec2 dNC = (b.xy * p2.z) / a.xy;
//take the nearest cell
d = min(d,min(dNC.x, dNC.y))+fDeltaNC;
level++;
//use additional convergence speed-up
#ifdef USE_QDM_ASCEND_INTERVAL
if(frac(level*0.5) > EPSILON)
level++;
#elseif USE_QDM_ASCEND_CONST
level++;
#endif
}
p2 = p + v * d;
}
depth += size;
level--;
GlobalIterationCount++;
}
return(best_depth);
//
// Manual Bilinear filtering
//
float rayLength = length(p2.xy - p.xy) + fDeltaNC;
float dA = p2.z * (rayLength - BILINEAR_SMOOTH_FACTOR * TEXEL_SPAN_HALF) / rayLength;
float dB = p2.z * (rayLength + BILINEAR_SMOOTH_FACTOR * TEXEL_SPAN_HALF) / rayLength;
vec4 p2a = vec4(p + v * dA, 0.0);
vec4 p2b = vec4(p + v * dB, 0.0);
dA = texture2DLod(NormalTex, p2a.xy, p2a.w).w;
dB = texture2DLod(NormalTex, p2b.xy, p2b.w).w;
dA = abs(p2a.z - dA);
dB = abs(p2b.z - dB);
p2 = mix(p2a.xyz, p2b.xyz, dA / (dA + dB));
p = p2;
}
float ray_intersect(vec2 dp, vec2 ds)
{
vec3 p = vec3( dp, 0.0 );
vec3 v = vec3( ds, 1.0 );
QDM( p, v );
return p.z;
}
void main (void)
{
if ( quality_level >= 3.5 ) {
linear_search_steps = 20;
}
vec3 ecPos3 = ecPosition.xyz / ecPosition.w;
vec3 V = normalize(ecPos3);
vec3 s = vec3(dot(V, VTangent), dot(V, VBinormal), dot(VNormal, -V));
vec2 ds = s.xy * depth_factor / s.z;
vec2 dp = gl_TexCoord[0].st - ds;
float d = ray_intersect(NormalTex, dp, ds);
float d = ray_intersect(dp, ds);
vec2 uv = dp + ds * d;
vec3 N = texture2D(NormalTex, uv).xyz * 2.0 - 1.0;
@ -89,7 +147,7 @@ void main (void)
vec3 sl = normalize( vec3( dot( l, VTangent ), dot( l, VBinormal ), dot( -l, VNormal ) ) );
ds = sl.xy * depth_factor / sl.z;
dp -= ds * d;
float dl = ray_intersect(NormalTex, dp, ds);
float dl = ray_intersect(dp, ds);
if ( dl < d - 0.05 )
shadow_factor = dot( constantColor.xyz, vec3( 1.0, 1.0, 1.0 ) ) * 0.25;
}

View file

@ -33,7 +33,7 @@
<y>320</y>
<width>100</width>
<height>20</height>
<min>25000.0</min>
<min>29000.0</min>
<max>55000.0</max>
<property>/local-weather/config/distance-to-load-tile-m</property>
<binding>

View file

@ -35,9 +35,6 @@
<value>Coldfront</value>
<value>Warmfront</value>
<value>Tropical</value>
<value>---</value>
<value>Glider's sky</value>
<value>Blue thermals</value>
<!--<value>Test tile</value>-->
<binding>
<command>dialog-apply</command>
@ -104,7 +101,7 @@
<value>constant in tile</value>
<value>aloft interpolated</value>
<value>aloft waypoints</value>
<!--<value>airmass interpolated</value>-->
<!-- <value>airmass interpolated</value> -->
<binding>
<command>dialog-apply</command>
</binding>
@ -150,8 +147,8 @@
<y>150</y>
<width>15</width>
<height>15</height>
<label>worker threads</label>
<property>/local-weather/tmp/thread-flag</property>
<label>generate thermals</label>
<property>/local-weather/config/generate-thermal-lift-flag</property>
<binding>
<command>dialog-apply</command>
</binding>
@ -162,8 +159,8 @@
<y>125</y>
<width>15</width>
<height>15</height>
<label>asymmetric range</label>
<property>/local-weather/tmp/asymmetric-tile-loading-flag</property>
<label>debug output</label>
<property>/local-weather/config/debug-output-flag</property>
<binding>
<command>dialog-apply</command>
</binding>
@ -193,6 +190,18 @@
</binding>
</checkbox>
<checkbox>
<x>150</x>
<y>100</y>
<width>15</width>
<height>15</height>
<label>dynamical convection</label>
<property>/local-weather/config/dynamical-convection-flag</property>
<binding>
<command>dialog-apply</command>
</binding>
</checkbox>
<text>
<x>10</x>
<y>75</y>
@ -250,7 +259,7 @@
<button>
<x>45</x>
<y>0</y>
<legend>Clear clouds</legend>
<legend>Clear / End</legend>
<!--<default>true</default>-->
<equal>true</equal>
<binding>
@ -262,7 +271,7 @@
<button>
<x>135</x>
<y>0</y>
<legend>Cancel</legend>
<legend>Close</legend>
<equal>true</equal>
<key>Esc</key>
<binding>

View file

@ -576,6 +576,15 @@
</binding>
</item>
<item>
<label>Reload HUD</label>
<binding>
<command>reinit</command>
<subsystem>hud</subsystem>
</binding>
</item>
<item>
<label>Reload Panel</label>
<binding>