MVC & sounds

Writing my 1st game at the moment. I know Java well but not writing games. I’ve implemented a MVC pattern and all is working well.

My model get’s ticked every game frame and my renderers get told to draw every frame. The renderers get asked to draw every frame. They query the model for it’s current state and draw it.

Is this a common/good implementation model?

I’m planning on implementing sounds next. I’m thinking of making my model fire synchronous events for things that happen. A ‘SoundRenderer’ will listen to these events, and decide on what sounds to play.

Is this a common/good implementation model?

thanks, D.

I am using MVC too, and I definitly think it is the way to go.

What sound concerns, I was wondering about that too? In my opinion sound is pretty much related to the view. So, you add remove/change items in the view - you output a sound for it.

Advantage: It’s easy to maintain - add one line of code (e.g. “SoundPlayer.play();”) to wherever you need it based on display changes. Usually I have 100+ lines of GUI code and 1 line of sound player code - which does not bloat the GUI/view. Also it makes synchronization between sound & view easier.

Disadvantage: ??? - I am not sure if there is one? You should program SoundPlayer so it runs in a separate thread to not block your GUI. I.e. SoundPlayer.play() just adds a new song to play to the sound player thread. “play(<…>)” should return immediately.

Yeah my sound support would essentially be a view. It would work in a different way though as my renderer “view” polls the model everytime it is ticked for the current state, whereas the sound “view” will be event driven - ie it listens to events from the model.

I think I’m happy with this implementation, I just thought I’d throw it out there for comments.

D.

When considering overall design direction sound has been a consideration for me. One worry I have had about using a separate sound thread would be sync. If you’re just talking about changing background sound tracks and such it’s probably safe, but sound effects that are off by even a little bit are often far more noticable than a skipped frame in my opinion.

It sounds ( no pun ) like you have a safe design. If the sound thread is doing nothing more than watching for request events and processing requested sounds then it shouldn’t be too burdened. But how well does it manage multiple sounds? if you have a soundtrack playing, a couple seconds of dialog going and suddenly something requests rocket_launched.wav followed almost immediately by explosion.wav do you have the sound effects preempt the dialog or layer over it?