From: mfranz Date: Thu, 9 Mar 2006 09:04:03 +0000 (+0000) Subject: NasalSys.[ch]xx: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2796f3f4a59b6b9d943c9a5f6de4fdabc41cd6b8;p=flightgear.git NasalSys.[ch]xx: implement FGNasalModelData class for execution of XML and scripts. modelLoaded() is called by the model loader, and the destructor on branch removal. modelmgr.cxx: tilemgr.cxx: tileentry.[ch]xx: make scenery and custom objects run their Nasal scripts on loading and unloading. Let OBJECT_STATIC object not be cached. --- diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 50f5e60cc..82c00f948 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -18,6 +18,7 @@ #include
#include +#include #include "modelmgr.hxx" @@ -56,7 +57,7 @@ FGModelMgr::init () node->getStringValue("path", "Models/Geometry/glider.ac"), globals->get_props(), - globals->get_sim_time_sec() ); + globals->get_sim_time_sec(), 0, new FGNasalModelData ); model->init( object ); // Set position and orientation either diff --git a/src/Scenery/tileentry.cxx b/src/Scenery/tileentry.cxx index 173b1d2b5..b9487b0e0 100644 --- a/src/Scenery/tileentry.cxx +++ b/src/Scenery/tileentry.cxx @@ -876,7 +876,8 @@ FGTileEntry::load( const string_list &path_list, bool is_base ) = new FGDeferredModel( custom_path.str(), obj->path.str(), tile_bucket, - this, obj_trans ); + this, obj_trans, + obj->type == OBJECT_SHARED ); FGTileMgr::model_ready( dm ); diff --git a/src/Scenery/tileentry.hxx b/src/Scenery/tileentry.hxx index 75883f397..fee04866c 100644 --- a/src/Scenery/tileentry.hxx +++ b/src/Scenery/tileentry.hxx @@ -25,9 +25,9 @@ #define _TILEENTRY_HXX -#ifndef __cplusplus +#ifndef __cplusplus # error This library requires C++ -#endif +#endif #ifdef HAVE_CONFIG_H # include @@ -78,24 +78,27 @@ private: FGTileEntry *tile; ssgSharedPtr obj_trans; SGBucket bucket; + bool cache_obj; public: inline FGDeferredModel() { } inline FGDeferredModel( const string& mp, const string& tp, SGBucket b, - FGTileEntry *t, ssgTransform *ot ) + FGTileEntry *t, ssgTransform *ot, bool co ) { model_path = mp; texture_path = tp; bucket = b; tile = t; obj_trans = ot; + cache_obj = co; } inline ~FGDeferredModel() { } inline const string& get_model_path() const { return model_path; } inline const string& get_texture_path() const { return texture_path; } inline const SGBucket& get_bucket() const { return bucket; } + inline const bool get_cache_state() const { return cache_obj; } inline FGTileEntry *get_tile() const { return tile; } inline ssgTransform *get_obj_trans() const { return obj_trans; } }; diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 83230557c..ea36df530 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -40,6 +40,7 @@ #include
#include
#include
+#include #include "newcache.hxx" #include "scenery.hxx" @@ -316,7 +317,9 @@ void FGTileMgr::update_queues() globals->get_model_lib()->load_model( ".", dm->get_model_path(), globals->get_props(), - globals->get_sim_time_sec() ); + globals->get_sim_time_sec(), + dm->get_cache_state(), + new FGNasalModelData ); if ( obj_model != NULL ) { dm->get_obj_trans()->addKid( obj_model ); shadows->addOccluder( (ssgBranch *) obj_model->getParent(0), diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 2201d9b1d..36a344ef5 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -666,3 +666,42 @@ naRef FGNasalSys::removeListener(int argc, naRef* args) return naNum(_listener.size()); } + + +// FGNasalModelData class. If sgLoad3DModel() is called with a pointer to +// such a class, then the modelLoaded() function is executed by the loader, +// and the destructor when the model branch is removed from the scene graph. +// They are used for calling a model's and scripts. + +void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop, + ssgBranch *) +{ + SGPropertyNode *n = prop->getNode("nasal"), *load; + if (!n) + return; + + load = n->getNode("load"); + _unload = n->getNode("unload"); + if (!load && !_unload) + return; + + _module = path; + const char *s = load ? load->getStringValue() : ""; + FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal"); + nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s)); +} + +FGNasalModelData::~FGNasalModelData() +{ + if (_module.empty()) + return; + + FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal"); + if (_unload) { + const char *s = _unload->getStringValue(); + nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s)); + } + nas->deleteModule(_module.c_str()); +} + + diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 669b26eea..c4acd37b7 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -4,6 +4,9 @@ #include #include #include +#include + +#include
#include SG_USING_STD(map); @@ -151,4 +154,16 @@ private: FGNasalSys* _nas; }; + +class FGNasalModelData : public SGModelData { +public: + FGNasalModelData() : _unload(0) {} + ~FGNasalModelData(); + void modelLoaded(const string& path, SGPropertyNode *prop, ssgBranch *); + +private: + string _module; + SGPropertyNode_ptr _unload; +}; + #endif // __NASALSYS_HXX