<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Separating Logic from Drawing Part 2</title>
		<link>http://www.allegro.cc/forums/view/606173</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 26 Jan 2011 10:20:51 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was thinking: I&#39;m saving processing time by using a timer for drawing and doing a good design and saving processing time doing a logic timer too...</p><p>But to improve even more the game design, I was thinking in doing the drawing<br />not at the same time the logic is...</p><p>Because I was doing something like this:</p><p>Logic/Draw:<br />0 = false<br />1 = true</p><pre>
Example:

Logic  Per Second : 30
Frames Per Second : 15

Logic:   1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0

Draw :   1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0

</pre><p>

So as you can see the drawing is done at the same time the logic is...</p><p>Would make any difference if I do something like this?</p><pre>

Logic  Per Second : 30
Frames Per Second : 15

Logic:   1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0

Draw :   0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0

</pre><p>

So, when I&#39;m drawing I&#39;m doing no logic, and at that way there isn&#39;t gonna be jumping scenes or stuffs like that...</p><p>But the question is... Would it make any difference in performance?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 24 Jan 2011 19:42:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nope. *</p><p>(* Depends on specifics not included in your post.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Mon, 24 Jan 2011 19:44:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think this type of implementation is more valuable for sophisticated games, when the Logic is very complex...</p><div class="quote_container"><div class="title"><a href="http://">X-G</a> said:</div><div class="quote"><p>Depends on specifics not included in your post</p></div></div><p>

Well, actually I have nothing else to say...</p><p>If a game take X_time doing logic, and X_time doing drawing a way to stay away from adding this two times is doing the drawing or the logic...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 24 Jan 2011 20:22:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>And do what? You&#39;re still spending the same number of cycles doing logic, rendering, or waiting. It doesn&#39;t really matter* if you wait half a frame before rendering, then wait half a frame again, or if you just render and then wait a frame.</p><p>You&#39;re not gettinga way from having to spend time_logic + time_rendering, you&#39;re just inserting a bit of wait time in between for no obvious reason.</p><p>(* Again... aside from unspecified factors and minor influences.)</p><p>(And by the way, 15 fps is going to be extremely choppy.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Mon, 24 Jan 2011 20:25:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>One basic problem is that you have to be careful how to overlap logic and drawing. For example this will work:</p><pre>
[logic]         [logic]           [logic]
       [draw]          [draw]            [draw]
</pre><p>

This will not:</p><pre>
[logic]         [logic]           [logic]
[rendering]    [rendering]    [rendering]
</pre><p>

In the above case the logic is still modifying the game state which is also used for rendering. The result will be  that things won&#39;t work at all, objects may be missing or appear duplicated. If you solve it by putting a mutex around your [logic] and [rendering] blocks then you force things to run sequentially again even if they are in different threads. Something which may work would be:</p><pre>
[logic]         [logic]           [logic]
       [copy][rendering][copy][rendering][copy][rendering]
</pre><p>

