I'm designing an AudioMixer
thing, and the way I currently have it designed is that calling mixer.play()
returns an AudioInstance
. When that AudioInstance
is dropped, the clip stops playing.
So far so good.
Now - what I'd like to do, is add a .pause_all()
method to AudioMixer
which will loop through all the instances and pause them.
This means the mixer now needs to also keep a reference to the instances - but I don't want it to count towards ownership. I.e. if AudioInstance
is dropped outside of the mixer, it should be properly dropped (and stop playing).
So I'm thinking that instead of play()
returning AudioInstance
, it will return Rc<AudioInstance>
and internally add a weak reference to an internal collection. Then pause_all()
will loop through all of these, and for all that are upgradeable, pause the clip.
I think, up until here, also fine... but here comes the question-
Do I need to clean up that collection? (i.e. do weak references cost much to just keep pushing to an ever-growing Vec
? like... I don't think the number would ever get past 10,000 or so)
If I do, I suppose it's not so bad... each instance could be given a unique id
and a reference to the collection, and clean itself up when dropped (a structure like beach_map could work here).. this might also be better overall since it gives me more power in the mixer API to do things by id, but just wondering if this is really necessary...