flopoloco's picture

GameWindow Timing Issue

I remember being said that the next OpenTK version will include a new timing mechanism, anyhow, here's a test I made in current 0.9.1 .

using System;
using System.Drawing;
using System.Diagnostics;
using OpenTK;
using OpenTK.Graphics;
 
namespace OpenTKTest
{
	class Program : GameWindow
	{
		private Random random;
		private double nextTime, currentTime;
		private int r, g, b;
 
		public Program() : base(640, 480)
		{
			random = new Random();
		}
 
		public override void OnLoad(EventArgs e)
		{
		}
 
		public override void OnUpdateFrame(UpdateFrameEventArgs e)
		{
			currentTime += e.Time;
 
			if (currentTime > nextTime)
			{
				nextTime =currentTime + 1;
				r = random.Next(0, 254);
				g = random.Next(0, 254);
				b = random.Next(0, 254);
				Trace.WriteLine(String.Format("Check on:\t {0}", currentTime.ToString()));
			}
 
		}
 
 
		public override void OnRenderFrame(RenderFrameEventArgs e)
		{
			GL.ClearColor(Color.FromArgb(255, r, g, b));
			GL.Clear(ClearBufferMask.ColorBufferBit);
			SwapBuffers();
		}
 
 
		public static void Main(string[] args)
		{
			using (Program program = new Program())
			{
				program.Run();
			}
		}
	}
}

Trace results:

...
Check on:	 14,8649442999998
Check on:	 15,8650569999998
Check on:	 16,8651670999993
Check on:	 18,2261955999991
Check on:	 19,2262548999984
Check on:	 20,226323599998
Check on:	 21,2263256999972
Check on:	 22,502357799997
Check on:	 23,502364599998
Check on:	 24,502434599999
Check on:	 26,3859432999997
Check on:	 27,3859854000009
Check on:	 28,3860231000013
Check on:	 29,3860308000011
Check on:	 30,3860916000009

In 16 and 24 I was moving the application window (holding the mouse button) for a couple of seconds resulting a loss of one second (might break the application logic, I think I seen it in AirplaneWars example). So it's good to test it out in the SVN ;)


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

For some reason, Windows stop sending events when you click & drag an application window. This causes all GameWindow processing to stop - no UpdateFrames, no RenderFrames, nothing gets through, until the window is released.

If anyone happens to know a workaround for this issue, please tell!

martinsm's picture

Usually it is solved like this - when window recieves WM_ENTERSIZEMOVE message (it is entering window move or resize modal loop), then you create timer. And in timer callback you just do the usual thing when application is idle (update game logic, draw window content). And when window recieves WM_EXITSIZEMOVE message, then you kill this timer.

Read here: http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=30067...
(ignore Direct3D stuff, search for A Bit of Polish section)

the Fiddler's picture

Thanks for the link, I'll try to see how to this can fit in the current system.

flopoloco's picture

Keep up the good work :)