GFrameHandler 1.0

GFrameHandler is a tiny but handy tool for basic cycle loop and frame manipulations. It is aimed for using in game but could be used in any kind of applications.


Overview

GFrameHandler is written using standard C++, it should work well with most C++ compilers. List of available GFrameHandler for specific operating system or library :
  • GFrameHandler for Windows
  • GFrameHandler for SDL
  • GFrameHandler for Clanlib
GFrameHandler for Windows could be used in developing any Windows(Win95 or later) game. For SDL and Clanlib version, it should have no problem to be integrated in application for any platform supported by correspond libraries.

GFrameHandler consists only one class, just include GFrameHandler.h and GFrameHandler.cpp to your project to use this tiny tool. Basically it's just required to create GFrameHandler object before the main loop and having frame_handler.calculate() ( and GFrameHandler::limit_frame() as well if you need to limit frame rate ) call each frame. The following is an example for using GFrameHandler to limit FPS :-
/* If GFrameHandler is instantiated much earlier before it, it's recommended to call GFrameHandler::reset() here ( right before the cycle loop ) */
GFrameHandler frame_handler;
frame_handler.set_fps_limit(40);

//main loop
while(running)
{
/*
blah blah....
*/

/* It is highly recommended to have GFrameHandler::limit_frame() function call right before GFrameHandler::calculate().
*/
frame_handler.limit_frame();
frame_handler.calculate();

}



Member Functions of GFrameHandler

  • void reset(void)
Reset all stored variables. If the GFrameHandler is instantiated much earlier before main loop, call this function right before main loop.

  • void set_fps_limit(int fps)
Set maximum FPS( frames per second) limit.

  • void set_tpf_limit(int millisecond)
Set minimum TPF( time per frame ) limit. This is basically same with set_fps_limit(int) but with better control. FPS = 1/TPF(in second).

  • void limit_frame(void)
Call this function in each cycle to limit the frame time. The default frame time limit is 20 millisecond, use set_fps_limit(int) or set_tpf_limit(int) for different frame rate locking. *Highly recommended to have this function call right before calculate().

  • void limit_frame_fast(void)
This has the same functionality with limit_fps() but could release slightly more CPU time when it is possible, the trade off is lower accuracy. *Highly recommended to have this function call right before calculate().

  • void calculate(void)
Calculate current FPS and frame time. It is recommended to call this member function at the end at the cycle.

  • int get_fps(void)
Get current FPS.

  • int get_elapsed_time(void)
Get elapsed time since previous frame ( current frame time ) in millisecond.



License

GFrameHandler is distributed under Boost Software License( Version 1.0 ). See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.



Special Thanks


Special and deep thanks to Lf3T-Hn4D ( http://lefthand.xullum.net ), who has shared his knowledge and given me comments to make this library better.




Last Update : 19/05/2006


GFrameHandler © 2006 by Wong Chin Foo
email : chinfoo@galaxist.net

http://www.galaxist.net