<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>More effecient method than using classes...?</title>
		<link>http://www.allegro.cc/forums/view/603094</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 09 Feb 2010 18:17:26 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey guys. I&#39;m programming a side scrolling platforming game, and I was wondering if other people go about games the same way, or if my method is horribly inefficient, or what.</p><p>Pretty much, for example, my platforms are made up of blocks with variable width and height. I&#39;ve created a class named &#39;obstacle&#39; that contains an x, y, width, height, a couple of other variables, and a couple of functions such as drawObstacle().</p><p>To draw the obstacles, for instance, I loop through every single obstacle in the obstacle class and call it&#39;s drawObstacle() function.</p><p>Does this sound about right guys? Is this pretty much how it should be, with classes and such? The reason I am asking, is because I was talking to my teacher about my platforming game, and he was saying something about classes being horribly inefficient and recommended using AVL trees instead, but upon checking what an AVL tree is, I couldn&#39;t see how that could possibly be used for my obstacles instead of classes... I&#39;m thinking he didn&#39;t know what he was talking about, but I could easily be wrong.</p><p>On a side note, are structs noticeably more efficient than classes?</p><p>Any ideas or comments would be welcome. I&#39;d be interested in hearing if you guys go about using classes for multiple objects as well like I do, or if you do something different. Thanks for your help!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Falciase)</author>
		<pubDate>Tue, 09 Feb 2010 01:17:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I had to look it up too.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
