Obviously for a game to work you need a game loop... Normally, my game loop would consist of something like this:
while(running){
update();
render();
Thread.sleep(10);
}
This seemed to work fine at first, but then after I started to make my games a bit more complicated the frame rate of my game dropped by 90% in most cases, sometimes they would hang at around <10fps on a high spec system just by simply rendering a couple of 2D image. So I thought to myself: "Should I try putting the render loop on a different thead?". With that in mind, I made a system similar to this:
new Thread(new Render()).start();
new Thread(new GameLogic()).start();
private class Render implements Runnable{
public void run(){
while(running){
render();
}
}
private class GameLogic implements Runnable{
public void run(){
while(running){
update();
Thread.sleep(10);
}
}
}
}
This then caused the graphics to become out of sync with the game update, which then caused the occasional jitter which got quite annoying, later on, I then discovered a use where there is no wait in the loop itself and everything runs as fast as it can, but then you multiply everything in the gameLogic by a deltaTime variable to ensure the game movement is solid. Basically I want to know which way of implementing a game loop is most efficient and whether or not you should render and do gameLogic on the same loop.