#include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx>
+#include <Scripting/NasalSys.hxx>
#include "modelmgr.hxx"
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
= new FGDeferredModel( custom_path.str(),
obj->path.str(),
tile_bucket,
- this, obj_trans );
+ this, obj_trans,
+ obj->type == OBJECT_SHARED );
FGTileMgr::model_ready( dm );
#define _TILEENTRY_HXX
-#ifndef __cplusplus
+#ifndef __cplusplus
# error This library requires C++
-#endif
+#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
FGTileEntry *tile;
ssgSharedPtr<ssgTransform> 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; }
};
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/viewer.hxx>
+#include <Scripting/NasalSys.hxx>
#include "newcache.hxx"
#include "scenery.hxx"
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),
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 <load> and <unload> 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());
+}
+
+
#include <simgear/misc/sg_path.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/nasal/nasal.h>
+#include <simgear/scene/model/model.hxx>
+
+#include <Main/globals.hxx>
#include <map>
SG_USING_STD(map);
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