from direct.showbase.Pool import Pool
Pool is a collection of python objects that you can checkin and checkout. This is useful for a cache of objects that are expensive to load and can be reused over and over, like splashes on cannonballs, or bulletholes on walls. The pool is unsorted. Items do not have to be unique or be the same type.
Internally the pool is implemented with 2 lists, free items and used items.
p = Pool([1, 2, 3, 4, 5]) x = p.checkout() p.checkin(x)
- class Pool(free=None)¶
- __init__(self, free=None)¶
- add(self, item)¶
Add an item to the free list.
- checkin(self, item)¶
Put back a checked out item. Error if the item is not checked out.
Get an arbitrary item from the pool.
- cleanup(self, cleanupFunc=None)¶
Completely cleanup the pool and all of its objects. cleanupFunc will be called on every free and used item.
Returns the number of free items and the number of used items.
Returns true if there is at least one free item.
- isFree(self, item)¶
Returns true if this item is free for check out.
- isUsed(self, item)¶
Returns true if this item has already been checked out.
- notify = <direct.directnotify.Notifier.Notifier object>¶
- remove(self, item)¶
Remove an item. Error is flagged if the item is not in the pool.
Resets the pool so all items are free.