Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.         public var physStepCounter:int = 0;//number of physics steps per frame.
  3.  
  4.         private var _prevTime:Number = 0;
  5.         private var _currTime:Number;
  6.         private var _elapsedTime:Number;
  7.         private var _accumulator:Number = 0;
  8.  
  9.         public var interations:int = 10;
  10.         public var physScale:Number = 30;//3d units to 1 b2d unit!
  11.         public var accMult:Number = 1;//This is what we use to speed up or slow down time in the engine. Changes physics steps and Entity Thinking per frame!!! CAREFUL.
  12.         public var loopFPS:Number = 30.0;//this uses 33ms for timestep, also equals about 30fps.
  13.         //TODO: Perhaps use target FPS?
  14.         public var timeStep:Number = accMult / loopFPS;//this uses 33ms for timestep, also equals about 30fps.
  15.  
  16.         /**
  17.          * Game loop
  18.          */
  19.         private function gameLoop(e:Event):void
  20.         {
  21.             //FIXME: Combine this crap?
  22.  
  23.             // update loop
  24.             if (C2D.accumulator)
  25.             {
  26.                 _currTime = getTimer();
  27.                 _elapsedTime = (_currTime - _prevTime) * 0.001;
  28.                 _prevTime = _currTime;
  29.  
  30.                 if (_elapsedTime > 0.25)
  31.                 {
  32.                     _elapsedTime = 0.25;
  33.                 }
  34.  
  35.                 _accumulator += _elapsedTime * accMult;
  36.  
  37.                 timeStep = accMult / loopFPS;
  38.  
  39.                 Tweener.setTimeScale(accMult);
  40.  
  41.                 while (_accumulator >= timeStep)
  42.                 {
  43.                     update();
  44.                     physStepCounter++;
  45.                     _accumulator -= timeStep;
  46.                 }
  47.                 //trace('update function fire! ' + physStepCounter);
  48.                 physStepCounter = 0;
  49.             }
  50.             else
  51.             {
  52.                 update();
  53.             }
  54.             // render loop
  55.             render();
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement