STATE_engine_get_computer_speed_factor

 

 


   This function is intended to help in writing a program that:
  		1- Keep the same speed all the time even if the frames per second rate changes. This means that when the player in your program \ game
  		   move from one room to another he will continue to have the same speed even if one room
  		   has many more polygons than the other. In other words: it helps to keep the same speed
  		   even if the frames per second rate changes.
  
  		2- Make your program run equally on all computers.
  
   Usage:
   ------
  
    Example: Lets say we want to move an object by 100 units each second
    In this case we should write something similar to the following:
  
  		factor=STATE_engine_get_computer_speed_factor();
  		corrected_number= 100*factor;
  		move_my_object(corrected_number);
  
   Important notes:
  
   1- Since the program cycle duration is the time from the beginning of one render to the next render,
  	  one has to do two renders before getting a non-zero returned value.
  	  This should not be a problem. Here is Why: Consider the usage example above. A returned value of 0 will
  	  cause a call to move_my_object(0) which results that nothing will move before the third render which means
  	  that at the first tenth of a second of your game\application (approximately one tenth) there wont be any movement.
  	  
  
   2- The return value of this function is constantly changing to reflect
  	  changes in the CPU load. This means you have to call the function each
  	  time before you use it (dont call it once and then use the same value over and over ...). 
  
   3- This function is extremely fast. Like most of STATE functions it only retrieves an internal value
  	  This means that there is no penalty for calling it frequently.
    
  	Return Value:
  		The factor returned is actually the average duration of the last 50 rendering cycles (from the beginning of one render to the beginning of the next render)
  		The time is given in tenth of a second (for example if the returned value is 3.2 it means that the average of the last render cycles took 0.32 seconds)
  		The return value will be 0 till there are at least two renders done.
  		
  		
  
  
    Remarks:
  
  		Here is how to calculate the FPS (Frames Per Second) achived by your program using the STATE_engine_get_computer_speed_factor()
  
  				double average_program_cycle_duration_in_seconds=STATE_engine_get_computer_speed_factor()/10;   The average duration of the last 50 cycles
  				if(average_program_cycle_duration_is_seconds==0) return;   protect against division by zero ...		
  				double FPS=1/average_program_cycle_duration_in_seconds;
  				output_text("The current frames per second rate is %lf", FPS);
  
  

 

 

Go to page 1      Select API

 

Copyright © 2007 3DSTATE Corporation. www.3dstate.com