]> git.mxchange.org Git - flightgear.git/commitdiff
Expose the time of day setting through the fg_command and property interface
authorcurt <curt>
Tue, 16 Sep 2003 22:35:16 +0000 (22:35 +0000)
committercurt <curt>
Tue, 16 Sep 2003 22:35:16 +0000 (22:35 +0000)
so a gui interface can be built.

src/Main/fg_commands.cxx
src/Network/props.cxx

index 0efd3c09d86236000cfc73d64d1cc05e5f0a88cd..50ab54f307a660b8a870d5cda425943dbc7824da 100644 (file)
@@ -25,6 +25,7 @@
 #if defined(HAVE_PLIB_PSL)
 #  include <Scripting/scriptmgr.hxx>
 #endif
+#include <Time/sunsolver.hxx>
 #include <Time/tmp.hxx>
 
 #include "fg_init.hxx"
@@ -478,6 +479,67 @@ do_lighting_update (const SGPropertyNode * arg)
 }
 
 
+/**
+ * Update the lighting manually.
+ */
+static bool
+do_timeofday (const SGPropertyNode * arg)
+{
+    const string &offset_type = arg->getStringValue("timeofday", "noon");
+
+    static const SGPropertyNode *longitude
+        = fgGetNode("/position/longitude-deg");
+    static const SGPropertyNode *latitude
+        = fgGetNode("/position/latitude-deg");
+    static const SGPropertyNode *cur_time_override
+        = fgGetNode("/sim/time/cur-time-override", true);
+
+    SGTime *t = globals->get_time_params();
+    int orig_warp = globals->get_warp();
+    time_t cur_time = t->get_cur_time();
+    cout << "cur_time = " << cur_time << endl;
+    cout << "orig_warp = " << orig_warp << endl;
+
+    int warp = 0;
+    if ( offset_type == "noon" ) {
+        warp = fgTimeSecondsUntilNoon( cur_time,
+                                       longitude->getDoubleValue()
+                                         * SGD_DEGREES_TO_RADIANS,
+                                       latitude->getDoubleValue()
+                                         * SGD_DEGREES_TO_RADIANS ); 
+    } else if ( offset_type == "midnight" ) {
+        warp = fgTimeSecondsUntilMidnight( cur_time,
+                                           longitude->getDoubleValue()
+                                             * SGD_DEGREES_TO_RADIANS,
+                                           latitude->getDoubleValue()
+                                             * SGD_DEGREES_TO_RADIANS ); 
+    } else if ( offset_type == "dawn" ) {
+        warp = fgTimeSecondsUntilDawn( cur_time,
+                                       longitude->getDoubleValue()
+                                         * SGD_DEGREES_TO_RADIANS,
+                                       latitude->getDoubleValue()
+                                         * SGD_DEGREES_TO_RADIANS ); 
+     } else if ( offset_type == "dusk" ) {
+        warp = fgTimeSecondsUntilDusk( cur_time,
+                                       longitude->getDoubleValue()
+                                         * SGD_DEGREES_TO_RADIANS,
+                                       latitude->getDoubleValue()
+                                         * SGD_DEGREES_TO_RADIANS ); 
+    }
+    cout << "warp = " << warp << endl;
+    globals->set_warp( orig_warp + warp );
+
+    t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
+               latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
+               cur_time_override->getLongValue(),
+               globals->get_warp() );
+
+    fgUpdateSkyAndLightingParams();
+
+    return true;
+}
+
+
 /**
  * Built-in command: toggle a bool property value.
  *
@@ -906,6 +968,7 @@ static struct {
     { "screen-capture", do_screen_capture },
     { "tile-cache-reload", do_tile_cache_reload },
     { "lighting-update", do_lighting_update },
+    { "timeofday", do_timeofday },
     { "property-toggle", do_property_toggle },
     { "property-assign", do_property_assign },
     { "property-adjust", do_property_adjust },
index ba72a1aeb0bbeaaa06f756e33b97b92bc5bf0b8d..9d4fdc182a212968372fc6fecc791c23a0d6a28c 100644 (file)
@@ -332,6 +332,14 @@ PropsChannel::foundTerminator()
                             = args.getNode("subsystem", i-2, true);
                         node->setStringValue( tokens[i].c_str() );
                     }
+                } else if ( tokens[1] == "timeofday" ) {
+                    for ( unsigned int i = 2; i < tokens.size(); ++i ) {
+                        cout << "props: adding subsystem = " << tokens[i]
+                             << endl;
+                        SGPropertyNode *node
+                            = args.getNode("timeofday", i-2, true);
+                        node->setStringValue( tokens[i].c_str() );
+                    }
                 }
                 if ( !globals->get_commands()
                          ->execute(tokens[1].c_str(), &args) )