Update of /cvsroot/plib/plib/src/ssg
In directory usw-pr-cvs1:/tmp/cvs-serv12357
Modified Files:
ssg.h ssgAnimation.cxx
Log Message:
Bernie Bright:
I have successfully used ulClock to add frame rate independent timing to
ssgTimedSelector. setDuration() now takes an extra argument that specifies
either frame or clock based timing. The value defaults to frame to maintain
backwards compatibility. I have only tested this on Linux.
Since I don't have cvs write access and my email to Steve bounced the changes
can be downloaded from <http://www.users.bigpond.net.au/bbright/ssg.tar.gz>.
Index: ssg.h
===================================================================
RCS file: /cvsroot/plib/plib/src/ssg/ssg.h,v
retrieving revision 1.151
retrieving revision 1.152
diff -u -d -r1.151 -r1.152
--- ssg.h 17 Oct 2002 12:05:00 -0000 1.151
+++ ssg.h 24 Oct 2002 14:21:22 -0000 1.152
@@ -1788,6 +1788,12 @@
SSG_ANIM_SHUTTLE
} ;
+enum ssgAnimTimeMode
+{
+ SSG_ANIM_FRAME,
+ SSG_ANIM_CLOCK
+};
+
class ssgTimedSelector : public ssgSelector
{
@@ -1803,6 +1809,9 @@
int start ;
int end ;
+ ssgAnimTimeMode time_mode ;
+ static ulClock ck ;
+
void compute_loop_time ()
{
loop_time = 0 ;
@@ -1813,6 +1822,14 @@
protected:
virtual void copy_from ( ssgTimedSelector *src, int clone_flags ) ;
+
+ float get_time() const
+ {
+ if (time_mode == SSG_ANIM_FRAME)
+ return static_cast<float>( ssgGetFrameCounter() );
+ else
+ return ck.update(), ck.getAbsTime();
+ }
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
@@ -1823,10 +1840,13 @@
int getStep () ;
+ ssgAnimTimeMode getTimeMode() const { return time_mode; }
+
float getDuration ( int i = 0 ) { return times [ i ] ; }
- void setDuration ( float ti, int i = -1 )
+ void setDuration ( float ti, int i = -1, ssgAnimTimeMode m = SSG_ANIM_FRAME )
{
+ time_mode = m;
if ( i >= 0 && i < max_kids )
times [ i ] = ti ;
else
@@ -1842,13 +1862,13 @@
if ( m == SSG_ANIM_PAUSE )
{
- pause_time = (float) ssgGetFrameCounter () ;
+ pause_time = get_time() ;
curr = getStep () ;
}
else
if ( m == SSG_ANIM_RESUME )
{
- start_time += (float) ssgGetFrameCounter () - pause_time ;
+ start_time += get_time () - pause_time ;
if ( running != SSG_ANIM_STOP )
m = SSG_ANIM_START ;
@@ -1856,7 +1876,7 @@
else
if ( m == SSG_ANIM_START )
{
- start_time = (float) ssgGetFrameCounter () ;
+ start_time = get_time () ;
curr = getStep () ;
}
Index: ssgAnimation.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/ssg/ssgAnimation.cxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ssgAnimation.cxx 2 Sep 2002 06:05:47 -0000 1.14
+++ ssgAnimation.cxx 24 Oct 2002 14:21:23 -0000 1.15
@@ -24,12 +24,15 @@
#include "ssgLocal.h"
+ulClock ssgTimedSelector::ck;
+
void ssgTimedSelector::copy_from ( ssgTimedSelector *src, int clone_flags )
{
ssgSelector::copy_from ( src, clone_flags ) ;
running = src -> running ;
mode = src -> mode ;
+ time_mode = src -> time_mode ;
start_time = src -> start_time ;
pause_time = src -> pause_time ;
@@ -68,6 +71,9 @@
times [ i ] = 1.0f ;
curr = start = end = 0 ;
+
+ time_mode = SSG_ANIM_FRAME ;
+ ck.reset() ;
}
@@ -100,7 +106,7 @@
int ssgTimedSelector::getStep ()
{
- float t = (float) ssgGetFrameCounter () ;
+ float t = get_time () ;
if ( running == SSG_ANIM_STOP || running == SSG_ANIM_PAUSE )
return curr ;
@@ -142,7 +148,7 @@
t -= times [ k ] ;
//DaveM: i removed this line because, in shuttle mode, start plays twice
-// k-- ;
+ k-- ;
if ( k < start ) k = start ;
if ( k > end ) k = end ;
@@ -174,6 +180,7 @@
_ssgReadInt ( fd, & curr ) ;
_ssgReadInt ( fd, & start ) ;
_ssgReadInt ( fd, & end ) ;
+ _ssgReadInt ( fd, (int *) & time_mode ) ;
return ssgSelector::load(fd) ;
}
@@ -190,6 +197,7 @@
_ssgWriteInt ( fd, curr ) ;
_ssgWriteInt ( fd, start ) ;
_ssgWriteInt ( fd, end ) ;
+ _ssgWriteInt ( fd, (int) time_mode ) ;
return ssgSelector::save(fd) ;
}
|