google-code-export / pushbuttonengine

Automatically exported from code.google.com/p/pushbuttonengine
0 stars 0 forks source link

Patch for adjustable tickrate. #162

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
From http://pushbuttonengine.com/forum/viewtopic.php?f=5&t=911

Index: src/com/pblabs/engine/core/ProcessManager.as
===================================================================
--- src/com/pblabs/engine/core/ProcessManager.as    (revision 995)
+++ src/com/pblabs/engine/core/ProcessManager.as    (working copy)
@@ -31,6 +31,10 @@
      */
     public class ProcessManager
     {
+        private static var _ticksPerSecond:int = 30;
+        private static var _tickRate:Number    = 1 / _ticksPerSecond;
+        private static var _tickRateMs:Number  = _tickRate * 1000;
+        
         /**
          * If true, disables warnings about losing ticks.
          */
@@ -39,17 +43,37 @@
         /**
          * The number of ticks that will happen every second.
          */
-        public static const TICKS_PER_SECOND:int = 30;
+        public static function get TICKS_PER_SECOND():int
+        {
+            return _ticksPerSecond;
+        }

         /**
+         * @private
+         */
+        public static function set TICKS_PER_SECOND(value:int):void
+        {
+            _ticksPerSecond = value;
+            
+            _tickRate   = 1.0 / Number(value);
+            _tickRateMs = _tickRate * 1000;
+        }
+        
+        /**
          * The rate at which ticks are fired, in seconds.
          */
-        public static const TICK_RATE:Number = 1.0 / Number(TICKS_PER_SECOND);
+        public static function get TICK_RATE():Number
+        {
+            return _tickRate;
+        }

         /**
          * The rate at which ticks are fired, in milliseconds.
          */
-        public static const TICK_RATE_MS:Number = TICK_RATE * 1000;
+        public static function get TICK_RATE_MS():Number
+        {
+            return _tickRateMs;
+        }

         /**
          * The maximum number of ticks that can be processed in a frame.
@@ -549,7 +573,7 @@
                 // Wipe the old array now we're done with it.
                 oldDeferredMethodQueue.length = 0;

-                Profiler.exit("callLater");        
+                Profiler.exit("callLater");
             }

             // Process any queued items.

Original issue reported on code.google.com by ben.garney on 23 May 2010 at 8:39