In computer science, an AVL tree is a self-balancing binary search tree
</p></div></div><p>
Seems odd he would use a rare acronym when describing a common technique.  He could have said &quot;self-balancing binary search tree.&quot;</p><p>Secondly, a binary search tree has absolutely nothing to do with using classes for physical obstacles in a game.  Your professor needs to lay off the crack.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dustin Dettmer)</author>
		<pubDate>Tue, 09 Feb 2010 01:44:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What you are doing now sounds fine. Structs aren&#39;t faster than classes unless you explicitly avoid the virtual lookup table, but even then you aren&#39;t saving much. Using classes you should probably try to have a base class that has some draw() method and then make obstacles and whatever else a derived class.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> DrawableThing<span class="k2">{</span>
  <span class="k1">virtual</span> <span class="k1">void</span> draw<span class="k2">(</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">class</span> Obstacle: <span class="k1">public</span> DrawabaleThing<span class="k2">{</span>
  <span class="k1">virtual</span> <span class="k1">void</span> draw<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// implement this in a .cpp file</span>
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">class</span> WhateverElse: <span class="k1">public</span> DrawableThing<span class="k2">{</span>
  <span class="k1">virtual</span> <span class="k1">void</span> draw<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>

AVL trees don&#39;t seem to have any relation to this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Tue, 09 Feb 2010 01:45:50 +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/603094/850452#target">Falciase</a> said:</div><div class="quote"><p>classes being horribly inefficient and recommended using AVL trees instead</p></div></div><p>
... I&#39;m getting a &quot;variables vs. HTML&quot; vibe from this. Either you misheard or misquoted your teacher, or your teacher is mentally deficient.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Tue, 09 Feb 2010 03:03:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You may want to consider using vectors or another type of STL container to store and manage pointers to your objects. Using that method, you can easily iterate through your objects and call appropriate methods on them such as draw ().</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">using</span> <span class="k1">namespace</span> std <span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span><span class="c">// Declare the vector</span>
<span class="number">  4</span>std::vector <span class="k3">&lt;</span>obstacle <span class="k3">*</span><span class="k3">&gt;</span> obstacles <span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="c">// Declare the obstacle pointer</span>
<span class="number">  7</span>obstacle <span class="k3">*</span>brickWall <span class="k3">=</span> <span class="k1">new</span> obstacle <span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="c">// Push the obstacle pointer onto the vector</span>
<span class="number"> 10</span>obstacles.push_back <span class="k2">(</span>brickWall<span class="k2">)</span> <span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="k1">void</span> drawAllObstacles <span class="k2">(</span><span class="k2">)</span>
<span class="number"> 13</span><span class="k2">{</span>
<span class="number"> 14</span>  <span class="k1">if</span> <span class="k2">(</span>obstacles.size <span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 15</span>  <span class="k2">{</span>
<span class="number"> 16</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> obstacles.size <span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span> i<span class="k2">)</span>
<span class="number"> 17</span>    <span class="k2">{</span>
<span class="number"> 18</span>      draw <span class="k2">(</span>obstacles <span class="k2">[</span>i<span class="k2">]</span><span class="k2">)</span> <span class="k2">;</span>
<span class="number"> 19</span>    <span class="k2">}</span>
<span class="number"> 20</span>  <span class="k2">}</span>
<span class="number"> 21</span><span class="k2">}</span>
</div></div><p>

This is also efficient because you can easily &#39;push&#39; objects on the structure and &#39;pop&#39; them off when you are done with them.</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">void</span> doObstacleLogic <span class="k2">(</span><span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <span class="c">// You don't want to call methods on pointers that don't exist</span>
<span class="number">  4</span>  <span class="k1">if</span> <span class="k2">(</span>obstacles.size <span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  5</span>  <span class="k2">{</span>
<span class="number">  6</span>    <span class="c">// Iterate through the container</span>
<span class="number">  7</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> obstacles.size <span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span> i<span class="k2">)</span>
<span class="number">  8</span>    <span class="k2">{</span>
<span class="number">  9</span>      <span class="k1">if</span> <span class="k2">(</span>obstacles <span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>isDestroyed <span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 10</span>      <span class="k2">{</span>
<span class="number"> 11</span>        <span class="c">// remove pointer from the container</span>
<span class="number"> 12</span>        obstacles.erase <span class="k2">(</span>obstacles.begin <span class="k2">(</span><span class="k2">)</span> <span class="k3">+</span> i<span class="k2">)</span> <span class="k2">;</span>
<span class="number"> 13</span>      <span class="k2">}</span>
<span class="number"> 14</span>    <span class="k2">}</span>
<span class="number"> 15</span>  <span class="k2">}</span>
<span class="number"> 16</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BitCruncher)</author>
		<pubDate>Tue, 09 Feb 2010 03:08:23 +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/603094/850474#target">BitCruncher</a> said:</div><div class="quote"><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> doObstacleLogic <span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="c">// You don't want to call methods on pointers that don't exist</span>
  <span class="k1">if</span> <span class="k2">(</span>obstacles.size <span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
  <span class="k2">{</span>
    <span class="c">// Iterate through the container</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> obstacles.size <span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span> i<span class="k2">)</span>
    <span class="k2">{</span>
      <span class="k1">if</span> <span class="k2">(</span>obstacles <span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>isDestroyed <span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
      <span class="k2">{</span>
        <span class="c">// remove pointer from the container</span>
        obstacles.erase <span class="k2">(</span>obstacles.begin <span class="k2">(</span><span class="k2">)</span> <span class="k3">+</span> i<span class="k2">)</span> <span class="k2">;</span>
      <span class="k2">}</span>
    <span class="k2">}</span>
  <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div></div></div><p>
This will miss every obstacle after a destroyed obstacle. And I don&#39;t believe an iterator + arbitrary_number is standards compliant. The proper way would be:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">typedef</span> std::vector<span class="k3">&lt;</span>obstacle<span class="k3">*</span><span class="k3">&gt;</span> ObstacleVector<span class="k2">;</span>
ObstacleVector obstacles<span class="k2">;</span>
...
<span class="k1">for</span><span class="k2">(</span>ObstacleVector::iterator iter <span class="k3">=</span> obstacles.begin<span class="k2">(</span><span class="k2">)</span>,iter_end <span class="k3">=</span> obstacles.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    iter <span class="k3">!</span><span class="k3">=</span> iter_end<span class="k2">;</span><span class="c">/*do nothing*/</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">if</span><span class="k2">(</span><span class="k2">(</span><span class="k3">*</span>iter<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>isDestroyed<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
    <span class="k2">{</span>
        <span class="k1">delete</span> <span class="k3">*</span>iter<span class="k2">;</span>
        iter <span class="k3">=</span> obstacles.erase<span class="k2">(</span>iter<span class="k2">)</span><span class="k2">;</span>
        <span class="c">// iter_end was invalidated by erase(), restore it</span>
        iter_end <span class="k3">=</span> obstacles.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
    <span class="k1">else</span>
        iter<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Tue, 09 Feb 2010 03:46:58 +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/603094/850489#target">Kitty Cat</a> said:</div><div class="quote"><p>
And I don&#39;t believe an iterator + arbitrary_number is standards compliant.
</p></div></div><p>
It is. vector&#39;s implement the <a href="http://www.cplusplus.com/reference/std/iterator/RandomAccessIterator/">RandomAccessIterator</a> which allows for that sort of thing. Your method is still better though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 09 Feb 2010 04:01:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m thinking my teacher misunderstood what I was telling him, really.</p><p>@ (BitCruncher || Kitty Cat):<br />Is this method you listed substantially more effecient than using classes like I am currently using? Like, twice as good? Or is it just a small improvement as far as speed is concerned?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Falciase)</author>
		<pubDate>Tue, 09 Feb 2010 04:51:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Using classes is fine. As far as your explanation goes, I assume you&#39;re doing the same that BitCruncher said first(though he did bad coding), and Kitty Cat posted the method well.</p><p>I doubt there&#39;ll be any improvements in speed switching from classes to struct. Also, you&#39;d be crippling yourself from C++ features.</p><p>And I think this is what your teacher thought: You told him that you had a list of obstacles, and you iterated through it every frame. I think he thought in the case that your game had about, say, thousands of obstacles, when only 13 were seen at the screen, it would be a waste to check if each one of those was on the screen. The worst case might be when you need to check the collisions. With such a high number of obstacles, you&#39;d need to check for every entity that could move with each of the obstacles.</p><p>I don&#39;t know if your game has a really big amount of obstacles. If you feel like you need optimizing, there&#39;s plenty of threads this has been discussed. And the answers were always the kind like binary search trees.</p><p>My opinion? Don&#39;t bother with it too much unless you need a really big set of obstacles.</p><p>BTW, would you mind illustrating a bit better how this &quot;obstacle&quot; system works? Maybe a tilemap would do a better job if everything in the game is like a grid.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dario ff)</author>
		<pubDate>Tue, 09 Feb 2010 05:19:02 +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/603094/850489#target">Kitty Cat</a> said:</div><div class="quote"><p>
And I don&#39;t believe an iterator + arbitrary_number is standards compliant. The proper way would be:
</p></div></div><p>
The &quot;proper&quot; way is to do advance(itr, 5)<span class="ref"><sup>[<a href="#">1</a>]</sup></span>. This is complimented by distance(itr1, itr2)<span class="ref"><sup>[<a href="#">2</a>]</sup></span>.
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://www.cplusplus.com/reference/std/iterator/advance/">http://www.cplusplus.com/reference/std/iterator/advance/</a></li><li><a href="http://www.cplusplus.com/reference/std/iterator/distance/">http://www.cplusplus.com/reference/std/iterator/distance/</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dustin Dettmer)</author>
		<pubDate>Tue, 09 Feb 2010 06:03:24 +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/603094/850489#target">Kitty Cat</a> said:</div><div class="quote"><p>
</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">typedef</span> std::vector<span class="k3">&lt;</span>obstacle<span class="k3">*</span><span class="k3">&gt;</span> ObstacleVector<span class="k2">;</span>
<span class="number">  2</span>ObstacleVector obstacles<span class="k2">;</span>
<span class="number">  3</span>...
<span class="number">  4</span><span class="k1">for</span><span class="k2">(</span>ObstacleVector::iterator iter <span class="k3">=</span> obstacles.begin<span class="k2">(</span><span class="k2">)</span>,iter_end <span class="k3">=</span> obstacles.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>    iter <span class="k3">!</span><span class="k3">=</span> iter_end<span class="k2">;</span><span class="c">/*do nothing*/</span><span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>    <span class="k1">if</span><span class="k2">(</span><span class="k2">(</span><span class="k3">*</span>iter<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>isDestroyed<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  8</span>    <span class="k2">{</span>
<span class="number">  9</span>        <span class="k1">delete</span> <span class="k3">*</span>iter<span class="k2">;</span>
<span class="number"> 10</span>        iter <span class="k3">=</span> obstacles.erase<span class="k2">(</span>iter<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>        <span class="c">// iter_end was invalidated by erase(), restore it</span>
<span class="number"> 12</span>        iter_end <span class="k3">=</span> obstacles.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k2">}</span>
<span class="number"> 14</span>    <span class="k1">else</span>
<span class="number"> 15</span>        iter<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="number"> 16</span><span class="k2">}</span>
</div></div><p>
</p></div></div><p>

IMO, I think it&#39;s much cleaner and clarifying (though maybe slower) to use a separate container for the &quot;dead&quot; objects. Any objects that are pronounced &quot;dead&quot; will be added to this separate container. The actual deletion will be done after the update loop. Something like this:</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">typedef</span> std::vector<span class="k3">&lt;</span>obstacle<span class="k3">*</span><span class="k3">&gt;</span> ObstacleVector<span class="k2">;</span>
<span class="number">  2</span><span class="k1">typedef</span> ObstacleVector::iterator ObstacleIterator<span class="k2">;</span>
<span class="number">  3</span>ObstacleVector obstacles, deadObstacles<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="c">// .....</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="c">// The update loop</span>
<span class="number">  8</span><span class="k1">for</span> <span class="k2">(</span>ObstacleIterator i <span class="k3">=</span> obstacles.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i <span class="k3">!</span><span class="k3">=</span> obstacles.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number">  9</span><span class="k2">{</span>
<span class="number"> 10</span>   <span class="k1">if</span> <span class="k2">(</span><span class="k2">(</span><span class="k3">*</span>i<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>isDead<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 11</span>      deadObstacles.push_back<span class="k2">(</span><span class="k3">*</span>i<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span>   <span class="k1">else</span>
<span class="number"> 14</span>      <span class="k2">(</span><span class="k3">*</span>i<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>update<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span><span class="k2">}</span>
<span class="number"> 16</span>
<span class="number"> 17</span><span class="c">// The actual deletion</span>
<span class="number"> 18</span><span class="k1">for</span> <span class="k2">(</span>ObstacleIterator i <span class="k3">=</span> deadObstacles.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i <span class="k3">!</span><span class="k3">=</span> deadObstacles.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 19</span><span class="k2">{</span>
<span class="number"> 20</span>   ObstacleIterator iRemove <span class="k3">=</span> find<span class="k2">(</span>obstacles.begin<span class="k2">(</span><span class="k2">)</span>, obstacles.end<span class="k2">(</span><span class="k2">)</span>, <span class="k3">*</span>i<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>   obstacles.erase<span class="k2">(</span>iRemove<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>   <span class="k1">delete</span> <span class="k2">(</span><span class="k3">*</span>i<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span><span class="k2">}</span>
<span class="number"> 24</span>deadObstacles.clear<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

That&#39;s how I handle &quot;dead&quot; objects. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>[EDITED]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fishcake)</author>
		<pubDate>Tue, 09 Feb 2010 07:27:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@ dario ff:<br /><a href="http://sites.google.com/site/falconfivedev/updates/maploadingbasiccollisiondetection">Click here for a basic explanation of how my current system works.</a> So far it&#39;s working pretty darn well. I&#39;m programming the game on a 400mhz PC that&#39;s over ten years old so to ensure I code as efficiently as I can :] So far I can have more blocks than I&#39;d reasonably need on the PC with an unreasonable amount of objects testing collisions with said blocks, so I won&#39;t be switching from classes for this game. Perhaps I&#39;ll check it out after I finish this one <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Falciase)</author>
		<pubDate>Tue, 09 Feb 2010 07:53:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey, that&#39;s pretty cool. You&#39;re using a technique I used myself some years ago, and I like recommending that one. It&#39;s good to organise your obstacles into sub-sectors. Also, I think that programming on 400mhz PC is a pretty good strategy. I did programming before with a 800 mhz back then, and it&#39;s a really good experience to learn more efficient methods.</p><p>But I think you didn&#39;t get right what&#39;s a binary search tree. Think about it like another type of list, optimized for getting what elements you want according to a search criteria. You&#39;re not replacing classes, you just add them new members and organize them differently.</p><p>But I wouldn&#39;t bother with them. Your method proves the idea I always recommend works perfect.</p><p>It seems you&#39;ve got a lot of will to work on your game. Developing an efficient debug mode keeps me from programming sometimes <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>BTW, if you&#39;re having any doubts about programming slopes, you can maybe get away with some maths depending on the x position related to the tile.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dario ff)</author>
		<pubDate>Tue, 09 Feb 2010 08:13:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@ Falciase,</p><p>Very nice work on the engine.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/603094/850498#target">Falciase</a> said:</div><div class="quote"><p>Is this method you listed substantially more effecient than using classes like I am currently using? Like, twice as good? Or is it just a small improvement as far as speed is concerned?</p></div></div><p>

Vectors aren&#39;t a substitute for classes; rather they are a method of multiple object handling; similar to arrays.</p><p><a href="http://cplusplus.com/reference/stl/vector/">Vectors</a></p><p>You should check them out.</p><p>@ Dustin Dettmer, Kitty Cat,</p><p>Thanks for the corrections. I had always coded them that way and I never ran into run-time errors but it may have caused undetected internal memory errors.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BitCruncher)</author>
		<pubDate>Tue, 09 Feb 2010 08:32:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@ dario ff:<br />Thanks for the reassurance, it&#39;s nice to know someone else has successfully done the same thing-- and to think I thought I was working on a novel concept, hahah. And yeah, working on slopes as we speak XD definitely simply using the offset x to calculate where the y should be. It&#39;s not quite working properly yet, but I&#39;m sure I&#39;ll get it eventually-- if not, you are sure to see another post from a noob (me) on these forums XD</p><p>@ Bitcruncher:<br />Thanks! Been working alot on it as of late.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Falciase)</author>
		<pubDate>Tue, 09 Feb 2010 09:08:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In C++, a class and a struct are exactly the same thing, the only difference is that the default visibility for a class is &#39;private&#39;, while for a struct, it is &#39;public&#39;. Because of this, there is no runtime performance difference at all.</p><p>Avoiding classes or structs for performance reasons is plain silly; whether something is a class or not does not have anything to do with runtime performance at all.</p><p>The problem you&#39;re actually dealing with (and which you seem to have solved) is a very common one in games: Given a number of objects, how can I detect collisions as efficiently as possible?<br />The brute-force approach (compare every object against every other object) works, but its complexity is O(n²), in other words, given n objects, you need to perform n² comparisons.<br />A better approach is your sector-based one; it&#39;s easy to program, and it works well for many types of games. Typically the maximum number of objects per sector is limited, so you only need to perform a fixed number of comparisons per item: O(n).<br />Something like quadtrees is harder to program, and more efficient, but you&#39;ll only see real benefits if your scenes are complex and have a rather unbalanced distribution of objects in them (i.e., some hotspots where most of your objects are, and large areas that are almost empty).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Tue, 09 Feb 2010 18:17:26 +0000</pubDate>
	</item>
</rss>

