|
globally available functions and resources |
Ariesnl
Member #2,902
November 2002
|
I'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.
What would you do, and why ? Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
GullRaDriel
Member #3,861
September 2003
|
Variable and function in a namespace if you want to stick to C++ style, In ANY case, not a singleton one. Why ? Because it looks awful. If I were doing it in C++ I would go with #1 as it's the case which will allow the best control over the api when mixed with other api's. "Code is like shit - it only smells if it is not yours" |
Audric
Member #907
January 2001
|
If there's one of those patterns that you've not practiced, it may be an opportunity to try. In this case, you can't shoot yourself in the foot : the sound system depends on a unique resource which is your PC's sound output, you are not likely to suddenly need multiple concurrent sound systems. Otherwise, I would use whatever looks the most like the neighboring code. |
Mark Oates
Member #1,146
March 2001
|
For a sound manager, I would probably go with an object, something like this: 1class Sound
2{
3private:
4 class SoundRecord
5 {
6 public:
7 std::string identifier;
8 ALLEGRO_SAMPLE *sample;
9 // ...
10 };
11 std::vector<SoundRecord *> samples;
12
13public:
14 // some methods like...
15 bool preload(std::string identifier, std::string filename);
16 void play(std::string identifier);
17 void start_stream(std::string identifier);
18 void fade_out(std::string identifier, float speed);
19 // ...
20};
Focus on the interface you want more than anything else. -- |
Ariesnl
Member #2,902
November 2002
|
It is gonna use allegro anyway.. I also noticed you cannot compare sampleIDs ... ?? Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
Audric
Member #907
January 2001
|
Last time I had such need, I linked it the opposite way : If an emitted sound could be cancelled / interrupted later ("Ka-me-ha-me... - Ouch!"), the emitter passed his own identifier. |
|