Assuming the underlying low level audio logic is encapsulated in some outside class... what is the best way to add audio effects to a component-based entity framework?
I am taking the approach that entities are just IDs and a type of database is used to associate components with entity IDs. The I can create masks for the systems to query particular types from the database.
So for example for components I might have:
And the corresponding systems:
VisualSystem, which processes visual components, hands off to outside renderer.
PhysicsSystem, which processes physics, updates position vectors.
So the question is, how best to add audio to this system... or should I even bother? The problem I am having is mapping sounds to actions and when to play sounds.
Here are some approaches I've thought of::
PhysicsComponents to have a some collision sound field and when a collision occurs, play the sound within the physics system.
Same as 1 but instead when a collision is detected add a
SoundComponent(sound)to the entity and lets the
SoundSystemsee that and consume it (so the sound plays once for example). This still means
PhysicsComponentwould have a sound field. So really this just shifts the playing of audio into a system.
I don't like either of those approaches. They are not very suitable to expanding the game either. Now I would need a field for every possible sound a unit could generate.
Really I think individual entities should dictate which sound to play based on some component attached to them I would assume. The question then becomes how to know when to play that sound.
Sorry if this is all very vague. Any tips appreciated.