Implementing a basic object pool
Let's first start off by creating an object pool for a simple class that we can create multiples of:
class GameObject { private: // Character's health int currentHealth; int maxHealth; // Character's name std::string name; public: GameObject(); void Initialize(std::string _name = "Unnamed", int _maxHealth = -1); std::string GetInfo(); };
So, this sample GameObject
class contains a name of the object to identify it by and some example properties to make the class seem more game-object-like. Obviously, you can easily add more properties and the same principles apply. In this case, we have a function called Initialize
, which provides both a set
and reset
of values for the class. Finally, I added in a GetInfo
function to print out information about the class so we can verify that things are working correctly.
The implementation for the class will look something like this:
/*****************************************************...