Skip to main content
deleted 18 characters in body
Source Link

There is a nuance here. You asked:

So I am wondering, why not just do something like:

while(running){ Update(); }

I believe this would call every frame. Am I doing something completely crazy here? is there a much better method?

This is false. If you place your Update() method inside a simple while(true) loop, it will be called as much times as the processor can handle. If your processor can run it 123456 times a second, it will.

The method the tutorial you follow is using is called a fixed time-step update. In other words, you call your Update() function X times a second (often 60) at fixed intervals (1/60 or 0.0166... seconds).

By using a simple while(true) loop, you can use a technique called a delta-time update. This technique calls the Update() functions as many times as it can, but passes the time elapsed between 2 loops to the Update() function, so that you can make your calculations accordingly.

There is a lot of documentation on the various advantages and disadvantages of both methods, a quick Google search or a search on this site should give plenty information. But nobody can tell you which one is the ABSOLUTE better.

NOTE: In your example, the Update() function is only running 1 time per second. You'd need to change a line in order to have the 60 updates per second you want:

delta += (now - lastTime) / ns / amountOfTicks;

There is a nuance here. You asked:

So I am wondering, why not just do something like:

while(running){ Update(); }

I believe this would call every frame. Am I doing something completely crazy here? is there a much better method?

This is false. If you place your Update() method inside a simple while(true) loop, it will be called as much times as the processor can handle. If your processor can run it 123456 times a second, it will.

The method the tutorial you follow is using is called a fixed time-step update. In other words, you call your Update() function X times a second (often 60) at fixed intervals (1/60 or 0.0166... seconds).

By using a simple while(true) loop, you can use a technique called a delta-time update. This technique calls the Update() functions as many times as it can, but passes the time elapsed between 2 loops to the Update() function, so that you can make your calculations accordingly.

There is a lot of documentation on the various advantages and disadvantages of both methods, a quick Google search or a search on this site should give plenty information.

NOTE: In your example, the Update() function is only running 1 time per second. You'd need to change a line in order to have the 60 updates per second you want:

delta += (now - lastTime) / ns / amountOfTicks;

There is a nuance here. You asked:

So I am wondering, why not just do something like:

while(running){ Update(); }

I believe this would call every frame.

This is false. If you place your Update() method inside a simple while(true) loop, it will be called as much times as the processor can handle. If your processor can run it 123456 times a second, it will.

The method the tutorial you follow is using is called a fixed time-step update. In other words, you call your Update() function X times a second (often 60) at fixed intervals (1/60 or 0.0166... seconds).

By using a simple while(true) loop, you can use a technique called a delta-time update. This technique calls the Update() functions as many times as it can, but passes the time elapsed between 2 loops to the Update() function, so that you can make your calculations accordingly.

There is a lot of documentation on the various advantages and disadvantages of both methods, a quick Google search or a search on this site should give plenty information. But nobody can tell you which one is the ABSOLUTE better.

NOTE: In your example, the Update() function is only running 1 time per second. You'd need to change a line in order to have the 60 updates per second you want:

delta += (now - lastTime) / ns / amountOfTicks;
Source Link

There is a nuance here. You asked:

So I am wondering, why not just do something like:

while(running){ Update(); }

I believe this would call every frame. Am I doing something completely crazy here? is there a much better method?

This is false. If you place your Update() method inside a simple while(true) loop, it will be called as much times as the processor can handle. If your processor can run it 123456 times a second, it will.

The method the tutorial you follow is using is called a fixed time-step update. In other words, you call your Update() function X times a second (often 60) at fixed intervals (1/60 or 0.0166... seconds).

By using a simple while(true) loop, you can use a technique called a delta-time update. This technique calls the Update() functions as many times as it can, but passes the time elapsed between 2 loops to the Update() function, so that you can make your calculations accordingly.

There is a lot of documentation on the various advantages and disadvantages of both methods, a quick Google search or a search on this site should give plenty information.

NOTE: In your example, the Update() function is only running 1 time per second. You'd need to change a line in order to have the 60 updates per second you want:

delta += (now - lastTime) / ns / amountOfTicks;