Using my new object pooling system

So I sat down today to start to actually use the new object pooling system I created last time. I realised pretty quickly that my ComponentPool was poorly named since I also wanted to pool my Bullets (which are GameObjects).

Also, my BulletObjects are currently responsible (during their Update function) for checking to see if they need to mark themselves as inactive. The BulletManager then polls each BulletObject to see if it’s been listed as inactive. However with my new object pooling the BulletManager doesn’t actually have access to the array of BulletObjects – just the BulletObject pool that I added.

The object pool class also stores an array of bools to keep track of which elements are active. So, what is the best way for my BulletObject pool to work out that a BulletObject is no longer active?

Some quick thoughts – I could set up some sort of Visitor pattern for the object pool so I can send custom functions in? But the Visitor pattern has always felt rather messy and a bit like it’s cheating OOP. Then perhaps an Event class that acts similar to Events in C#? (Hey, I work in C# all day). This example looks promising. The the BulletManager could handle the event and call the object pool’s Destroy method for the BulletObject that triggered the event.

I think I’m leaning towards the Event implementation, but I’d be curious to hear other ideas!

Advertisements

One thought on “Using my new object pooling system

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s