1
0
Fork 0

Reduce AI/MP lags when removing models

Move load of removing OSG objects to the OSG pager thread
This commit is contained in:
ThorstenB 2011-10-11 21:43:24 +02:00
parent 020d6a6363
commit 53e6c0ac5f
2 changed files with 32 additions and 3 deletions

View file

@ -129,9 +129,7 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
FGAIBase::~FGAIBase() { FGAIBase::~FGAIBase() {
// Unregister that one at the scenery manager // Unregister that one at the scenery manager
if (globals->get_scenery()) { removeModel();
globals->get_scenery()->get_scene_graph()->removeChild(aip.getSceneGraph());
}
if (props) { if (props) {
SGPropertyNode* parent = props->getParent(); SGPropertyNode* parent = props->getParent();
@ -143,6 +141,29 @@ FGAIBase::~FGAIBase() {
fp = 0; fp = 0;
} }
/** Cleanly remove the model
* and let the scenery database pager do the clean-up work.
*/
void
FGAIBase::removeModel()
{
FGScenery* pSceneryManager = globals->get_scenery();
if (pSceneryManager)
{
osg::ref_ptr<osg::Object> temp = _model.get();
pSceneryManager->get_scene_graph()->removeChild(aip.getSceneGraph());
// withdraw from SGModelPlacement and drop own reference (unref)
aip.init( 0 );
_model = 0;
// pass it on to the pager, to be be deleted in the pager thread
pSceneryManager->getPagerSingleton()->queueDeleteRequest(temp);
}
else
{
SG_LOG(SG_AI, SG_ALERT, "AIBase: Could not unload model. Missing scenery manager!");
}
}
void FGAIBase::readFromScenario(SGPropertyNode* scFileNode) void FGAIBase::readFromScenario(SGPropertyNode* scFileNode)
{ {
if (!scFileNode) if (!scFileNode)
@ -248,6 +269,12 @@ bool FGAIBase::init(bool search_in_AI_path) {
osg::Node * mdl = SGModelLib::loadPagedModel(f, props, new FGNasalModelData(props)); osg::Node * mdl = SGModelLib::loadPagedModel(f, props, new FGNasalModelData(props));
if (_model.valid())
{
// reinit, dump the old model
removeModel();
}
_model = new osg::LOD; _model = new osg::LOD;
_model->setName("AI-model range animation node"); _model->setName("AI-model range animation node");

View file

@ -216,6 +216,8 @@ protected:
void CalculateMach(); void CalculateMach();
double UpdateRadar(FGAIManager* manager); double UpdateRadar(FGAIManager* manager);
void removeModel();
static int _newAIModelID(); static int _newAIModelID();
private: private: