Jump to content
  • Advertisement
Sign in to follow this  
Xanather

Fixed Server Game Loop

This topic is 2221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

namespace ServerGameLoopTest
{
class Program
{
static void Main(string[] args)
{
Server server = new Server();
server.Start();
}
}
class Server
{
Timer timer = new Timer(16);
DateTime prevtime;
public void Start()
{
prevtime = DateTime.Now;
timer.Elapsed += new ElapsedEventHandler(GameLoop);
timer.Enabled = true;
Console.ReadLine();
}
private void GameLoop(object source, ElapsedEventArgs e)
{
RunGameLogic(e.SignalTime.Subtract(prevtime));
prevtime = e.SignalTime;
}
private void RunGameLogic(TimeSpan timesincelastframe)
{
Console.WriteLine(timesincelastframe.Milliseconds); //testing purposes, should always show 16
//game logic here
}
}
}
[/source]
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
Advertisement
Sign in to follow this  

  • 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!