Archived

This topic is now archived and is closed to further replies.

Austrian Coder

which design is better?

Recommended Posts

Austrian Coder    122
Hi everybody... since a long time i am working on my first engine. Now i have there a little problem. Is it better to make ist like this: // ================================== // a single sound or fx class CSound { public: int channel; FMUSIC_MODULE *mod; FSOUND_STREAM *stream; bool is3d; // is this a 3d sound? }; // ================================== // the soundsystem class CSoundSystem { private: Array sound; CVector3 ListenerLastPos; CVector3 ListenerPos; bool fmodOk; public: CSoundSystem(); virtual ~CSoundSystem(); bool Init(SoundSystem SoundSystemType, int Driver = 0, int MixRate = 44100); CSound* Load(String Filename bool Is3D; bool Play(CSound* sound); void Stop(CSound* sound); void Delete(CSound* sound); void Pause(CSound* sound); void Update(float TimeDelta); // for 3D-Sound ... lot of other stuff ... }; extern CSoundSystem* gSoundSystem; Then I use it like this: CSound* Background = gSoundSystem->Load("background.mp3", false); gSoundSystem->SetVolume(Background, 50); Or is it better to make only a CSound class and it can handle everything by itselfe? like: CSound Background; Background->Load("background.mp3", false); Background->SetVolume(50); Thanks, Austrian Coder

Share this post


Link to post
Share on other sites
Red Ghost    368
I would prefer the first approach but a little more refined:
To me a sound is responsible of its own playing. I would add the play and pause method to your CSound class. Your sound class will not only hold background music but also sound effects (laser sound, dog bark, whatever ...). Thus when you update your agent model to the state HIT_BY_LASER (just an example), you can call the Laser sound object and tell it to play itself.

Hope that helps.
Ghostly yours,
Red.

Share this post


Link to post
Share on other sites
shaft    126
You almost have the manager pattern. If you plan on "managing" more than 1 sound, use the manager pattern (similar to your first approach).

Share this post


Link to post
Share on other sites