luxeengine / alpha

alpha - deprecated 2015~2016. unrelated to the new engine! view the new engine here - https://luxeengine.com/
MIT License
565 stars 74 forks source link

structural; Pool; missing a way to return to pool #293

Closed davisable closed 8 years ago

davisable commented 9 years ago

So the luxe.structural.Pool implementation has a create/new and get method but, unless I'm missing something, there's no way to return items to the pool after they've been used.

I think this is essential for a Pool implementation.

ruby0x1 commented 9 years ago

Actually the implementation is more specifically a type of cyclic cache (which I'm sure you can see) rather than a dead pool.

I have been meaning to add more flexibility as different types (and name them more accordingly).

Since the usage patterns for other types of pools are more specific, Do you have any specific usage pattern suggestions to put forward?

davisable commented 9 years ago

I come from a Unity3d background and the pool systems in use there were mostly similar -- instantiating is expensive in Unity so basically in something like this [1], after 'getting'/firing the projectile and the projectile hits something, instead of destroying the projectile sprite, you'd make it no longer visible then return it to the pool with a "Recycle" method so it can be reactivated and used.

Another feature that's common in pool implementations I've seen is to auto-grow the pool (by instantiating more pool items) if you attempt a get() after all pool elements are already used.

[1] https://gist.github.com/underscorediscovery/218decd48cc54890cc22

ruby0x1 commented 9 years ago

Right ok - so that's pretty much what I had in mind for one of the other variations.

It may make sense to make these a type of "configuration" for the pool within the existing implementation, we'll have to see if that convolutes it too much.

Thanks for the feedback!