<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>OpenLayer FpsCounter proposal</title>
		<link>http://www.allegro.cc/forums/view/555019</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 28 Dec 2005 01:37:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>goal: support for frame skipping, setting a maximum fps, and setting a minimum fps</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>FpsCounter::Start<span class="k2">(</span> <span class="n">70</span>.<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span> <span class="c">//this sets dt relative to whateverith fps</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td>FpsCounter::SetLimits<span class="k2">(</span> <span class="k1">float</span> frameskip_below <span class="k3">=</span> <span class="n">20</span>.<span class="n">0</span>, <span class="k1">float</span> max_fps <span class="k3">=</span> <span class="n">2048</span>.<span class="n">0</span>, <span class="k1">float</span> min_fps <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td><span class="k1">while</span><span class="k2">(</span><span class="n">1</span><span class="k2">)</span> <span class="c">//gameloop</span></td></tr><tr><td class="number">6</td><td><span class="k2">{</span></td></tr><tr><td class="number">7</td><td>&#160;</td></tr><tr><td class="number">8</td><td>FpsCounter::NewFrameStarted<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//mandatory </span></td></tr><tr><td class="number">9</td><td><span class="k1">float</span> fps <span class="k3">=</span> FpsCounter::GetFps<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td><span class="k1">float</span> deltaTime <span class="k3">=</span> FpsCounter::GetDeltaTime<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//if (fps &lt; min_fps) , return 1/min_fps</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td><span class="c">//game logic goes here</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>FpsCounter::StartDrawing <span class="c">//macro for "if (fps &lt;= min_fps) or if(fps &gt;= frameskip_below){"</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td><span class="c">// ONLY drawing (maybe sound?) goes here, NO game logic.  Have warning in manual</span></td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td>RefreshScreen<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//enforces max_fps</span></td></tr><tr><td class="number">19</td><td>&#160;</td></tr><tr><td class="number">20</td><td>FpsCounter::EndDrawing <span class="c">//macro for "}"</span></td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
Another idea:<br />Only support Settings::maximum_fps. <br />Don&#39;t make frameskipping and minimum framerates part of the API, but show users how to do them with a small demo program.<br />This is how my physics lib is. I only make complex / tedious things part of the api, and provide examples to teach all of the simple stuff.</p><p>About the accuracy, there&#39;s a way you can get a good dt every frame (like in doom3). I forget which book of mine it&#39;s in, but there&#39;s a way to read directly from an x86 system&#39;s quartz clock.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fuzinavl)</author>
		<pubDate>Fri, 23 Dec 2005 14:33:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
goal: support for frame skipping, setting a maximum fps, and setting a minimum fps
</p></div></div><p>
What is the point of this? IMHO game should render as much FPS as it can.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
About the accuracy, there&#39;s a way you can get a good dt every frame (like in doom3). I forget which book of mine it&#39;s in, but there&#39;s a way to read directly from an x86 system&#39;s quartz clock.
</p></div></div><p>
QueryPerformance* (Windows) and gettimeofday (Linux) should give enough accuracy.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
FpsCounter::StartDrawing //macro for &quot;if (fps &lt;= min_fps) or if(fps &gt;= target_fps){&quot;
</p></div></div><p>
As far as I know, macros completely ignore namespaces.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Krzysztof Kluczek)</author>
		<pubDate>Fri, 23 Dec 2005 15:19:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
IMHO game should render as much FPS as it can.
</p></div></div><p>Why? There is absolutely no use of drawing more visual frames than there are logic frames.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Fri, 23 Dec 2005 15:42:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Depends - you might have a prediction/interpolation system.<br />And you might have different things update at different rates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (vpenquerch)</author>
		<pubDate>Fri, 23 Dec 2005 16:38:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Depends - you might have a prediction/interpolation system.<br />And you might have different things update at different rates.
