Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMTimer Class Reference

Timer. More...

#include <PLMTimer.hpp>

Inheritance diagram for PLMTimer:

Inheritance graph
[legend]
List of all members.

Public Methods

 PLMTimer (u32 val=0)
u32 GetTicks () const
u32 StoreTicks ()
u32 GetStoredTicks () const
u32 GetDiffNow () const
u32 GetDiffReplace ()
void Reset (u32 val=0)
void Wait (u32 delay)
void WaitAcc (u32 delay)
u32 NbInstances ()
u32 SDLState ()

Detailed Description

Timer.

This object can :

  • get current application time,
  • store current time
  • wait for a specific amount of time
For example, if you want to know how long a routine needs to execute :
    PLMTimer t;
    t.StoreTicks ();
    ... some code ...
    cout << "Time: " << t.GetDiffNow() << endl;

Another use of timers is in event-oriented applications :

    void MainLoop ()
    {
      PLMTimer t;
      while (! quit)
        {
          t.StoreTicks ();

          get_new_events();
          handle_events();
          
          u32 diff = t.GetDiffNow ();
          if (diff < FPS) t.Wait (FPS-diff);
        }
    }
This way, each loop is executed regurlarly and your program does not waste too much CPU resources.


Constructor & Destructor Documentation

PLMTimer::PLMTimer u32    val = 0
 

Create a new timer initialized with val.


Member Function Documentation

u32 PLMTimer::GetTicks   [inline]
 

Get current application time, in ticks (no modification).

u32 PLMTimer::StoreTicks   [inline]
 

Get current time and store it internally (replace previous value).

u32 PLMTimer::GetStoredTicks   [inline]
 

Get last saved time (no modification).

u32 PLMTimer::GetDiffNow   [inline]
 

Get time difference between now and last saved time (no modification).

u32 PLMTimer::GetDiffReplace   [inline]
 

Same as GetDiffNow() but replace saved time by current time.

void PLMTimer::Reset u32    val = 0 [inline]
 

Reset saved time to 0.

void PLMTimer::Wait u32    delay [inline]
 

Wait (stop execution) for delay milliseconds (precision = 10 ms).

void PLMTimer::WaitAcc u32    delay
 

Wait (stop execution) for delay milliseconds (precision = 10 ms).

This version is designed to be a little bit more accurate, but more expensive in CPU time.

u32 PLMSDLMgr::NbInstances   [inline, inherited]
 

Get the current number of instances (classes using SDL).

u32 PLMSDLMgr::SDLState   [inline, inherited]
 

Get the current value of SDL flags (initialized sub-systems).


The documentation for this class was generated from the following file:
  • PLMTimer.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:45 2004.