FPS counter code problem in R12



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/03/2011 at 20:14, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R12 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    I got this coffee code from a friend that I converted to c++ for use in my plugin.  From what I understand it originally came direct from Maxon (can't find the post that confirms that atm, but I remember it clearly).

    Anyway, the code has worked perfectly in R10-R11.5... but in R12 it gets all funky on me.  In previous versions, with a document frame rate of 30fps, it'll hold steady at 29.9.  In R12 it likes to sporadically spike.  Usually up into the high 30's, but I've seen values in the 40 and even 50's, which doesn't make any sense whatsoever, given the document frame rate is 30fps.  I should also mention that this effect doesn't stabilize at all if I lower the frame rate, nor does it seem to depend on the scene itself; empty scenes and scenes full of tasty stuff that needs calculating all suffer from this.

    Here's the original coffee code:

    var gLastTime = 0;
    var oldfps    = 0;
    var lastframe = 0;
      
    main(doc,op)
    {
      var curTime = time();
      var fps = 0.5+1000.0 / (curTime-gLastTime);
      gLastTime = curTime;
      
      var average = Mix(oldfps , fps ,0.2);
      op#ID_USERDATA:1 = tostring(average,".1f");
      
      var curframe = doc->GetTime()->GetFrame(doc->GetFps());
      
      if(curframe!=lastframe) oldfps = average;
      else oldfps = oldfps;
      
      lastframe = curframe;
      
    }
    

    And my c++ conversion of that code:

    BaseTime time = doc->GetTime();
    LONG currentframe = time.GetFrame(doc->GetFps());
    LONG docFPS = doc->GetFps();
      
    //FPS Counter code
    if(CheckIsRunning(CHECKISRUNNING_ANIMATIONRUNNING)==TRUE)
    {
    	LONG cTime = GeGetTimer();
    	FPS = 0.5+1000/(cTime-lastTime);
    	lastTime = cTime;
    	Real average = Mix(oldFPS, FPS, 0.2);
    	bc->SetString(ID_HFPS,(RealToString(average, 2, 1, FALSE, 0)+"fps"));
    	if (currentframe!=lastFrame) oldFPS = average; else oldFPS = oldFPS;
    }
    lastFrame = currentframe;
    

    So, I'm curious what the problem is?  It's almost like scenes don't calculate at a consistent rate in R12.  If that is the case, it's fairly negligible... but my plugin deals in realtime animation, so it's fairly important;)  It doesn't affect the output of my plugin as far as I can tell, but it looks bad when when my fps counter stutters worse than Porky Pig;)

    thanks for any insight,
    kvb


Log in to reply