473,388 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Strange "framerate drop" using with my own timer class

I wrote a small timer class for use in a graphics engine I am working on
for teaching myself.

The small time based animations I tried with it seem to work fine but
displaying the frame rate I noticed a certain "drop in framerate" to
appear at regular intervals without any apparent reason.

Here's the code I'm using:

class BasicTimer
{
public:
void update();
float getTimePerFrame() const;
BasicTimer();
~BasicTimer();

private:
// Copy constructor and assignment operator
// Declared private for copy protection
BasicTimer(const BasicTimer& rFrom);
BasicTimer& operator=(const BasicTimer& rFrom);

// Attributes
float timeOfThisFrame_;
float timePerFrame_; // In seconds
float timeOfLastFrame_;
};

inline BasicTimer::BasicTimer()
: timeOfThisFrame_(0.0f),
timePerFrame_(0.0167f),
timeOfLastFrame_(static_cast<float>(clock()) /
static_cast<float>(CLOCKS_PER_SEC))
{
}

inline BasicTimer::~BasicTimer()
{
}

inline void BasicTimer::update()
{
timeOfThisFrame_ = static_cast<float>(clock()) /
static_cast<float>(CLOCKS_PER_SEC);

// Prevent overflow (however unlikely considering the data range)
if (timeOfThisFrame_ - timeOfLastFrame_ >= 0.0f)
{
timePerFrame_ = timeOfThisFrame_ - timeOfLastFrame_;
}

timeOfLastFrame_ = timeOfThisFrame_;
}

inline float BasicTimer::getTimePerFrame() const
{
return timePerFrame_;
}

I display the framerate in my main() by calling:

std::cout << (1.0f / timer.getTimePerFrame()) << std::endl;

and I get either 1.INF usually since I am only drawing two triangles
right now, or some value around 60.0 if I activate VSynch on my GPU's
driver.

Anyway, every 10 frames or so that framrate drops. Either from 1.INF to
60, or from 60.0 to 30.0 depending on what mode I am on.

It's really happening at somewhat regular intervals but I don't see
what's causing it. The animation seems to be smooth enough so the values
seem to be correct, but why do some frames at regular intervals take
longer to render?
Apr 11 '07 #1
0 1645

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul Miller | last post by:
We've run into minidom's inabilty to handle large (20+MB) XML files, and need a replacement that can handle it. Unfortunately, we're pretty dependent on a DOM, so a pulldom or SAX replacement is...
7
by: Larry R Harrison Jr | last post by:
I am looking for javascript and a basic tutorial on how to make mouse-over drop-down menus--the type that when you "hover" over a subject links relevant to that subject "emerge" which you can then...
4
by: Larry R Harrison Jr | last post by:
I have them working now, courtesy of the link given in the prior thread--the HVMenu over at Dynamic Drive myself. http://www.dynamicdrive.com I have them working as side-bar menus, not...
1
by: John | last post by:
Hi everyone. I'm having a real problem with a drop-down menu that I'm using. Simply, as I scroll down the page, it follows me. I don't want this!! I guess it's all my fault for using...
2
by: Alanoly J. Andrews | last post by:
Hi, I have two tables (that I know of) in a database that seem to be corrupted. All SQL statements on the tables hang, "select * from..", "select count (*) from", "delete from..". I can't even...
7
by: Risen | last post by:
Hi,all, I want to execute SQL command " DROP DATABASE mydb" and "Restore DATABASE ....." in vb.net 2003. But it always shows error. If any body can tell me how to execute sql command as above?...
0
by: Sebastian | last post by:
Hello! I work with ASP.NET Futures and I would like to realize a "Drag & Drop" - functionality on my Page. I have three "draggable Div's" and three "DropZones", but how can I get the "ID" from...
2
by: Doug | last post by:
Hi, I can't figure out how to create a drop-down list box. The help file says it exists. The icon in the help file matches the combobox in the toolbox. I tried using a combox box, both with and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.