<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>One if condition is wrecking my game loop</title>
		<link>http://www.allegro.cc/forums/view/617809</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 22 Apr 2019 22:51:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I try different things in my game loop to test them while I was trying to optimize my previous loop something happened.</p><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> <span class="k1">while</span><span class="k2">(</span>main_loop<span class="k2">)</span>
<span class="number">  2</span>    <span class="k2">{</span>
<span class="number">  3</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> event<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>        <span class="c">//if(al_is_event_queue_empty(queue))</span>
<span class="number">  6</span>        <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>queue, <span class="k3">&amp;</span>event<span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>
<span class="number">  8</span>        <span class="k1">if</span><span class="k2">(</span>event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_DISPLAY_CLOSE<span class="k2">)</span>
<span class="number">  9</span>            main_loop <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>        <span class="k1">if</span><span class="k2">(</span>event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_TIMER<span class="k2">)</span>
<span class="number"> 12</span>        <span class="k2">{</span>
<span class="number"> 13</span>        <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span>        <a href="http://www.allegro.cc/manual/al_draw_rounded_rectangle"><span class="a">al_draw_rounded_rectangle</span></a><span class="k2">(</span><span class="n">400</span><span class="k3">-</span><span class="n">100</span> <span class="k3">+</span> x, <span class="n">300</span><span class="k3">-</span><span class="n">20</span>, <span class="n">400</span><span class="k3">+</span><span class="n">100</span> <span class="k3">+</span> x, <span class="n">300</span><span class="k3">+</span><span class="n">20</span>, <span class="n">20</span>, <span class="n">20</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">70</span>, <span class="n">60</span> , <span class="n">100</span><span class="k2">)</span>, <span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span>            <span class="k1">if</span><span class="k2">(</span>y<span class="k2">)</span>
<span class="number"> 18</span>            <span class="k2">{</span>
<span class="number"> 19</span>                <span class="k1">if</span><span class="k2">(</span>x&gt;<span class="k3">=</span><span class="k3">-</span><span class="n">400</span><span class="k2">)</span>
<span class="number"> 20</span>                    x<span class="k3">+</span><span class="k3">=</span><span class="k3">-</span><span class="n">5</span><span class="k2">;</span>
<span class="number"> 21</span>                <span class="k1">else</span>
<span class="number"> 22</span>                    y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 23</span>            <span class="k2">}</span>
<span class="number"> 24</span>            <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>y<span class="k2">)</span>
<span class="number"> 25</span>            <span class="k2">{</span>
<span class="number"> 26</span>                <span class="k1">if</span><span class="k2">(</span>x<span class="k3">&lt;</span><span class="k3">=</span><span class="n">400</span><span class="k2">)</span>
<span class="number"> 27</span>                    x<span class="k3">+</span><span class="k3">=</span><span class="n">5</span><span class="k2">;</span>
<span class="number"> 28</span>                <span class="k1">else</span>
<span class="number"> 29</span>                    y <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 30</span>            <span class="k2">}</span>
<span class="number"> 31</span>
<span class="number"> 32</span>        <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 33</span>        <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">0</span>.<span class="n">02</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>        <span class="k2">}</span>
<span class="number"> 35</span>
<span class="number"> 36</span>        <span class="k1">if</span><span class="k2">(</span>event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_KEY_DOWN<span class="k2">)</span>
<span class="number"> 37</span>        <span class="k2">{</span>
<span class="number"> 38</span>            <span class="k1">switch</span><span class="k2">(</span>event.keyboard.keycode<span class="k2">)</span>
<span class="number"> 39</span>            <span class="k2">{</span>
<span class="number"> 40</span>                <span class="k1">case</span> ALLEGRO_KEY_ESCAPE <span class="k2">:</span>
<span class="number"> 41</span>                    <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 42</span>                    <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 43</span>            <span class="k2">}</span>
<span class="number"> 44</span>        <span class="k2">}</span>
<span class="number"> 45</span>
<span class="number"> 46</span>    <span class="k2">}</span>
</div></div><p>

the if condition I commented out is causing any event other than the timer event from happening.</p><p>If anybody can tell me why is this happening?</p><p>also, what is the difference between a line and a soft line?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Sun, 14 Apr 2019 09:30:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a></span> should not change anything, it is just to tell you if the queue is empty or not. So your problem has to be something else.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 14 Apr 2019 10:56:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="https://www.allegro.cc/forums/thread/617809/1041999#target">Doctor Cop</a> said:</div><div class="quote"><p>
</p><div class="source-code snippet"><div class="inner"><pre>    <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> event<span class="k2">;</span>

    <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>queue<span class="k2">)</span><span class="k2">)</span>
        <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>queue, <span class="k3">&amp;</span>event<span class="k2">)</span><span class="k2">;</span>

    <span class="k1">if</span><span class="k2">(</span>event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_DISPLAY_CLOSE<span class="k2">)</span>
</pre></div></div><p>
</p></div></div><p>

If the event queue is NOT empty then the event object is uninitialized (or maybe has garbage or maybe has last iteration&#39;s value). I don&#39;t think that this is a good construct. Surely, Allegro is going to know how to check that faster than you can. I think you should always call <span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 14 Apr 2019 11:26:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I changed this line:-</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>queue<span class="k2">)</span><span class="k2">)</span>
        <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>queue, <span class="k3">&amp;</span>event<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

with this one:-</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>queue<span class="k2">)</span><span class="k2">)</span>
        <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>queue, <span class="k3">&amp;</span>event<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

