public void Run( ) { USER32.MSG msg = new USER32.MSG( ); USER32.PeekMessage(out msg, this.hInstance, 0, 0, USER32.PM_NOREMOVE); while (msg.message != USER32.WM_QUIT) { if (USER32.PeekMessage(out msg, this.hInstance, 0, 0, USER32.PM_REMOVE)) { USER32.TranslateMessage(ref msg); USER32.DispatchMessage(ref msg); } else { if (this.canUpdate) { this.elapsedTime = ( float )((this.oldTime - this.newTime) / ( float )this.ticksPerSecond); this.Update(this.elapsedTime); this.canUpdate = false; } KERNEL32.QueryPerformanceCounter(ref newTime); if (this.newTime > this.oldTime) { switch (this.gDevice.GraphicsDeviceStatus) { case GraphicsDeviceStatus.NotReset: this.gDevice.Reset( ); break; case GraphicsDeviceStatus.Lost: throw new InvalidOperationException("Graphics device instance lost."); } this.gDevice.Clear(Microsoft.Xna.Framework.Color.Black); this.gDevice.RasterizerState = RasterizerState.CullClockwise; this.gDevice.DepthStencilState = DepthStencilState.Default; this.Draw( ); this.gDevice.Present( ); this.oldTime += this.ticksPerFrame; if (this.oldTime < this.newTime) { this.oldTime = (this.newTime + this.ticksPerFrame); } this.canUpdate = true; } } } }
public void Run( ) { USER32.MSG msg = new USER32.MSG( ); USER32.PeekMessage(out msg, this.hInstance, 0, 0, USER32.PM_NOREMOVE); while (msg.message != USER32.WM_QUIT) { if (USER32.PeekMessage(out msg, this.hInstance, 0, 0, USER32.PM_REMOVE)) { USER32.TranslateMessage(ref msg); USER32.DispatchMessage(ref msg); } else { if (this.canUpdate) { this.elapsedTime = ( float )((this.oldTime - this.newTime) / ( float )this.ticksPerSecond); this.Update(this.elapsedTime); this.canUpdate = false; } KERNEL32.QueryPerformanceCounter(ref newTime); if (this.newTime > this.oldTime) { OPENGL32.glClearColor(0, 0, 0, 0); OPENGL32.glClear(OPENGL32.GL_COLOR_BUFFER_BIT | OPENGL32.GL_DEPTH_BUFFER_BIT); OPENGL32.glLoadIdentity( ); this.Draw( ); OPENGL32.glFlush( ); GDI32.SwapBuffers(this.dcHandle); this.oldTime += this.ticksPerFrame; if (this.oldTime < this.newTime) { this.oldTime = (this.newTime + this.ticksPerFrame); } this.canUpdate = true; } } } }