XFuFPSCount.cpp Source File

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# XFuFPSCount.cpp

Go to the documentation of this file.

    00001 /*! \file
    00002  * X-Forge Util <br>
    00003  * Copyright 2000-2003 Fathammer Ltd
    00004  *
    00005  * \brief Frame rate counter class
    00006  *
    00007  * $Id: XFuFPSCount.cpp,v 1.5 2003/08/12 13:34:08 lars Exp $
    00008  * $Date: 2003/08/12 13:34:08 $
    00009  * $Revision: 1.5 $
    00010  */
    00011
    00012 #include <xfcore/XFcCore.h>
    00013 #include <xfutil/XFuFPSCount.h>
    00014
    00015 XFuFPSCount::XFuFPSCount()
    00016 {
    00017     mTicks = NULL;
    00018     mTickCount = 0;
    00019     mCurrentTick = 0;
    00020 }
    00021
    00022 XFuFPSCount::~XFuFPSCount()
    00023 {
    00024     delete[] mTicks;
    00025 }
    00026
    00027
    00028 XFuFPSCount * XFuFPSCount::create(INT32 aFrameInterval)
    00029 {
    00030     XFuFPSCount * t = new XFuFPSCount;
    00031
    00032     if (t == NULL)
    00033         return NULL;
    00034
    00035     // Minimum number of tick stamps is 2.
    00036     if (aFrameInterval < 2)
    00037         aFrameInterval = 2;
    00038
    00039     t->mTickCount = aFrameInterval;
    00040
    00041     t->mTicks = new INT32[aFrameInterval];
    00042
    00043     if (t->mTicks == NULL)
    00044     {
    00045         delete t;
    00046         return NULL;
    00047     }
    00048
    00049     INT32 i;
    00050     for (i = 0; i < aFrameInterval; i++)
    00051         t->mTicks[i] = 0xffffff;
    00052
    00053     return t;
    00054 }
    00055
    00056 void XFuFPSCount::tick()
    00057 {
    00058     mCurrentTick++;
    00059     if (mCurrentTick >= mTickCount)
    00060         mCurrentTick = 0;
    00061     mTicks[mCurrentTick] = XFcCore::getTick();
    00062 }
    00063
    00064 REAL XFuFPSCount::getFPS()
    00065 {
    00066     INT32 v = (mCurrentTick + 1);
    00067     if (v >= mTickCount) v = 0;
    00068     INT32 delta = mTicks[mCurrentTick] - mTicks[v];
    00069     if (mTickCount < 2)
    00070         return 0;
    00071     if (delta < 1)
    00072         return 0; // actually, this should be 'infinite'
    00073     return REALi(1000) / ((REAL)(delta) / (REAL)(mTickCount - 1));
    00074 }
    00075
    00076

|  | X-Forge Documentation Confidential Copyright © 2002-2003 Fathammer |  | Documentation generated with doxygen by Dimitri van Heesch