]> git.mxchange.org Git - flightgear.git/commitdiff
Initial work on 'reposition' command
authorJames Turner <zakalawe@mac.com>
Mon, 24 Feb 2014 06:10:29 +0000 (22:10 -0800)
committerJames Turner <zakalawe@mac.com>
Mon, 24 Feb 2014 19:43:21 +0000 (19:43 +0000)
- use old-style reset as the basis for a lightweight 'reposition' command. This does not restore state, or reset
time management, but does reset the FDM and re-finalize position.

src/Main/fg_commands.cxx
src/Main/fg_init.cxx
src/Main/fg_init.hxx

index efbb4a97124c253c514dae1e263fc65f9540c399..206a92b57532b25ed56589ac910a0ab4474e38d4 100644 (file)
@@ -209,6 +209,15 @@ do_reset (const SGPropertyNode * arg)
     return true;
 }
 
+/**
+ */
+static bool
+do_reposition (const SGPropertyNode * arg)
+{
+  fgStartReposition();
+  return true;
+}
+
 /**
  * Built-in command: replay the FDR buffer
  */
@@ -1549,6 +1558,7 @@ static struct {
     { "nasal", do_nasal },
     { "exit", do_exit },
     { "reset", do_reset },
+    { "reposition", do_reposition },
     { "pause", do_pause },
     { "load", do_load },
     { "save", do_save },
index 3abb334601472843151010de39fdc7721254706f..86494da846f2509b7b287240743e9c9bdff37ef2 100644 (file)
@@ -937,10 +937,81 @@ void fgReInitSubsystems()
     fgSetBool("/sim/sceneryloaded",false);
 }
 
+
+// re-position is a simplified version of the traditional (legacy)
+// reset procedure. We only need to poke systems which will be upset by
+// a sudden change in aircraft position. Since this potentially includes
+// Nasal, we trigger the 'reinit' signal.
+void fgStartReposition()
+{
+  SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
+  SG_LOG( SG_GENERAL, SG_INFO, "fgStartReposition()");
+  
+  // ensure we are frozen
+  bool freeze = master_freeze->getBoolValue();
+  if ( !freeze ) {
+    master_freeze->setBoolValue(true);
+  }
+  
+  // set this signal so Nasal scripts can take action.
+  fgSetBool("/sim/signals/reinit", true);
+  fgSetBool("/sim/crashed", false);
+  
+  globals->get_subsystem("flight")->unbind();
+  
+  // update our position based on current presets
+  // this will mark position as needed finalized which we'll do in the
+  // main-loop
+  flightgear::initPosition();
+  
+  simgear::SGTerraSync* terraSync =
+  static_cast<simgear::SGTerraSync*>(globals->get_subsystem("terrasync"));
+  if (terraSync) {
+    terraSync->reposition();
+  }
+  
+  // Force reupdating the positions of the ai 3d models. They are used for
+  // initializing ground level for the FDM.
+  //globals->get_subsystem("ai-model")->reinit();
+  
+  // Initialize the FDM
+  globals->get_subsystem("flight")->reinit();
+  
+  // reset replay buffers
+  globals->get_subsystem("replay")->reinit();
+  
+  // ugly: finalizePosition waits for METAR to arrive for the new airport.
+  // we don't re-init the environment manager here, since historically we did
+  // not, and doing so seems to have other issues. All that's needed is to
+  // schedule METAR fetch immediately, so it's available for finalizePosition.
+  // So we manually extract the METAR-fetching component inside the environment
+  // manager, and re-init that.
+  SGSubsystemGroup* envMgr = static_cast<SGSubsystemGroup*>(globals->get_subsystem("environment"));
+  if (envMgr) {
+    envMgr->get_subsystem("realwx")->reinit();
+  }
+  
+  // need to bind FDMshell again, since we manually unbound it above...
+  globals->get_subsystem("flight")->bind();
+  
+  // need to reset aircraft (systems/instruments) so they can adapt to current environment
+  globals->get_subsystem("systems")->reinit();
+  globals->get_subsystem("instrumentation")->reinit();
+  
+  globals->get_subsystem("ATIS")->reinit();
+  
+  // setup state to end re-init
+  fgSetBool("/sim/signals/reinit", false);
+  if ( !freeze ) {
+    master_freeze->setBoolValue(false);
+  }
+  fgSetBool("/sim/sceneryloaded",false);
+}
+
 void fgStartNewReset()
 {
     SGPropertyNode_ptr preserved(new SGPropertyNode);
-    
+  
     if (!copyPropertiesWithAttribute(globals->get_props(), preserved, SGPropertyNode::PRESERVE))
         SG_LOG(SG_GENERAL, SG_ALERT, "Error saving preserved state");
     
index beefcbea87eb774a532ee20f242da46b35fdf1f0..f61134c26c8a3bbbb163a6030d30a0440bd3e5ca 100644 (file)
@@ -65,6 +65,9 @@ void fgPostInitSubsystems();
 // Reset: this is what the 'reset' command (and hence, GUI) is attached to
 void fgReInitSubsystems();
 
+// Re-position: when only location is changing, we can do considerably
+// less work than a full re-init.
+void fgStartReposition();
 
 void fgStartNewReset();