I am building a game where I need top handle A LOT of sound effects. I created an object pool for the effects to be able to reuse them. My problem is how I should write a nice pool solution without having to create a pool for each sound type. The checkout function of the pool returns the first sound in the list.
This little dirty solution checks if the item we borrow from the pool has the same sound that I want to create. If it is the same sound, I don´t create the sound again. If it is not, I create it even if I know there are instances of the correct sound in the pool.
var item : ISoundItem = _soundPool.checkOut();
if(item.name != name)
item.create(name, _soundFactory.create(name), config);
This dirty solution has reduced my instances to about seven instances from being hundreds, but I think I can optimize it even more.
I have been thinking of passing the sound name to the checkout function, but is it really worth having to loop through the pool each time?
Any ideas?