<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>slow graphics, but move fast when window is moved</title>
		<link>http://www.allegro.cc/forums/view/591181</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 04 May 2007 03:01:39 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi everyone, I was hoping someone could help me.</p><p>I am finding that my graphics routine is running slow. I converted my code from VC++ Windows GDI to Allegro and I am finding that there is a significant decrease in the speed in which the graphics is being updated on the screen. A snippet of my code is below. All it does is create a window and place 3 circles in the window and updates the location of those objects via the Update() function.</p><p>The really strange thing is that if I move the window created by Allegro i.e. the window inwhich all the graphics is being displayed, the graphics move much faster.</p><p>Would anyone know what is going on?</p><p>Cheers,<br />voirin</p><p>----------------------------------
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>Object <span class="k3">*</span> member <span class="k3">=</span> <span class="k1">new</span> Object<span class="k2">[</span>numberOfObjects<span class="k2">]</span><span class="k2">;</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="k1">void</span> moveCircle<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">4</td><td>       </td></tr><tr><td class="number">5</td><td>        <span class="k2">{</span>... other routines<span class="k2">}</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>  <span class="k1">for</span> <span class="k2">(</span> <span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> numberOfObjects<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span> <span class="k2">)</span></td></tr><tr><td class="number">8</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">9</td><td>    member<span class="k3">&lt;</span>i&gt;.Update<span class="k2">(</span> <span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>    member<span class="k3">&lt;</span>i&gt;.Draw<span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a><span class="k2">)</span><span class="k2">;</span> <span class="c">// draws circle (screen, x, y, r, color);</span></td></tr><tr><td class="number">11</td><td>  <span class="k2">}</span> </td></tr><tr><td class="number">12</td><td><span class="k2">}</span>    </td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td>  member<span class="k2">[</span><span class="n">0</span><span class="k2">]</span> <span class="k3">=</span> Object<span class="k2">(</span><span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>                 </td></tr><tr><td class="number">18</td><td>  member<span class="k2">[</span><span class="n">1</span><span class="k2">]</span> <span class="k3">=</span> Object<span class="k2">(</span><span class="n">10</span>,<span class="n">10</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>  member<span class="k2">[</span><span class="n">2</span><span class="k2">]</span> <span class="k3">=</span> Object<span class="k2">(</span><span class="n">20</span>,<span class="k3">-</span><span class="n">15</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>&#160;</td></tr><tr><td class="number">21</td><td>  <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>  <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>  <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">8</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>  <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span> GFX_AUTODETECT_WINDOWED, WINDOW_WIDTH, WINDOW_HEIGHT, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>&#160;</td></tr><tr><td class="number">26</td><td>  <span class="k1">while</span><span class="k2">(</span> <span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">27</td><td>    moveCircles<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>  <span class="k2">}</span>    </td></tr><tr><td class="number">29</td><td>    </td></tr><tr><td class="number">30</td><td>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">31</td><td><span class="k2">}</span></td></tr><tr><td class="number">32</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (peter walker)</author>
		<pubDate>Fri, 27 Apr 2007 12:33:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should use the desktop color depth, use desktop_color_depth() to get it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc ( mEmO)</author>
		<pubDate>Fri, 27 Apr 2007 13:16:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should control the execution speed of your program with rests.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Fri, 27 Apr 2007 13:59:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>... no. No you shouldn&#39;t. Use proper timing. Not rest(). <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Fri, 27 Apr 2007 14:20:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That code suggests you&#39;re drawing everything directly to the screen. Use a backbuffer instead, e.g.</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> <span class="k1">double</span><span class="k3">=</span>NULL<span class="k2">;</span>

... somewhere in initialisation...
<span class="k1">double</span><span class="k3">=</span><a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>,<a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span>
<span class="k1">void</span> moveCircle<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
       

        <span class="k2">{</span>... other routines<span class="k2">}</span>
        clear<span class="k2">(</span><span class="k1">double</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">for</span> <span class="k2">(</span> <span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> numberOfObjects<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span> <span class="k2">)</span>
  <span class="k2">{</span>
    member<span class="k3">&lt;</span>i&gt;.Update<span class="k2">(</span> <span class="k2">)</span><span class="k2">;</span>
    member<span class="k3">&lt;</span>i&gt;.Draw<span class="k2">(</span><span class="k1">double</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// draws circle (screen, x, y, r, color);</span>
  <span class="k2">}</span> 
        <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span><span class="k1">double</span>, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, etc, etc<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Fri, 27 Apr 2007 14:37:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the replies everyone. I&#39;ll incorporate the suggestions into my code and see how well it executes. Im away from my code till monday.</p><p>I want the graphics to run as fast as possible. That is my primary aim - fast object movement - no rest or pauses in the program. </p><p>Thanks again<br />cheers, voirin
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (peter walker)</author>
		<pubDate>Fri, 27 Apr 2007 15:50:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You should control the execution speed of your program with rests.
</p></div></div><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
... no. No you shouldn&#39;t. Use proper timing. Not rest().
</p></div></div><p>

Actually, you&#39;re both right. Proper timing should be implemented using Allegro&#39;s timer system or the Windows High Performance Timer, but you should also add a rest(0) or Sleep(0) to the end of a program loop so that CPU time can be properly given to Allegro&#39;s other threads and to other programs running in the background.</p><p>Also, if the application runs faster while you&#39;re moving the window than when not you might want to disable your background applications and see if one of them is eating up the resources your application wants.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Fri, 27 Apr 2007 17:33:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">peter walker said:</div><div class="quote"><p>
I want the graphics to run as fast as possible. That is my primary aim - fast object movement - no rest or pauses in the program.
</p></div></div><p>
OK for the idea of &quot;timing your drawing code&quot;, but don&#39;t dismiss rest(0).</p><p>If you don&#39;t explicitely yield to Windows when it&#39;s the best moment to do so, Windows WILL suspend your program at random moments, and it will cause an extra waste of time every time it&#39;s in the middle of a sensitive operation  - like a screen redraw, with locked DirecX surfaces.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 27 Apr 2007 17:34:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[n00b question] I&#39;ve asked here before, but I still don&#39;t know how to use proper timing instead of rest() I&#39;ll probalby just go look it up in the manual though, so don&#39;t worry.[/n00b question]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Black)</author>
		<pubDate>Fri, 04 May 2007 02:13:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Aah.. time to spread the love of the wiki: <a href="http://wiki.allegro.cc/Timers">http://wiki.allegro.cc/Timers</a><br />And instead of rest() i recommend my semaphore solution. Of course you can call other semaphore functions to implement all of the regular volatile int models if you so need for your un-lagger or whatever. </p><p>note: as a community we really should post all answers to common (and not so common) questions on the wiki and points users to that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Goalie Ca)</author>
		<pubDate>Fri, 04 May 2007 03:01:39 +0000</pubDate>
	</item>
</rss>
