// modellib.cxx - implement an SSG model library.
+#ifdef HAVE_CONFIG_H
+# include <simgear_config.h>
+#endif
+
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
#include "model.hxx"
#include "animation.hxx"
+#include "personality.hxx"
#include "modellib.hxx"
SGModelLib::~SGModelLib ()
{
- map<string, ssgBase *>::iterator it = _table.begin();
- while (it != _table.end()) {
- it->second->deRef();
- _table.erase(it);
- }
}
void
return;
- map<string, ssgBase *>::iterator it = _table.begin();
+ map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.begin();
while (it != _table.end()) {
- ssgBase *item = it->second;
// If there is only one reference, it's
// ours; no one else is using the item.
- if (item->getRef() == 1) {
- item->deRef();
+ if (!it->second.isShared()) {
+ string key = it->first;
_table.erase(it);
- }
- it++;
+ it = _table.upper_bound(key);
+ } else
+ it++;
}
}
-struct SGPersonalityBranch : public ssgBranch {
- ssgBranch *_old_current;
-};
-
static int
personality_pretrav_callback(ssgEntity * entity, int mask)
{
((SGPersonalityBranch *)entity)->_old_current = SGAnimation::current_object;
- SGAnimation::current_object = (ssgBranch *)entity;
+ SGAnimation::current_object = (SGPersonalityBranch *)entity;
return 1;
}
SGModelLib::load_model( const string &fg_root,
const string &path,
SGPropertyNode *prop_root,
- double sim_time_sec )
+ double sim_time_sec,
+ bool cache_object,
+ SGModelData *data )
{
ssgBranch *personality_branch = new SGPersonalityBranch;
personality_branch->setTravCallback(SSG_CALLBACK_PRETRAV, personality_pretrav_callback);
// FIXME: normalize path to
// avoid duplicates.
- map<string, ssgBase *>::iterator it = _table.find(path);
- if (it == _table.end()) {
- ssgEntity *model = sgLoad3DModel( fg_root, path, prop_root,
- sim_time_sec );
- model->ref();
- _table[path] = model; // add one reference to keep it around
+ map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.find(path);
+ if (!cache_object || it == _table.end()) {
+ ssgSharedPtr<ssgEntity> model = sgLoad3DModel(fg_root, path, prop_root,
+ sim_time_sec, 0, data );
+ if (cache_object)
+ _table[path] = model; // add one reference to keep it around
+
personality_branch->addKid( model );
} else {
- personality_branch->addKid( (ssgEntity *)it->second );
+ personality_branch->addKid( it->second );
}
return personality_branch;
}