Sign in to follow this  

Fixed Server Game Loop

Recommended Posts

[source lang="csharp"]using System;
using System.Timers;

namespace ServerGameLoopTest
class Program
static void Main(string[] args)
Server server = new Server();
class Server
Timer timer = new Timer(16);
DateTime prevtime;
public void Start()
prevtime = DateTime.Now;
timer.Elapsed += new ElapsedEventHandler(GameLoop);
timer.Enabled = true;
private void GameLoop(object source, ElapsedEventArgs e)
prevtime = e.SignalTime;
private void RunGameLogic(TimeSpan timesincelastframe)
Console.WriteLine(timesincelastframe.Milliseconds); //testing purposes, should always show 16
//game logic here
So i am tying to create a fixed time step loop for a server using the Timer object provided by the .net Framework 4.0.
I am going to assume doing this is the wrong way of doing it. When running this "as is" (the code above)
the printed timespan is 16 milliseconds, then 30 milliseconds, then 32 (i think), then 16 again. and it cycles
through this. The point is that this is not a fixed time step. Why is this, should I not use the timer object
to do this? If so what else? I am trying to get a fixed time step a the client (XNA) and server (no XNA at all so
i need to create a game loop). both programs will have a loop of every 16 milliseconds (62.5 FPS)

All replies are appriciated.

Thanks, Xanather.

Share this post

Link to post
Share on other sites

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

Sign in to follow this