> Hi,
> I have made a patch which allows one to change the speed of the virtual
> clock, so that slow/fast motion effects can be achieved. It would be cool if
>  this could be added to svn. Thanks!
> Chris.

I've made a new patch 'svn diff'. Hopefully it is easier to apply. I would 
appreciate if people could test out the movie recorder, to see how it is 
affected by the speed changing.
Thanks,
Chris
Index: plugins/movierecorder/movierecorder.cpp
===================================================================
--- plugins/movierecorder/movierecorder.cpp	(revision 24998)
+++ plugins/movierecorder/movierecorder.cpp	(working copy)
@@ -71,6 +71,7 @@
   ffakeClockTicks = 0;
   fakeClockTicks = 0;
   fakeClockElapsed = 0;
+  fakeClockSpeed = 1.0f;
   paused = false;
 }
 
@@ -418,7 +419,8 @@
     {
       csSleep(fakeClockElapsed - realTicksPerFrame);
     }
-  } 
+  }
+  fakeClockElapsed = csTicks(fakeClockElapsed * fakeClockSpeed); 
 }
 
 void csMovieRecorder::ClockSuspend ()
@@ -433,6 +435,16 @@
     realVirtualClock->Resume();
 }
 
+float csMovieRecorder::ClockGetClockSpeed ()
+{
+  return fakeClockSpeed;
+}
+
+void csMovieRecorder::ClockSetClockSpeed (float speed)
+{
+  fakeClockSpeed = speed;
+}
+
 csTicks csMovieRecorder::ClockGetElapsedTicks () const
 {
   return fakeClockElapsed;
Index: plugins/movierecorder/movierecorder.h
===================================================================
--- plugins/movierecorder/movierecorder.h	(revision 24998)
+++ plugins/movierecorder/movierecorder.h	(working copy)
@@ -78,6 +78,9 @@
   csTicks fakeClockTicks;
   /// How many ticks in our fake clocks have elapsed since last advance.
   csTicks fakeClockElapsed;
+  /// The speed at which out fake clock advances at.
+  float fakeClockSpeed;
+
   bool paused;
   // some statistic
   int numFrames;
@@ -133,6 +136,8 @@
   void ClockAdvance ();
   void ClockSuspend ();
   void ClockResume ();
+  float ClockGetClockSpeed ();
+  void ClockSetClockSpeed (float speed);
   csTicks ClockGetElapsedTicks () const;
   csTicks ClockGetCurrentTicks () const;
 
@@ -194,6 +199,14 @@
     {
       if (parent) parent->ClockResume();
     }
+    virtual float GetClockSpeed ()
+    {
+      return parent ? parent->ClockGetClockSpeed() : 0;
+    }
+    virtual void SetClockSpeed (float speed)
+    {
+      if (parent) parent->ClockSetClockSpeed(speed);
+    }
     virtual csTicks GetElapsedTicks () const
     {
       return parent ? parent->ClockGetElapsedTicks() : 0;
Index: include/iutil/virtclk.h
===================================================================
--- include/iutil/virtclk.h	(revision 24998)
+++ include/iutil/virtclk.h	(working copy)
@@ -72,6 +72,17 @@
    * csGetTicks().
    */
   virtual csTicks GetCurrentTicks () const = 0;
+
+  /**
+   * Query the speed at which the clock is ticking. 1.0 is normal speed.
+   */
+  virtual float GetClockSpeed () = 0;
+
+  /**
+   * Set the speed at which the clock is ticking.
+   * \param speed New clock speed.
+   */
+  virtual void SetClockSpeed (float speed) = 0;
 };
 
 #endif // __CS_IUTIL_VIRTCLK_H__
Index: include/csutil/virtclk.h
===================================================================
--- include/csutil/virtclk.h	(revision 24998)
+++ include/csutil/virtclk.h	(working copy)
@@ -54,6 +54,9 @@
   csTicks currentVirtualTime;
   /// Absolute time in milliseconds
   csTicks currentRealTime;
+  ///The speed at which the clock ticks
+  float clockSpeed;
+
   uint flags;
 public:
   csVirtualClock ();
@@ -62,6 +65,8 @@
   virtual void Advance ();
   virtual void Suspend ();
   virtual void Resume ();
+  virtual float GetClockSpeed () { return clockSpeed; }
+  virtual void SetClockSpeed (float speed) {clockSpeed = speed;}; 
   virtual csTicks GetElapsedTicks () const { return elapsedTime; }
   virtual csTicks GetCurrentTicks () const { return currentVirtualTime; }
 };
Index: libs/csutil/virtclk.cpp
===================================================================
--- libs/csutil/virtclk.cpp	(revision 24998)
+++ libs/csutil/virtclk.cpp	(working copy)
@@ -24,7 +24,9 @@
 csVirtualClock::csVirtualClock () : 
   scfImplementationType (this), elapsedTime (0), currentVirtualTime (0), 
   currentRealTime(0), flags (flagFirstShot)
-{ }
+{
+  clockSpeed = 1.0f;
+}
 
 csVirtualClock::~csVirtualClock () { }
 
@@ -44,8 +46,8 @@
       // csTicks(-1) is the period for a unsigend value
       elapsedTime = currentRealTime + (csTicks(-1) - last) + 1;
     else
-      elapsedTime = currentRealTime - last;
-    currentVirtualTime += elapsedTime;
+      elapsedTime = csTicks((currentRealTime - last) * clockSpeed);
+      currentVirtualTime += elapsedTime;
   }
 }
 
Index: apps/walktest/walktest.cpp
===================================================================
--- apps/walktest/walktest.cpp	(revision 24998)
+++ apps/walktest/walktest.cpp	(working copy)
@@ -1015,7 +1015,6 @@
 
   plugin_mgr = CS_QUERY_REGISTRY (object_reg, iPluginManager);
   vc = CS_QUERY_REGISTRY (object_reg, iVirtualClock);
-
   myG3D = CS_QUERY_REGISTRY (object_reg, iGraphics3D);
   if (!myG3D)
   {
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to