Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The server needs to handle the physics, because all the movement will be handled by it. So for that I need a game loop. The thing is that the server doesn't have the render part, it's just a console.

All the posts I found on the internet were involving the render part. I'm not stupid, I know I should not take in consideration that part but then which type of loop should I use? (fixedtimestep, semi-fixed). My game functionality would resemble League Of Legends or Dota 2 functionality.

Actual questions:

1.What is the server functionality for this type of game?

2.What does the game loop look like?

Additional info: I use libGDX for the client part, and JBox2D on the server part, KryoNet for Networking and thinking of using lwjgl (only the System class) for Native timers.

share|improve this question
Related: gamedev.stackexchange.com/questions/46023/… –  Byte56 Jun 21 '13 at 14:39
I don't know if i understood this right but i think he uses dynamic time-step there. –  Romeo Jun 21 '13 at 14:43
The OP is using a variable time-step. However, the answers recommend a fixed or semi-fixed time-step. See also this question: gamedev.stackexchange.com/questions/12347/… –  Byte56 Jun 21 '13 at 15:10
Let's say i use deWiTTERS game loop. How can i get the tick count in Java ( GetTickCount() ). –  Romeo Jun 21 '13 at 15:18
Just a side note: anything involving physics is almost always more stable using a fixed time step, especially with inexpensive integrators and double-especially if any springs are involved. –  Patrick Hughes Jun 21 '13 at 17:23

1 Answer 1

When handling games with a fixed time step, which is what you would need to simulate a physics system, it is best not to go with the system Timer as it is not as precise as other methods (even though the difference is small). Here is an example of how you might go about running a game loop that iterates 60 times a second.

public void run() {
    double ns = 1000000000.0 / 60.0;
    double delta = 0;

    long lastTime = System.nanoTime();
    long timer = System.currentTimeMillis();

    while (running) {
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;

        while (delta >= 1) {

The running boolean would be set to true at the start of a program and is better practice than simply putting true, especially if there are multiple threads (You would need to have another thread listening for input from clients).

What makes this method better than using a Timer is if there is a hiccup or delay in one of the game ticks it is able to compensate. (ie. if the game for whatever reason only iterates 59 times in a second, the next second it will run 61 times) This is important considering the server may fall behind occasionally for whatever reason.

The tick() method would consist of all of the code to run the game. (The parts that include movement and such)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.