Here I split the rendering part into a [copy] part which makes a copy of the game state. Or alternatively create a rendering representation (e.g. a list of triangles). Once that is done the subsequent rendering can overlap the logic again as the list of triangles being rendered by D3D/OpenGL isn&#39;t modified by the logic thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 24 Jan 2011 20:39:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think he&#39;s actually using more than one thread. That&#39;s what the * in my first post was about (obviously a multithreaded approach requires more caution). I think he just has two timers running at the same time, but responding to them sequentially.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Mon, 24 Jan 2011 20:40:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No actually what I&#39;m doing is something very simple:</p><p><span class="remote-thumbnail"><span class="json">{"name":"log.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/5\/a54f7d5493658a27696cacb57e481012.jpg","w":400,"h":300,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/5\/a54f7d5493658a27696cacb57e481012"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/5/a54f7d5493658a27696cacb57e481012-240.jpg" alt="log.jpg" width="240" height="180" /></span></p><p>With some mathematics I figure out when I have to draw so the drawing correspond to 15 FPS... inside the 30 FPS logic loop...</p><p>The problem is that when I&#39;m inside the logic I don&#39;t know how long is going to take to finish the process, the same happends with the drawing.</p><p>I can&#39;t say to my drawing function, &quot;hey you&#39;re taking too much time, stop&quot;</p><p>So, even when your game is made to run at 30 FPS in some old computer this might not be happening, and for that reasons some games let you know the quantity of FPS.</p><p>And for that reason I came up with this idea, if I do the logic and the drawing at the same time, this might reduce the FPS of my game at that point, but if I do only the drawing and only the logic, this might let the CPU/GPU do one thing at the time, and this I could improve the FPS of my game...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 24 Jan 2011 21:45:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I can&#39;t understand why you think Logic + Render + Wait + Wait would somehow take longer than Logic + Wait + Render + Wait.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606173/900086#target">AMCERASOLI</a> said:</div><div class="quote"><p>I do only the drawing and only the logic</p></div></div><p>
You&#39;re already doing this! It&#39;s all a single thread so by the time you get around to drawing, your logic has already finished running!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Mon, 24 Jan 2011 21:51:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not saying that...</p><p>Lets say that a game is made to run with a logic of 30 FPS.</p><p>1 Sec = 100 CS</p><p>that means that 100 ÷ 30 = 3.3 CS</p><p>So the game has 3.3 CS to do the logic or the drawing, to keep running at 30 FPS, but if it take more than 3.3 CS the FPS will be reduced.</p><p>So... if I do the logic and the rendering at the same time, as you can see in the table below my FPS will be affected... </p><pre>
Processes     ||  Time
_____________________________
Logic + Render = 4 CS
Logic          = 1 CS
Render         = 3 CS

</pre><p>


In my new implementation (the Image up there, in my previous post), I&#39;m just doing one thing at the time... But in my old implementation that is what I was talking about, I was doing</p><pre>
----- 30 FPS -----
   Logic

   if(draw){

   draw
   
   }

</pre><p>

So the logic was always running, and at the same time, at some point, the rendering was also done together with the logic...</p><p>For that reason I think is much better to do the draw or the logic, but never at the same time.</p><p>Well At least That Is What I Think <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 24 Jan 2011 22:52:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606173/900090#target">AMCERASOLI</a> said:</div><div class="quote"><p>
For that reason I think is much better to do the draw or the logic, but never at the same time.
</p></div></div><p>
Without using a supplementary thread you are not drawing while doing some logic.<br />Your computer isn&#39;t smart enough to split your code along your multi-core CPU without you doing a little bit of a job.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 24 Jan 2011 23:19:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Everyone is saying the same thing, but you&#39;re not listening: <b>Unless your application is threaded, things happen sequentially, not in parallel</b>. Your math table there is <b>wrong</b>. Your logic and rendering are <b>not</b> being done &quot;at the same time&quot;. They are done one after the other.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Mon, 24 Jan 2011 23:24:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well I don&#39;t want go further with this discussions because I already solve it, I just was asking to get an overview about what people think, if drawing and at the same time doing logic is the same of doing only logic or only drawing.</p><p>What I can tell you is that I don&#39;t need a Multithreath algorithm to do logic and drawing at the same time (and when I say &quot;at the same time&quot;, I am talking about doing something in a period of time and not actually doing several things in the CPU ), maybe your point of view is different from mine.</p><div class="quote_container"><div class="title"><a href="http://">GullRaDriel</a> said:</div><div class="quote"><p>Your computer isn&#39;t smart enough to split your code along your multi-core CPU without you doing a little bit of a job</p></div></div><p>

Dont worry, in a future I&#39;ll use one core for the logic and another for the drawing <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>Or not wait... there is hexa-core processor too, so I&#39;m going to use 4 cores for drawing and 2 for logics, yheaa <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 24 Jan 2011 23:57:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title"><a href="http://">MCERASOLI</a> said:</div><div class="quote"><p>What I can tell you is that I don&#39;t need a Multithreath algorithm to do logic and drawing at the same time (and when I say &quot;at the same time&quot;, I am talking about doing something in a period of time and not actually doing several things in the CPU )</p></div></div><p>

