Timed animations now working again.
This commit is contained in:
parent
677ec873be
commit
b85ff8c210
3 changed files with 26 additions and 13 deletions
|
@ -497,6 +497,7 @@ void fgRenderFrame() {
|
||||||
}
|
}
|
||||||
// Keep resetting sim time while the sim is initializing
|
// Keep resetting sim time while the sim is initializing
|
||||||
globals->set_sim_time_sec( 0.0 );
|
globals->set_sim_time_sec( 0.0 );
|
||||||
|
Animation::set_sim_time_sec( 0.0 );
|
||||||
} else {
|
} else {
|
||||||
// idle_state is now 1000 meaning we've finished all our
|
// idle_state is now 1000 meaning we've finished all our
|
||||||
// initializations and are running the main loop, so this will
|
// initializations and are running the main loop, so this will
|
||||||
|
@ -1024,6 +1025,7 @@ static void fgMainLoop( void ) {
|
||||||
delta_time_sec = 0;
|
delta_time_sec = 0;
|
||||||
last_time_stamp = current_time_stamp;
|
last_time_stamp = current_time_stamp;
|
||||||
globals->inc_sim_time_sec( delta_time_sec );
|
globals->inc_sim_time_sec( delta_time_sec );
|
||||||
|
Animation::set_sim_time_sec( globals->get_sim_time_sec() );
|
||||||
|
|
||||||
static long remainder = 0;
|
static long remainder = 0;
|
||||||
long elapsed;
|
long elapsed;
|
||||||
|
@ -1038,6 +1040,7 @@ static void fgMainLoop( void ) {
|
||||||
SGTime *t = globals->get_time_params();
|
SGTime *t = globals->get_time_params();
|
||||||
|
|
||||||
sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
|
sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
|
||||||
|
sglog().setLogLevels( SG_ALL, SG_INFO );
|
||||||
|
|
||||||
FGLocation * acmodel_location = 0;
|
FGLocation * acmodel_location = 0;
|
||||||
if(cur_fdm_state->getACModel() != 0) {
|
if(cur_fdm_state->getACModel() != 0) {
|
||||||
|
|
|
@ -349,6 +349,9 @@ fgLoad3DModel( const string &fg_root, const string &path,
|
||||||
// Implementation of Animation
|
// Implementation of Animation
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Initialize the static data member
|
||||||
|
double Animation::sim_time_sec = 0.0;
|
||||||
|
|
||||||
Animation::Animation (SGPropertyNode_ptr props, ssgBranch * branch)
|
Animation::Animation (SGPropertyNode_ptr props, ssgBranch * branch)
|
||||||
: _branch(branch)
|
: _branch(branch)
|
||||||
{
|
{
|
||||||
|
@ -365,7 +368,7 @@ Animation::init ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Animation::update ()
|
Animation::update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +443,7 @@ SelectAnimation::~SelectAnimation ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SelectAnimation::update ()
|
SelectAnimation::update()
|
||||||
{
|
{
|
||||||
if (_condition != 0 && _condition->test())
|
if (_condition != 0 && _condition->test())
|
||||||
((ssgSelector *)_branch)->select(0xffff);
|
((ssgSelector *)_branch)->select(0xffff);
|
||||||
|
@ -461,7 +464,7 @@ SpinAnimation::SpinAnimation( SGPropertyNode *prop_root,
|
||||||
_prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
|
_prop((SGPropertyNode *)prop_root->getNode(props->getStringValue("property", "/null"), true)),
|
||||||
_factor(props->getDoubleValue("factor", 1.0)),
|
_factor(props->getDoubleValue("factor", 1.0)),
|
||||||
_position_deg(props->getDoubleValue("starting-position-deg", 0)),
|
_position_deg(props->getDoubleValue("starting-position-deg", 0)),
|
||||||
_last_time_sec( sim_time_sec /* globals->get_sim_time_sec() */ )
|
_last_time_sec( sim_time_sec )
|
||||||
{
|
{
|
||||||
_center[0] = props->getFloatValue("center/x-m", 0);
|
_center[0] = props->getFloatValue("center/x-m", 0);
|
||||||
_center[1] = props->getFloatValue("center/y-m", 0);
|
_center[1] = props->getFloatValue("center/y-m", 0);
|
||||||
|
@ -477,7 +480,7 @@ SpinAnimation::~SpinAnimation ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SpinAnimation::update( double sim_time_sec )
|
SpinAnimation::update()
|
||||||
{
|
{
|
||||||
double dt = sim_time_sec - _last_time_sec;
|
double dt = sim_time_sec - _last_time_sec;
|
||||||
_last_time_sec = sim_time_sec;
|
_last_time_sec = sim_time_sec;
|
||||||
|
@ -511,7 +514,7 @@ TimedAnimation::~TimedAnimation ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TimedAnimation::update( double sim_time_sec )
|
TimedAnimation::update()
|
||||||
{
|
{
|
||||||
if ((sim_time_sec - _last_time_sec) >= _duration_sec) {
|
if ((sim_time_sec - _last_time_sec) >= _duration_sec) {
|
||||||
_last_time_sec = sim_time_sec;
|
_last_time_sec = sim_time_sec;
|
||||||
|
@ -602,7 +605,7 @@ TranslateAnimation::~TranslateAnimation ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TranslateAnimation::update ()
|
TranslateAnimation::update()
|
||||||
{
|
{
|
||||||
if (_table == 0) {
|
if (_table == 0) {
|
||||||
_position_m = (_prop->getDoubleValue() + _offset_m) * _factor;
|
_position_m = (_prop->getDoubleValue() + _offset_m) * _factor;
|
||||||
|
|
|
@ -53,8 +53,7 @@ class FGLocation;
|
||||||
* instead, they should use the FGModelLoader declared in loader.hxx.
|
* instead, they should use the FGModelLoader declared in loader.hxx.
|
||||||
*/
|
*/
|
||||||
ssgBranch * fgLoad3DModel( const string& fg_root, const string &path,
|
ssgBranch * fgLoad3DModel( const string& fg_root, const string &path,
|
||||||
SGPropertyNode *prop_root,
|
SGPropertyNode *prop_root, double sim_time_sec );
|
||||||
double sim_time_sec );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,10 +85,18 @@ public:
|
||||||
/**
|
/**
|
||||||
* Update the animation.
|
* Update the animation.
|
||||||
*/
|
*/
|
||||||
virtual void update ();
|
virtual void update();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
static double sim_time_sec;
|
||||||
|
|
||||||
ssgBranch * _branch;
|
ssgBranch * _branch;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -137,7 +144,7 @@ public:
|
||||||
SelectAnimation( SGPropertyNode *prop_root,
|
SelectAnimation( SGPropertyNode *prop_root,
|
||||||
SGPropertyNode_ptr props );
|
SGPropertyNode_ptr props );
|
||||||
virtual ~SelectAnimation ();
|
virtual ~SelectAnimation ();
|
||||||
virtual void update ();
|
virtual void update();
|
||||||
private:
|
private:
|
||||||
FGCondition * _condition;
|
FGCondition * _condition;
|
||||||
};
|
};
|
||||||
|
@ -155,7 +162,7 @@ public:
|
||||||
SGPropertyNode_ptr props,
|
SGPropertyNode_ptr props,
|
||||||
double sim_time_sec );
|
double sim_time_sec );
|
||||||
virtual ~SpinAnimation ();
|
virtual ~SpinAnimation ();
|
||||||
virtual void update( double sim_time_sec );
|
virtual void update();
|
||||||
private:
|
private:
|
||||||
SGPropertyNode_ptr _prop;
|
SGPropertyNode_ptr _prop;
|
||||||
double _factor;
|
double _factor;
|
||||||
|
@ -175,7 +182,7 @@ class TimedAnimation : public Animation
|
||||||
public:
|
public:
|
||||||
TimedAnimation (SGPropertyNode_ptr props);
|
TimedAnimation (SGPropertyNode_ptr props);
|
||||||
virtual ~TimedAnimation ();
|
virtual ~TimedAnimation ();
|
||||||
virtual void update( double sim_time_sec );
|
virtual void update();
|
||||||
private:
|
private:
|
||||||
double _duration_sec;
|
double _duration_sec;
|
||||||
double _last_time_sec;
|
double _last_time_sec;
|
||||||
|
@ -219,7 +226,7 @@ public:
|
||||||
TranslateAnimation( SGPropertyNode *prop_root,
|
TranslateAnimation( SGPropertyNode *prop_root,
|
||||||
SGPropertyNode_ptr props );
|
SGPropertyNode_ptr props );
|
||||||
virtual ~TranslateAnimation ();
|
virtual ~TranslateAnimation ();
|
||||||
virtual void update ();
|
virtual void update();
|
||||||
private:
|
private:
|
||||||
SGPropertyNode_ptr _prop;
|
SGPropertyNode_ptr _prop;
|
||||||
double _offset_m;
|
double _offset_m;
|
||||||
|
|
Loading…
Add table
Reference in a new issue