</p></div></div><p>
Then you can do all that without drawing the frame. Besides the completely valid reason that HoHo argues, many of us with laptops have a great dislike for applications that just use 100% CPU because they might as well. They make our laptops warmer, use the battery more quickly and cause fans to come on. I hate fans!</p><p>I also agree with fuzinavl that it does make sense to incorporate this stuff into OpenLayer, as I believe the remit of OL is &quot;stuff that most people will find helpful&quot;?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Fri, 23 Dec 2005 17:12:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Why? There is absolutely no use of drawing more visual frames than there are logic frames.
</p></div></div><p>
This is the reason for not using logic updates, not a reason for drawing less frames than you can. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Besides the completely valid reason that HoHo argues, many of us with laptops have a great dislike for applications that just use 100% CPU because they might as well. They make our laptops warmer, use the battery more quickly and cause fans to come on. I hate fans!
</p></div></div><p>
I haven&#39;t seen any commercial game where you can limit CPU usage/FPS, but it sounds reasonable.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Krzysztof Kluczek)</author>
		<pubDate>Fri, 23 Dec 2005 18:06:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>&gt; Then you can do all that without drawing the frame.</p><p>Sure, but I was saying you could have a system (not saying<br />it&#39;s particularly good or anything btw) where the logic update<br />computes new positions for, hmm, stuff. Any render till the<br />next update can then interpolate positions and draw them there.<br />You then have smoother movement (albeit with some delay) when<br />you have high framerate, without having more updates. IYSWIM.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (vpenquerch)</author>
		<pubDate>Fri, 23 Dec 2005 18:35:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I haven&#39;t seen any commercial game where you can limit CPU usage/FPS, but it sounds reasonable.
</p></div></div><p>
No, but many games, commercial and otherwise, do not eat 100% CPU just because they can. If they only need 50% of the CPU to do everything they need, they only use 50%. Of course most of those games aren&#39;t written in Allegro since the poor timer precision pushes most people into a busy wait.</p><p>That said - your idea is nice. I would happily sacrifice FPS in many things if I could trade for the fan never coming on!
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Sure, but I was saying you could have a system
</p></div></div><p>
Yes, I misunderstood you somewhat. I think we all essentially agree - drawing more frames than the viewer will see is bad, not keeping gameplay rate consistent if you don&#39;t get a particular specific framerate is bad.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Fri, 23 Dec 2005 18:44:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
setting a minimum fps
</p></div></div><p>
That&#39;d be awesome <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Fri, 23 Dec 2005 18:52:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>DAMN! My post dissappeared for that logging off thing! OK, in short:</p><p>A frame rate limiter is necessary not only for heat problems but also for protecting high-precision calculations and gameplay. In my game I use one which defaults to &quot;min2/max59&quot; and user-adjustable through settings file(I don&#39;t have a menu yet) I just tried setting them to &quot;min2/max15&quot; and CPU_Usage started fluctuating between 8-13% on my system. I&#39;m sure a laptop user wold appreciate that(when it becomes a real game that is!) I don&#39;t have much experience with laptops but hearing a whooshing sound while you are listening to enemy footsteps should be an annoying thing!</p><p>Tech point: My algorithm is about the same with that(with a different formula) It waits for the necessary amount of time if it goes too fast, and it slows down time to avoid stupid(and not funny) things when the speed goes too low.</p><p>EDIT:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
setting a minimum fps -&gt; That&#39;d be awesome
</p></div></div><p>
Yes, it is! Noone acts like Flash Gordon in my game. And you can&#39;t eat 15 bullets in one single frame!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Murat AYIK)</author>
		<pubDate>Fri, 23 Dec 2005 18:53:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>Murat AYIK</b>, what does proper frame limiter code look like?<br />Standard waiting loops don&#39;t return control to other things for brief times.  Also, control must be returned on-time!</p><p><b>Everyone</b>, the pseudocode for minimum_fps and frameskipping is posted above.  You don&#39;t necessarily need to wait for OL to integrate it. </p><p>for my game, I&#39;d:<br />----------------<br />min_fps = 25.0 because my collision detection code can&#39;t handle turns greater than 90 degrees. (max_rotation = six 360&#39;s/second) My graphics code is very lightweight.<br />----------------<br />max_fps = 60.0 because the fps counter code tests only once every 10 or so frames. What if the game usually runs at 85 fps, but whenever there is a collision, the framerate drops to 59? The user would get 2-9 frames of slowdown for every complex collision.<br />----------------<br />target_fps = 40.0 because that&#39;s what&#39;s visually reasonable (to me anyway)</p><p>so:<br /> &lt; 25 fps = state of slowdown<br />25 - 40 fps = state of frameskipping<br />40 - 60 fps = let it be<br /> &gt; 60 fps = forced down to 60 fps
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fuzinavl)</author>
		<pubDate>Fri, 23 Dec 2005 20:44:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
what does proper frame limiter code look like?
</p></div></div><p>
Forgot to say, my game is 3D(without OL) and usually uses very tiny floats. My fps_controller is designed to handle that. Also it looks like our (purpose for) min_fps handling is different. Still 25 min_fps might  cause an inconsistent speed, but again that depends on your game. I don&#39;t read input while waiting because keyboard_buffer and mouse mickeys do that for me. Movement keys are not buffered but they are pressed for long periods due to nature of their task. These work excellent for my game&#39;s needs and they might be useful with/without changes for yours too.</p><p>My algorithm is basically this:<br />- If new_ticks &lt; expected then wait(expected_new - new_ticks)<br />- If new_ticks &gt; max_new then timer = (prev + max_new)</p><p>The second should be the very first thing in logic and used carefully since it messes with the timer directly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Murat AYIK)</author>
		<pubDate>Fri, 23 Dec 2005 21:19:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could you post a simple working gameloop featuring your nifty fps control code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fuzinavl)</author>
		<pubDate>Tue, 27 Dec 2005 05:01:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK, this is what I use. It is not compilable and probably the funniest code snippet ever seen but it shows the stuff clearly(just spread them around in a nice OOP way). You will see that it halts both the logic and render, that is what I need and most probably what you need too. I believe it will suit your needs without much modification, if any. There is no div_by_zeros, no roadrunners, no artillery_turned_to_UZIs! I know some games where you can do the last thing for two seconds if you press screenshot button for a few seconds!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Murat AYIK)</author>
		<pubDate>Tue, 27 Dec 2005 19:46:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Gah! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> I&#39;m going _tick crazy!!  <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />  Makes total sense now.<br />I think a frameskip_below variable can easily be added.</p><p>curious: <br />1) how/when do you get timer_tick to update itself?<br />2) how do you get MILISECS_PER_TICK?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fuzinavl)</author>
		<pubDate>Tue, 27 Dec 2005 22:06:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
1) how/when do you get timer_tick to update itself?<br />2) how do you get MILISECS_PER_TICK?
</p></div></div><p>
As I said, it is not a compilable program and just shows the technique. Starting the timer is pretty obvious and most probably something you already know, so I excluded it only to make the file look simpler(right after install_timer is fine) Likewise, the msec_per_tick and ticks_per_sec should be defined by you. I mean if you want to use 100 ticks per second, add:<br />#define TICKS_PER_SECOND  100<br />#define MSECS_PER_TICK    10   // or (1000 / TICKS_PER_SECOND)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Murat AYIK)</author>
		<pubDate>Wed, 28 Dec 2005 01:37:15 +0000</pubDate>
	</item>
</rss>