How is that even possible? Maybe I&#39;m missing something here. But it seems you are mixing up something fundamental here. You cannot do two things at once without some type of multiprocessing capability and solution. And when I read your post, it seems like you are saying that you can. I think you need to re-read X-G&#39;s replies because he addresses that point specifically.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BigSir)</author>
		<pubDate>Tue, 25 Jan 2011 08:33:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Another point to make here is : Why separate the framerates of your logic and drawing to begin with?</p><p>Why bother calling logic if you&#39;re not going to display the result of that logic? The only reason to do more than one logic call per drawing call is to free up the time spent drawing, <i>but only if you need to</i>. This is where your timer comes in handy. If your game isn&#39;t running full speed on a slow computer, then you can skip drawing frames if you have to. Simply call logic the same number of times as you have ticks on your timer and then call draw. The framerate will be lower than what you hope for, but it will still appear to be moving at the same speed, although some objects may start teleporting.</p><p>I think you&#39;re making things more complicated than they need to be to achieve the results you are looking for.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 25 Jan 2011 10:43:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK, quick rundown of common timing approaches.
</p><ul><li><p><b>fixed global framerate</b> - the standard in older consoles; just lock into the system&#39;s frame rate and code your logic so that one logic update per frame works. For PCs, this is useless, because you can&#39;t reliably control the physical frame rate.
</p></li><li><p><b>fixed logic rate</b> - set a timer for the logic, then after each redraw, see by how many ticks it has advanced and update your logic that many times.
</p></li><li><p><b>variable delta</b> - use a high-resolution timer to measure the time elapsed between the previous redraw and the current one, code your logic so that it takes a delta-time parameter, and call it once per redraw
</p></li><li><p><b>multi-threaded</b> - set up two threads, one for the logic and one for the drawing; these two need to communicate through some sort of thread-safe mechanism (almost a classic producer/consumer scenario).</p></li></ul><p>Unless you go for the last approach, you will never have drawing and logic going on at the same time though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Wed, 26 Jan 2011 06:00:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think my algorithm is so dumb that doesn&#39;t have a name... <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>Suposse this is my code</p><p>blablablabla<br />blablablabla<br />blablablabla<br />blablablabla<br />blablablabla<br />blablablabla</p><p>Which is running at 30FPS...</p><p>It doesn&#39;t matters if is logic, drawing or anything else... That code over there is running at 30FPS</p><p>then I decide that, that code is going to do some logic and then draw something, so I do this;</p><p><b>logic</b> blabla<br />blablablabla<br /><b>Draw</b>  blabla<br />blablablabla<br />blablablabla<br />blablablabla</p><p>Then.. Since the logic of my game, is controlling 400 objects which interact each other, I say:</p><p>Ok... I&#39;m doing the logic at 30FPS and the drawing at 30FPS too, right?</p><p>But since the drawing take much longer than the logic, and I really don&#39;t need to redraw my screen at 30FPS... I do this...</p><p>draw=0;//This is outside the code running at 30FPS (a global variable lets say))</p><p>if(++draw!=15){<br /><b>logic</b> blabla<br />blablablabla<br />blablablabla<br />} else {<br />draw=0;<br /><b>Draw</b>  blabla<br />blablablabla<br />blablablabla<br />}</p><p>Now, even when my logic is running at 30FPS the drawing doesn&#39;t...</p><p>What name have this type of Algorithm???
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 26 Jan 2011 06:53:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre>draw<span class="k3">=</span><span class="n">0</span><span class="k2">;</span><span class="c">//This is outside the code running at 30FPS (a global variable lets say))</span>

<span class="k1">if</span><span class="k2">(</span><span class="k3">+</span><span class="k3">+</span>draw<span class="k3">!</span><span class="k3">=</span><span class="n">15</span><span class="k2">)</span><span class="k2">{</span>
logic blabla
blablablabla
blablablabla
<span class="k2">}</span> <span class="k1">else</span> <span class="k2">{</span>
draw<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>
Draw blabla
blablablabla
blablablabla
<span class="k2">}</span>
</pre></div></div><p>

