Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSimonForsman

Posted 23 August 2012 - 06:49 AM

remember that sleep will sleep for ATLEAST the time specified, it can and usually will sleep for longer.

Also , its a good idea to add the elapsedtime to the timer rather than reseting it at the start.

Since you are running a single thread you want something like:

lastTickTime = currentTime();
timePerTick = 1000.0 / updatesPerSecond;
while(running) {
	 curTime = currentTime();
	 while (curTime > lastTickTime+timePerTick) {
		 update();
		 lastTickTime+=timePerTick;
	 }
	 render();
}

This should be good enough, If your render framerate is capped by v-sync (I've never written a singlethreaded Android app so i always sleep in the update threads while the renderer runs as fast as it can, capped by the displays v-sync).

If this causes your app to render at more than 60 fps(no v-sync) you can add a timer check for the render function aswell and sleep for one ms or so if there is alot of time left until the renderer should run. (If the renderer should run soon its better to skip the sleep and just run the loop again since the sleep only specifies the minimum amount of time to sleep for)

#4SimonForsman

Posted 23 August 2012 - 06:47 AM

remember that sleep will sleep for ATLEAST the time specified, it can and usually will sleep for longer.

Also , its a good idea to add the elapsedtime to the timer rather than reseting it at the start.

Since you are running a single thread you want something like:

lastTickTime = currentTime();
timePerTick = 1000.0 / updatesPerSecond;
while(running) {
	 curTime = currentTime();
	 while (curTime > lastTickTime+timePerTick) {
		 update();
		 lastTickTime+=timePerTick;
	 }
	 render();
}

This should be good enough, If your render framerate is capped by v-sync (I've never written a singlethreaded Android app so i always sleep in the update threads while the renderer runs as fast as it can, capped by the displays v-sync).

If this causes your app to render at more than 60 fps(no v-sync) you can add a timer check for the render function aswell and sleep for one ms or so if there is alot of time left until the renderer should run. (If the renderer should run soon its better to skip the sleep and just run the loop again)

#3SimonForsman

Posted 23 August 2012 - 06:42 AM

remember that sleep will sleep for ATLEAST the time specified, it can and usually will sleep for longer.

Also , its a good idea to add the elapsedtime to the timer rather than reseting it at the start.

Since you are running a single thread you want something like:

lastTickTime = currentTime();
timePerTick = 1000.0 / updatesPerSecond;
while(running) {
	 curTime = currentTime();
	 while (curTime > lastTickTime+timePerTick) {
		 update();
		 lastTickTime+=timePerTick;
	 }
	 render();
}

This should be good enough, If your render framerate is capped by v-sync (I've never written a singlethreaded Android app so i always sleep in the update threads while the renderer runs as fast as it can, capped by the displays v-sync).

If this causes your app to render at more than 60 fps(no v-sync) you can add a timer check for the render function aswell and do a 1ms sleep if its not time to render yet.

#2SimonForsman

Posted 23 August 2012 - 06:36 AM

remember that sleep will sleep for ATLEAST the time specified, it can and usually will sleep for longer.

Also , its a good idea to add the elapsedtime to the timer rather than reseting it at the start.

Since you are running a single thread you want something like:

lastTickTime = currentTime();
timePerTick = 1000.0 / updatesPerSecond;
while(running) {
     curTime = currentTime();
     while (curTime > lastTickTime+timePerTick) {
         update();
         lastTickTime+=timePerTick;
     }
     render();
     Thread.sleep(1);
}

This should be good enough, If your render framerate is capped by v-sync you can probably remove the sleep. (I've never written a singlethreaded Android app so i always sleep in the update threads while the renderer runs as fast as it can, capped by the displays v-sync)

#1SimonForsman

Posted 23 August 2012 - 06:15 AM

remember that sleep will sleep for ATLEAST the time specified, it can and usually will sleep for longer.

PARTNERS