1 // modellib.cxx - implement an SSG model library.
4 # include <simgear_config.h>
7 #include <simgear/compiler.h>
8 #include <simgear/props/props.hxx>
11 #include "animation.hxx"
12 #include "personality.hxx"
14 #include "modellib.hxx"
18 ////////////////////////////////////////////////////////////////////////
19 // Implementation of SGModelLib.
20 ////////////////////////////////////////////////////////////////////////
22 SGModelLib::SGModelLib ()
26 SGModelLib::~SGModelLib ()
33 // This routine is disabled because I believe I see multiple
36 // 1. It blindly deletes all managed models that aren't used
37 // elsewhere. Is this what we really want???? In the one
38 // FlightGear case that calls this method, this clearly is not the
39 // intention. I believe it makes more sense to simply leave items
40 // in the lbrary, even if they are not currently used, they will be
41 // there already when/if we want to use them later.
43 // 2. This routine only does a deRef() on the model. This doesn't actually
44 // delete the ssg tree so there is a memory leak.
46 SG_LOG( SG_GENERAL, SG_ALERT,
47 "WARNGING: a disabled/broken routine has been called. This should be fixed!" );
51 map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.begin();
52 while (it != _table.end()) {
53 // If there is only one reference, it's
54 // ours; no one else is using the item.
55 if (!it->second.isShared()) {
56 string key = it->first;
58 it = _table.upper_bound(key);
65 personality_pretrav_callback(ssgEntity * entity, int mask)
67 ((SGPersonalityBranch *)entity)->_old_current = SGAnimation::current_object;
68 SGAnimation::current_object = (SGPersonalityBranch *)entity;
73 personality_posttrav_callback(ssgEntity * entity, int mask)
75 SGAnimation::current_object = ((SGPersonalityBranch *)entity)->_old_current;
76 ((SGPersonalityBranch *)entity)->_old_current = 0;
81 SGModelLib::load_model( const string &fg_root,
83 SGPropertyNode *prop_root,
88 ssgBranch *personality_branch = new SGPersonalityBranch;
89 personality_branch->setTravCallback(SSG_CALLBACK_PRETRAV, personality_pretrav_callback);
90 personality_branch->setTravCallback(SSG_CALLBACK_POSTTRAV, personality_posttrav_callback);
92 // FIXME: normalize path to
94 map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.find(path);
95 if (!cache_object || it == _table.end()) {
96 ssgSharedPtr<ssgEntity> model = sgLoad3DModel(fg_root, path, prop_root,
97 sim_time_sec, 0, data );
99 _table[path] = model; // add one reference to keep it around
101 personality_branch->addKid( model );
103 personality_branch->addKid( it->second );
105 return personality_branch;
109 // end of modellib.cxx