Correct me if I&#39;m wrong (I have a nasty cold, and I&#39;m tired...) but wouldn&#39;t that code draw twice a second rather than 30 or even 15 times a second?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 26 Jan 2011 06:59:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The code which is inside the else statmen is running at 2 FPS...<br />I haven&#39;t say 15FPS... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 26 Jan 2011 07:03:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606173/900331#target">AMCERASOLI</a> said:</div><div class="quote"><p>The code which is inside the else statmen is running at 2 FPS...</p></div></div><p>Why would you want that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 26 Jan 2011 07:05:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Because with some maths I can make it run at 15FPS... and instead of running my code at 30 I could do 200FPS and my drawing at 100FPS, in other projects. what worries me is the implementation...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 26 Jan 2011 07:08:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ummm... Is your game really going to need incredibly precise maths? If not, I&#39;d say just go with Delta timing. It&#39;s quite easy, and you&#39;ve just got to be careful of using the timestep properly. You&#39;ll get your game running with any FPS in any computer(though clamping the Delta Time is good practice or else you&#39;re going to have a massive frame skip at the slightest lag).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dario ff)</author>
		<pubDate>Wed, 26 Jan 2011 07:13:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well actually isn&#39;t... the last time that I mess with precise maths was... was... I don&#39;t remember...</p><p>I just found this one the... &quot;easiest one&quot; so if this inmplementation doesn&#39;t have a name, now is going to be called the &quot;E.O.&quot; Ok? <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><div class="quote_container"><div class="title"><a href="http://">Thomas Fjellstrom</a> said:</div><div class="quote"><p>(I have a nasty cold, and I&#39;m tired...)</p></div></div><p>

BTW here in Spain we&#39;re at 2ºC what is happening there in Canada?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 26 Jan 2011 07:30:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606173/900338#target">AMCERASOLI</a> said:</div><div class="quote"><p>BTW here in Spain we&#39;re at 2ºC what is happening there in Canada?</p></div></div><p>Prior to last week, it was -25c or colder, and we got a <span class="cuss"><span><span class="cuss"><span>shit</span></span></span></span> load of snow. This past few days however, starting on Thursday or so we got close to 0c, and today it hit 5c, which was nice. But my furnace stopped working on Friday. No heat till yesterday afternoon, except what I could get from the sun, and my oven for a couple hours each day.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 26 Jan 2011 07:42:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A broken furnace in Canada??? Oh boy... I would have two replacement if I were living in Canada.. 4 if were Russia... <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />.</p><p>Here in Spain - A Coruña we&#39;re betwen -8ºC to 7ºC... nothing special... Well take it easy... summer is... is... well not so close but... ahh whatever...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 26 Jan 2011 07:52:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606173/900346#target">AMCERASOLI</a> said:</div><div class="quote"><p>A broken furnace in Canada??? Oh boy... I would have two replacement if I were living in Canada..</p></div></div><p>A replacement will cost me at least $2400. I can&#39;t afford to have a new one let alone two new ones <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>I was very lucky that it decided to die after the cold snap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 26 Jan 2011 07:53:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If we&#39;re going to talk about weather now, let me add that it&#39;s 28C over here, and the news report that it&#39;s over 42C on the capital city. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dario ff)</author>
		<pubDate>Wed, 26 Jan 2011 07:56:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well yes... my problem was solve, In Fact I Just Finished to talk with Bill Gates, he called me to tell me that he wants to buy my Algorithm... I&#39;m millionaire... So... I got to go... I need to buy a ticket to Hawaii... CYA..</p><p>PS: What? 28ºC?... You&#39;re a lucky guy....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 26 Jan 2011 08:09:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>42ºC! lucky? well, only the ones who have an air conditioner unit, I have one! <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Wed, 26 Jan 2011 09:37:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606173/900365#target">Paul whoknows</a> said:</div><div class="quote"><p>42ºC! lucky? well, only the ones who have an air conditioner unit, I have one! </p></div></div><p>Not when you have to pay 10-20c/kWh. And the AC is a little too small to do the job so it eats up more power than spec&#39;ed...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 26 Jan 2011 10:05:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>  delta_time <span class="k3">=</span> get_current_time<span class="k2">(</span><span class="k2">)</span> <span class="k3">-</span> old_delta_time<span class="k2">;</span>
