1
0
Fork 0

NasalSys.[ch]xx:

implement FGNasalModelData class for execution of XML <load> and <unload>
  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.
This commit is contained in:
mfranz 2006-03-09 09:04:03 +00:00
parent b0b5c2dda9
commit 2796f3f4a5
6 changed files with 68 additions and 6 deletions

View file

@ -18,6 +18,7 @@
#include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx>
#include <Scripting/NasalSys.hxx>
#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

View file

@ -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 );

View file

@ -25,9 +25,9 @@
#define _TILEENTRY_HXX
#ifndef __cplusplus
#ifndef __cplusplus
# error This library requires C++
#endif
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
@ -78,24 +78,27 @@ private:
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; }
};

View file

@ -40,6 +40,7 @@
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/viewer.hxx>
#include <Scripting/NasalSys.hxx>
#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),

View file

@ -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 <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());
}

View file

@ -4,6 +4,9 @@
#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);
@ -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