Hi Thorsten (& all),

some time ago I had added an option to introduce Nasal submodules, or,
to be more exact, to introduce Nasal modules using fgdata/Nasal/...
subdirectories and add an option to load such modules on demand only
(using a single enable/disable property per module).

This has several advantages:
* Nasal files can be grouped neatly instead of all scripts being mixed
up in a single fgdata/Nasal directory. Grouping makes a lot of sense for
modules consisting of several scripts - local weather is the best
example.
* Guaranteed loading sequence. Submodules are loaded _after_ the main
fgdata/Nasal scripts, so they can rely on all fgdata/Nasal content to be
already present. No more need for awkward listener callbacks, just to
make sure that basic "props" or "gui" modules are available.
* Finally, users have the option to disable loading modules.
Unfortunately, just loading scripts (code/data) into memory already
causes certain _run-time_ performance effects - even if the Nasal code
was never executed (so even when all listeners/timers were disabled).

Admittedly, I'm concerned that the rising number of complex Nasal
modules degrades the simulation performance for everyone. Having an
option to disable modules completely seems a good idea, so everyone can
choose for himself. And when something is not even loaded, it's
naturally guaranteed that it cannot have any performance effects at all.

I'd like to use the local weather module as a good example here. I'm
planning to do the same with a few other modules (tutorial.nas,
jetways*.nas, maybe multiplayer, and the new Nasal Boeing CDU).

I've done some tests with a "local weather submodule" and it seems fine.
Few modifications are required - mainly affects the init handlers (need
to listen to a different signal) and some GUI aspects (add an option to
enable/load the Nasal module, enable/disable menu items). I've attached
the changes. Before applying the patch, move the existing weather
scripts into a new subdirectory "Nasal/local_weather":

# create new subdirectory "local_weather"
mkdir fgdata/Nasal/local_weather

# move existing files to new directory
mv fgdata/Nasal/compat_layer.nas fgdata/Nasal/local_weather/.
mv fgdata/Nasal/weather_dynamics.nas fgdata/Nasal/local_weather/.
mv fgdata/Nasal/weather_tiles.nas fgdata/Nasal/local_weather/.
mv fgdata/Nasal/local_weather.nas fgdata/Nasal/local_weather/.
mv fgdata/Nasal/weather_tile_management.nas fgdata/Nasal/local_weather/.

# apply patch (attached)
cd fgdata && patch -p1 < local_weather.patch

I'd like to push the change to fgdata before the release. Please test if
you're happy with these changes - or let me know if you saw issues.

cheers,
Thorsten

diff --git a/Nasal/local_weather/compat_layer.nas b/Nasal/local_weather/compat_layer.nas
index 0fbd8e4..4605aed 100644
--- a/Nasal/local_weather/compat_layer.nas
+++ b/Nasal/local_weather/compat_layer.nas
@@ -67,8 +67,19 @@
 # The compatibility layer is currently work in progress and will be extended as new Nasal 
 # APIs are being added to FlightGear.
 
+var weather_dynamics = nil;
+var weather_tile_management = nil;
+var compat_layer = nil;
+var weather_tiles = nil;
+
+
+_setlistener("/nasal/local_weather/loaded", func { 
+
+compat_layer = local_weather;
+weather_dynamics = local_weather;
+weather_tile_management = local_weather;
+weather_tiles = local_weather;
 
-_setlistener("/sim/signals/nasal-dir-initialized", func { 
 
 var result = "yes";
 
diff --git a/Nasal/local_weather/local_weather.nas b/Nasal/local_weather/local_weather.nas
index 52c7a2f..eecb95a 100644
--- a/Nasal/local_weather/local_weather.nas
+++ b/Nasal/local_weather/local_weather.nas
@@ -4414,10 +4414,18 @@ setprop(lw~"tiles/tile-counter",0);
 
 setprop(lwi~"ipoint-number",0);
 
+var updateMenu = func {
+	var isEnabled = getprop("/nasal/local_weather/enabled");
+	gui.menuEnable("local_weather", isEnabled);
+	gui.menuEnable("local_weather_tiles", isEnabled);
+}
+
+_setlistener("/nasal/local_weather/enabled", updateMenu);
 
 # wait for Nasal to be available and do what is in startup()
 
-_setlistener("/sim/signals/nasal-dir-initialized", func {
+_setlistener("/nasal/local_weather/loaded", func {
+	updateMenu();
 	startup();
 });
 
diff --git a/gui/dialogs/local_weather_config.xml b/gui/dialogs/local_weather_config.xml
index 5826cff..f72bb54 100644
--- a/gui/dialogs/local_weather_config.xml
+++ b/gui/dialogs/local_weather_config.xml
@@ -6,10 +6,22 @@
 
  <name>local_weather_config</name>
  <width>400</width>
- <height>400</height>
+ <height>440</height>
  <modal>false</modal>
 
 
+<checkbox>
+   <x>5</x>
+   <y>400</y>
+   <width>15</width>
+   <height>15</height>
+   <label>Enable local weather module</label>
+   <property>/nasal/local_weather/enabled</property>
+   <binding>
+    <command>dialog-apply</command>
+   </binding>
+</checkbox>
+
 <text>
   <x>5</x>
   <y>370</y>
diff --git a/gui/menubar.xml b/gui/menubar.xml
index bbaa69a..fba2618 100644
--- a/gui/menubar.xml
+++ b/gui/menubar.xml
@@ -329,14 +329,8 @@
 
 		<item>
 			<label>Local Weather</label>
-			<binding>
-				<command>dialog-show</command>
-				<dialog-name>local_weather</dialog-name>
-			</binding>
-		</item>
-
-		<item>
-			<label>Local Weather Tiles</label>
+			<name>local_weather</name>
+			<enabled>false</enabled>
 			<binding>
 				<command>dialog-show</command>
 				<dialog-name>local_weather_tiles</dialog-name>
@@ -344,7 +338,8 @@
 		</item>
 
 		<item>
-			<label>Local Weather Config</label>
+			<label>Local Weather Options</label>
+			<name>local_weather_config</name>
 			<binding>
 				<command>dialog-show</command>
 				<dialog-name>local_weather_config</dialog-name>
@@ -699,6 +694,16 @@
 		</item>
 
 		<item>
+			<label>Local Weather Testing</label>
+			<name>local_weather</name>
+			<enabled>false</enabled>
+			<binding>
+				<command>dialog-show</command>
+				<dialog-name>local_weather</dialog-name>
+			</binding>
+		</item>
+
+		<item>
 			<label>Print Visible Scene Info</label>
 			<binding>
 				<command>print-visible-scene</command>
diff --git a/preferences.xml b/preferences.xml
index cc5f58a..d64e8fd 100644
--- a/preferences.xml
+++ b/preferences.xml
@@ -1226,6 +1226,12 @@ Started September 2000 by David Megginson, da...@megginson.com
 		</log>
 	</logging>
 
+	<nasal>
+	    <local_weather>
+  		<enabled type="bool" userarchive="y">false</enabled>
+	    </local_weather>
+	</nasal>
+
 </PropertyList>
 
 <!-- end of preferences.xml -->
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2 
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to