<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>OOP Design and Resource Management</title>
		<link>http://www.allegro.cc/forums/view/608680</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 05 Nov 2011 00:35:29 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey people. I just recently got C++ The Language, and it&#39;s really helping me see how amazingly bad my code is and is giving me some great ideas on how to make my game engine API more manageable and stable.</p><p>So, I have to have a resource manager in my design; it just makes sense. The way I ahve been doing this is to have a single class, ResourceManager, that loads all the datafiles, etc, and also contains all the drawing functions so that anything that needs to be drawn also has indirect access to the data; in this case a user might have an Animation class that contains a list of unsigned ints that are frame indices from the datafile, these are sent to the ResourceManager&#39;s draw functions as arguments, etc. </p><p><b>TL;DR</b></p><p>Should I use a Singleton(which means Resource::f() syntax) or do what Stroustrup seems to like in C++TL, which would be 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="number">  2</span><span class="c">// ResourceInterface.h</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">namespace</span> Resources <span class="k2">{</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="k1">void</span> FlipBuffer<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span><span class="k1">void</span> Draw<span class="k2">(</span><span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">unsigned</span> frame, <span class="k1">unsigned</span> a<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>...
<span class="number">  9</span>
<span class="number"> 10</span><span class="k2">}</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="c">// ResourceImplementation.cpp</span>
<span class="number"> 13</span>
<span class="number"> 14</span><span class="k1">namespace</span> Resources <span class="k2">{</span>
<span class="number"> 15</span>
<span class="number"> 16</span>    <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span> buffer<span class="k2">;</span>
<span class="number"> 17</span>    <a href="http://www.allegro.cc/manual/DATAFILE"><span class="a">DATAFILE</span></a> <span class="k3">*</span> data<span class="k2">;</span>
<span class="number"> 18</span>
<span class="number"> 19</span><span class="k2">}</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="k1">void</span> Resources::Draw<span class="k2">(</span><span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">unsigned</span> frame, <span class="k1">unsigned</span> a<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 22</span>
<span class="number"> 23</span>    <a href="http://www.allegro.cc/manual/set_trans_blender"><span class="a">set_trans_blender</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, a<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>    <a href="http://www.allegro.cc/manual/draw_trans_sprite"><span class="a">draw_trans_sprite</span></a><span class="k2">(</span>buffer, <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>data<span class="k2">[</span>frame<span class="k2">]</span>.dat, x, y<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>
<span class="number"> 26</span><span class="k2">}</span>
<span class="number"> 27</span>
<span class="number"> 28</span><span class="c">// etc...</span>
</div></div><p>

So, users of the Resource code can just</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">using</span> Resources<span class="k2">;</span>
Draw<span class="k2">(</span>myX, myY, anim-&gt;CurrentFrame<span class="k2">(</span><span class="k2">)</span>, anim-&gt;A<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

instead of (a) exposing the Resource interface directly and (b) having to use verbose syntax.</p><p>Personally, I prefer using the namespace. Which is better?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (_Kronk_)</author>
		<pubDate>Wed, 26 Oct 2011 21:43:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Neither. The &quot;best&quot; is to use a non-static (non-Singleton) instance of your resource manager <i>object</i>. Also, your resource manager probably shouldn&#39;t know how to draw anything. That&#39;s mixing up concerns. Your resource manager should manage resources well. Nothing more.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935319#target">_Kronk_</a> said:</div><div class="quote"><p>
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">namespace</span> Resources <span class="k2">{</span>
   <span class="c">// ...</span>
<span class="k2">}</span>

<span class="k1">void</span> Draw<span class="k2">(</span><span class="c">//...</span>
</pre></div></div><p>
</p></div></div><p>
<span class="source-code">Draw</span> is supposed to be inside of the namespace. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> But again, it shouldn&#39;t be. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> I like to have a &quot;renderer&quot; object that knows how to draw to the back-buffer/display/screen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Wed, 26 Oct 2011 22:09:07 +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/608680/935323#target">bamccaig</a> said:</div><div class="quote"><p>
Neither. The &quot;best&quot; is to use a non-static (non-Singleton) instance of your resource manager object. Also, your resource manager probably shouldn&#39;t know how to draw anything. That&#39;s mixing up concerns. Your resource manager should manage resources well. Nothing more.</p></div></div><p>

The reason I have it doing the drawing is that it keeps the allegro backend from users; any code relating to DATAFILEs or BITMAPs is completely contained in the Resource Manager. I suppose I could rename it &quot;GraphicsManager&quot; or something similar to show the relationship better. I&#39;m actually planning on writing an RAII wrapper class for BITMAPs and DATAFILEs, so that a ResourceManager might end up being obselete anyway.</p><p>If I were to use a single instance of ResourceManager somewhere and then pass around references/pointers to it, that changes the user&#39;s relationship to it; you go from
</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="number">  2</span><span class="c">// Drawing_Thingy.h</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">class</span> Thing <span class="k2">{</span>
<span class="number">  5</span>
<span class="number">  6</span>    protected:
<span class="number">  7</span>
<span class="number">  8</span>        <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">unsigned</span> frame, <span class="k1">unsigned</span> a<span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>    public:
<span class="number"> 11</span>
<span class="number"> 12</span>        <span class="k1">void</span> Draw<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="number"> 15</span><span class="c">// Drawing_Thingy.cpp</span>
<span class="number"> 16</span>
<span class="number"> 17</span><span class="p">#include "Drawing_Thingy.h"</span>
<span class="number"> 18</span><span class="p">#include "Resources.h"</span>
<span class="number"> 19</span><span class="k1">using</span> Resources<span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="k1">void</span> Thing::Draw<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 22</span>    
<span class="number"> 23</span>    DrawImage<span class="k2">(</span>x, y, frame, a<span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 24</span>
<span class="number"> 25</span><span class="k2">}</span>
</div></div><p>
which has an understood <b>the</b> ResourceManager relationship to
</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="number">  2</span><span class="c">// Drawing_Thingy2.h</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">class</span> Thing <span class="k2">{</span>
<span class="number">  5</span>
<span class="number">  6</span>    protected:
<span class="number">  7</span>
<span class="number">  8</span>        <span class="k1">int</span> x, <span class="k1">int</span> y, <span class="k1">unsigned</span> frame, <span class="k1">unsigned</span> a<span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>    public:
<span class="number"> 11</span>
<span class="number"> 12</span>        <span class="k1">void</span> Draw<span class="k2">(</span>ResourceManager<span class="k3">&amp;</span> r<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span><span class="k2">}</span>
<span class="number"> 14</span>
<span class="number"> 15</span><span class="c">// Drawing_Thingy2.cpp</span>
<span class="number"> 16</span>
<span class="number"> 17</span><span class="k1">void</span> Thing::Draw<span class="k2">(</span>ResourceManager<span class="k3">&amp;</span> r<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 18</span>
<span class="number"> 19</span>    r.DrawImage<span class="k2">(</span>x, y, frame, a<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="k2">}</span>
</div></div><p>
which has an understood <b>a</b> ResourceManager relationship, when in reality there is only one ResourceManager.</p><p>Another question is where would the ResourceManager live? If it were made a member of the Game class, you would have to use syntax like
</p><div class="source-code snippet"><div class="inner"><pre>things<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>Draw<span class="k2">(</span>Game-&gt;Resources<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
which isn&#39;t nearly as clean or easy to read as the namespace option.</p><ul><li><p>edit</p></li></ul><p>Well, I&#39;ll have to go for a regular instance-centric design anyway. Just realized that I can&#39;t have an RAII wrapper construct/destruct in a semi-global scope like a namespace when I&#39;m using allegro <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (_Kronk_)</author>
		<pubDate>Thu, 27 Oct 2011 00:51: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/608680/935333#target">_Kronk_</a> said:</div><div class="quote"><p>
The reason I have it doing the drawing is that it keeps the allegro backend from users; any code relating to DATAFILEs or BITMAPs is completely contained in the Resource Manager.</p><p>...</p><p>...there is only one ResourceManager.</p><p>Another question is where would the ResourceManager live? If it were made a member of the Game class, you would have to use syntax like</p><div class="source-code snippet"><div class="inner"><pre>things<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>Draw<span class="k2">(</span>Game-&gt;Resources<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

which isn&#39;t nearly as clean or easy to read as the namespace option.
</p></div></div><p>
You asked for good practices and I&#39;m giving them to you. <img src="http://www.allegro.cc/forums/smileys/angry.gif" alt="&gt;:(" /> Don&#39;t shoot the messenger. Global state is always a bad thing because it&#39;s too easy to break things. With the namespace solution, all anyone has to do to foil your plans is <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>ResourceManager::bitmaps<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">)</span></span>. Have fun with that. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> With the Singleton solution, it&#39;s impossible to test without affecting the entire application, which can cause other strange things to break. With a local object you are in complete control of what can talk to it and it is in complete control of what its willing to tell them.</p><p>I wouldn&#39;t pass the resource manager into a <i>thing</i> and have it draw itself with the resource manager though. From the sound of it all of your <i>things</i> are going to have very similar <span class="source-code">Draw</span> methods. I would try to implement a common interface (abstract base class) for all things drawable and have a renderer object draw those. Your <i>things</i> will implement this drawable interface. The <i>one</i> renderer object can know about the <i>one</i> resource manager and then it&#39;s just a matter of saying...</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">for</span><span class="k2">(</span><span class="k3">&lt;</span>each drawable thing&gt;<span class="k2">)</span>
<span class="k2">{</span>
    renderer.render<span class="k2">(</span><span class="k3">&lt;</span>thing&gt;<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

The renderer can worry about figuring out which resource to draw for which thing  and how based on the interface(s) (you can have multiple drawable interfaces, <i>if</i> you need them, and therefore many overloads of <span class="source-code">Renderer::render</span>, but you probably won&#39;t need this unless you do something beyond drawing a sprite per <i>thing</i>).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 27 Oct 2011 01:50: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/608680/935344#target">bamccaig</a> said:</div><div class="quote"><p>
You asked for good practices and I&#39;m giving them to you.  Don&#39;t shoot the messenger.
</p></div></div><p>

Sorry, didn&#39;t mean to come across that way. I was just kind of frustrated trying to find the best solution. It seems like I&#39;ve been working on this forever <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p><p>So where would the Renderer be? It wouldn&#39;t be global, so maybe a member of the game class?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (_Kronk_)</author>
		<pubDate>Thu, 27 Oct 2011 06:54:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t put the cart before the horse.  The most important thing to think about is how you want to use the interface.  First ask yourself &quot;What would make it the most reasonable and usable?&quot;</p><p>For example, I hide all my image managing behind the following functions:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>get_image<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename<span class="k2">)</span><span class="k2">;</span>
<span class="k1">bool</span> preload_image<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename<span class="k2">)</span><span class="k2">;</span>
<span class="k1">bool</span> reload_image<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename<span class="k2">)</span><span class="k2">;</span>
<span class="k1">void</span> set_image_path<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The above functions include several convience behaviors, including that get_image will never return a null pointer and crash my program.  If you haven&#39;t preloaded an image yet, no big deal, it will be loaded on first call to get_image and is ready from that point on.  Whenever I draw, I draw with the image filename, which acts as the identifier:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>get_image<span class="k2">(</span><span class="s">"monkey.png"</span><span class="k2">)</span>, <span class="n">50</span>, <span class="n">20</span>, NULL<span class="k2">)</span><span class="k2">;</span></span></p><p>This way I don&#39;t have to remember indexes or variable names.  Everything is consistent.</p><p>There are a multitude of ways that these functions could be &quot;solved&quot; under the hood, but in the end, it doesn&#39;t matter.  The important thing is that you should think about how you want to use it first.  Then solve for that.</p><p>Passing around pointers and instances, and juggling namespaces and whatnots is only going to make things worse.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Thu, 27 Oct 2011 07:35:33 +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/608680/935319#target">_Kronk_</a> said:</div><div class="quote"><p> Personally, I prefer using the namespace. Which is better?</p></div></div><p>Neither.</p><p>Remember that object-oriented design is about objects. You shouldn&#39;t have any manager classes, it&#39;s a mistake. You should have objects that represent the actual entities of your program.</p><p>So, from the text you posted, I can infer the following objects:</p><ul><li><p>Datafile. Obvious.</p><br /></li><li><p>Bitmap. Bitmaps can be loaded separately, or returned from datafiles.</p><br /></li><li><p>other resources like bitmap that can be loaded separately, but also be in a data file, like sounds, fonts, colors, etc.</p><br /></li><li><p>Animation class. When created, it should be setup with the appropriate resources loaded by the above classes.</p><br /></li><li><p>GameObject or Sprite or something like that; this object knows how to use an animation object in order to have a visual presence in the game world.
</p></li></ul></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 27 Oct 2011 16:11:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You always want to think, things might change, I might need more than 1 of something. In fact ideally (but not likely) your game should be able to be instanced multiple times and run separate instances of itself on multiple threads happily. I realize the underlying graphics or audio apis might not allow this but you want to think with this idea in mind; anything is bound to change, and singletons are bad.</p><p>Namespaces are a bit like packages in Java, or folders in a file system.</p><p>Because C++ relies heavily on libraries you want to know where classes come from.</p><p>Internally it can be used to organize though:</p><div class="source-code snippet"><div class="inner"><pre>gui::widget::TextBox<span class="k3">*</span> textBox <span class="k3">=</span> <span class="k1">new</span>  gui::widget::TextBox<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
base::Entity<span class="k3">*</span> hunter <span class="k3">=</span> <span class="k1">new</span> character::enemy::Hunter<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

That&#39;s overkill but you get the idea. They are used to organize your classes, not to be your classes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Thu, 27 Oct 2011 18:22:32 +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/608680/935357#target">_Kronk_</a> said:</div><div class="quote"><p>
Sorry, didn&#39;t mean to come across that way. I was just kind of frustrated trying to find the best solution. It seems like I&#39;ve been working on this forever <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div></div><p>
I hope you didn&#39;t take me too seriously. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> It might seem awkward or tedious at first until you actually start doing this. You will [hopefully] see how much easier it is to write and organize though. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935357#target">_Kronk_</a> said:</div><div class="quote"><p>
So where would the Renderer be? It wouldn&#39;t be global, so maybe a member of the game class?
</p></div></div><p>
That is an option. It could just be a local variable in whatever function/method the main game loop is in. Where it is depends on your design. It really doesn&#39;t need to be known to much of the program though. Mostly only the part that renders the game, which is hopefully only done in one part of the program. It can probably be a local variable somewhere, but it might make sense to make it a member of an object instead.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935365#target">axilmar</a> said:</div><div class="quote"><p>
Remember that object-oriented design is about objects.
</p></div></div><p>
Yes.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935365#target">axilmar</a> said:</div><div class="quote"><p>
You shouldn&#39;t have any manager classes, it&#39;s a mistake.
</p></div></div><p>
Not really. Managing/manipulating/organizing objects is a necessary thing and in a truly object-oriented world it would be objects that do these things also.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935365#target">axilmar</a> said:</div><div class="quote"><p>
You should have objects that represent the actual entities of your program.
</p></div></div><p>
Yes.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935365#target">axilmar</a> said:</div><div class="quote"><p>
When created, it should be setup with the appropriate resources loaded by the above classes.
</p></div></div><p>
It&#39;s debatable whether a bitmap object should know how to load itself from a file. It&#39;s especially awkward in C++ where throwing exceptions from a constructor is not so simple. I&#39;ve found that it&#39;s often useful to have a separate class do this. The bitmap object itself becomes just a dumb data object and then you have higher-level objects that manipulate them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 27 Oct 2011 18:58:12 +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/608680/935365#target">axilmar</a> said:</div><div class="quote"><p> Remember that object-oriented design is about objects. You shouldn&#39;t have any manager classes, it&#39;s a mistake.</p></div></div><p>I don&#39;t know about classes manager (I don&#39;t use them when doing OOP), but resource managers it&#39;s also a very good idea in OOP.</p><p>A lot of objects may use the same resources like sounds or images, if you create 50 instances of the same object obviously you&#39;re not going to load an image per each object.</p><p>I use to send a pointer to the resource manager to each of my objects, and if the objects needs an image or sound etc... talks with the resource manager, and the resource managers do all that it needs to do to find that file: search in the .exe directory, sear on internet etc...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Thu, 27 Oct 2011 19:41:47 +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/608680/935371#target">bamccaig</a> said:</div><div class="quote"><p> Not really. Managing/manipulating/organizing objects is a necessary thing and in a truly object-oriented world it would be objects that do these things also.</p></div></div><p>Truly object-oriented worlds do not have manager objects. Look around you; do you see any manager object? you don&#39;t.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> It&#39;s debatable whether a bitmap object should know how to load itself from a file.</p></div></div><p>Not debatable at all, for me. The bitmap knows its internal organization of information, and so the bitmap should be able to load itself from a file.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> It&#39;s especially awkward in C++ where throwing exceptions from a constructor is not so simple.</p></div></div><p>There is no problem in throwing exceptions from constructors. If an exception is thrown from a constructor, the destructor of all up to that point constructed objects will be invoked, as if the object was deleted.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>  I&#39;ve found that it&#39;s often useful to have a separate class do this. The bitmap object itself becomes just a dumb data object and then you have higher-level objects that manipulate them.</p></div></div><p>And throw simplicity out of the window, for no benefit?</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935376#target">AMCerasoli</a> said:</div><div class="quote"><p> A lot of objects may use the same resources like sounds or images, if you create 50 instances of the same object obviously you&#39;re not going to load an image per each object.I use to send a pointer to the resource manager to each of my objects, and if the objects needs an image or sound etc... talks with the resource manager, and the resource managers do all that it needs to do to find that file: search in the .exe directory, sear on internet etc...</p></div></div><p>You can always create the resource once and then share it amongst all parts of your code. You don&#39;t need a resource manager for that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 27 Oct 2011 20:09:39 +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/608680/935382#target">axilmar</a> said:</div><div class="quote"><p> You can always create the resource once and then share it amongst all parts of your code. You don&#39;t need a resource manager for that.</p></div></div><p>If you want and unorganized code, and repetitive code all the time, you can do what you say.</p><p>isn&#39;t the same:</p><div class="source-code snippet"><div class="inner"><pre>std::list<span class="k3">&lt;</span>C_bullet<span class="k3">*</span><span class="k3">&gt;</span> bullets<span class="k2">;</span>
bullets.push_back<span class="k2">(</span><span class="k1">new</span> Fast<span class="k2">(</span><span class="k3">&amp;</span>Res_manager<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
bullets.push_back<span class="k2">(</span><span class="k1">new</span> Blow<span class="k2">(</span><span class="k3">&amp;</span>Res_manager<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
bullets.push_back<span class="k2">(</span><span class="k1">new</span> Vola<span class="k2">(</span><span class="k3">&amp;</span>Res_manager<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Than:</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><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bullet_img <span class="k3">=</span> al_loa...
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>exp_img <span class="k3">=</span> al_loa...
<span class="number">  3</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>air1_bmp <span class="k3">=</span> al_loa...
<span class="number">  4</span><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>snd_blow1 <span class="k3">=</span> al_load...
<span class="number">  5</span><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>snd_blow2<span class="k3">=</span> al_load...
<span class="number">  6</span><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>snd_fall1<span class="k3">=</span> al_load...
<span class="number">  7</span><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>snd_fall3<span class="k3">=</span> al_load...
<span class="number">  8</span>
<span class="number">  9</span>std::list<span class="k3">&lt;</span>C_bullet<span class="k3">*</span><span class="k3">&gt;</span> bullets<span class="k2">;</span>
<span class="number"> 10</span>bullets.push_back<span class="k2">(</span><span class="k1">new</span> Fast<span class="k2">(</span>bullet_img, sound_touch, sound_roll, snd_fall3<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>bullets.push_back<span class="k2">(</span><span class="k1">new</span> Blow<span class="k2">(</span>bullet_img, exp_img, air1_bmp, snd_blow1, snd_blow2<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>bullets.push_back<span class="k2">(</span><span class="k1">new</span> Vola<span class="k2">(</span>air1_bmp, air2_bmp, snd_fall1, snd_fall3<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>al_destroy_bit...
<span class="number"> 15</span>al_destroy_bit...
<span class="number"> 16</span>al_destroy_bit...
<span class="number"> 17</span>al_destroy_sam...
<span class="number"> 18</span>al_destroy_sam...
<span class="number"> 19</span>etc...
</div></div><p>

And those are just ~3 arguments per objects... if they where more would be worse.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Thu, 27 Oct 2011 20:29:56 +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/608680/935382#target">axilmar</a> said:</div><div class="quote"><p>Truly object-oriented worlds do not have manager objects. Look around you; do you see any manager object? you don&#39;t.</p></div></div><p>
It&#39;s a proof that we don&#39;t live in an object-oriented world;)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 27 Oct 2011 20:33:13 +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/608680/935387#target">AMCerasoli</a> said:</div><div class="quote"><p> If you want and unorganized code, and repetitive code all the time, you can do what you say.</p></div></div><p>Your example isn&#39;t fair. When you are using the resource manager, you are forgetting to tell the resource manager which resources will be needed. Your code should have been like this:</p><div class="source-code snippet"><div class="inner"><pre>Res_manager.load_bitmap<span class="k2">(</span><span class="s">"bullet"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_bitmap<span class="k2">(</span><span class="s">"exp"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_bitmap<span class="k2">(</span><span class="s">"air1"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_sample<span class="k2">(</span><span class="s">"blow1"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_sample<span class="k2">(</span><span class="s">"blow2"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_sample<span class="k2">(</span><span class="s">"fall1"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_sample<span class="k2">(</span><span class="s">"fall2"</span><span class="k2">)</span><span class="k2">;</span>
Res_manager.load_sample<span class="k2">(</span><span class="s">"fall3"</span><span class="k2">)</span><span class="k2">;</span>

std::list<span class="k3">&lt;</span>C_bullet<span class="k3">*</span><span class="k3">&gt;</span> bullets<span class="k2">;</span>
bullets.push_back<span class="k2">(</span><span class="k1">new</span> Fast<span class="k2">(</span><span class="k3">&amp;</span>Res_manager, <span class="s">"bullet"</span>, <span class="s">"touch"</span>, <span class="s">"roll"</span>, <span class="s">"fall3"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
bullets.push_back<span class="k2">(</span><span class="k1">new</span> Blow<span class="k2">(</span><span class="k3">&amp;</span>Res_manager, <span class="s">"bullet"</span>, <span class="s">"exp"</span>, <span class="s">"air1"</span>, <span class="s">"blow1"</span>, <span class="s">"blow2"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
bullets.push_back<span class="k2">(</span><span class="k1">new</span> Vola<span class="k2">(</span><span class="k3">&amp;</span>Res_manager, <span class="s">"air1"</span>, <span class="s">"air2"</span>, <span class="s">"fall1"</span>, <span class="s">"fall3"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

There is little difference between your approach and mine.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935388#target">Audric</a> said:</div><div class="quote"><p> It&#39;s a proof that we don&#39;t live in an object-oriented world;)</p></div></div><p>But objects is what exists around us.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 27 Oct 2011 20:55:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>... Are you crazy? why would I tell the object which resource to load from outside?. The object already know that...</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="number">  2</span><span class="k1">class</span> bullet <span class="k2">:</span> <span class="k1">public</span> C_bullet<span class="k2">{</span>
<span class="number">  3</span>  private:
<span class="number">  4</span>     <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bm1<span class="k2">;</span>
<span class="number">  5</span>     <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a><span class="k3">*</span> sn1<span class="k2">;</span>
<span class="number">  6</span>  public:
<span class="number">  7</span>     bullet<span class="k2">(</span>RES_MANAGER <span class="k3">*</span>res_manager<span class="k2">)</span><span class="k2">:</span>
<span class="number">  8</span>        bm1 <span class="k2">(</span>res_manager-&gt;bm_loader<span class="k2">(</span><span class="s">"bullet.png"</span><span class="k2">)</span><span class="k2">)</span>, 
<span class="number">  9</span>        sn1 <span class="k2">(</span>res_manager-&gt;sn_loader<span class="k2">(</span><span class="s">"sound1.ogg"</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 10</span>     <span class="k2">{</span><span class="k2">}</span>
<span class="number"> 11</span>     
<span class="number"> 12</span>     ~bullet<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number"> 13</span>        res_manager-&gt;unneeded_res<span class="k2">(</span><span class="s">"bullet.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>        res_manager-&gt;unneeded_res<span class="k2">(</span><span class="s">"sound1.ogg"</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="k2">}</span><span class="k2">;</span>
</div></div><p>

And that way all I have to do is just:
</p><div class="source-code snippet"><div class="inner"><pre>bullets.push_back<span class="k2">(</span><span class="k1">new</span> bullet<span class="k2">(</span><span class="k3">&amp;</span>Res_manager<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Thu, 27 Oct 2011 21:25:11 +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/608680/935393#target">AMCerasoli</a> said:</div><div class="quote"><p> ... Are you crazy? why would I tell the object which resource to load from outside?. The object already know that...</p></div></div><p>How would you reuse the code then? your bullet example is not reusable code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 27 Oct 2011 21:27:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sharing code between bullet and another class is irrelevant.</p><p>The point of a resource manager is to get a kind of cache, where the first demander of a resource causes the load, and any other demander will be given a reference to the same resource, avoiding a second disk access and uncompress.</p><p>(The second demander may be a second instance of &quot;Bullet&quot;, or a very different class like the HUD if it uses the same sprites to display ammo)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 27 Oct 2011 21:50:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In the real world objects aren&#39;t reusable, at least not this kind of objects. This is the end of the chain, a bullet.</p><p>A bullet has its purposes, if you want a big bullet then you would do:</p><div class="source-code snippet"><div class="inner"><pre>big_bullet <span class="k2">:</span> <span class="k1">public</span> C_bullet<span class="k2">{</span>..
</pre></div></div><p>

All the rest would be the same, so the reusable code here is <span class="source-code">C_bullet</span> which has physics functions and variables that are going to be needed by all the kind of bullets... Well at least that&#39;s how I see it.</p><p>If you want to change just the images used by your <span class="source-code">big_bullet</span> I would create another object... After all it&#39;s another object.</p><div class="source-code snippet"><div class="inner"><pre>big_black_bullet <span class="k2">:</span> <span class="k1">public</span> C_bullet<span class="k2">{</span>.. <span class="c">// this makes more damage so I change that here</span>
big_red_bullet <span class="k2">:</span> <span class="k1">public</span> C_bullet<span class="k2">{</span>..   <span class="c">// this makes less damage</span>
</pre></div></div><p>

How to change the physics?, simple:</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="number">  2</span><span class="k1">class</span> big_black_bullet <span class="k2">:</span> <span class="k1">public</span> C_bullet<span class="k2">{</span>
<span class="number">  3</span>  private:
<span class="number">  4</span>     <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bm1<span class="k2">;</span>
<span class="number">  5</span>     <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a><span class="k3">*</span> sn1<span class="k2">;</span>
<span class="number">  6</span>  public:
<span class="number">  7</span>     bullet<span class="k2">(</span>RES_MANAGER <span class="k3">*</span>res_manager<span class="k2">)</span><span class="k2">:</span>
<span class="number">  8</span>        bm1 <span class="k2">(</span>res_manager-&gt;bm_loader<span class="k2">(</span><span class="s">"bullet.png"</span><span class="k2">)</span><span class="k2">)</span>, 
<span class="number">  9</span>        sn1 <span class="k2">(</span>res_manager-&gt;sn_loader<span class="k2">(</span><span class="s">"sound1.ogg"</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="number"> 12</span>        set_damage<span class="k2">(</span><span class="n">30</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// change the damage. </span>
<span class="number"> 13</span>
<span class="number"> 14</span>     <span class="k2">}</span>
<span class="number"> 15</span>     
<span class="number"> 16</span>     ~bullet<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number"> 17</span>        res_manager-&gt;unneeded_res<span class="k2">(</span><span class="s">"bullet.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>        res_manager-&gt;unneeded_res<span class="k2">(</span><span class="s">"sound1.ogg"</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="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Thu, 27 Oct 2011 21:53:28 +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/608680/935382#target">axilmar</a> said:</div><div class="quote"><p>
Truly object-oriented worlds do not have manager objects. Look around you; do you see any manager object? you don&#39;t.
</p></div></div><p>
Our world isn&#39;t a purely object-oriented world. An object is something &quot;tangible and relatively stable.&quot; There are a ton of things in our world that don&#39;t fit that description. This post isn&#39;t an object in the real world.</p><p>There still are &quot;managers&quot; though. The laws of the universe, for example, manage much (everything?) of what happens. We can&#39;t actually move in space. We can only operate muscles inside of us that interact with our limbs that interact with our surroundings; our surroundings then push us around. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935382#target">axilmar</a> said:</div><div class="quote"><p>
Not debatable at all, for me. The bitmap knows its internal organization of information, and so the bitmap should be able to load itself from a file.
</p></div></div><p>
A bitmap and an image file (even a bitmap file) are two different things. They&#39;re very closely related (especially the bitmap file), but they are still distinct.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935382#target">axilmar</a> said:</div><div class="quote"><p>
There is no problem in throwing exceptions from constructors. If an exception is thrown from a constructor, the destructor of all up to that point constructed objects will be invoked, as if the object was deleted.
</p></div></div><p>
Yes, but you are still responsible for cleaning up any non-RAII state that the constructor has done so far. I didn&#39;t say that it wasn&#39;t possible. I just said it was awkward.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935382#target">axilmar</a> said:</div><div class="quote"><p>
And throw simplicity out of the window, for no benefit?
</p></div></div><p>
There is benefit. It makes more sense. In the real world, an image doesn&#39;t <i>do</i> anything. It&#39;s a static object. It can be manipulated, but it needs something external to manipulate it. The same is true of most other objects. There are things that the objects themselves can do, but there are also things that can be done with the objects.</p><p>The latter is usually the one that we&#39;re dealing with. A hammer doesn&#39;t pound in nails. A person, for example, pounds in a nail with a hammer. The hammer has attributes that make it good for pounding in nails, but the hammer itself doesn&#39;t do anything.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935382#target">axilmar</a> said:</div><div class="quote"><p>
You can always create the resource once and then share it amongst all parts of your code. You don&#39;t need a resource manager for that.
</p></div></div><p>
That&#39;s what a resource manager does for you. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> It can potentially do it much easier. But if you&#39;re going to be sharing these objects then it&#39;s all the better that they be just dumb (preferably immutable) objects.</p><p>A bullet should not have functions on it to describe its physics, IMHO. A bullet should just describe the attributes of the bullet itself (and since it does nothing, doesn&#39;t really need any functionality). It&#39;s a dumb object. It might have a mass, maybe it has a shape, but how it interacts with the world is up to the particular world that its in. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 27 Oct 2011 22:51:38 +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/608680/935405#target">bamccaig</a> said:</div><div class="quote"><p> A bullet should not have functions on it to describe its physics, IMHO. A bullet should just describe the attributes of the bullet itself (and since it does nothing, doesn&#39;t really need any functionality). It&#39;s a dumb object. It might have a mass, maybe it has a shape, but how it interacts with the world is up to the particular world that its in. </p></div></div><p>Yes bamccaig, and we&#39;re going to spend the rest of our life creating a perfect and completely similar world in which we live on. At the end with 80 years old axilmar is going to have a library of 50.000.000 files, which actually don&#39;t do anything, you would need to join 30 classes to make a ball move in the screen... ahahahahaha. I think you went too far body.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> ball <span class="k2">:</span> <span class="k1">public</span> texture, <span class="k1">public</span> material, <span class="k1">public</span> molecules, <span class="k1">public</span> atoms<span class="k2">{</span>..
</pre></div></div><p>

<img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Thu, 27 Oct 2011 23:04:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You don&#39;t have to model every last detail. You only need to model what exists in your world. That doesn&#39;t change how they should be manipulated. Usually objects interact with other objects. Sometimes they interact in weird ways with the entire world. If you try to store that in each object then the entire world is going to have to know about the entire world. If you use higher-level managers or service objects then you can centralize this functionality much easier, IMHO.</p><p>Ultimately, the language doesn&#39;t put any restrictions on you. A method is just a dumb function that gets an implicit argument passed to it. It&#39;s up to the programmer to figure out what is appropriate where. <span class="source-code">Bullet::shoot<span class="k2">(</span>Player <span class="k3">&amp;</span><span class="k2">)</span></span> could just as easily be <span class="source-code">Player::shootWith<span class="k2">(</span>Bullet <span class="k3">&amp;</span><span class="k2">)</span></span>. So which is it? Both? It could instead be, <span class="source-code">World::shoot<span class="k2">(</span>Player <span class="k3">&amp;</span>, Bullet <span class="k3">&amp;</span><span class="k2">)</span></span>. The <span class="source-code">Player</span> doesn&#39;t need to know about the <span class="source-code">Bullet</span> and visa-versa.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 27 Oct 2011 23:47:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think I&#39;m finally starting to see the light on all this <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Thanks guys. Up until this point, I&#39;ve been kind of half-heartedly OOP, but it&#39;s obvious now how effective it can be to put more thought into my designs. </p><p>A rough outline of my new design:</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="number">  2</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  3</span>
<span class="number">  4</span>    init_allegro<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>    
<span class="number">  6</span>    <span class="k1">try</span> <span class="k2">{</span>
<span class="number">  7</span>
<span class="number">  8</span>        Game game<span class="k2">;</span>
<span class="number">  9</span>        game.Run<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>    <span class="k2">}</span>
<span class="number"> 12</span>
<span class="number"> 13</span>    <span class="k1">catch</span><span class="k2">(</span>MyException<span class="k3">&amp;</span> e<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 14</span>
<span class="number"> 15</span>        cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Exception: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> e.name <span class="k3">&lt;</span><span class="k3">&lt;</span> endl <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Cause: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> e.cause <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span>    <span class="k2">}</span>
<span class="number"> 18</span>
<span class="number"> 19</span><span class="k2">}</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="k1">void</span> Game::Run<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 22</span>
<span class="number"> 23</span>    <span class="k1">try</span> <span class="k2">{</span>
<span class="number"> 24</span>
<span class="number"> 25</span>        ResourceManager resources<span class="k2">(</span>cfg file name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>        ObjectManager objects<span class="k2">(</span>cfg file name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>        Map map<span class="k2">(</span>cfg file name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>        Renderer renderer<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>        
<span class="number"> 30</span>        <span class="k1">if</span><span class="k2">(</span>NeedUpdate<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 31</span>
<span class="number"> 32</span>            objects.Update<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 33</span>
<span class="number"> 34</span>            map.Draw<span class="k2">(</span>renderer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 35</span>            objects.Draw<span class="k2">(</span>renderer<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 36</span>            renderer.FlipBuffer<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>
<span class="number"> 38</span>        <span class="k2">}</span>
<span class="number"> 39</span>
<span class="number"> 40</span>    <span class="k2">}</span>
<span class="number"> 41</span>
<span class="number"> 42</span>    <span class="k1">catch</span><span class="k2">(</span>MyException<span class="k3">&amp;</span> e<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 43</span>
<span class="number"> 44</span>        cout <span class="k3">&lt;</span><span class="k3">&lt;</span> blah<span class="k2">;</span>
<span class="number"> 45</span>
<span class="number"> 46</span>    <span class="k2">}</span>
<span class="number"> 47</span>
<span class="number"> 48</span><span class="k2">}</span>
</div></div><p>

I&#39;m also going to be working from a RAII standpoint in code as well. I&#39;m kind of stoked. This is going to be much less of a beast to work with than my previous design <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (_Kronk_)</author>
		<pubDate>Fri, 28 Oct 2011 01:27:16 +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/608680/935397#target">Audric</a> said:</div><div class="quote"><p> Sharing code between bullet and another class is irrelevant</p></div></div><p>Reuse is irrelevant? since when?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> The point of a resource manager is to get a kind of cache, where the first demander of a resource causes the load, and any other demander will be given a reference to the same resource, avoiding a second disk access and uncompress.</p></div></div><p>A variable is good enough for this purpose. No need for a cache.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935398#target">AMCerasoli</a> said:</div><div class="quote"><p> In the real world objects aren&#39;t reusable, at least not this kind of objects. This is the end of the chain, a bullet.</p></div></div><p>In the real world, we should reuse as much code as possible.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> If you want to change just the images used by your big_bullet I would create another object... After all it&#39;s another object.</p></div></div><p>So if all a class does is change the images, why not have one class and load the images to the object externally using a function? it makes more sense.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935405#target">bamccaig</a> said:</div><div class="quote"><p> There still are &quot;managers&quot; though. The laws of the universe, for example, manage much (everything?) of what happens. We can&#39;t actually move in space. We can only operate muscles inside of us that interact with our limbs that interact with our surroundings; our surroundings then push us around. </p></div></div><p>That&#39;s not management, that&#39;s interactions based on rules.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> A bitmap and an image file (even a bitmap file) are two different things. They&#39;re very closely related (especially the bitmap file), but they are still distinct.</p></div></div><p>I didn&#39;t say otherwise. Still, a bitmap should use the image file internally to load itself from disk. That&#39;s proper OO.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Yes, but you are still responsible for cleaning up any non-RAII state that the constructor has done so far. I didn&#39;t say that it wasn&#39;t possible. I just said it was awkward.</p></div></div><p>That&#39;s what smart pointers are for. There is nothing awkward to it.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> The latter is usually the one that we&#39;re dealing with. A hammer doesn&#39;t pound in nails. A person, for example, pounds in a nail with a hammer. The hammer has attributes that make it good for pounding in nails, but the hammer itself doesn&#39;t do anything.</p></div></div><p>Then you would need a person object that knows everything. Not good OOP.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> That&#39;s what a resource manager does for you. </p></div></div><p>And therefore a resource manager is redundant.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> It can potentially do it much easier.</p></div></div><p>I&#39;ve yet to see an example of how a resource manager makes it easier. Anyone care to post one?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> A bullet should not have functions on it to describe its physics, IMHO. A bullet should just describe the attributes of the bullet itself (and since it does nothing, doesn&#39;t really need any functionality). It&#39;s a dumb object. It might have a mass, maybe it has a shape, but how it interacts with the world is up to the particular world that its in.</p></div></div><p>No, that&#39;s part of the Bullet subclass, not an external object. The common attributes of bullets belong to the Bullet class, and the particular physics of the world belong to the Bullet subclass.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935407#target">AMCerasoli</a> said:</div><div class="quote"><p> Yes bamccaig, and we&#39;re going to spend the rest of our life creating a perfect and completely similar world in which we live on. At the end with 80 years old axilmar is going to have a library of 50.000.000 files, which actually don&#39;t do anything, you would need to join 30 classes to make a ball move in the screen... ahahahahaha. I think you went too far body.</p></div></div><p>On the contrary, I&#39;d have one Bullet class.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 28 Oct 2011 01:48:17 +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/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
I&#39;ve yet to see an example of how a resource manager makes it easier. Anyone care to post one?
</p></div></div><p>
Not needing to keep track of duplicate bitmaps accross all yout program manually. Also, the example posted earlier assumes that the resources needed are known at compile time (they&#39;re hardcoded). It&#39;s also nice that, when entering a new level, the resource manager automatically frees any resource that will not be used by the new map, but keeping the ones that will be used (a lot of games fail at this though, and always unload everything and reload again the needed resources at each map change). How do you do this without a resource manager?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Fri, 28 Oct 2011 02:02:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A resource manager can do reference counting on expensive resources like bitmaps.</p><p>This way each class that might need a Bitmap just requests it from the RM and the class calls releaseBitmap() once it is destroyed and so resources are never duplicated and only freed when they are no longer needed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Fri, 28 Oct 2011 02:30:40 +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/608680/935429#target">axilmar</a> said:</div><div class="quote"><p> In the real world, we should reuse as much code as possible.</p></div></div><p>Who is saying the contrary?. A resource manager is exactly the best way to reuse code.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> So if all a class does is change the images, why not have one class and load the images to the object externally using a function? it makes more sense.</p></div></div><p>Not in OOP. I made that just as an example, I would change more than just an image if I were creating a new class.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I&#39;ve yet to see an example of how a resource manager makes it easier. Anyone care to post one?</p></div></div><p>I can&#39;t believe that you&#39;re saying that... I&#39;m definitively not going to take the time to explain you how a resource manager makes things easier, cleaner and if you are doing it in a different thread even faster, because:</p><ol><li><p>You haven&#39;t considered a game with more than 20 images and...
</p></li><li><p>You attitude seems very stubborn.</p></li></ol><p>I can&#39;t believe that you, as a experienced programmer, haven&#39;t realize of the benefits of a resource manager. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Fri, 28 Oct 2011 03:13:34 +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/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935397#target">Audric</a> said:</div><div class="quote"><p>Sharing code between bullet and another class is irrelevant</p></div></div><p>
Reuse is irrelevant? since when?</p></div></div><p>
It&#39;s irrelevant to the issue that was discussed so far.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935397#target">Audric</a> said:</div><div class="quote"><p>The point of a resource manager is to get a kind of cache, where the first demander of a resource causes the load, and any other demander will be given a reference to the same resource, avoiding a second disk access and uncompress.</p></div></div><p>
A variable is good enough for this purpose. No need for a cache.</p></div></div><p>
You don&#39;t seem to understand that the resource manager is generic and dynamic. You write it with for example a nice std::map&lt;string, BITMAP *&gt;, and you&#39;ll never have to modify one line of its code while you write the game and use more and more resources.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 28 Oct 2011 04:41:08 +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/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
That&#39;s not management, that&#39;s interactions based on rules.
</p></div></div><p>
What enforces the rules? A &quot;manager&quot; of some sort. Call it &quot;God&quot;, call it the universe, call it whatever you want. In the real world we don&#39;t know what is responsible, but in your game you need something to be responsible. You can have a hundred different objects all enforcing little rules or you can have higher-level objects that enforce all (or all related) rules. These higher-level objects have the advantage of being able to see more of the big picture too, without violating any design principles.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
I didn&#39;t say otherwise. Still, a bitmap should use the image file internally to load itself from disk. That&#39;s proper OO.
</p></div></div><p>
A bitmap is a bitmap. It is a map of bits. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> That&#39;s all it is. It doesn&#39;t need to know anything of files, file formats, file systems, file permissions, etc. It <u>can</u>, but that doesn&#39;t mean that it should. It should ideally do one thing and do it well. It&#39;s already a map of bits. It doesn&#39;t need to be a file reader/parser as well. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
That&#39;s what smart pointers are for. There is nothing awkward to it.
</p></div></div><p>
Compared to other languages, it is awkward. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
Then you would need a person object that knows everything. Not good OOP.
</p></div></div><p>
No, you wouldn&#39;t. You could have a higher-level class, lets call it <span class="source-code">God</span> (for a laugh), that knows about both a <span class="source-code">Person</span> and a <span class="source-code">Hammer</span>. <span class="source-code">Person</span> might know that it hits a <span class="source-code">Nail</span> with a <span class="source-code">Hammer</span> to pound it into <span class="source-code">Lumber</span>, but its not the <span class="source-code">Person</span> itself that repositions the <span class="source-code">Nail</span> in the <span class="source-code">Lumber</span>. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> It&#39;s the <span class="source-code">Game</span> or the <span class="source-code">World</span> or the <span class="source-code">God</span> or the <span class="source-code">PhysicsEngine</span>.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
And therefore a resource manager is redundant.
</p></div></div><p>
The idea behind a resource manager is that its a repository of resources that can be easily passed around the application, granting access to shared resources (potentially with restrictions or limitations). You haven&#39;t shown anything equivalent. Anything equivalent that you do propose will be a resource manager with a different name. Even if you inline the code, it&#39;s still a resource manager. Just a poorly organized one.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935429#target">axilmar</a> said:</div><div class="quote"><p>
...and the particular <b>physics of the world</b> <i>belong to the</i> <b>Bullet</b> subclass.
</p></div></div><p>
If that doesn&#39;t set off design alarm bells I don&#39;t know what will. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 28 Oct 2011 04:53:42 +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/608680/935431#target">Oscar Giner</a> said:</div><div class="quote"><p> Not needing to keep track of duplicate bitmaps accross all yout program manually</p></div></div><p>That&#39;s sweet for GUIs, where bitmaps are defined externally, but not for games, where bitmaps are defined internally. You could do the same by a global variable, or a struct that contains a global variable. It does not seem that what you mention requires a resource manager.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>  the resource manager automatically frees any resource that will not be used by the new map</p></div></div><p>Smart pointers handle this gracefully.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> How do you do this without a resource manager?</p></div></div><p>How about simple functions that load resources when required, plus smart pointers to resources? I see no need for a resource manager. The resource manager tests, at each request, if the resource is loaded, and if not, it loads the resource. I don&#39;t think that this is necessary for the simple games. Perhaps it is necessary for dynamically loaded games, where resources are loaded as the game runs. But then, the resource manager will do a lot more things, like keeping stats of video memory occupied, keeping important textures around etc.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935437#target">jmasterx</a> said:</div><div class="quote"><p> This way each class that might need a Bitmap just requests it from the RM and the class calls releaseBitmap() once it is destroyed and so resources are never duplicated and only freed when they are no longer needed.</p></div></div><p>Why request the bitmap from the resource manager and not simply access it from a struct? when the bitmap is needed, it is usually already loaded in another point in the code.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935443#target">AMCerasoli</a> said:</div><div class="quote"><p> Who is saying the contrary?. A resource manager is exactly the best way to reuse code.</p></div></div><p>A resource manager is not related to code reuse at all, unless the same requests are meaningful in different games, which is a very rare case.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> You haven&#39;t considered a game with more than 20 images and...<br /> I can&#39;t believe that you, as a experienced programmer, haven&#39;t realize of the benefits of a resource manager.</p></div></div><p>The first thing I coded for my GUI was the resource manager. However, a find a resource manager for a game a strange idea.</p><p>I prefer not to do this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> Bullet <span class="k2">{</span>
public:
    Bullet<span class="k2">(</span>ResourceManager <span class="k3">&amp;</span>rm<span class="k2">)</span> <span class="k2">{</span>
        m_bitmap <span class="k3">=</span> rm.getBitmap<span class="k2">(</span><span class="s">"explosion"</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>

I prefer this:</p><div class="source-code snippet"><div class="inner"><pre>Resources res<span class="k2">;</span>
res.m_explosion_bitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"explosion.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">class</span> Bullet <span class="k2">{</span>
public:
    Bullet<span class="k2">(</span>Resources <span class="k3">&amp;</span>res<span class="k2">)</span> <span class="k2">{</span>
        m_bitmap <span class="k3">=</span> res.m_explosion_bitmap<span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>

In other words, I prefer resources loaded in a step prior to game objects being constructed, for various reasons (which I can explain, if you wish).</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935451#target">Audric</a> said:</div><div class="quote"><p> It&#39;s irrelevant to the issue that was discussed so far.</p></div></div><p>Reuse is not irrelevant. We are essentially discussing good design, and reuse is one part of good design.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> You don&#39;t seem to understand that the resource manager is generic and dynamic. You write it with for example a nice std::map&lt;string, BITMAP *&gt;, and you&#39;ll never have to modify one line of its code while you write the game and use more and more resources.</p></div></div><p>You may not have to modify the resource manager code, but you certainly have to modify the loading resources code. So, if you have to modify the loading resources code, then you don&#39;t need a resource manager.</p><p>Do you, in your games, load bitmaps dynamically, when first requested? I don&#39;t, and I can&#39;t imagine anyone doing so in a game, unless you do a game so heavily textured that you need to load textures from disk dynamically, ala Rage. But then, your resource manager code is not a simple std::map&lt;string, BITMAP *&gt;, it&#39;s a lot more complicated.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935453#target">bamccaig</a> said:</div><div class="quote"><p> What enforces the rules?</p></div></div><p>The program itself.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> These higher-level objects have the advantage of being able to see more of the big picture too, without violating any design principles.</p></div></div><p>And then you complicate the design to the degree that your code doesn&#39;t make sense and cannot be reused or modified a few weeks later.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> It can, but that doesn&#39;t mean that it should. It should ideally do one thing and do it well. It&#39;s already a map of bits. It doesn&#39;t need to be a file reader/parser as well. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p></div></div><p>I didn&#39;t say that. I agree, a bitmap doesn&#39;t need to be a file reader/parser. However, a bitmap shall internally use a file object that is a file reader/parser. It&#39;s important be able to tell the bitmap &quot;bitmap, load yourself from this resource&quot;. If you can&#39;t do that, the responsibility of supplying an appropriate resource falls onto you, and suddenly you must know two things instead of one.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Compared to other languages, it is awkward.</p></div></div><p>No, these other languages are the awkward ones. Assuming that you are talking about languages with garbage collection and non-deterministic resource management.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> No, you wouldn&#39;t. You could have a higher-level class, lets call it God (for a laugh), that knows about both a Person and a Hammer. Person might know that it hits a Nail with a Hammer to pound it into Lumber, but its not the Person itself that repositions the Nail in the Lumber. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> It&#39;s the Game or the World or the God or the PhysicsEngine.</p></div></div><p>Absolutely wrong design, and very distant from the OO theory.<br /> 
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> The idea behind a resource manager is that its a repository of resources that can be easily passed around the application, granting access to shared resources (potentially with restrictions or limitations).</p></div></div><p>As I said above, a resource manager makes sense for the GUI, but not for a game.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> You haven&#39;t shown anything equivalent. </p></div></div><p>I did. See above.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Anything equivalent that you do propose will be a resource manager with a different name. Even if you inline the code, it&#39;s still a resource manager. Just a poorly organized one.</p></div></div><p>What I propose is not equivalent, and therefore not a resource manager ;-).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> If that doesn&#39;t set off design alarm bells I don&#39;t know what will.</p></div></div><p>That&#39;s proper OO: new behaviors are introduced by subclassing, honoring the is-a relationship. </p><p>Where and how did you learn OOP?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 31 Oct 2011 18:46: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/608680/935638#target">axilmar</a> said:</div><div class="quote"><p>
I prefer this:
</p><div class="source-code snippet"><div class="inner"><pre>Resources res<span class="k2">;</span>
res.m_explosion_bitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"explosion.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">class</span> Bullet <span class="k2">{</span>
public:
    Bullet<span class="k2">(</span>Resources <span class="k3">&amp;</span>res<span class="k2">)</span> <span class="k2">{</span>
        m_bitmap <span class="k3">=</span> res.m_explosion_bitmap<span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>
</p></div></div><p>
I&#39;m sure others will tear you apart on most of your other nonsense, but this I just had to address myself. Do you seriously suggest a Resources class with thousands of members, one for each object type? What if your game is extensible via configuration files (like <i>any</i> game should be)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 31 Oct 2011 19:35:15 +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/608680/935646#target">SiegeLord</a> said:</div><div class="quote"><p> I&#39;m sure others will tear you apart on most of your other nonsense, but this I just had to address myself. Do you seriously suggest a Resources class with thousands of members, one for each object type?</p></div></div><p>&quot;Nonsense&quot;...please. Hear me out first.</p><p>I do seriously suggest a Resources class with thousands of members. Here are the advantages of this solution:</p><ul><li><p>type safety. If you user a resource manager, and have thousands of resources, type errors will not be caught until you run the game and test each and every resource. With my solution, type errors will be limited to the resource loading code.</p><br /></li><li><p>name safety. If you user a resource manager, and have thousands of resources, managing thousands of resource name strings scattered all over the code quickly becomes a liability. With my solution, if you misspell a resource name, expressed as a variable identifier, the code will not compile.</p><br /></li><li><p>CPU and ram performance. With the resource manager, searching a map by using a string as a key can seriously hurt performance, especially if this action is repeated at every frame. With my solution, none of this happens, and the CPU cycles and memory can be used for other purposes.</p><br /></li><li><p>GPU and vram performance. If bitmaps are not loaded all together in one phase, i.e. if bitmaps are loaded the first time they are needed, and if there are many many bitmaps, then there is the danger of the video ram being exhausted, and perhaps important bitmaps may be loaded in ram instead of vram. Creating a system where textures are loaded quickly from disk requires extremely fast disks, otherwise the video performance will be problematic. See the recently released game &quot;Rage&quot; for such an example: its megatexture solution failed spectacularly on PCs with slow disks. When the player turned around quickly, the textures could not be loaded as fast as needed, resulting in very bad graphics that were slowly and visibly replaced with good graphics.</p><br /></li><li><p>player convenience. If bitmaps are loaded as they needed from the disk, there might be a case of slowdown during the action, i.e. the framerate dropping because of I/O. I don&#39;t like that in games, and most other people wouldn&#39;t like that either. So, as a programmer, I prefer to load all the appropriate files before engaging on the action. But loading all the files at one place defeats the purpose of a resource manager. </p></li></ul><p>Now that I&#39;ve said all this, I think that it is valid to say that there is no point in a resource manager in a video game, when a resource manager can have all the above-mentioned disadvantages.</p><p>A Resources class may not be a monolithic class, if you are worried over built times. </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> What if your game is extensible via configuration files (like any game should be)?</p></div></div><p>Extensible with what? new graphics and sounds? my approach still uses configuration files to load the resources, so I fail to see where is the problem.</p><p>Except if you mean other extensions via configuration files that I am unaware of.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 31 Oct 2011 21:40: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/608680/935638#target">axilmar</a> said:</div><div class="quote"><p>
That&#39;s sweet for GUIs, where bitmaps are defined externally, but not for games, where bitmaps are defined internally.
</p></div></div><p>
What!? Any medium sized game will have the bitmaps defined externally... For very small games it&#39;s ok to have the resources hardcoded into the code, but you don&#39;t want to do that for anything bigger.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Smart pointers handle this gracefully.
</p></div></div><p>
Not in the scenario of bitmaps defined externally.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
A resource manager is not related to code reuse at all, unless the same requests are meaningful in different games, which is a very rare case.
</p></div></div><p>
A resource manager is just that, and it can be easily reused for different games.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
In other words, I prefer resources loaded in a step prior to game objects being constructed, for various reasons (which I can explain, if you wish).
</p></div></div><p>
And I agree with that, and I don&#39;t see how that has anything to do with using or not a resource manager <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />.</p><p>&lt;edit&gt;
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935665#target">axilmar</a> said:</div><div class="quote"><p>
type safety. If you user a resource manager, and have thousands of resources, type errors will not be caught until you run the game and test each and every resource. With my solution, type errors will be limited to the resource loading code.</p><p>name safety. If you user a resource manager, and have thousands of resources, managing thousands of resource name strings scattered all over the code quickly becomes a liability. With my solution, if you misspell a resource name, expressed as a variable identifier, the code will not compile.
</p></div></div><p>
But then resources must be hardcoded into the game code. You want to separate code from level dessign and art. What you say is only useful for small games.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
CPU and ram performance. With the resource manager, searching a map by using a string as a key can seriously hurt performance, especially if this action is repeated at every frame. With my solution, none of this happens, and the CPU cycles and memory can be used for other purposes.
</p></div></div><p>
You can perfectly store a pointer to the resource once, so you don&#39;t need to access the map each frame.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
See the recently released game &quot;Rage&quot; for such an example: its megatexture solution failed spectacularly on PCs with slow disks.
</p></div></div><p>
Nope, the problem was elsewhere (there was a bug that affected 2 core CPU&#39;s, and also bad video drivers). After the updates I get constant 60 fps on my 3 years old CPU and HD. The slowdown wasn&#39;t because of the HD (it works fine on XBOX360 and PS3, and I don&#39;t think their HD&#39;s are that fast), it was because of way too high CPU usage that Id solved in the first patch (and also to workaround a bug in ATI drivers that lead to a very big CPU usage by the driver when streaming the textures).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
player convenience. If bitmaps are loaded as they needed from the disk, there might be a case of slowdown during the action, i.e. the framerate dropping because of I/O. I don&#39;t like that in games, and most other people wouldn&#39;t like that either. So, as a programmer, I prefer to load all the appropriate files before engaging on the action. But loading all the files at one place defeats the purpose of a resource manager.
</p></div></div><p>
You can force loading/unloading resources only at level change or when you want. And no, that doesn&#39;t defeat the purpose of a resource manager.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Mon, 31 Oct 2011 21:48:10 +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/608680/935665#target">axilmar</a> said:</div><div class="quote"><p>
Extensible with what? new graphics and sounds? my approach still uses configuration files to load the resources, so I fail to see where is the problem.</p><p>Except if you mean other extensions via configuration files that I am unaware of.
</p></div></div><p>

A concrete example. In my game I have an objects folder where you define new game objects, like so:</p><p>File: slime.obj
</p><pre class="terminal">class = land_creature
sprite = slime</pre><p>

File: slime_colossus.obj
</p><pre class="terminal">class = land_creature
sprite = colossus</pre><p>

Internally there&#39;s just one class (LandCreature), but the configuration files control the sprite + behaviour of the specific type of the object.</p><p>How would you handle that in your hard-coded Resource class?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 31 Oct 2011 22:36:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oscar already covered this, but I thought I would point it out as well - using a resource manager doesn&#39;t mean you can&#39;t load all your resources at the same time.</p><p>You can preload everything you want to, and then just get references to it later, as well as use an UnloadAll method to clear levels.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 01 Nov 2011 05:42:52 +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/608680/935671#target">Oscar Giner</a> said:</div><div class="quote"><p> What!? Any medium sized game will have the bitmaps defined externally... For very small games it&#39;s ok to have the resources hardcoded into the code, but you don&#39;t want to do that for anything bigger.</p></div></div><p>Yes, bitmaps will be defined externally. But you will need to address those bitmaps somehow from your code. So, you don&#39;t get away with hardcoding some references in the code anyway.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Not in the scenario of bitmaps defined externally.</p></div></div><p>Please elaborate. In my opinion, an std::shared_ptr&lt;BITMAP *&gt; will successfully keep a bitmap around until no longer needed. Why do you think otherwise?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> A resource manager is just that, and it can be easily reused for different games.</p></div></div><p>I repeat: the resource manager class can be reused, but the code that uses the resource manager cannot be reused, as it is custom per game.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> And I agree with that, and I don&#39;t see how that has anything to do with using or not a resource manager</p></div></div><p>Someone suggested earlier that a resource manager is used in cases like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> Bullet <span class="k2">{</span>
public:
    <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp1<span class="k2">;</span>
    Bullet<span class="k2">(</span>ResourceManager <span class="k3">&amp;</span>rm<span class="k2">)</span> <span class="k2">{</span>
        bmp1 <span class="k3">=</span> rm.getBitmap<span class="k2">(</span><span class="s">"bmp1"</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>

I disagree with the above, i.e. loading graphics dynamically, when game objects are created, for the reasons I explain in my previous post.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> But then resources must be hardcoded into the game code. You want to separate code from level dessign and art. What you say is only useful for small games.</p></div></div><p>Some kind of hardcoded reference is required at code level. It cannot be avoided. The resources will not be magically loaded.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> You can perfectly store a pointer to the resource once, so you don&#39;t need to access the map each frame.</p></div></div><p>But that&#39;s what I said and people told me it was nonsense.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Nope, the problem was elsewhere</p></div></div><p>Ok. Thanks for the info.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> You can force loading/unloading resources only at level change or when you want. And no, that doesn&#39;t defeat the purpose of a resource manager.</p></div></div><p>But if you don&#39;t need dynamic loading of resources, and if you want type and name safety that the resource manager doesn&#39;t provide, then why do you need a resource manager? I don&#39;t see any reason for it.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935684#target">SiegeLord</a> said:</div><div class="quote"><p> How would you handle that in your hard-coded Resource class?</p></div></div><p>Where did I say that in my code, resources will be hardcoded? I never said that. </p><p>Anyway, I&#39;d load the objects from the config file. But, somewhere in the code, there would be a reference to the slime object, like this:</p><p><span class="source-code">LandCreature slime <span class="k3">=</span> resourceManager.loadObject<span class="k2">(</span><span class="s">"slime"</span><span class="k2">)</span><span class="k2">;</span></span></p><p>So the above can be happily replaced with:</p><p><span class="source-code">LandCreature slime <span class="k3">=</span> Object::load<span class="k2">(</span><span class="s">"slime"</span><span class="k2">)</span><span class="k2">;</span></span></p><p>If I had a config file, I&#39;d do this:</p><p><span class="source-code">LandCreature slime <span class="k3">=</span> Object::load<span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_config_value"><span class="a">al_get_config_value</span></a><span class="k2">(</span><span class="s">"slime"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span></p><p>You probably are talking about a configuration file, not a resource manager.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935732#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Oscar already covered this, but I thought I would point it out as well - using a resource manager doesn&#39;t mean you can&#39;t load all your resources at the same time.You can preload everything you want to, and then just get references to it later, as well as use an UnloadAll method to clear levels.</p></div></div><p>So why do you need a resource manager, if you don&#39;t load your resources dynamically?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 01 Nov 2011 20:06:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Ok, let me make my configuration files a bit more clear...</p><p>File: slime.obj
</p><pre class="terminal">class = land_creature
sprite = slime.png</pre><p>

File: slime_colossus.obj
</p><pre class="terminal">class = land_creature
sprite = colossus.png</pre><p>

And inside the constructor of the land creature:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k2">{</span>
  Bitmap <span class="k3">=</span> ResourceManager.GetBitmap<span class="k2">(</span>Config.GetString<span class="k2">(</span><span class="s">"sprite"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Or to put it another way, how are you implementing:
</p><div class="source-code snippet"><div class="inner"><pre>LandCreature slime <span class="k3">=</span> Object::load<span class="k2">(</span><span class="s">"slime"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Because to me all you&#39;ve done is created a resource manager where the resource is now objects.</p><p>EDIT: Oh, and let me make this perfectly clear. At no point anywhere in the source code is there any mention of such a thing as a &quot;slime&quot; or a &quot;slime_colossus&quot;. There&#39;s no mention of &quot;slime.png&quot; and &quot;colossus.png&quot; anywhere either. All those things are loaded at runtime.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 01 Nov 2011 20:48:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Resource managers seems to make many things easier for me.</p><p>It becomes easier to share the same resource without loading the same resource multiple times by mistake.</p><p>Loading resources from script/data files also becomes easier, without again, having to worry about duplicating resources in memory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (l j)</author>
		<pubDate>Tue, 01 Nov 2011 20:56:48 +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/608680/935812#target">SiegeLord</a> said:</div><div class="quote"><p> Oh, and let me make this perfectly clear. At no point anywhere in the source code is there any mention of such a thing as a &quot;slime&quot; or a &quot;slime_colossus&quot;. There&#39;s no mention of &quot;slime.png&quot; and &quot;colossus.png&quot; anywhere either. All those things are loaded at runtime.</p></div></div><p>So, you are not talking about a resource manager actually, you are simply talking about creating instances of objects from configuration files. That&#39;s hardly the same as what we have been discussing.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935813#target">taron </a> said:</div><div class="quote"><p> Resource managers seems to make many things easier for me.It becomes easier to share the same resource without loading the same resource multiple times by mistake.Loading resources from script/data files also becomes easier, without again, having to worry about duplicating resources in memory.</p></div></div><p>Ok. How is that more helpful than having a variable to the resource?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 01 Nov 2011 21:20:20 +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/608680/935816#target">axilmar</a> said:</div><div class="quote"><p>
So, you are not talking about a resource manager actually, you are simply talking about creating instances of objects from configuration files. That&#39;s hardly the same as what we have been discussing.
</p></div></div><p>
What? Seriously... what?</p><p>Objects use resources. It doesn&#39;t matter how they are created, they need resources. I manage those resources using a resource manager. How will you manage resources using your technique in my case? I&#39;ve shown you an implementation of a constructor that uses a resource manager. Please show me one that uses your technique.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 01 Nov 2011 21:29: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/608680/935818#target">SiegeLord</a> said:</div><div class="quote"><p> What? Seriously... what?Objects use resources. It doesn&#39;t matter how they are created, they need resources. I manage those resources using a resource manager. </p></div></div><p>The resource manager discussed in this thread is one about loading resources dynamically, on a need basis, by name of the resource.</p><p>Your resource manager is a facility that allows you to instantiate game objects from configuration files.</p><p>Can&#39;t you see the difference?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> How will you manage resources using your technique in my case? I&#39;ve shown you an implementation of a constructor that uses a resource manager. Please show me one that uses your technique.</p></div></div><p>Already shown it to you:</p><p><span class="source-code">Object slime <span class="k3">=</span> Object::load<span class="k2">(</span><span class="s">"slime"</span><span class="k2">)</span><span class="k2">;</span></span></p><p>The above is not a resource manager, it&#39;s a simple function that loads a slime object.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 01 Nov 2011 22:30:32 +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/608680/935824#target">axilmar</a> said:</div><div class="quote"><p>
The resource manager discussed in this thread is one about loading resources dynamically, on a need basis, by name of the resource.
</p></div></div><p>
How does my constructor not fit that description? The game might instantiate a slime at any point during the runtime, then it would need the slime.png resource loaded, which would be taken care of by the resource manager. Slime might be deleted, or the level might be unloaded and then the slime.png resource should be unloaded too. The ability to create objects based on the description in a configuration file is not resource management per se, but it is a use case that <i>requires</i> a resource manager.</p><p>EDIT: Or how about this. Forget objects and take your description:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The resource manager discussed in this thread is one about loading resources dynamically, on a need basis, by name of the resource.
</p></div></div><p>

And now answer me, how do you handle the case where the name of the resource is a dynamic value, unknown at compile time.</p><p>I don&#39;t see where this confusion is coming from, I think I&#39;m being very clear in what I am asking.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 01 Nov 2011 22:35:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you not yet realized that axilmar will politely argue semantics on any given topic until Jesus&#39; second coming? Even if you fundamentally agree on something, it&#39;s doubtful you&#39;d ever come to that conclusion...</p><p>Anyway, if your method works without any major problems, it&#39;s silly to argue it&#39;s wrong because it introduces an extraterrestrial object. Programming is about getting things done, not creating a model of the Real World(TM).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 02 Nov 2011 00:09:14 +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/608680/935826#target">SiegeLord</a> said:</div><div class="quote"><p> The ability to create objects based on the description in a configuration file is not resource management per se</p></div></div><p>Cool, that&#39;s what I meant.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> but it is a use case that requires a resource manager.</p></div></div><p>Does it really require a resource manager? given that 1) resources are loaded before the game begins, 2) careful management of vram is required and 3) using tree maps or hash maps may cause performance problems during the game, are you sure that a resource manager like the one we discuss is required? </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> And now answer me, how do you handle the case where the name of the resource is a dynamic value, unknown at compile time.</p></div></div><p>In a use case you describe, tree/hash maps are only required when the resources are loaded and passed to the created objects. Even if you don&#39;t create all the objects at the start of a game&#39;s level, you can create the stubs that will create the game objects, and thus solving the problems I mentioned above.</p><p>Can you now answer me how would you handle the problems I described earlier?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I don&#39;t see where this confusion is coming from, I think I&#39;m being very clear in what I am asking.</p></div></div><p>You formed the question in such a way that it was not clear (at least to me) what was the use case.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935834#target">Matthew Leverton</a> said:</div><div class="quote"><p> Have you not yet realized that axilmar will politely argue semantics on any given topic until Jesus&#39; second coming? Even if you fundamentally agree on something, it&#39;s doubtful you&#39;d ever come to that conclusion...</p></div></div><p>I apologize for being too analytical, but I believe that the devil is in the details, as they say. Cases like these need a deep analysis, they are not easy.</p><p>For example, imagine making a game for the PC using Allegro 5. There is no problem with using a resource manager, since a modern PC has plenty of RAM and CPU power. </p><p>But if you transfer the game to an iPhone or a console, the game may not run properly, due to severe CPU and RAM limitations. </p><p>There might be a case that a level that loads bitmaps dynamically, as suggested, starts smoothly on an iDevice or console, but then it hungs up or slows down when a certain bitmap is loaded while the game is running.</p><p>I have seen such an example on the iPhone games developed by the company I work for. The game run smoothly on the simulator, which run on a Mac, and also run smoothly on the iPad and latest iPhone, but slowed down on an earlier iPhone. It was a case of resource management detail that caused a massive code restructuring and set us back more than a month.</p><p>See, I don&#39;t argue for the sake of arguing :-).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Wed, 02 Nov 2011 17:21:53 +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/608680/935926#target">axilmar</a> said:</div><div class="quote"><p>
using tree maps or hash maps may cause performance problems during the game,
</p></div></div><p>
You only use search trees or hash maps in your editors (for ease of use, being able to give things a name). But once you &quot;compile&quot; the resources into a format for use by the game itself, all accesses are by index.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
careful management of vram is required
</p></div></div><p>
That&#39;s a thing a resource manager can do pretty well. For example resources can have a priority, so in case of low vram, resources with low priority are moved to system RAM.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Wed, 02 Nov 2011 21:18:19 +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/608680/935936#target">Oscar Giner</a> said:</div><div class="quote"><p> You only use search trees or hash maps in your editors (for ease of use, being able to give things a name). But once you &quot;compile&quot; the resources into a format for use by the game itself, all accesses are by index.</p></div></div><p>So, if I am to use an index, which must be known at compile time, why not use a simple variable? what&#39;s the pros of an index over a variable?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> That&#39;s a thing a resource manager can do pretty well. For example resources can have a priority, so in case of low vram, resources with low priority are moved to system RAM.</p></div></div><p>What about resources that are already requested from the resource manager? if I have a pointer to a bitmap, and then the resource manager moves my bitmap to the system memory, then my bitmap will be invalid.</p><p>Furthermore, in order for the resource manager to do this, it will have to process every resource it currently has, and therefore the game will probably pause, even for a few seconds (because determining the best possible way to lay out different sized bitmaps in memory is not a trivial task). Which is not acceptable, I think.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Wed, 02 Nov 2011 21:34:07 +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/608680/935940#target">axilmar</a> said:</div><div class="quote"><p>
So, if I am to use an index, which must be known at compile time
</p></div></div><p>
No, it&#39;s not known at compile time. Where did I say that?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What about resources that are already requested from the resource manager? if I have a pointer to a bitmap, and then the resource manager moves my bitmap to the system memory, then my bitmap will be invalid.
</p></div></div><p>
If you want to allow that, you&#39;ll need a Bitmap class that takes care of this scenario, and the program always interfaces through this, never directly accessing allegro bitmaps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Wed, 02 Nov 2011 22:42: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/608680/935948#target">Oscar Giner</a> said:</div><div class="quote"><p> No, it&#39;s not known at compile time. Where did I say that?</p></div></div><p>You said earlier (quote): </p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935936#target">Oscar Giner</a> said:</div><div class="quote"><p> But once you &quot;compile&quot; the resources into a format for use by the game itself, all accesses are by index.</p></div></div><p>So, I imagine you are talking about something like Allegro 4&#39;s resource files, aren&#39;t you? so, you are talking about index constants produced by the tools. </p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935948#target">Oscar Giner</a> said:</div><div class="quote"><p> If you want to allow that, you&#39;ll need a Bitmap class that takes care of this scenario, and the program always interfaces through this, never directly accessing allegro bitmaps.</p></div></div><p>But it&#39;s not possible to solve it, even with a Bitmap class: once the Bitmap class obtains the pointer, the bitmap must not be moved, otherwise the pointer will be invalid.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Wed, 02 Nov 2011 22:56:19 +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/608680/935926#target">axilmar</a> said:</div><div class="quote"><p>
1) resources are loaded before the game begins
</p></div></div><p>
As many people have pointed out, this is orthogonal to using a resource manager or not.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
2) careful management of vram is required
</p></div></div><p>
I think you overstate the care needed. You get many benefits of a resource manager (the simple <span class="source-code">std::map<span class="k3">&lt;</span>string, <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k3">&gt;</span></span> variety) even with infinite VRAM simply because resource manager avoids loading identical files multiple times.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
3) using tree maps or hash maps may cause performance problems during the game
</p></div></div><p>
As many people have pointed out, you can cache the lookup in a member variable of the class. This is a straw-man argument.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
In a use case you describe, tree/hash maps are only required when the resources are loaded and passed to the created objects.
</p></div></div><p>
I still don&#39;t understand how I am being misunderstood. That&#39;s the entire point. Resource managers are needed when dynamic objects are created that use resources.</p><p>Seriously... this is ridiculous. I am going to write up a fully functioning resource manager example, and ask you to modify the code with your technique. Then it&#39;ll be clear exactly what I and you mean.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 02 Nov 2011 23:05: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/608680/935950#target">axilmar</a> said:</div><div class="quote"><p>
But it&#39;s not possible to solve it, even with a Bitmap class: once the Bitmap class obtains the pointer, the bitmap must not be moved, otherwise the pointer will be invalid. 
</p></div></div><p>

</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> Bitmap <span class="k2">{</span>
<span class="c">//...</span>

   <span class="k1">operator</span> <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span> <span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> bitmap<span class="k2">;</span><span class="k2">}</span>
<span class="k2">}</span><span class="k2">;</span>
</pre></div></div><p>
Problem solved. Every time you need your BITMAP* you get it from your Bitmap. Then it will never be invalid.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 02 Nov 2011 23:12:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Alright, here it is:</p><div class="source-code"><div class="toolbar"><span class="name">main.cpp</span><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="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro_image.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;map&gt;</span>
<span class="number">  4</span><span class="p">#include &lt;string&gt;</span>
<span class="number">  5</span><span class="p">#include &lt;vector&gt;</span>
<span class="number">  6</span><span class="p">#include &lt;iostream&gt;</span>
<span class="number">  7</span>
<span class="number">  8</span><span class="k1">using</span> std::cout<span class="k2">;</span>
<span class="number">  9</span><span class="k1">using</span> std::map<span class="k2">;</span>
<span class="number"> 10</span><span class="k1">using</span> std::string<span class="k2">;</span>
<span class="number"> 11</span><span class="k1">using</span> std::pair<span class="k2">;</span>
<span class="number"> 12</span><span class="k1">using</span> std::vector<span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> verbose_load<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> filename<span class="k2">)</span>
<span class="number"> 15</span><span class="k2">{</span>
<span class="number"> 16</span>  cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Loading: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> filename <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 17</span>  <span class="k1">return</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span>filename<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span><span class="k2">}</span>
<span class="number"> 19</span>
<span class="number"> 20</span><span class="k1">struct</span> SResourceManager
<span class="number"> 21</span><span class="k2">{</span>
<span class="number"> 22</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> Load<span class="k2">(</span>string filename<span class="k2">)</span>
<span class="number"> 23</span>  <span class="k2">{</span>
<span class="number"> 24</span>    BitmapsIt it <span class="k3">=</span> Bitmaps.find<span class="k2">(</span>filename<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>    <span class="k1">if</span><span class="k2">(</span>it <span class="k3">=</span><span class="k3">=</span> Bitmaps.end<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 26</span>    <span class="k2">{</span>
<span class="number"> 27</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bmp <span class="k3">=</span> verbose_load<span class="k2">(</span>filename.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>      <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>bmp<span class="k2">)</span>
<span class="number"> 29</span>        cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Couldn't load: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> filename <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 30</span>      <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>      Bitmaps.insert<span class="k2">(</span>pair<span class="k3">&lt;</span>string, <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k3">&gt;</span><span class="k2">(</span>filename, bmp<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>      <span class="k1">return</span> bmp<span class="k2">;</span>
<span class="number"> 33</span>    <span class="k2">}</span>
<span class="number"> 34</span>    <span class="k1">else</span>
<span class="number"> 35</span>    <span class="k2">{</span>
<span class="number"> 36</span>      <span class="k1">return</span> it-&gt;second<span class="k2">;</span>
<span class="number"> 37</span>    <span class="k2">}</span>
<span class="number"> 38</span>  <span class="k2">}</span>
<span class="number"> 39</span>
<span class="number"> 40</span>private:
<span class="number"> 41</span>  <span class="k1">typedef</span> map<span class="k3">&lt;</span>string, <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k3">&gt;</span><span class="k2">:</span><span class="k2">:</span>iterator BitmapsIt<span class="k2">;</span>
<span class="number"> 42</span>  map<span class="k3">&lt;</span>string, <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k3">&gt;</span> Bitmaps<span class="k2">;</span>
<span class="number"> 43</span><span class="k2">}</span><span class="k2">;</span>
<span class="number"> 44</span>
<span class="number"> 45</span><span class="k1">struct</span> SObject
<span class="number"> 46</span><span class="k2">{</span>
<span class="number"> 47</span>  SObject<span class="k2">(</span>SResourceManager<span class="k3">&amp;</span> manager, string name, <a href="http://www.allegro.cc/manual/ALLEGRO_CONFIG"><span class="a">ALLEGRO_CONFIG</span></a><span class="k3">*</span> config<span class="k2">)</span>
<span class="number"> 48</span>  <span class="k2">{</span>
<span class="number"> 49</span>    <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> bitmap_name <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_config_value"><span class="a">al_get_config_value</span></a><span class="k2">(</span>config, name.c_str<span class="k2">(</span><span class="k2">)</span>, <span class="s">"bitmap"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 50</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>bitmap_name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 51</span>    Bitmap <span class="k3">=</span> manager.Load<span class="k2">(</span>bitmap_name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 52</span>    cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Created object: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> name <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="number"> 53</span>  <span class="k2">}</span>
<span class="number"> 54</span>private:
<span class="number"> 55</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> Bitmap<span class="k2">;</span>
<span class="number"> 56</span><span class="k2">}</span><span class="k2">;</span>
<span class="number"> 57</span>
<span class="number"> 58</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number"> 59</span><span class="k2">{</span>
<span class="number"> 60</span>  <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 61</span>  <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 62</span>  
<span class="number"> 63</span>  SResourceManager manager<span class="k2">;</span>
<span class="number"> 64</span>  vector<span class="k3">&lt;</span>SObject<span class="k3">*</span><span class="k3">&gt;</span> objects<span class="k2">;</span>
<span class="number"> 65</span>  
<span class="number"> 66</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_CONFIG"><span class="a">ALLEGRO_CONFIG</span></a><span class="k3">*</span> objects_config <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_config_file"><span class="a">al_load_config_file</span></a><span class="k2">(</span><span class="s">"objects.ini"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 67</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>objects_config<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 68</span>  
<span class="number"> 69</span>  ALLEGRO_CONFIG_SECTION<span class="k3">*</span> it<span class="k2">;</span>
<span class="number"> 70</span>  <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> section <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_first_config_section"><span class="a">al_get_first_config_section</span></a><span class="k2">(</span>objects_config, <span class="k3">&amp;</span>it<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 71</span>  
<span class="number"> 72</span>  <span class="k1">while</span><span class="k2">(</span>section <span class="k3">!</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 73</span>  <span class="k2">{</span>
<span class="number"> 74</span>    string section_name<span class="k2">(</span>section<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 75</span>    <span class="k1">if</span><span class="k2">(</span>section_name <span class="k3">!</span><span class="k3">=</span> <span class="s">""</span><span class="k2">)</span>
<span class="number"> 76</span>    <span class="k2">{</span>
<span class="number"> 77</span>      objects.push_back<span class="k2">(</span><span class="k1">new</span> SObject<span class="k2">(</span>manager, section_name, objects_config<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 78</span>    <span class="k2">}</span>
<span class="number"> 79</span>    
<span class="number"> 80</span>    section <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_next_config_section"><span class="a">al_get_next_config_section</span></a><span class="k2">(</span><span class="k3">&amp;</span>it<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 81</span>  <span class="k2">}</span>
<span class="number"> 82</span>  
<span class="number"> 83</span>  <a href="http://www.allegro.cc/manual/al_destroy_config"><span class="a">al_destroy_config</span></a><span class="k2">(</span>objects_config<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 84</span>  
<span class="number"> 85</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 86</span><span class="k2">}</span>
</div></div><p>

There is very limited error detection and cleanup, but those things are separate from the question at hand. The code opens up an objects.ini file, which contains object names followed by bitmaps that represent an object, like so:</p><div class="source-code"><div class="toolbar"><span class="name">objects.ini</span><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="k2">[</span>apple<span class="k2">]</span>
<span class="number">  2</span>bitmap <span class="k3">=</span> apple.bmp
<span class="number">  3</span>
<span class="number">  4</span><span class="k2">[</span>pear<span class="k2">]</span>
<span class="number">  5</span>bitmap <span class="k3">=</span> pear.bmp
<span class="number">  6</span>
<span class="number">  7</span><span class="k2">[</span>poisoned_apple<span class="k2">]</span>
<span class="number">  8</span>bitmap <span class="k3">=</span> apple.bmp
</div></div><p>

The task of the code is to create each object and load its associated bitmap. Note that two of the objects share the same bitmap. However, if you run the code you get this output:</p><pre class="terminal">Loading: apple.bmp
Created object: apple
Loading: pear.bmp
Created object: pear
Created object: poisoned_apple</pre><p>

Although three objects were created, only two bitmaps were loaded.</p><p>So yeah... please show me how you&#39;d solve this issue in your code. I&#39;ve attached the current versions of the files to this post. The code expects the objects.ini file to be in the same directory, and the bitmap paths to be specified relative to the working directory. Keep in mind that I&#39;ll be testing your code with a different objects.ini file and different bitmaps. My code can handle such case, can yours?</p><p>EDIT:</p><p>And before you claim that my code doesn&#39;t do the pre-loading bit you want... think of the code in question as <i>the</i> pre-loading code. It&#39;s a bit inefficient in the sense that you&#39;ll have to delete the objects after you&#39;re done, but it gets the job done.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 03 Nov 2011 00:34:35 +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/608680/935960#target">SiegeLord</a> said:</div><div class="quote"><p>
So yeah... please show me how you&#39;d solve this issue in your code. I&#39;ve attached the current versions of the files to this post. Keep in mind that I&#39;ll be testing your code with a different objects.ini file and different bitmaps. My code can handle such case, can yours? 
</p></div></div><p>
Them&#39;s are fightin&#39; words, pilgrim!</p><p>Get Ready To Rummmmmmbbbbbblllllle!</p><p><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 03 Nov 2011 00:42:31 +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/608680/935950#target">axilmar</a> said:</div><div class="quote"><p>
So, I imagine you are talking about something like Allegro 4&#39;s resource files, aren&#39;t you? so, you are talking about index constants produced by the tools.
</p></div></div><p>
When I said &quot;compile&quot; (and this is why I put it between quotes) I wasn&#39;t talking about the C/C++ source code, but about the resources themselves. The same as you compile windows resources into a binary form. The tools just output a format where all extra info like resource names is lost, and only the indexes are kept. The code never uses those indexes directly: if you have for example a map editor, the editor will output a map format that refers to the resources by index.</p><p>All this of course if you really care about the performance of hash maps or trees, which you shouldn&#39;t even on a 10 years old CPU. It has the drawback that adding new resources means you have to regenerate all the game files (maps, animations...) so the indexes get updated.</p><p>Note: the point is not that you should use this (unless you&#39;re working with ancient hardware) but that it&#39;s possible to have a resource manager without the supposed performance problems you claim about hash maps or search trees.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
But it&#39;s not possible to solve it, even with a Bitmap class: once the Bitmap class obtains the pointer, the bitmap must not be moved, otherwise the pointer will be invalid.
</p></div></div><p>
You know, there are ways to inform the Bitmap objects that the bitmap has changed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Thu, 03 Nov 2011 02:13:01 +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/608680/935954#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Problem solved.</p></div></div><p>Not solved at all:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span>bitmap1<span class="k2">)</span><span class="k2">;</span>
Bitmap bitmap1<span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</span> move_bitmap_to_system_ram<span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
draw_bitmap<span class="k2">(</span>bitmap1<span class="k2">)</span><span class="k2">;</span> <span class="c">//KABOOM: bitmap pointer is invalid.</span>
</pre></div></div><p>

</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935960#target">SiegeLord</a> said:</div><div class="quote"><p> please show me how you&#39;d solve this issue in your code.<br /> think of the code in question as the pre-loading code.</p></div></div><p>I think you have seriously misunderstood the thread. People are not talking about using a resource manager at the loading stage, <b>but during the actual game</b>. The code that has been suggested as an example of good design is 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">class</span> bullet <span class="k2">:</span> <span class="k1">public</span> C_bullet<span class="k2">{</span>
<span class="number">  2</span>  private:
<span class="number">  3</span>     <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bm1<span class="k2">;</span>
<span class="number">  4</span>     <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a><span class="k3">*</span> sn1<span class="k2">;</span>
<span class="number">  5</span>  public:
<span class="number">  6</span>     bullet<span class="k2">(</span>RES_MANAGER <span class="k3">*</span>res_manager<span class="k2">)</span><span class="k2">:</span>
<span class="number">  7</span>        bm1 <span class="k2">(</span>res_manager-&gt;bm_loader<span class="k2">(</span><span class="s">"bullet.png"</span><span class="k2">)</span><span class="k2">)</span>, 
<span class="number">  8</span>        sn1 <span class="k2">(</span>res_manager-&gt;sn_loader<span class="k2">(</span><span class="s">"sound1.ogg"</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  9</span>     <span class="k2">{</span><span class="k2">}</span>
<span class="number"> 10</span>     
<span class="number"> 11</span>     ~bullet<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number"> 12</span>        res_manager-&gt;unneeded_res<span class="k2">(</span><span class="s">"bullet.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>        res_manager-&gt;unneeded_res<span class="k2">(</span><span class="s">"sound1.ogg"</span><span class="k2">)</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="k2">;</span>
</div></div><p>

I repeat, in case it was not understood: the above is proposed as a solution DURING THE ACTUAL GAME. Not at the loading stage.</p><p>I find it bad design to use a resource manager during the actual game, for the reasons I outlined above.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/935969#target">Oscar Giner</a> said:</div><div class="quote"><p> When I said &quot;compile&quot; (and this is why I put it between quotes) I wasn&#39;t talking about the C/C++ source code, but about the resources themselves. The same as you compile windows resources into a binary form. The tools just output a format where all extra info like resource names is lost, and only the indexes are kept. The code never uses those indexes directly: if you have for example a map editor, the editor will output a map format that refers to the resources by index.</p></div></div><p>But in a Win32 application, resources compiled into a binary form are accessed either by number or by name. </p><p>So, I ask you again: how would you access those resources in your game, if not by index or by name?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> All this of course if you really care about the performance of hash maps or trees, which you shouldn&#39;t even on a 10 years old CPU. </p></div></div><p>I think you are mistaken. If a tree map or hash map has a lot of items, as in thousands of items, then searching it adds noticeable delays to a video game that must be updated every 16 milliseconds (for a 60 frames per second update), when coupled with all the other things that must be calculated, especially for devices like consoles and phones. </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> but that it&#39;s possible to have a resource manager without the supposed performance problems you claim about hash maps or search trees.</p></div></div><p>Sure you can, if you precompile the tree or hash map into an array. But, if you do this at every created object:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> Bullet <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>myBitmap<span class="k2">;</span>
    Bullet<span class="k2">(</span>ResourceManager <span class="k3">&amp;</span>rm<span class="k2">)</span> <span class="k2">{</span>
        myBitmap <span class="k3">=</span> resourceManager<span class="k2">[</span>RESOURCE_EXPLOSION<span class="k2">]</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    ResourceManager rm<span class="k2">;</span>
    rm.loadResources<span class="k2">(</span><span class="s">"resource1.res"</span><span class="k2">)</span><span class="k2">;</span>
    ...
    bullets.push_back<span class="k2">(</span><span class="k1">new</span> Bullet<span class="k2">(</span>rm<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Why not do this, which is exactly the same and spares you the trouble of using a resource manager and compiling resources?</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">class</span> Bullet <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>myBitmap<span class="k2">;</span>
    Bullet<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">)</span> <span class="k2">{</span>
        myBitmap <span class="k3">=</span> bmp<span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>


<span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>explosionBitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"explosion.bmp"</span><span class="k2">)</span><span class="k2">;</span>
    ...
    bullets.push_back<span class="k2">(</span><span class="k1">new</span> Bullet<span class="k2">(</span>explosionBitmap<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 (axilmar)</author>
		<pubDate>Thu, 03 Nov 2011 20:44:56 +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/608680/936073#target">axilmar</a> said:</div><div class="quote"><p>
So, I ask you again: how would you access those resources in your game, if not by index or by name?
</p></div></div><p>
Read what I said again. The code itself never has hardcoded any resource index (if you want that then of course you&#39;ll need something similar to Windows resources: a generated header with all the #define&#39;s for the indexes, but that&#39;s bad since it means you need to recompile your game when resources change). The resource indexes needed are always stored in the game files (generated config files, map/level files, item/enemy/whatever files...).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I think you are mistaken. If a tree map or hash map has a lot of items, as in thousands of items, then searching it adds noticeable delays to a video game that must be updated every 16 milliseconds
</p></div></div><p>
Do you know that search time of a binary search tree is just O(log2(n)), right? It&#39;s very efficient when the number of items is very high. And a hash table is even more efficient, you can get O(1) in most searches with a good hash function.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Thu, 03 Nov 2011 21:32:47 +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/608680/936073#target">axilmar</a> said:</div><div class="quote"><p>
Not solved at all:</p><p>BITMAP *bmp = load_bitmap(bitmap1);<br />Bitmap bitmap1(bmp);<br />bmp = move_bitmap_to_system_ram(bmp);<br />draw_bitmap(bitmap1); //KABOOM: bitmap pointer is invalid.
</p></div></div><p>
You&#39;re overlooking the really obvious here - don&#39;t use BITMAP*&#39;s directly, that&#39;s why you&#39;re having problems.</p><div class="source-code snippet"><div class="inner"><pre>Bitmap bmp<span class="k2">(</span><span class="s">"PrettyPicture.bmp"</span> , VIDEO<span class="k2">)</span><span class="k2">;</span>
bmp.MoveToSystemRam<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/blit"><span class="a">blit</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>bmp , <a href="http://www.allegro.cc/manual/screen"><span class="a">screen</span></a> , <span class="n">0</span> , <span class="n">0</span> , <span class="n">0</span> , <span class="n">0</span> , bmp.W<span class="k2">(</span><span class="k2">)</span> , bmp.H<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
With an implicit cast from Bitmap to BITMAP* it&#39;s even easier, and then you always have a valid BITMAP*.</p><p>If you&#39;re going to write a Bitmap class, at least have it take full ownership of the BITMAP* it uses. If you want to call <span class="source-code"><a href="http://www.allegro.cc/manual/destroy_bitmap"><span class="a">destroy_bitmap</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>bmp<span class="k2">)</span><span class="k2">;</span></span> that&#39;s your own dumb fault.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
I think you have seriously misunderstood the thread. People are not talking about using a resource manager at the loading stage, but during the actual game. The code that has been suggested as an example of good design is this:<br />...<br />I repeat, in case it was not understood: the above is proposed as a solution DURING THE ACTUAL GAME. Not at the loading stage.
</p></div></div><p>
A single lookup during a constructor call is not expensive at all, and you don&#39;t need to repeatedly look up the same resource once you&#39;ve acquired it. And a resource manager allows you to quickly and easily load and unload levels at a time.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
I think you are mistaken. If a tree map or hash map has a lot of items, as in thousands of items, then searching it adds noticeable delays to a video game that must be updated every 16 milliseconds (for a 60 frames per second update), when coupled with all the other things that must be calculated, especially for devices like consoles and phones. 
</p></div></div><p>
I think you&#39;re over estimating how many lookups actually need to be made. You don&#39;t have to perform a lookup for every constructor call if you don&#39;t want to. You can easily use a lazy lookup scheme with a static resource pointer for shared resources. You only have to look it up with the resource manager once.</p><p>I think you&#39;re avoiding the main problem that a resource manager solves - simple and quick loading and unloading of resources.</p><p>Take your example :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>explosionBitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"explosion.bmp"</span><span class="k2">)</span><span class="k2">;</span>
    ...
    bullets.push_back<span class="k2">(</span><span class="k1">new</span> Bullet<span class="k2">(</span>explosionBitmap<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
You will have more than just a few resources to load and unload during your game :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
   ResourceManager rm<span class="k2">;</span>
   rm.LoadLevel<span class="k2">(</span><span class="s">"Level1.txt"</span><span class="k2">)</span><span class="k2">;</span>

   <a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span> explosion <span class="k3">=</span> rm.GetBitmap<span class="k2">(</span><span class="s">"Explosion"</span><span class="k2">)</span><span class="k2">;</span>
   <span class="c">// dynamically create new explosions using the single reference acquired from the lookup</span>

   rm.UnloadLevel<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
Do you really think that manually loading every single resource is a better solution than using a manager that can <i><b>manage</b></i> a set of resources by itself?</p><p>A further bonus of a resource manager is that it can throw an exception and log an error if there is a request made for a resource it does not have. That may not give you compile time error checking, but it&#39;s better than nothing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 03 Nov 2011 21:35: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/608680/936083#target">Oscar Giner</a> said:</div><div class="quote"><p> Read what I said again. The code itself never has hardcoded any resource index</p></div></div><p>Then how are you going to use those resources in the game?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Do you know that search time of a binary search tree is just O(log2(n)), right? It&#39;s very efficient when the number of items is very high. And a hash table is even more efficient, you can get O(1) in most searches with a good hash function.</p></div></div><p>But you have to take into account the cache and the memory access speed. It&#39;s not only the algorithm that counts. That is, if you want to have a 60 FPS game on a device like an iPad, for example. And that&#39;s valid only if the tree is balanced.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/936084#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> You&#39;re overlooking the really obvious here - don&#39;t use BITMAP*&#39;s directly, that&#39;s why you&#39;re having problems.</p></div></div><p>But the resource manager will do use BITMAP*s directly.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> A single lookup during a constructor call is not expensive at all. </p></div></div><p>Even if you have a game where you have lots of objects (like bullets, for example) created all the time? </p><p>Even if it is not that expensive, what about the other issues? type and name safety, for example?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I think you&#39;re over estimating how many lookups actually need to be made. You don&#39;t have to perform a lookup for every constructor call if you don&#39;t want to. </p></div></div><p>But the suggested solution was to use the resource manager within the constructor of an object in order to get the resource.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I think you&#39;re avoiding the main problem that a resource manager solves - simple and quick loading and unloading of resources.</p></div></div><p>Does loading and unloading of resources really need a resource manager? why not use a simple context structure with shared pointers to loaded resources?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Do you really think that manually loading every single resource is a better solution than using a manager that can manage a set of resources by itself?</p></div></div><p>But if you&#39;re going to request the resource from the resource manager, why not load it directly? i.e. why this:</p><div class="source-code snippet"><div class="inner"><pre>ResourceManager rm<span class="k2">;</span>
rm.LoadLevel<span class="k2">(</span><span class="s">"Level1.txt"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span> explosion <span class="k3">=</span> rm.GetBitmap<span class="k2">(</span><span class="s">"Explosion"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

And not this?</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a><span class="k3">*</span> explosion <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"Explosion"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Since you have to refer to the resource from the code anyway, why is a resource manager needed?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Do you really think that manually loading every single resource is a better solution than using a manager that can manage a set of resources by itself?</p></div></div><p>In the example you posted, <b>you are loading every single resource</b>, by doing this: <tt>BITMAP* explosion = rm.GetBitmap(&quot;Explosion&quot;);</tt></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> A further bonus of a resource manager is that it can throw an exception and log an error if there is a request made for a resource it does not have. That may not give you compile time error checking, but it&#39;s better than nothing.</p></div></div><p>The same thing can be done by a simple loading function.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Thu, 03 Nov 2011 22:47:56 +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/608680/936073#target">axilmar</a> said:</div><div class="quote"><p>
I repeat, in case it was not understood: the above is proposed as a solution DURING THE ACTUAL GAME. Not at the loading stage.
</p></div></div><p>
Are you being daft on purpose? The only reason I said that my code was the pre-loading code is because you yourself wanted everything being pre-loaded. My code, my edit notwithstanding, was exactly meant to show what happens during a game.</p><p>With that clarification over, my challenge still stands. I am sure at this point that you will not do it because: a) it&#39;s impossible to do it using your method, b) you&#39;re a demagogue.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 03 Nov 2011 23:26: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/608680/936105#target">axilmar</a> said:</div><div class="quote"><p>
But the resource manager will do use BITMAP*s directly.
</p></div></div><p>
You have to remember who owns the BITMAP* though, it&#39;s the manager, not the user of the pointer. And you could just as easily have the manager return a pointer to the Bitmap which would always give you the correct BITMAP* when asked for it. (Use the Bitmap, not the BITMAP*).</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
Even if you have a game where you have lots of objects (like bullets, for example) created all the time? 
</p></div></div><p>
I already answered this, you can still use a static pointer that is only looked up once, if it is really such a concern.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
But the suggested solution was to use the resource manager within the constructor of an object in order to get the resource.
</p></div></div><p>
Like I said, not necessary if performance is really a concern, and your lookups are actually your bottleneck.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
Does loading and unloading of resources really need a resource manager? why not use a simple context structure with shared pointers to loaded resources?
</p></div></div><p>
Well, you&#39;re going to have to store your resources somewhere, why not in a manager that can unload them all at once instead of one at a time?</p><p>Assume you use shared pointers instead - if you dynamically load resources, you still need a container with all the shared pointers in it so they stay loaded as long as necessary. That&#39;s all a manager is, a glorified container with the ability to load and unload resources when necessary. I think this is really just splitting hairs anymore. Both should work equally well.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
But if you&#39;re going to request the resource from the resource manager, why not load it directly? i.e. why this:</p><p>ResourceManager rm;<br />rm.LoadLevel(&quot;Level1.txt&quot;);<br />BITMAP* explosion = rm.GetBitmap(&quot;Explosion&quot;);</p><p>And not this?</p><p>BITMAP* explosion = load_bitmap(&quot;Explosion&quot;);</p><p>Since you have to refer to the resource from the code anyway, why is a resource manager needed?
</p></div></div><p>
Because then you don&#39;t need to destroy every resource manually, you can just call <span class="source-code">rm.UnloadLevel<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span> and be done with it. And if you use shared pointers, you still need a container to hold them in so they don&#39;t go out of scope and so you can get them when you need to copy them.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
In the example you posted, you are loading every single resource, by doing this: BITMAP* explosion = rm.GetBitmap(&quot;Explosion&quot;);
</p></div></div><p>
No, that&#39;s just the lookup. The loading is done in LoadLevel. And when you&#39;re done you call UnloadLevel. Simple, neat, quick.</p><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
The same thing can be done by a simple loading function. 
</p></div></div><p>
And if you have <u>dynamic</u> resources then you need a container to hold them in. That&#39;s all a resource manager is! How would you combine scripting with shared pointers? You would still have to have a container for them.</p><p>I don&#39;t see what we&#39;re arguing about here. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 03 Nov 2011 23:29:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See <a href="http://static.allegro.cc/image/cache/8/0/80957c72518411bd61070d1b9a026d61.jpg">here</a>.</p><p>The smart pointer solution isn&#39;t enough in itself to work for a dynamic game (i.e., one that isn&#39;t hard coded) while simultaneously sharing resources.</p><p>Let&#39;s say that you have a lot of resources and want to only load the ones that are needed for the current level. When you switch levels, how will you know which resources are needed, which ones need to be loaded anew, and which ones can be cleaned up? And where will you get those already loaded resources? A shared pointer is insufficient here. Sure, you have already loaded the resource, but where is it? How do you get the shared pointer if not from a resource manager?</p><p>You can&#39;t address it by name. Everything about it is dynamically configured. The static code can&#39;t know what it&#39;s dealing with. For all intents and purposes, it&#39;s an orphaned object at this point because there&#39;s no &quot;repository&quot; of resources to fetch it from. The last object that used it from the previous level will be destroyed, dropping the smarter pointer reference count to 0, causing that resource to be destroyed also. Now you have to reload all of shared resources all over again for nothing. Talk about waste.</p><p>A resource manager can solve all of these problems easily. Once again, anything you come up with to explain how to solve this problem will be a resource manager by a different name. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> What you&#39;re describing is premature optimization.</p><p><i>ZOMG, what if we decide to port it to my wrist watch?!</i> No. Choose efficient data structures and algorithms and the compiler should already do a good job of keeping things efficient. A good abstract design should already make it easy to make backend changes to speed things up if necessary without a total rewrite. If you have to hack it up on some obscure platform because you&#39;re pushing the limits of what it can do then hack it up on <i>that</i> platform. Reliability and integrity are more important than performance. It doesn&#39;t matter how quickly you calculate the wrong answer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 03 Nov 2011 23:58: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/608680/936105#target">axilmar</a> said:</div><div class="quote"><p>
And that&#39;s valid only if the tree is balanced.
</p></div></div><p>
I think it&#39;s obvious it&#39;s a balanced tree. It&#39;s stupid implementing a tree that&#39;s not balanced, specially since the tree is constant (no insertion or deletion of elements after the initial load). So are you telling me it was necessary that I said that explicitly? Come on, this is getting ridiculous (even more).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
But you have to take into account the cache and the memory access speed.
</p></div></div><p>
Yes, and that may be a good reason to use a hash table over a tree, since it&#39;s much more cache friendly (unless somehow you make all the nodes in the tree to be stores consecutively in memory).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
That is, if you want to have a 60 FPS game on a device like an iPad, for example.
</p></div></div><p>
Even if accessing a tree was as slow as you say (which it isn&#39;t), you only access it the first time you want to get a resource, after that, you have the resource object stored somewhere, no need to access it through the resource manager all the time.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Then how are you going to use those resources in the game?
</p></div></div><p>
I already explained that, read please. Are you making fun of us? I&#39;m starting to think that (and not only for this thread).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Fri, 04 Nov 2011 02:43:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To keep the long story short, keep Matthew&#39;s bills down, and avoiding replying individually to everyone, here is the deal.</p><p><b>The problem.</b></p><p>If a resource manager is used, the programmer has to do the following:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>res1 <span class="k3">=</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>resourceManager.getResource<span class="k2">(</span><span class="s">"res1"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>res2 <span class="k3">=</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>resourceManager.getResource<span class="k2">(</span><span class="s">"res2"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>res3 <span class="k3">=</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span><span class="k2">)</span>resourceManager.getResource<span class="k2">(</span><span class="s">"res3"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
The above has:</p><ul><li><p>performance issues, when done repeatedly in a fast-paced action game.
</p></li><li><p>type safety issues. &#39;Res1&#39; may not be a bitmap.
</p></li><li><p>name safety issues. &#39;Res1&#39; may be erroneously typed &#39;Resl&#39;, for example.</p></li></ul><p><b>The solution.</b></p><p>So, to avoid the problems, my chosen way to deal with resources is the following:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>res1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"res1"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>res2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"res2"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>res3 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"res3"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The advantages of this over the resource manager are:</p><ul><li><p>better performance; no lookups are needed during the game.
</p></li><li><p>more type safety. The above code will not compile if the resource is not a bitmap.
</p></li><li><p>more name safety; if I use the variable &#39;res1&#39; in my code, instead of the string &quot;res1&quot;, there are less chances of a bug because of identifier mistyping.</p></li></ul><p><b>Requirement 1 - caching individual resources.</b></p><p>Now, if one wants to achieve caching of resources, i.e. to avoid loading resources if already loaded, one can use simple solutions, like this:</p><div class="source-code snippet"><div class="inner"><pre>shared_ptr<span class="k3">&lt;</span>BITMAP&gt; res1, res2, res3<span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>res1, <span class="s">"res1"</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>res2, <span class="s">"res2"</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>res3, <span class="s">"res3"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The above solution achieves the caching effect without sacrificing performance, type and name safety.</p><p><b>Requirement 2 - caching resources of a configuration file.</b></p><p>If one wants to load multiple resources specified in a text file, one can do the following:</p><div class="source-code snippet"><div class="inner"><pre>shared_ptr<span class="k3">&lt;</span>BITMAP&gt; res1, res2, res3<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_CONFIG"><span class="a">ALLEGRO_CONFIG</span></a> <span class="k3">*</span>config <span class="k3">=</span> load_config<span class="k2">(</span><span class="s">"level1.txt"</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>res1, get_config_value<span class="k2">(</span><span class="s">"res1"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>res2, get_config_value<span class="k2">(</span><span class="s">"res2"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>res3, get_config_value<span class="k2">(</span><span class="s">"res3"</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The above solution achieves the loading resources from files dynamically without sacrificing performance, type and name safety.</p><p><b>Requirement 3 - unloading a whole bunch of resources at once.</b></p><p>For even better design, multiple resources can be divided into structures, 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">struct</span> BulletBitmaps <span class="k2">{</span>
<span class="number">  2</span>    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion1<span class="k2">;</span>
<span class="number">  3</span>    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion2<span class="k2">;</span>
<span class="number">  4</span>    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion3<span class="k2">;</span>
<span class="number">  5</span><span class="k2">}</span><span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">struct</span> SpaceshipBitmaps <span class="k2">{</span>
<span class="number">  8</span>    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; spaceship1<span class="k2">;</span>
<span class="number">  9</span>    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; spaceship2<span class="k2">;</span>
<span class="number"> 10</span>    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; spaceship3<span class="k2">;</span>
<span class="number"> 11</span><span class="k2">}</span><span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span><span class="k1">struct</span> Resources <span class="k2">{</span>
<span class="number"> 14</span>    shared_ptr<span class="k3">&lt;</span>BulletBitmaps&gt; bulletBitmaps<span class="k2">;</span>
<span class="number"> 15</span>    shared_ptr<span class="k3">&lt;</span>spaceshipBitmaps&gt; spaceshipBitmaps<span class="k2">;</span>
<span class="number"> 16</span><span class="k2">}</span><span class="k2">;</span>
</div></div><p>

If you want to dispose of a whole bunch of resources at once, you can do this:</p><div class="source-code snippet"><div class="inner"><pre>Resources res<span class="k2">;</span>
...
res.bulletBitmaps.reset<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//get rid of bullet bitmaps</span>
res.spaceshipBitmaps.reset<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//get rid of spaceship bitmaps</span>
</pre></div></div><p>

<b>Why reference counting is unavoidable.</b></p><p>A resource manager cannot unload resources anyway until it is explicitly told to do so, which requires reference counting of resources, so using reference counting is inevitable.</p><p>Since reference counting must be used, the use of shared_ptr is mandated.</p><p><b>Why using maps of identifiers to resources is not required.</b></p><p>The whole debate is based on the observation that if a resource is named by an identifier in a program, then this identifier better be a variable and not a string, in order not to lose performance, type safety and name safety.</p><p>In other words, for each time a resource manager is used:</p><div class="source-code snippet"><div class="inner"><pre>Type var<span class="k2">;</span>
var <span class="k3">=</span> resourceManager.getResource<span class="k2">(</span><span class="s">"resource name"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

The same thing can be achieved without a resource manager:</p><div class="source-code snippet"><div class="inner"><pre>Type var<span class="k2">;</span>
var <span class="k3">=</span> load_resource_if_not_loaded<span class="k2">(</span>var, <span class="s">"resource name"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

<b>What about unnamed resources?</b></p><p>Well, if a resource is unnamed (i.e. it has no identifier that it can be addressed by), then the discussion is pointless, because we are talking about named resources. A resource manager cannot be used with unnamed resources.</p><p>An unnamed resource, in this case, will be loaded in a different way; for example, by serially reading a file and constructing resources one after the other.</p><p><b>Isn&#39;t what you propose a resource manager?</b></p><p>Yes it is! albeit of a different kind!</p><p><b>TL;DR</b></p><p>Each request to a resource manager can be replaced by a variable in order to improve performance, type and name safety.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 04 Nov 2011 16:18:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Type safety:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP"><span class="a">BITMAP</span></a> <span class="k3">*</span>ship_north<span class="k3">=</span> resourceManager.getBitmap<span class="k2">(</span><span class="s">"res1"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/SAMPLE"><span class="a">SAMPLE</span></a> <span class="k3">*</span>death_sound <span class="k3">=</span> resourceManager.getSample<span class="k2">(</span><span class="s">"res2"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 04 Nov 2011 18:13: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/608680/936213#target">axilmar</a> said:</div><div class="quote"><p>
name safety issues. &#39;Res1&#39; may be erroneously typed &#39;Resl&#39;, for example.
</p></div></div><p>
In your solution the same can happen.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
more name safety; if I use the variable &#39;res1&#39; in my code, instead of the string &quot;res1&quot;, there are less chances of a bug because of identifier mistyping.
</p></div></div><p>
In the resource manager solution you also use the variable <i>res1</i>.</p><p>Type safety (or lack of) is the same in both solutions.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
better performance; no lookups are needed during the game.
</p></div></div><p>
Whats the time of that look up, compared to the time of the disk access needed to load the resource? You don&#39;t lose any performance, loading the resource takes 99.99% of the time. Trying to optimize the other 0.001% is stupid.</p><p>Ans what Audric said about type safety.</p><p>So your solution doesn&#39;t solve anything.</p><p>And BTW, with a resource manager, the load functions won&#39;t return you directly a BITMAP *, but a Bitmap class, that holds this bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Fri, 04 Nov 2011 20:31: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/608680/936213#target">axilmar</a> said:</div><div class="quote"><p>
A resource manager cannot unload resources anyway until it is explicitly told to do so, which requires reference counting of resources, so using reference counting is inevitable.</p><p>Since reference counting must be used, the use of shared_ptr is mandated.
</p></div></div><p>
I have two issues with this. Firstly, you can structure your game such that the game&#39;s logic determines when the resources are guaranteed to be unloaded. In my newest iteration of resource managers, there is a resource manager per level and all objects within a level use that resource manager. When the level is unloaded, all the resources cached within the resource manager are guaranteed to be unused, and thus are freed. This obviously has the issue of increasing individual level load times, but it has the benefit of not having to micromanage resource usage. It also leads to smoother in-level performance (see the discussion in the next paragraph).</p><p>This brings me to the second issue. Using a <span class="source-code">shared_ptr</span> for resources loaded from disk makes no sense. I imagine that when you <span class="source-code">shared_ptr</span> loses all of its ownership, then the resource if unloaded. Now your magical function <span class="source-code">load_resource_if_not_loaded</span> will load the resource anew when it is called again. This will lead to a horrible performance for objects which sometimes exist in the level, but often times don&#39;t (e.g. player&#39;s bullets) because they will have to load the resource every time the first bullet is created! You&#39;d need to create some bizzare secondary cache that <span class="source-code">shared_ptr</span> &#39;s unload their resources to, and that <span class="source-code">load_resource_if_not_loaded</span> try to load their resources from first. You&#39;d definitely want to implement your own reference counting that holds on to resources for future reuse, if you must do reference counting.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What about unnamed resources?
</p></div></div><p>
What about resources that have names only at runtime, <b>like in my example which you still refuse to implement using your method</b>. And no, <span class="source-code">load_resource_if_not_loaded</span> will not work, and neither will the &#39;BulletBitmaps&#39; trick.</p><p>And I just realized even if they were known at runtime... guess what! Your method fails.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">struct</span> BulletBitmaps <span class="k2">{</span>
    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion1<span class="k2">;</span>
    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion2<span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>

BulletBitmaps resources<span class="k2">;</span>

load_bitmap_if_not_yet_loaded<span class="k2">(</span>resources.explosion1, <span class="s">"explosion1.bmp"</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>resources.explosion2, <span class="s">"explosion1.bmp"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

or</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">struct</span> PlayerBitmaps <span class="k2">{</span>
    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion<span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">struct</span> EnemyBitmaps <span class="k2">{</span>
    shared_ptr<span class="k3">&lt;</span>BITMAP&gt; explosion<span class="k2">;</span>
<span class="k2">}</span><span class="k2">;</span>

PlayerBitmaps player_resources<span class="k2">;</span>
EnemyBitmaps enemy_resources<span class="k2">;</span>

load_bitmap_if_not_yet_loaded<span class="k2">(</span>player_resources.explosion, <span class="s">"explosion1.bmp"</span><span class="k2">)</span><span class="k2">;</span>
load_bitmap_if_not_yet_loaded<span class="k2">(</span>enemy_resources.explosion, <span class="s">"explosion1.bmp"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

In both cases your method will load <i>identical</i> bitmaps multiple times!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 04 Nov 2011 21:14:36 +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/608680/936235#target">Oscar Giner</a> said:</div><div class="quote"><p> In your solution the same can happen.<br /> In the resource manager solution you also use the variable res1.<br /> Type safety (or lack of) is the same in both solutions.</p></div></div><p>Not the same. In my solution, I use the string identifier once, and then use the variable thereafter. In the resource manager solution, the identifier string may be used more than once.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Trying to optimize the other 0.001% is stupid.</p></div></div><p>If the other 0.001% is in reality 0.01% or even worse, 0.1%, and applied 60 times per second, then there might be an issue.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608680/936243#target">SiegeLord</a> said:</div><div class="quote"><p> This brings me to the second issue. Using a shared_ptr for resources loaded from disk makes no sense. I imagine that when you shared_ptr loses all of its ownership, then the resource if unloaded. Now your magical function load_resource_if_not_loaded will load the resource anew when it is called again. This will lead to a horrible performance for objects which sometimes exist in the level, but often times don&#39;t (e.g. player&#39;s bullets) because they will have to load the resource every time the first bullet is created! You&#39;d need to create some bizzare secondary cache that shared_ptr &#39;s unload their resources to, and that load_resource_if_not_loaded try to load their resources from first. You&#39;d definitely want to implement your own reference counting that holds on to resources for future reuse, if you must do reference counting.</p></div></div><p>You missed the global variable that will keep the object around with reference count = 1.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> What about resources that have names only at runtime, like in my example which you still refuse to implement using your method. And no, load_resource_if_not_loaded will not work, and neither will the &#39;BulletBitmaps&#39; trick.</p></div></div><p>Then you need a map and a few functions, obviously. But that&#39;s not what I discuss here.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> In both cases your method will load identical bitmaps multiple times!</p></div></div><p>You organized your resources in the wrong way. It&#39;s like you used two different resource managers. Each resource that is common should have one variable holding it. </p><p>With my method, you can achieve loading a resource twice, if you want one of the resources to be modified at runtime. You cannot do that with a resource manager: you have to duplicate the resource externally.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Fri, 04 Nov 2011 21:36:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">axilmar said:</div><div class="quote"><p>
[You&#39;re absolutely right, and I don&#39;t agree with you, but I&#39;m still right.]
</p></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p><p>Also: anything that you can do without a resource manager you can do with a resource manager. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 04 Nov 2011 22:00:39 +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/608680/936247#target">axilmar</a> said:</div><div class="quote"><p>
Then you need a map and a few functions, obviously. But that&#39;s not what I discuss here.
</p></div></div><p>
Yeah... you don&#39;t discuss real games, but some kind of fantasy programs. Real games are rife with runtime names for resources.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Each resource that is common should have one variable holding it. 
</p></div></div><p>
You can&#39;t know that it is common until runtime!</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
With my method, you can achieve loading a resource twice, if you want one of the resources to be modified at runtime.
</p></div></div><p>
With your method you <i>have</i> to load each resource twice, as I&#39;ve shown. With a resource manager you get sharing by default, and you can get a unique copy, if need be, by cloning the resource.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
you have to duplicate the resource externally.
</p></div></div><p>
Yes. Why is that bad? Also, in my games I&#39;ve never had to clone a resource to date.</p><p>So far it seems that you are trying to solve problems that are not there with a more verbose solution that has severe limitations and requires a lot of thought to get to work. A resource manager is a simple concept that pays dividends with only a few lines of reusable code (I&#39;ve reused essentially the same bitmap resource manager in 5 games now) and is robust to many use cases.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 05 Nov 2011 00:17:34 +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/608680/936247#target">axilmar</a> said:</div><div class="quote"><p>
Not the same. In my solution, I use the string identifier once, and then use the variable thereafter. In the resource manager solution, the identifier string may be used more than once.
</p></div></div><p>
Yes the same. You have load_resource_if_not_loaded that you&#39;ll call more times. Actually you&#39;ll call that function when, if using a resource manager, you&#39;d call the resource manager getter method. So the total number of times a resource is accessed by name is the same in both methods.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If the other 0.001% is in reality 0.01% or even worse, 0.1%, and applied 60 times per second, then there might be an issue.
</p></div></div><p>
err... like... no? Even if it was 1%. If loading takes 5s, that 1% increases it to 5.05s (this is the load time of all resources, not of a single one). So what? Are you telling my that a level load time of an extra 0.05s is worth the effort of a more unmanageable system? (and lets face, this is not the case, accessing an element in a tree of thousand of elements takes less than a ms, it&#39;s just 16 memory accesses).</p><p>And then the second part... why applied 60 times per second? You only load resources once :/ But even if you want some kind of texture streaming engine, UE3 engine does it and works on mobile devices and on current consoles.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sat, 05 Nov 2011 00:35:29 +0000</pubDate>
	</item>
</rss>
