Closed Genbox closed 3 years ago
This is too much of a challenge to implement without any unwanted behavior. For now, the engine itself will pool aggressively for internal objects, but user objects will stay in userland. For large games, I suggest pooling bodies (etc.) manually.
Object pooling is an optimization method for reducing the load on garbage collectors. Velcro already makes heavy use of pooling for internal objects such as contacts. This proposal extends this capability to user objects such as Body, Shape and Fixture to further reduce the load on the garbage collector.
The proposal is to add an interface to all 'poolable' objects that contain a Reset() method. Each class will be responsible for providing their own implementation of Reset to make sure they have cleaned their internal state completely. Each user object will be extended with a Destroy() method as well, that can be called by the user when the object is no longer needed.
The factory classes will then be made 'pool' aware and fetch one from the pool rather than create a new object.
Advantages:
Disadvantages:
Misc:
Any comments, improvements or votes (thumbs up/down) are appreciated.