<span class="number">  2</span>  old_delta_time <span class="k3">=</span> get_current_time<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span>  <span class="k1">if</span> <span class="k2">(</span>logic_framerate<span class="k2">(</span>delta_time<span class="k2">)</span> <span class="k3">=</span><span class="k3">=</span> <span class="k1">true</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  5</span>    process_logic<span class="k2">(</span>delta_time<span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>  <span class="k2">}</span>
<span class="number">  7</span>
<span class="number">  8</span>  <span class="k1">if</span> <span class="k2">(</span>display_framerate<span class="k2">(</span>delta_time<span class="k2">)</span> <span class="k3">=</span><span class="k3">=</span> <span class="k1">true</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  9</span>    update_display<span class="k2">(</span>delta_time<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>  <span class="k2">}</span>
<span class="number"> 11</span>
<span class="number"> 12</span>  ...
<span class="number"> 13</span><span class="k2">}</span>
<span class="number"> 14</span>
<span class="number"> 15</span><span class="k1">void</span> process_logic<span class="k2">(</span><span class="k1">double</span> dt<span class="k2">)</span>
<span class="number"> 16</span><span class="k2">{</span>
<span class="number"> 17</span>  <span class="k1">static</span> currently_processed_logic <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 18</span>
<span class="number"> 19</span>  <span class="c">// If the application is suspended, then resumed, 'dt' can sometimes be VERY large</span>
<span class="number"> 20</span>  <span class="c">// and so, give a maximum amount of time that we will "skip" before resuming normal</span>
<span class="number"> 21</span>  <span class="c">// logic updates</span>
<span class="number"> 22</span>  <span class="k1">if</span> <span class="k2">(</span>dt <span class="k3">&gt;</span> TIME_CLAMP<span class="k2">)</span>
<span class="number"> 23</span>    dt <span class="k3">=</span> TIME_CLAMP<span class="k2">;</span>
<span class="number"> 24</span>
<span class="number"> 25</span>  <span class="c">// Run until we hit this give time</span>
<span class="number"> 26</span>  <span class="k1">double</span> continue_until_time <span class="k3">=</span> get_current_time<span class="k2">(</span><span class="k2">)</span> <span class="k3">+</span> dt<span class="k2">;</span>
<span class="number"> 27</span>
<span class="number"> 28</span>  <span class="k1">unsigned</span> <span class="k1">int</span> num_logic_entities <span class="k3">=</span> logic_entities.size<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>  <span class="k1">do</span> <span class="k2">{</span>
<span class="number"> 30</span>    logic_entities<span class="k2">[</span>currently_processed_logic<span class="k2">]</span>.update<span class="k2">(</span>dt<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>
<span class="number"> 32</span>    <span class="c">// Update the next logic item, rolling back to 0 when all items have been processed</span>
<span class="number"> 33</span>    <span class="k1">if</span> <span class="k2">(</span>currently_processed_logic <span class="k3">&lt;</span> num_logic_entities<span class="k2">)</span>
<span class="number"> 34</span>      currently_processed_logic<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="number"> 35</span>    <span class="k1">else</span>
<span class="number"> 36</span>      currently_processed_logic <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 37</span>  <span class="k2">}</span> <span class="k1">while</span> <span class="k2">(</span>get_current_time<span class="k2">(</span><span class="k2">)</span> <span class="k3">&lt;</span> continue_until_time<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 38</span><span class="k2">}</span>
<span class="number"> 39</span>
<span class="number"> 40</span>...
</div></div><p>

This is just pseudo-code. Essentially, the logic() portion is only given a fixed amount of time in which it can update everything. If it gets it done in time, great. If not, the function exits, the draw() function will possibly be drawn (and those elements would not have been updated/moved), and you will have to wait until the next logic update is called before the remainder of those items are updated.</p><p>It&#39;s not perfect, but then you can use it to explicitly limit the amount of time your functions can suck up the processor.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 26 Jan 2011 10:20:51 +0000</pubDate>
	</item>
</rss>