and it worked. I don&#39;t know, why? isn&#39;t al_is_event_queue_empty() supposed to return 1 if the queue is empty?</p><p>The most fascinating thing I find in this is how it even gets the first event when the event queue is empty, it shouldn&#39;t even pass the first iteration.</p><p>I can&#39;t confirm, the allegro docs are not loading. The whole liballeg.org site is not working. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /></p><p>[edit]<br />      Now liballeg.org is working and I just checked, it says what it should say.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Sun, 14 Apr 2019 17:06:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When the line checking for an empty event queue is skipped, then allegro will always wait for an event. This means your event is guaranteed to be initialized. If you uncomment it, it won&#39;t always wait for an event, which means your event is uninitialized.</p><p>The basic game loop is like this :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>quit<span class="k2">)</span> <span class="k2">{</span>
   <span class="k1">if</span> <span class="k2">(</span>redraw<span class="k2">)</span> <span class="k2">{</span>Redraw<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>redraw <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span><span class="k2">}</span>
   <span class="k1">do</span> <span class="k2">{</span>
      <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> ev<span class="k2">;</span>
      <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>queue , <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">;</span>

      <span class="k1">if</span> <span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> ...<span class="k2">)</span> <span class="k2">{</span>...<span class="k2">}</span>

   <span class="k2">}</span> <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>queue<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 14 Apr 2019 19:33:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OH!</p><p>   That&#39;s why!!!<br />   Now I get it. I&#39;ll study more about game loops. Is making an general application loop different than a game loop? I wonder.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Sun, 14 Apr 2019 19:52:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Game loops and app loops are pretty much the same. You want to deal with events as long as there are any in the queue, and then redraw. Rinse, repeat.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 14 Apr 2019 20:23:18 +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/617809/1042004#target">Doctor Cop</a> said:</div><div class="quote"><p>Is making an general application loop different than a game loop?</p></div></div><p> It depends on the application.  Some apps don&#39;t have a loop at all, others have but don&#39;t wait for events, others do it...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Mon, 15 Apr 2019 13:29:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Niunio : Is it really possible? How can an application be anything more than a program if it doesn&#39;t have a loop?</p><p>How and what it can be? What would be its purpose?</p><p>[Edit]
</p><ul><li><p>     And for the problem I did this : 
</p></li></ul><p>    ALLEGRO_TIMER *timer = al_create_timer(2.0/60.0);</p><ul><li><p>     It was set to al_create_timer(1.0/60.0);
</p></li></ul></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Wed, 17 Apr 2019 18:38:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think you&#39;re giving magical status to &quot;apps&quot;. All programs are applications. All applications are programs. &quot;Apps&quot; is just a short-form for applications. They&#39;re really just synonyms.</p><p>There are straight-forward programs that just do one thing and exit. Then there are interactive programs that loop until some condition is met to exit (or forever). GUI programs, games, and services/daemons (background programs that often have no user interface at all) generally loop indefinitely unless some exit condition is met (or until they&#39;re killed). <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><p>A loop in a program that runs indefinitely is generally the same as a game loop, except that typically the UI is abstracted through a framework, and the event processing is also often handled automatically through the framework. The application programmer generally doesn&#39;t see the loop in GUI programs (though they can choose to implement it themselves if they wish, but they&#39;re so standardized that there&#39;s generally no need to do this unless you need to do additional processing while handling events). Instead, they often register callbacks/event handlers to process events instead, and then just tell the framework to start the loop.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Wed, 17 Apr 2019 20:27:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I haven&#39;t given any merit or class to programmes. I studied it in school and it was written in my book that a single page program is a program and a multifile systematic structure of programs is called a software.</p><p>maybe that author was shady but I think it is a common misconception, every website I found on ducking had a different definition.</p><p>OK, So GUI frameworks work that way. Which framework do you use? What are its merits?</p><p>I&#39;m just curious cause I haven&#39;t used any official GUI framework yet, they all seem to be ugly so I avoided them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Thu, 18 Apr 2019 13:04:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll take this opportunity to plug EAGLE. See my signature.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 18 Apr 2019 14:15:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, Edgar but I already know about EAGLE and it&#39;s great but I was talking about those ugly frameworks who usually have an XML based language attached and sometimes they have their own IDE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Thu, 18 Apr 2019 14:23:06 +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/617809/1042061#target">Doctor Cop</a> said:</div><div class="quote"><p>Which framework do you use? What are its merits?</p></div></div><p> Just to satisfy your curiosity, I use <a href="http://wiki.freepascal.org/LCL">LCL</a>.  Also, I&#39;m developing a game engine that is component based and is quite similar than LCL/VCL: you just need to create some &quot;components&quot; that implement callbacks/event handlers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Sat, 20 Apr 2019 15:56:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Cool Nuino, I just watched a tutorial on Pascal, it was good!<br />You have great stuff going on.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Sat, 20 Apr 2019 18:28:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks. ^_^)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Mon, 22 Apr 2019 22:51:42 +0000</pubDate>
	</item>
</rss>
