]> git.mxchange.org Git - flightgear.git/commitdiff
Expose NasalSys::gcSave/gcRelease to Canvas
authorThomas Geymayer <tomgey@gmail.com>
Thu, 22 Nov 2012 00:06:04 +0000 (01:06 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Thu, 22 Nov 2012 00:06:22 +0000 (01:06 +0100)
src/Canvas/FGCanvasSystemAdapter.cxx
src/Canvas/FGCanvasSystemAdapter.hxx

index 0f56e3ed198f02dc20f84edb754059d9ec71369f..740973979a7e079becd974217a3db1826bcc8114 100644 (file)
@@ -1,9 +1,11 @@
 #include "FGCanvasSystemAdapter.hxx"
 
 #include <Main/globals.hxx>
+#include <Scripting/NasalSys.hxx>
 #include <Viewer/renderer.hxx>
 
 #include <osgDB/ReadFile>
+#include <stdexcept>
 
 namespace canvas
 {
@@ -67,4 +69,34 @@ namespace canvas
     return osgDB::readImageFile(tpath.c_str());
   }
 
+  /**
+   * Get current FGNasalSys instance.
+   */
+  static FGNasalSys* getNasalSys()
+  {
+    static FGNasalSys* nasal_sys = 0;
+    // TODO if Nasal is able to be removed and/or recreated at runtime we need
+    //      to ensure that always the current instance is used
+    if( !nasal_sys )
+    {
+      nasal_sys = dynamic_cast<FGNasalSys*>(globals->get_subsystem("nasal"));
+      if( !nasal_sys )
+        throw std::runtime_error("FGCanvasSystemAdapter: no NasalSys");
+    }
+
+    return nasal_sys;
+  }
+
+  //----------------------------------------------------------------------------
+  int FGCanvasSystemAdapter::gcSave(naRef r)
+  {
+    return getNasalSys()->gcSave(r);
+  }
+
+  //----------------------------------------------------------------------------
+  void FGCanvasSystemAdapter::gcRelease(int key)
+  {
+    getNasalSys()->gcRelease(key);
+  }
+
 }
index 44239ee04553df28141d1713a14cd09b0b343d1d..82896bda5f66f167f7c12c31674f4fc5d480d725 100644 (file)
@@ -20,6 +20,9 @@ namespace canvas
       virtual void addCamera(osg::Camera* camera) const;
       virtual void removeCamera(osg::Camera* camera) const;
       virtual osg::Image* getImage(const std::string& path) const;
+
+      virtual int gcSave(naRef r);
+      virtual void gcRelease(int key);
   };
 }