Hmmm. I must be calculating FPS wrong or my engine stinks :-(

Started by
6 comments, last by 3DXD 19 years, 10 months ago
Hello Again(Especially Etnu :-) ) I have been working hard to optimize my engine as much as possible(well for now). I took out all the duplicate walls, out by figuring out which walls were shared between "cube tiles" which cut my vertex count and poly count in near half(about 48%). I was originally rendering each wall in its own drawprimitive because each wall could have its own texture. After discussing this here and thinking about it, I instead wrote a collection class that allowed me to go through and based on the ordinal of the texture the wall was assigned create a "max" number of TriangleList vertex buffers. So if I have 8 textures I would have max 8 vertex buffers for those walls and therefor max 8 drawprimitives, instead of say 100 if i had 100 walls. This code works the same for the ceiling and floor as they can too have different textures per tile. However, for testing purposes I hard coded only one texture for the ceiling, floor and walls(its different for each of the three) but within that "quad type" its the same This means I only have one ceiling vertex buffer, one floor and one wall I also have my console which is a single quad (transformed) with a 256 by 256 jpg. I then draw some words on the screen using D3DFont Class. I am using DirectInput for the Mouse and Keyboard as my "camera" can move/run just like Doom and all the other shooters(although its not a shooter). I turned off my collision detection so you just freely run around. Problem is, that my FPS is always 0, which is pathetic :-( if thats really what it is, but my graphics are smooth, my character is screaming fast, no lag, no tearing in or anything and this is in full screen or windowed. So I figure maybe I am calculating it wrong(Debug or Release mode do the same thing). Here is pseudo code of what I am doing Dim iStart as Long Dim tmpFPS as integer (Global g_FPS as integer) iStart = System.DateTime.Now.Ticks Do ''read directinput stuff, move vectors and camera position etc ''render the "world"(walls/monsters/floor/ceiling) ''Calculate my FPS if (System.DateTime.Now.Ticks - iStart) > 1000 then g_FPS = tmpFPS tmpFPS = 0 iStart = System.datetime.now.Ticks else tmpFPS += 1 end if ''render the console with the FPS and some other words specifying my current "Tile cube" and where the exit is etc Loop So either my code stinks :-( and my quality of movement is pure luck or I am calculating this wrong. Any pointers are appreciated. p.s. I know my game loop isnt optimized, its just for testing purposes now. Thanks again!!
Advertisement
You''re weird
Btw, there''s no such thing as ''pure luck''.
I hope you are aware of that System.DateTime.Now.Ticks doesn''t return time elapsed in milliseconds.
It''s 100-nanoseconds.

From the .NET documentation...
The value of this property is the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001.

So try changing this line...
if (System.DateTime.Now.Ticks - iStart) > 1000 then
to...
if (System.DateTime.Now.Ticks - iStart) > 10000000 then
...
or use Environment.Tickcount instead (which is milliseconds)

<-Sweenie->
shwoo, thanks Sweenie :-) that did the trick.

30 FPS in Windowed
55-60 in Full screen

Gonna up my refresh rate and see what i get.

Thanks again so much!!!!!



[edited by - 3dxd on June 9, 2004 10:20:55 AM]
.Ticks isn''t particularly accurate. It is certainly nowhere near it''s theoretical resolution. If you want/need precise timing, you should use QueryPerformanceCounter/...Frequency(through P/Invoke).

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
For calculating frame rates, QueryPerformanceCounter is a little overboard. He is just counting the number of frames that are drawn every second, not timing each frame. QueryPerformanceCounter is only neccessary when doing time based modelling or something where you need to measure very small increments (< 20 ms) very accurately.

[edited by - Sr_Guapo on June 9, 2004 1:20:05 PM]
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
When I added the code to use QueryPerformanceCounter

My pretty much doubled+

Here is what I did

Public Declare Function QueryPerformanceCounter Lib "kernel32" _
(ByRef nSize As Int64) As Integer

Public Declare Function QueryPerformanceFrequency Lib "kernel32" _
(ByRef nSize As Int64) As Integer


Then I created a time function

Public Function GetTime() As Int64
Dim iTime As Int64
Dim i64 As Int64

Try
QueryPerformanceCounter(i64)

iTime = i64 / m_Frequency

Return iTime
Catch ex As Exception

End Try

End Function

I created some varibles
Private m_Current as int64
Private m_Start as int64

Then Before my Game Loop I initialized m_Start
m_Start = GetTime()

Game Loop
GetDirectInput
RenderStuff
Update FPS by
Try
m_Current = GetTime()
If (m_Current - m_Start) > 1.0F Then
m_FPS = tmpFPS
tmpFPS = 0
m_Start = m_Current
Else
tmpFPS += 1
End If
Catch ex As Exception
End Try
End Loop

To be honest I "think" this code is correct, the only thing I am not sure of is the > 1.0F.

I had found an example that used .5 and said that was half a second so I figured 1.0 was a full second.

Any chance anyone can validate that I am calculating this right?

Thanks!

With this code I am getting in full screen 120ish FPS and in windowed 70ish FPS(or higher)

Not sure if that is good or not.

This topic is closed to new replies.

Advertisement