<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>globally available functions and resources</title>
		<link>http://www.allegro.cc/forums/view/616287</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 20 May 2016 21:04:35 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m planning to write something like a soundmanager for my games.  There will only be one such a manager and everything that makes noise will use it.<br />What will be the better option</p><ul><li><p>variables and functions in a namespace.
</p></li><li><p>a class with only static members and functions
</p></li><li><p>singleton class</p></li></ul><p>What would you do, and why ?<br />Thnx for stopping by;-)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ariesnl)</author>
		<pubDate>Fri, 20 May 2016 17:47:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Variable and function in a namespace if you want to stick to C++ style,<br />Class and only static things if you wanna make it C style.</p><p>In ANY case, not a singleton one. Why ? Because it looks awful. </p><p>If I were doing it in C++ I would go with #1 as it&#39;s the case which will allow the best control over the api when mixed with other api&#39;s.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Fri, 20 May 2016 18:14:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If there&#39;s one of those patterns that you&#39;ve not practiced, it may be an opportunity to try. In this case, you can&#39;t shoot yourself in the foot : the sound system depends on a unique resource which is your PC&#39;s sound output, you are not likely to suddenly need multiple concurrent sound systems.</p><p>Otherwise, I would use whatever looks the most like the neighboring code.<br />For example if your code is mostly doing allegro5 calls like al_something(), I would prefer to have <span class="source-code">snd_something<span class="k2">(</span><span class="k2">)</span></span>, rather than <span class="source-code">Sound.Something<span class="k2">(</span><span class="k2">)</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 20 May 2016 18:40:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For a sound manager, I would probably go with an object, something like this:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">class</span> Sound
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>private:
<span class="number">  4</span>   <span class="k1">class</span> SoundRecord
<span class="number">  5</span>   <span class="k2">{</span>
<span class="number">  6</span>   public:
<span class="number">  7</span>      std::string identifier<span class="k2">;</span>
<span class="number">  8</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>sample<span class="k2">;</span>
<span class="number">  9</span>      <span class="c">// ...</span>
<span class="number"> 10</span>   <span class="k2">}</span><span class="k2">;</span>
<span class="number"> 11</span>   std::vector<span class="k3">&lt;</span>SoundRecord <span class="k3">*</span><span class="k3">&gt;</span> samples<span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span>public:
<span class="number"> 14</span>   <span class="c">// some methods like...</span>
<span class="number"> 15</span>   <span class="k1">bool</span> preload<span class="k2">(</span>std::string identifier, std::string filename<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>   <span class="k1">void</span> play<span class="k2">(</span>std::string identifier<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>   <span class="k1">void</span> start_stream<span class="k2">(</span>std::string identifier<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>   <span class="k1">void</span> <a href="http://www.allegro.cc/manual/fade_out"><span class="a">fade_out</span></a><span class="k2">(</span>std::string identifier, <span class="k1">float</span> speed<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>   <span class="c">// ...</span>
<span class="number"> 20</span><span class="k2">}</span><span class="k2">;</span>
</div></div><p>

Focus on the interface you want more than anything else. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Fri, 20 May 2016 19:35:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It is gonna use allegro anyway..<br />but I need a nicer way of loading and playing sounds than the hard coded mess I have right now. I also need a way to play continues sound (loop) and stop the correct instance at the right moment.  Right now I use a sample ID returned from al_play_sound  and a bool that tells me if that instance is playing.  But when you have a lot of looping sounds that must be stopped at the right moment.. it&#39;s not such a nice solution.</p><p>I also noticed you cannot compare sampleIDs ... ??
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ariesnl)</author>
		<pubDate>Fri, 20 May 2016 20:27:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Last time I had such need, I linked it the opposite way : If an emitted sound could be cancelled / interrupted later (&quot;Ka-me-ha-me... - Ouch!&quot;), the emitter passed his own identifier.<br />It was a bit long ago, but I think I used the memory address of the calling class instance, stored as a void pointer. The code handling a game character would typically call <span class="source-code">play_sound<span class="k2">(</span><span class="s">"kamehama"</span>, <span class="k1">this</span><span class="k2">)</span></span>, or if the sound had to run to completion no matter what, it would be <span class="source-code">play_sound<span class="k2">(</span><span class="s">"boom"</span>, NULL<span class="k2">)</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 20 May 2016 21:04:35 +0000</pubDate>
	</item>
</rss>
