{"author_name":"Helco","cat":"LD #23","comments":[{"author_name":"","time":"April 29, 2012 2:20 am","epoch":1335684000,"text":"I don&#8217;t understand what the problem is you&#8217;re having with computing the elapsed time in between frames, even if you have to use integers of milliseconds. You don&#8217;t have to use ints in your speed calculations, and you can use milliseconds directly by just dividing your characters&#8217; speed \/ second by 1000. I.e. If you have a character that moves 1 unit every second, he moves 0.001 units every millisecond.","spam":"N"},{"author_name":"","time":"April 29, 2012 4:02 am","epoch":1335690120,"text":"Oooooooh, I get it now. That&#8217;s funny :). I was confused because I&#8217;m used to seeing comma&#8217;s and dot&#8217;s switched from you in numbers :). I read 10.000 as 10.","spam":"N"},{"author_name":"","time":"April 29, 2012 5:30 am","epoch":1335695400,"text":"Just FYI, there are more ways than 2 to deal with framerates.  Important things to consider are vsync, determinism, and how you want your game to react to jitter\/slow computers.","spam":"N"},{"author_name":"yoklov","time":"April 29, 2012 9:07 am","epoch":1335708420,"text":"Well, just for the record, java&#8217;s nanosecond counter is a lie.  If it&#8217;s not exposed in C++, then java doesn&#8217;t get it.","spam":"N"},{"author_name":"Shadow","time":"April 29, 2012 10:26 am","epoch":1335713160,"text":"If you ask me for my opinion I don&#8217;t think that having such exaggerated FPS does help your game in any way. For starters is creating a problem for you.","spam":"N"},{"author_name":"","time":"April 29, 2012 2:43 pm","epoch":1335728580,"text":"If the user&#8217;s gfx hw and driver supports vsync then use it.  That&#8217;s the hardest part of the problem solved right there!","spam":"N"}],"epoch":1335675360,"likes":2,"metadata":{"p_key":"55888","p_author":"Helco","p_authorkey":"12090","p_urlkey":"91606","p_title":"The timer problem","p_cat":"LD #23","p_event":"LD23","p_time":"1335675360","p_likes":"2","p_comments":"6","p_status":"UPD5","us_key":"12090","us_name":"Helco","us_username":"helco","event_start":"1334880000","event_key":"10","event_name":"LD23"},"text":"<p>Hi,<\/p>\n <p>cause this problem was a bug in my LD game and will be a bug in other games I want to present it and possible solutions for it. I would like to know what you think about these or have another solution.<\/p>\n <p><strong>The \u00a0bug<\/strong><\/p>\n <p><strong><\/strong>\u00a0Not all computers are as fast as other computers. That&#8217;s why a game without any timing limiter would execute on other computers faster or slower.<\/p>\n <p><strong>Possible solutions<\/strong><\/p>\n <p><strong><\/strong>There are some possible solutions I already know:<\/p>\n <ul>\n <li>Limit the frame rate to a constant value (all procedural movement can be done with a constant value)<\/li>\n <li>Compute the elapsed time between two frames (the elapsed time must be multiplied with all speed values)<\/li>\n <\/ul>\n <p>I want to show you my opinion about these.<\/p>\n <p><strong>Limit the frame rate to a constant value<\/strong><\/p>\n <p>It looks very easy you calculate the time span of the current frame and subtract it from the time span a full frame for the desired frame rate and you have the time you must wait before a new frame may start. But what is when you notice that your game is suddenly slow? The problem in the code can be thousand code lines before the code you were actually working on, but you don&#8217;t saw it because you can&#8217;t see when the frame takes more time. The frame rate, if you don&#8217;t have a very bad computer, stays at his value.<\/p>\n <p><strong>Compute the elapsed time between two frames<\/strong><\/p>\n <p>That is what I did all the time and it worked. But at that time I used the graphic functions of the SDL, but I switched to OpenGL because SDL was too slow (especially for large images). As I used SDL the max frame rate was about 500 and this was good enough for me. As I started Mr.No&#8217;s Laboratory I got 10.000 FPS and the timer function was broken. The reason is that I use milliseconds for computing the elapsed time. But at 10.000 FPS a frame only take 0.1 seconds but the function for getting the milliseconds returns an\u00a0<em>unsigned int<\/em> (so there is no comma). The timing function works only with frame rates up to 1.000 frames per second (elapsed time=1)<\/p>\n <p>For ludum dare I already knew \u00a0this problem but I thought I solved it with computing the elapsed time every 50 frames (max frame rate=50.000). But I doesn&#8217;t work. Multiple people reported that the player is moving very fast. For a postmortem version I activate VSync (so the frame rate is about 60-75), but I want to keep my high frame rates. But what to do? I already know two solutions:<\/p>\n <ul>\n <li>using nanoseconds instead of milliseconds<\/li>\n <li>determine a proportion between the frames to skip (for the elapsed time calculation) and a performance of the computer (like cycles in one millisecond)<\/li>\n <\/ul>\n <p><strong>using nanoseconds<\/strong><\/p>\n <p>There is a easy-to-use function for java but for c++ I only know the functions for windows and even if I don&#8217;t port my applications to Linux or Mac I want to keep the possibility for it.+<\/p>\n <p><strong>determine a proportion<\/strong><\/p>\n <p>Using a code like:\u00a0<em>while (SDL_GetTicks()-ticksAtStart&lt;100) count++;<\/em> you get a performance value of your computer. Maybe there is a proportion between this value and the number of frames I must skip for a elapsed time value which I can use to do procedural movements.<\/p>\n <p>&nbsp;<\/p>\n <p>But whats your opinion about all these problems?<\/p>\n <p>Helco<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>","time":"April 28th, 2012 11:56 pm","title":"The timer problem"}