From 5614174b3943413124b565de04045ca8c6693194 Mon Sep 17 00:00:00 2001 From: frohlich Date: Tue, 31 Oct 2006 06:26:50 +0000 Subject: [PATCH] Modified Files: simgear/scene/model/Makefile.am simgear/scene/model/animation.cxx simgear/scene/model/animation.hxx simgear/scene/model/modellib.cxx simgear/scene/model/modellib.hxx Removed Files: simgear/scene/model/personality.cxx simgear/scene/model/personality.hxx: Updates to the animation system. Personality can be implemented easier now --- simgear/scene/model/Makefile.am | 2 - simgear/scene/model/animation.cxx | 324 ++++++++++------------------ simgear/scene/model/animation.hxx | 57 ++--- simgear/scene/model/modellib.cxx | 50 +---- simgear/scene/model/modellib.hxx | 3 - simgear/scene/model/personality.cxx | 56 ----- simgear/scene/model/personality.hxx | 42 ---- 7 files changed, 130 insertions(+), 404 deletions(-) delete mode 100755 simgear/scene/model/personality.cxx delete mode 100755 simgear/scene/model/personality.hxx diff --git a/simgear/scene/model/Makefile.am b/simgear/scene/model/Makefile.am index ac2b8e81..70b8449c 100644 --- a/simgear/scene/model/Makefile.am +++ b/simgear/scene/model/Makefile.am @@ -9,7 +9,6 @@ include_HEADERS = \ location.hxx \ model.hxx \ modellib.hxx \ - personality.hxx \ persparam.hxx \ placement.hxx \ placementtrans.hxx @@ -19,7 +18,6 @@ libsgmodel_a_SOURCES = \ location.cxx \ model.cxx \ modellib.cxx \ - personality.cxx \ persparam.cxx \ placement.cxx \ placementtrans.cxx \ diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index d99d846c..716cc546 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -28,7 +28,6 @@ #include #include "animation.hxx" -#include "personality.hxx" #include "model.hxx" @@ -160,10 +159,6 @@ read_interpolation_table (SGPropertyNode_ptr props) // Implementation of SGAnimation //////////////////////////////////////////////////////////////////////// -// Initialize the static data member -double SGAnimation::sim_time_sec = 0.0; -SGPersonalityBranch *SGAnimation::current_object = 0; - SGAnimation::SGAnimation (SGPropertyNode_ptr props, osg::Group * branch) : _branch(branch), animation_type(0) @@ -185,17 +180,16 @@ SGAnimation::init () { } -int -SGAnimation::update() -{ - return 1; -} - void SGAnimation::restore() { } +void +SGAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) +{ + traverse(node, nv); +} //////////////////////////////////////////////////////////////////////// @@ -260,8 +254,8 @@ SGRangeAnimation::~SGRangeAnimation () { } -int -SGRangeAnimation::update() +void +SGRangeAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { float ranges[2]; if ( _condition == 0 || _condition->test() ) { @@ -280,7 +274,7 @@ SGRangeAnimation::update() ranges[1] = 1000000000.f; } static_cast(_branch)->setRange(0, ranges[0], ranges[1]); - return 2; + traverse(node, nv); } @@ -345,8 +339,8 @@ SGSelectAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) //////////////////////////////////////////////////////////////////////// SGSpinAnimation::SGSpinAnimation( SGPropertyNode *prop_root, - SGPropertyNode_ptr props, - double sim_time_sec ) + SGPropertyNode_ptr props, + double sim_time_sec ) : SGAnimation(props, new osg::MatrixTransform), _use_personality( props->getBoolValue("use-personality",false) ), _prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)), @@ -389,53 +383,36 @@ SGSpinAnimation::SGSpinAnimation( SGPropertyNode *prop_root, } _axis.normalize(); + + if ( _use_personality ) { + _factor.shuffle(); + _position_deg.shuffle(); + } } SGSpinAnimation::~SGSpinAnimation () { } -int -SGSpinAnimation::update() +void +SGSpinAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { + double sim_time_sec = nv->getFrameStamp()->getReferenceTime(); if ( _condition == 0 || _condition->test() ) { double dt; float velocity_rpms; - if ( _use_personality && current_object ) { - SGPersonalityBranch *key = current_object; - if ( !key->getIntValue( this, INIT_SPIN ) ) { - key->setDoubleValue( _factor.shuffle(), this, FACTOR_SPIN ); - key->setDoubleValue( _position_deg.shuffle(), this, POSITION_DEG_SPIN ); - - key->setDoubleValue( sim_time_sec, this, LAST_TIME_SEC_SPIN ); - key->setIntValue( 1, this, INIT_SPIN ); - } - - _factor = key->getDoubleValue( this, FACTOR_SPIN ); - _position_deg = key->getDoubleValue( this, POSITION_DEG_SPIN ); - _last_time_sec = key->getDoubleValue( this, LAST_TIME_SEC_SPIN ); - dt = sim_time_sec - _last_time_sec; - _last_time_sec = sim_time_sec; - key->setDoubleValue( _last_time_sec, this, LAST_TIME_SEC_SPIN ); - - velocity_rpms = (_prop->getDoubleValue() * _factor / 60.0); - _position_deg += (dt * velocity_rpms * 360); - _position_deg -= 360*floor(_position_deg/360); - key->setDoubleValue( _position_deg, this, POSITION_DEG_SPIN ); - } else { - dt = sim_time_sec - _last_time_sec; - _last_time_sec = sim_time_sec; - - velocity_rpms = (_prop->getDoubleValue() * _factor / 60.0); - _position_deg += (dt * velocity_rpms * 360); - _position_deg -= 360*floor(_position_deg/360); - } + dt = sim_time_sec - _last_time_sec; + _last_time_sec = sim_time_sec; + + velocity_rpms = (_prop->getDoubleValue() * _factor / 60.0); + _position_deg += (dt * velocity_rpms * 360); + _position_deg -= 360*floor(_position_deg/360); osg::Matrix _matrix; set_rotation(_matrix, _position_deg, _center, _axis); static_cast(_branch)->setMatrix(_matrix); } - return 1; + traverse(node, nv); } @@ -448,7 +425,7 @@ SGTimedAnimation::SGTimedAnimation (SGPropertyNode_ptr props) : SGAnimation(props, new osg::Switch), _use_personality( props->getBoolValue("use-personality",false) ), _duration_sec(props->getDoubleValue("duration-sec", 1.0)), - _last_time_sec( sim_time_sec ), + _last_time_sec( 0 ), _total_duration_sec( 0 ), _step( 0 ) @@ -499,65 +476,23 @@ SGTimedAnimation::init() static_cast(getBranch())->setSingleChildOn(_step); } -int -SGTimedAnimation::update() +void +SGTimedAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { - if ( _use_personality && current_object ) { - SGPersonalityBranch *key = current_object; - if ( !key->getIntValue( this, INIT_TIMED ) ) { - double total = 0; - double offset = 1.0; - for ( size_t i = 0; i < _branch_duration_specs.size(); i++ ) { - DurationSpec &sp = _branch_duration_specs[ i ]; - double v = sp._min + sg_random() * ( sp._max - sp._min ); - key->setDoubleValue( v, this, BRANCH_DURATION_SEC_TIMED, i ); - if ( i == 0 ) - offset = v; - total += v; - } - // Sanity check : total duration shouldn't equal zero - if ( total < 0.01 ) { - total = 0.01; - } - offset *= sg_random(); - key->setDoubleValue( sim_time_sec - offset, this, LAST_TIME_SEC_TIMED ); - key->setDoubleValue( total, this, TOTAL_DURATION_SEC_TIMED ); - key->setIntValue( 0, this, STEP_TIMED ); - key->setIntValue( 1, this, INIT_TIMED ); - } - - _step = key->getIntValue( this, STEP_TIMED ); - _last_time_sec = key->getDoubleValue( this, LAST_TIME_SEC_TIMED ); - _total_duration_sec = key->getDoubleValue( this, TOTAL_DURATION_SEC_TIMED ); - _last_time_sec -= _total_duration_sec*floor((sim_time_sec - _last_time_sec)/_total_duration_sec); - double duration = _duration_sec; - if ( _step < _branch_duration_specs.size() ) { - duration = key->getDoubleValue( this, BRANCH_DURATION_SEC_TIMED, _step ); - } - if ( ( sim_time_sec - _last_time_sec ) >= duration ) { - _last_time_sec += duration; - _step += 1; - if ( _step >= getBranch()->getNumChildren() ) - _step = 0; - } - static_cast(getBranch())->setSingleChildOn(_step); - key->setDoubleValue( _last_time_sec, this, LAST_TIME_SEC_TIMED ); - key->setIntValue( _step, this, STEP_TIMED ); - } else { - _last_time_sec -= _total_duration_sec*floor((sim_time_sec - _last_time_sec)/_total_duration_sec); - double duration = _duration_sec; - if ( _step < _branch_duration_sec.size() ) { - duration = _branch_duration_sec[ _step ]; - } - if ( ( sim_time_sec - _last_time_sec ) >= duration ) { - _last_time_sec += duration; - _step += 1; - if ( _step >= getBranch()->getNumChildren() ) - _step = 0; - static_cast(getBranch())->setSingleChildOn(_step); - } + double sim_time_sec = nv->getFrameStamp()->getReferenceTime(); + _last_time_sec -= _total_duration_sec*floor((sim_time_sec - _last_time_sec)/_total_duration_sec); + double duration = _duration_sec; + if ( _step < _branch_duration_sec.size() ) { + duration = _branch_duration_sec[ _step ]; } - return 1; + if ( ( sim_time_sec - _last_time_sec ) >= duration ) { + _last_time_sec += duration; + _step += 1; + if ( _step >= getBranch()->getNumChildren() ) + _step = 0; + static_cast(getBranch())->setSingleChildOn(_step); + } + traverse(node, nv); } @@ -621,8 +556,8 @@ SGRotateAnimation::~SGRotateAnimation () delete _table; } -int -SGRotateAnimation::update() +void +SGRotateAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { if (_condition == 0 || _condition->test()) { if (_table == 0) { @@ -638,7 +573,7 @@ SGRotateAnimation::update() set_rotation(_matrix, _position_deg, _center, _axis); static_cast(_branch)->setMatrix(_matrix); } - return 2; + traverse(node, nv); } @@ -666,6 +601,11 @@ SGBlendAnimation::SGBlendAnimation( SGPropertyNode *prop_root, _colorMatrix = new osg::ColorMatrix; osg::StateSet* stateSet = _branch->getOrCreateStateSet(); stateSet->setAttribute(_colorMatrix.get()); + + if ( _use_personality ) { + _factor.shuffle(); + _offset.shuffle(); + } } SGBlendAnimation::~SGBlendAnimation () @@ -673,24 +613,11 @@ SGBlendAnimation::~SGBlendAnimation () delete _table; } -int -SGBlendAnimation::update() +void +SGBlendAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { double _blend; - if ( _use_personality && current_object ) { - SGPersonalityBranch *key = current_object; - if ( !key->getIntValue( this, INIT_BLEND ) ) { - key->setDoubleValue( _factor.shuffle(), this, FACTOR_BLEND ); - key->setDoubleValue( _offset.shuffle(), this, OFFSET_BLEND ); - - key->setIntValue( 1, this, INIT_BLEND ); - } - - _factor = key->getDoubleValue( this, FACTOR_BLEND ); - _offset = key->getDoubleValue( this, OFFSET_BLEND ); - } - if (_table == 0) { _blend = 1.0 - (_prop->getDoubleValue() * _factor + _offset); @@ -706,7 +633,7 @@ SGBlendAnimation::update() _prev_value = _blend; _colorMatrix->getMatrix()(3, 3) = _blend; } - return 1; + traverse(node, nv); } @@ -738,6 +665,11 @@ SGTranslateAnimation::SGTranslateAnimation( SGPropertyNode *prop_root, _axis[1] = props->getFloatValue("axis/y", 0); _axis[2] = props->getFloatValue("axis/z", 0); _axis.normalize(); + + if ( _use_personality ) { + _factor.shuffle(); + _offset_m.shuffle(); + } } SGTranslateAnimation::~SGTranslateAnimation () @@ -745,22 +677,10 @@ SGTranslateAnimation::~SGTranslateAnimation () delete _table; } -int -SGTranslateAnimation::update() +void +SGTranslateAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { if (_condition == 0 || _condition->test()) { - if ( _use_personality && current_object ) { - SGPersonalityBranch *key = current_object; - if ( !key->getIntValue( this, INIT_TRANSLATE ) ) { - key->setDoubleValue( _factor.shuffle(), this, FACTOR_TRANSLATE ); - key->setDoubleValue( _offset_m.shuffle(), this, OFFSET_TRANSLATE ); - } - - _factor = key->getDoubleValue( this, FACTOR_TRANSLATE ); - _offset_m = key->getDoubleValue( this, OFFSET_TRANSLATE ); - - key->setIntValue( 1, this, INIT_TRANSLATE ); - } if (_table == 0) { _position_m = (_prop->getDoubleValue() * _factor) + _offset_m; @@ -776,7 +696,7 @@ SGTranslateAnimation::update() set_translation(_matrix, _position_m, _axis); static_cast(_branch)->setMatrix(_matrix); } - return 2; + traverse(node, nv); } @@ -810,6 +730,14 @@ SGScaleAnimation::SGScaleAnimation( SGPropertyNode *prop_root, _max_y(props->getDoubleValue("y-max")), _max_z(props->getDoubleValue("z-max")) { + if ( _use_personality ) { + _x_factor.shuffle(); + _x_offset.shuffle(); + _y_factor.shuffle(); + _y_offset.shuffle(); + _z_factor.shuffle(); + _z_offset.shuffle(); + } } SGScaleAnimation::~SGScaleAnimation () @@ -817,30 +745,9 @@ SGScaleAnimation::~SGScaleAnimation () delete _table; } -int -SGScaleAnimation::update() +void +SGScaleAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { - if ( _use_personality && current_object ) { - SGPersonalityBranch *key = current_object; - if ( !key->getIntValue( this, INIT_SCALE ) ) { - key->setDoubleValue( _x_factor.shuffle(), this, X_FACTOR_SCALE ); - key->setDoubleValue( _x_offset.shuffle(), this, X_OFFSET_SCALE ); - key->setDoubleValue( _y_factor.shuffle(), this, Y_FACTOR_SCALE ); - key->setDoubleValue( _y_offset.shuffle(), this, Y_OFFSET_SCALE ); - key->setDoubleValue( _z_factor.shuffle(), this, Z_FACTOR_SCALE ); - key->setDoubleValue( _z_offset.shuffle(), this, Z_OFFSET_SCALE ); - - key->setIntValue( 1, this, INIT_SCALE ); - } - - _x_factor = key->getDoubleValue( this, X_FACTOR_SCALE ); - _x_offset = key->getDoubleValue( this, X_OFFSET_SCALE ); - _y_factor = key->getDoubleValue( this, Y_FACTOR_SCALE ); - _y_offset = key->getDoubleValue( this, Y_OFFSET_SCALE ); - _z_factor = key->getDoubleValue( this, Z_FACTOR_SCALE ); - _z_offset = key->getDoubleValue( this, Z_OFFSET_SCALE ); - } - if (_table == 0) { _x_scale = _prop->getDoubleValue() * _x_factor + _x_offset; if (_has_min_x && _x_scale < _min_x) @@ -874,7 +781,7 @@ SGScaleAnimation::update() osg::Matrix _matrix; set_scale(_matrix, _x_scale, _y_scale, _z_scale ); static_cast(_branch)->setMatrix(_matrix); - return 2; + traverse(node, nv); } @@ -918,25 +825,24 @@ SGTexRotateAnimation::~SGTexRotateAnimation () delete _table; } -int -SGTexRotateAnimation::update() +void +SGTexRotateAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { - if (_condition && !_condition->test()) - return 1; - - if (_table == 0) { - _position_deg = _prop->getDoubleValue() * _factor + _offset_deg; - if (_has_min && _position_deg < _min_deg) - _position_deg = _min_deg; - if (_has_max && _position_deg > _max_deg) - _position_deg = _max_deg; - } else { - _position_deg = _table->interpolate(_prop->getDoubleValue()); + if (!_condition || _condition->test()) { + if (_table == 0) { + _position_deg = _prop->getDoubleValue() * _factor + _offset_deg; + if (_has_min && _position_deg < _min_deg) + _position_deg = _min_deg; + if (_has_max && _position_deg > _max_deg) + _position_deg = _max_deg; + } else { + _position_deg = _table->interpolate(_prop->getDoubleValue()); + } + osg::Matrix _matrix; + set_rotation(_matrix, _position_deg, _center, _axis); + _texMat->setMatrix(_matrix); } - osg::Matrix _matrix; - set_rotation(_matrix, _position_deg, _center, _axis); - _texMat->setMatrix(_matrix); - return 2; + traverse(node, nv); } @@ -979,25 +885,24 @@ SGTexTranslateAnimation::~SGTexTranslateAnimation () delete _table; } -int -SGTexTranslateAnimation::update() +void +SGTexTranslateAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { - if (_condition && !_condition->test()) - return 1; - - if (_table == 0) { - _position = (apply_mods(_prop->getDoubleValue(), _step, _scroll) + _offset) * _factor; - if (_has_min && _position < _min) - _position = _min; - if (_has_max && _position > _max) - _position = _max; - } else { - _position = _table->interpolate(apply_mods(_prop->getDoubleValue(), _step, _scroll)); + if (!_condition || _condition->test()) { + if (_table == 0) { + _position = (apply_mods(_prop->getDoubleValue(), _step, _scroll) + _offset) * _factor; + if (_has_min && _position < _min) + _position = _min; + if (_has_max && _position > _max) + _position = _max; + } else { + _position = _table->interpolate(apply_mods(_prop->getDoubleValue(), _step, _scroll)); + } + osg::Matrix _matrix; + set_translation(_matrix, _position, _axis); + _texMat->setMatrix(_matrix); } - osg::Matrix _matrix; - set_translation(_matrix, _position, _axis); - _texMat->setMatrix(_matrix); - return 2; + traverse(node, nv); } @@ -1076,8 +981,8 @@ SGTexMultipleAnimation::~SGTexMultipleAnimation () delete [] _transform; } -int -SGTexMultipleAnimation::update() +void +SGTexMultipleAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { int i; osg::Matrix tmatrix; @@ -1120,7 +1025,7 @@ SGTexMultipleAnimation::update() } } _texMat->setMatrix(tmatrix); - return 2; + traverse(node, nv); } @@ -1279,7 +1184,8 @@ void SGMaterialAnimation::init() } } -int SGMaterialAnimation::update() +void +SGMaterialAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { if (_condition) { bool cond = _condition->test(); @@ -1287,8 +1193,10 @@ int SGMaterialAnimation::update() _update |= _static_update; _last_condition = cond; - if (!cond) - return 2; + if (!cond) { + traverse(node, nv); + return; + } } if (_read & DIFFUSE) @@ -1337,7 +1245,7 @@ int SGMaterialAnimation::update() setMaterialBranch(_branch); _update = 0; } - return 2; + traverse(node, nv); } void SGMaterialAnimation::updateColorGroup(ColorSpec *col, int flag) @@ -1710,8 +1618,8 @@ SGShadowAnimation::~SGShadowAnimation () delete _condition; } -int -SGShadowAnimation::update() +void +SGShadowAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv) { if (_condition) _condition_value = _condition->test(); @@ -1721,7 +1629,7 @@ SGShadowAnimation::update() } else { _branch->setNodeMask(~SG_NODEMASK_SHADOW_BIT&_branch->getNodeMask()); } - return 2; + traverse(node, nv); } bool SGShadowAnimation::get_condition_value(void) { diff --git a/simgear/scene/model/animation.hxx b/simgear/scene/model/animation.hxx index e2052b03..fefe4872 100644 --- a/simgear/scene/model/animation.hxx +++ b/simgear/scene/model/animation.hxx @@ -63,15 +63,6 @@ class SGPersonalityBranch; class SGAnimation : public osg::NodeCallback { public: - enum PersonalityVar { INIT_SPIN, LAST_TIME_SEC_SPIN, FACTOR_SPIN, - POSITION_DEG_SPIN, - INIT_TIMED, LAST_TIME_SEC_TIMED, TOTAL_DURATION_SEC_TIMED, - BRANCH_DURATION_SEC_TIMED, STEP_TIMED, - INIT_TRANSLATE, FACTOR_TRANSLATE, OFFSET_TRANSLATE, - INIT_BLEND, FACTOR_BLEND, OFFSET_BLEND, - INIT_SCALE, X_FACTOR_SCALE, Y_FACTOR_SCALE, Z_FACTOR_SCALE, - X_OFFSET_SCALE, Y_OFFSET_SCALE, Z_OFFSET_SCALE }; - SGAnimation (SGPropertyNode_ptr props, osg::Group * branch); virtual ~SGAnimation (); @@ -89,39 +80,17 @@ public: /** * Update the animation. */ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { - // note, callback is responsible for scenegraph traversal so - // should always include call traverse(node,nv) to ensure - // that the rest of cullbacks and the scene graph are traversed. - update(); - traverse(node, nv); - } - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); /** * Restore the state after the animation. */ virtual void restore(); - /** - * Set the value of sim_time_sec. This needs to be called every - * frame in order for the time based animations to work correctly. - */ - static void set_sim_time_sec( double val ) { sim_time_sec = val; } - - /** - * Current personality branch : enable animation to behave differently - * for similar objects - */ - static SGPersonalityBranch *current_object; - int get_animation_type(void) { return animation_type; } protected: - static double sim_time_sec; - osg::Group* _branch; int animation_type; @@ -148,7 +117,7 @@ public: SGRangeAnimation (SGPropertyNode *prop_root, SGPropertyNode_ptr props); virtual ~SGRangeAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: SGPropertyNode_ptr _min_prop; SGPropertyNode_ptr _max_prop; @@ -198,7 +167,7 @@ public: SGPropertyNode_ptr props, double sim_time_sec ); virtual ~SGSpinAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: bool _use_personality; SGPropertyNode_ptr _prop; @@ -220,7 +189,7 @@ public: SGTimedAnimation (SGPropertyNode_ptr props); virtual ~SGTimedAnimation (); virtual void init(); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: bool _use_personality; double _duration_sec; @@ -247,7 +216,7 @@ class SGRotateAnimation : public SGAnimation public: SGRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGRotateAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: SGPropertyNode_ptr _prop; double _offset_deg; @@ -273,7 +242,7 @@ public: SGTranslateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGTranslateAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: bool _use_personality; SGPropertyNode_ptr _prop; @@ -298,7 +267,7 @@ public: SGBlendAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGBlendAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: bool _use_personality; SGPropertyNode_ptr _prop; @@ -322,7 +291,7 @@ public: SGScaleAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGScaleAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: bool _use_personality; SGPropertyNode_ptr _prop; @@ -360,7 +329,7 @@ class SGTexRotateAnimation : public SGAnimation public: SGTexRotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGTexRotateAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: SGPropertyNode_ptr _prop; double _offset_deg; @@ -387,7 +356,7 @@ public: SGTexTranslateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGTexTranslateAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: SGPropertyNode_ptr _prop; double _offset; @@ -417,7 +386,7 @@ public: SGTexMultipleAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGTexMultipleAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: class TexTransform { @@ -468,7 +437,7 @@ public: const SGPath &texpath); virtual ~SGMaterialAnimation() {} virtual void init(); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); private: enum { DIFFUSE = 1, @@ -599,7 +568,7 @@ public: SGShadowAnimation ( SGPropertyNode *prop_root, SGPropertyNode_ptr props ); virtual ~SGShadowAnimation (); - virtual int update(); + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); bool get_condition_value(void); private: SGCondition * _condition; diff --git a/simgear/scene/model/modellib.cxx b/simgear/scene/model/modellib.cxx index 46c09154..70216e06 100644 --- a/simgear/scene/model/modellib.cxx +++ b/simgear/scene/model/modellib.cxx @@ -10,7 +10,6 @@ #include "model.hxx" #include "animation.hxx" -#include "personality.hxx" #include "modellib.hxx" @@ -31,35 +30,6 @@ SGModelLib::~SGModelLib () void SGModelLib::flush1() { - // This routine is disabled because I believe I see multiple - // problems with it. - // - // 1. It blindly deletes all managed models that aren't used - // elsewhere. Is this what we really want???? In the one - // FlightGear case that calls this method, this clearly is not the - // intention. I believe it makes more sense to simply leave items - // in the lbrary, even if they are not currently used, they will be - // there already when/if we want to use them later. - // - // 2. This routine only does a deRef() on the model. This doesn't actually - // delete the ssg tree so there is a memory leak. - - SG_LOG( SG_GENERAL, SG_ALERT, - "WARNGING: a disabled/broken routine has been called. This should be fixed!" ); - - return; - - map >::iterator it = _table.begin(); - while (it != _table.end()) { - // If there is only one reference, it's - // ours; no one else is using the item. - if (it->second->referenceCount() <= 1) { - string key = it->first; - _table.erase(it); - it = _table.upper_bound(key); - } else - it++; - } } osg::Node* @@ -70,25 +40,7 @@ SGModelLib::load_model( const string &fg_root, bool cache_object, SGModelData *data ) { - osg::Group *personality_branch = new SGPersonalityBranch; - personality_branch->setName("Model Personality Group"); - - // FIXME: normalize path to - // avoid duplicates. - map >::iterator it = _table.find(path); - if (!cache_object || it == _table.end()) { - osg::ref_ptr model = sgLoad3DModel(fg_root, path, prop_root, - sim_time_sec, 0, data ); - model->setName("Loaded model node"); - if (cache_object) - _table[path] = model; // add one reference to keep it around - - personality_branch->addChild( model.get() ); - } else { - personality_branch->addChild( it->second.get() ); - } - - return personality_branch; + return sgLoad3DModel(fg_root, path, prop_root, sim_time_sec, 0, data ); } diff --git a/simgear/scene/model/modellib.hxx b/simgear/scene/model/modellib.hxx index 3842a73f..b5613bc6 100644 --- a/simgear/scene/model/modellib.hxx +++ b/simgear/scene/model/modellib.hxx @@ -40,9 +40,6 @@ public: double sim_time_sec, bool cache_object, SGModelData *data = 0 ); -protected: - - map > _table; }; diff --git a/simgear/scene/model/personality.cxx b/simgear/scene/model/personality.cxx deleted file mode 100755 index c6a6d176..00000000 --- a/simgear/scene/model/personality.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/** - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "personality.hxx" -#include "animation.hxx" - -class SGPersonalityBranchCallback : public osg::NodeCallback -{ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { - SGPersonalityBranch* old_current = SGAnimation::current_object; - SGAnimation::current_object = static_cast(node); - traverse(node, nv); - SGAnimation::current_object = old_current; - } -}; - -SGPersonalityBranch::SGPersonalityBranch() -{ - setUpdateCallback(new SGPersonalityBranchCallback); -} - -void SGPersonalityBranch::setDoubleValue( double value, SGAnimation *anim, int var_id, int var_num ) -{ - _doubleValues[ Key( anim, var_id, var_num ) ] = value; -} - -void SGPersonalityBranch::setIntValue( int value, SGAnimation *anim, int var_id, int var_num ) -{ - _intValues[ Key( anim, var_id, var_num ) ] = value; -} - -double SGPersonalityBranch::getDoubleValue( SGAnimation *anim, int var_id, int var_num ) const -{ - map::const_iterator it = _doubleValues.find( Key( anim, var_id, var_num ) ); - if ( it != _doubleValues.end() ) { - return it->second; - } else { - return 0; - } -} - -int SGPersonalityBranch::getIntValue( SGAnimation *anim, int var_id, int var_num ) const -{ - map::const_iterator it = _intValues.find( Key( anim, var_id, var_num ) ); - if ( it != _intValues.end() ) { - return it->second; - } else { - return 0; - } -} diff --git a/simgear/scene/model/personality.hxx b/simgear/scene/model/personality.hxx deleted file mode 100755 index fc48088e..00000000 --- a/simgear/scene/model/personality.hxx +++ /dev/null @@ -1,42 +0,0 @@ -/** - * $Id$ - */ - -#ifndef _SG_PERSONALITY_HXX -#define _SG_PERSONALITY_HXX 1 - -#include -#include - -#include - -SG_USING_STD(map); - -class SGAnimation; - -// OSGFIXME avoid personality with cloning the structural trees. -class SGPersonalityBranch : public osg::Group { -public: - SGPersonalityBranch(); - void setDoubleValue( double value, SGAnimation *anim, int var_id, int var_num = 0 ); - void setIntValue( int value, SGAnimation *anim, int var_id, int var_num = 0 ); - double getDoubleValue( SGAnimation *anim, int var_id, int var_num = 0 ) const; - int getIntValue( SGAnimation *anim, int var_id, int var_num = 0 ) const; - -private: - struct Key { - Key( SGAnimation *a, int i, int n = 0 ) : anim(a), var_id(i), var_num(n) {} - SGAnimation *anim; - int var_id; - int var_num; - bool operator<( const Key &r ) const { - return anim < r.anim || - ( anim == r.anim && ( var_id < r.var_id || - ( var_id == r.var_id && var_num < r.var_num ) ) ); - } - }; - map _doubleValues; - map _intValues; -}; - -#endif // _SG_PERSONALITY_HXX