]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Set "/sim/fghome-readonly" to false also for Windows.
[flightgear.git] / src / Main / fg_init.cxx
index d65092bfe5ce780edfa1cc2ea4abc8c7fc0c53e0..dc56fb0af50d09d2b354c2980ce3745d22a9e1be 100644 (file)
@@ -50,6 +50,7 @@
 
 #include <osgViewer/Viewer>
 
+#include <simgear/canvas/Canvas.hxx>
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
@@ -64,6 +65,7 @@
 
 #include <simgear/scene/model/modellib.hxx>
 #include <simgear/scene/material/matlib.hxx>
+#include <simgear/scene/material/Effect.hxx>
 #include <simgear/scene/model/particles.hxx>
 #include <simgear/scene/tsync/terrasync.hxx>
 
@@ -87,6 +89,7 @@
 
 #include <Canvas/canvas_mgr.hxx>
 #include <Canvas/gui_mgr.hxx>
+#include <Canvas/FGCanvasSystemAdapter.hxx>
 #include <GUI/new_gui.hxx>
 #include <GUI/MessageBox.hxx>
 #include <Input/input.hxx>
@@ -407,16 +410,17 @@ bool fgInitHome()
 #else
     // POSIX, do open+unlink trick to the file is deleted on exit, even if we
     // crash or exit(-1)
-    size_t len = snprintf(buf, 16, "%d", getpid());
+    ssize_t len = snprintf(buf, 16, "%d", getpid());
     int fd = ::open(pidPath.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644);
     if (fd >= 0) {
-        ::write(fd, buf, len);
-        ::unlink(pidPath.c_str()); // delete file when app quits
-        result = true;
+        result = ::write(fd, buf, len) == len;
+        if( ::unlink(pidPath.c_str()) != 0 ) // delete file when app quits
+          result = false;
     }
-    
-    fgSetBool("/sim/fghome-readonly", false);
 #endif
+
+    fgSetBool("/sim/fghome-readonly", false);
+
     if (!result) {
         flightgear::fatalMessageBox("File permissions problem",
                                     "Can't write to user-data storage folder, check file permissions and FG_HOME.",
@@ -449,7 +453,7 @@ int fgInitConfig ( int argc, char **argv, bool reinit )
         options->init(argc, argv, dataPath);
     }
     
-    bool loadDefaults = flightgear::Options::sharedInstance()->shouldLoadDefaultConfig();
+    bool loadDefaults = options->shouldLoadDefaultConfig();
     if (loadDefaults) {
       // Read global preferences from $FG_ROOT/preferences.xml
       SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
@@ -469,22 +473,25 @@ int fgInitConfig ( int argc, char **argv, bool reinit )
     } else {
       SG_LOG(SG_GENERAL, SG_INFO, "not reading default configuration files");
     }// of no-default-config selected
-  
-    // Scan user config files and command line for a specified aircraft.
-    options->initAircraft();
+    
+    return flightgear::FG_OPTIONS_OK;
+}
 
+int fgInitAircraft(bool reinit)
+{
+    // Scan user config files and command line for a specified aircraft.
+    if (!reinit) {
+        flightgear::Options::sharedInstance()->initAircraft();
+    }
+    
     FindAndCacheAircraft f(globals->get_props());
     if (!f.loadAircraft()) {
-      return flightgear::FG_OPTIONS_ERROR;
+        return flightgear::FG_OPTIONS_ERROR;
     }
-
-    // parse options after loading aircraft to ensure any user
-    // overrides of defaults are honored.
-    return options->processOptions();
+    
+    return flightgear::FG_OPTIONS_OK;
 }
 
-
-
 /**
  * Initialize vor/ndb/ils/fix list management and query systems (as
  * well as simple airport db list)
@@ -689,6 +696,9 @@ void fgCreateSubsystems(bool duringReset) {
     ////////////////////////////////////////////////////////////////////
     // Initialize the canvas 2d drawing subsystem.
     ////////////////////////////////////////////////////////////////////
+    simgear::canvas::Canvas::setSystemAdapter(
+      simgear::canvas::SystemAdapterPtr(new canvas::FGCanvasSystemAdapter)
+    );
     globals->add_subsystem("Canvas", new CanvasMgr, SGSubsystemMgr::DISPLAY);
     globals->add_subsystem("CanvasGUI", new GUIMgr, SGSubsystemMgr::DISPLAY);
 
@@ -973,17 +983,29 @@ void fgStartNewReset()
     // potentially others) can queue delete requests on the pager.
     render->getViewer()->getDatabasePager()->cancel();
     
+    osgDB::Registry::instance()->clearObjectCache();
+    
     // preserve the event handler; re-creating it would entail fixing the
     // idle handler
     osg::ref_ptr<flightgear::FGEventHandler> eventHandler = render->getEventHandler();
     
     globals->set_renderer(NULL);
     globals->set_matlib(NULL);
-    simgear::SGModelLib::resetPropertyRoot();
+    globals->set_chatter_queue(NULL);
     
+    simgear::clearEffectCache();
+    simgear::SGModelLib::resetPropertyRoot();
+        
     globals->resetPropertyRoot();
     globals->restoreInitialState();
     
+    fgInitConfig(0, NULL, true);
+    fgInitGeneral(); // all of this?
+    
+    fgGetNode("/sim")->removeChild("aircraft-dir");    
+    fgInitAircraft(true);
+    flightgear::Options::sharedInstance()->processOptions();
+    
     render = new FGRenderer;
     render->setEventHandler(eventHandler);
     globals->set_renderer(render);
@@ -995,7 +1017,7 @@ void fgStartNewReset()
     flightgear::CameraGroup::buildDefaultGroup(viewer.get());
 
     fgOSResetProperties();
-    fgInitConfig(0, NULL, true);
+
     
 // init some things manually
 // which do not follow the regular init pattern