Building the object pool for Mach5
Now that we've seen an object pool in action, let's next learn how we can integrate the Object Pool pattern into the Mach5 game engine. Since we are creating a shooter game, one of the things that we spawn a lot during gameplay are the laser bullets from our ship, which makes it perfect for using object pool functionality. And unlike the previous examples, we'll see a version of the object pool that will not need to use pointers to access the pool, and we'll not have to worry about the pool being created. To do this, we'll need to make some adjustments to the starter project. First, we are going to need to change how our bullets are destroyed.
If you go into the Bullet.ini
file located at Mach5-master\EngineTest\EngineTest\ArcheTypes
, you'll see the following:
posX = 0 posY = 0 velX = 0 velY = 0 scaleX = 2.5 scaleY = 2.5 rot = 0 rotVel = 0 components = GfxComponent ColliderComponent OutsideViewKillComponent [GfxComponent] texture = bullet.tga drawSpace ...