Jump to content
  • Advertisement

NO

Sign in to follow this  
  • entries
    145
  • comments
    222
  • views
    138634

Timings

Sign in to follow this  
Tape_Worm

43 views

I'm having a shitload of trouble with my timing code. It's horrible. If anyone has an object for doing proper delta-frametime times and FPS times, I'd appreciate a look at it or some help pointing me in the right direction. I made a post about it on the .NET forum.

It's just too damn late.
Sign in to follow this  


3 Comments


Recommended Comments

It's pretty similar to the timer used by BlodBath (in your thread), but just for variety this is my timer. This is the clock.cs class:

using System;

namespace Rings.Utilities
{
public class Clock
{
#region Members

private static Clock mClock = null;

private long mnFrequency;
private long mnLastTime, mnFrameTime;
private long mnStartTime, mnEndTime; // Used for interval timing.
private float mfFrameInterval, mfFramesPerSecond;

#endregion

#region Properties

public static Clock GameClock
{
get
{
if (mClock == null)
mClock = new Clock();
return mClock;
}
}

public float FrameInterval
{
get { return mfFrameInterval; }
}
public float FramesPerSecond
{
get { return mfFramesPerSecond; }
}

#endregion

#region Methods

public Clock()
{
NativeMethods.QueryPerformanceFrequency(ref mnFrequency);
}

public void Update()
{
NativeMethods.QueryPerformanceCounter(ref mnFrameTime);

mfFrameInterval = (float)(mnFrameTime - mnLastTime) / mnFrequency;
mfFramesPerSecond = 1.0f / mfFrameInterval;

mnLastTime = mnFrameTime;
}

public void StartTiming()
{
NativeMethods.QueryPerformanceCounter(ref mnStartTime);
}

public double GetElapsedTime()
{
NativeMethods.QueryPerformanceCounter(ref mnEndTime);
return (double)(mnEndTime - mnStartTime) / (double)mnFrequency;
}

#endregion
}
}







The clock class relies on the native methods:

using System;
using System.Drawing;
using System.Runtime.InteropServices;


namespace Rings.Utilities
{
internal class NativeMethods
{
#region Structs


[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public IntPtr msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public Point p;
}

[StructLayout(LayoutKind.Sequential)]
public struct MemoryStatus
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}

#endregion

#region Methods

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool QueryPerformanceCounter(ref long PerformanceCount);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static

Share this comment


Link to comment
Thanks. You: rating++. I implemented the timing code. However, it's still acting really weird in full screen. I'm about ready to become an accountant. A bad one at that.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!