1 // modellib.cxx - implement an SSG model library.
3 #include <simgear/compiler.h>
4 #include <simgear/props/props.hxx>
7 #include "animation.hxx"
8 #include "personality.hxx"
10 #include "modellib.hxx"
14 ////////////////////////////////////////////////////////////////////////
15 // Implementation of SGModelLib.
16 ////////////////////////////////////////////////////////////////////////
18 SGModelLib::SGModelLib ()
22 SGModelLib::~SGModelLib ()
24 map<string, ssgBase *>::iterator it = _table.begin();
25 while (it != _table.end()) {
26 ssgDeRefDelete(it->second);
34 // This routine is disabled because I believe I see multiple
37 // 1. It blindly deletes all managed models that aren't used
38 // elsewhere. Is this what we really want???? In the one
39 // FlightGear case that calls this method, this clearly is not the
40 // intention. I believe it makes more sense to simply leave items
41 // in the lbrary, even if they are not currently used, they will be
42 // there already when/if we want to use them later.
44 // 2. This routine only does a deRef() on the model. This doesn't actually
45 // delete the ssg tree so there is a memory leak.
47 SG_LOG( SG_GENERAL, SG_ALERT,
48 "WARNGING: a disabled/broken routine has been called. This should be fixed!" );
52 map<string, ssgBase *>::iterator it = _table.begin();
53 while (it != _table.end()) {
54 ssgBase *item = it->second;
55 // If there is only one reference, it's
56 // ours; no one else is using the item.
57 if (item->getRef() == 1) {
66 personality_pretrav_callback(ssgEntity * entity, int mask)
68 ((SGPersonalityBranch *)entity)->_old_current = SGAnimation::current_object;
69 SGAnimation::current_object = (SGPersonalityBranch *)entity;
74 personality_posttrav_callback(ssgEntity * entity, int mask)
76 SGAnimation::current_object = ((SGPersonalityBranch *)entity)->_old_current;
77 ((SGPersonalityBranch *)entity)->_old_current = 0;
82 SGModelLib::load_model( const string &fg_root,
84 SGPropertyNode *prop_root,
87 ssgBranch *personality_branch = new SGPersonalityBranch;
88 personality_branch->setTravCallback(SSG_CALLBACK_PRETRAV, personality_pretrav_callback);
89 personality_branch->setTravCallback(SSG_CALLBACK_POSTTRAV, personality_posttrav_callback);
91 // FIXME: normalize path to
93 map<string, ssgBase *>::iterator it = _table.find(path);
94 if (it == _table.end()) {
95 ssgEntity *model = sgLoad3DModel( fg_root, path, prop_root,
98 _table[path] = model; // add one reference to keep it around
99 personality_branch->addKid( model );
101 personality_branch->addKid( (ssgEntity *)it->second );
103 return personality_branch;
107 // end of modellib.cxx