screwdriver-wrenchUtil

A utility module for GameModule (in plugin context too)

pool

Object pooling is to cache instances or objects to be reused later This can be used to reduce object creation and increase performance (exponentially)

local pool = util.pool
local partpool = pool.new("void", 5, template):expand(20)
-- a part pool of 20 parts, and will create 5 parts everytime it runs out

"void" here is a preset function that create template and hides them in the void when cached "adornment" is another preset that creates adornments and caches/hides them with .Visible

Member

.t

A table of preset functions

.new(string|function, number?, ...)

Creates a new pool using preset or function

local customObjectPool = pool.new(function(obj, taking)
    if obj then
        obj.Visible = taking -- show when object is used, hide when not
        return
		end
			
		-- if no obj then create and return
		return createObject()
end, 5):expand(10)
Method
Description

:expand(number?): self

Creates more objects (number | expansion | 1)

:give(object)

Puts object in the pool to be used later

:take(): object

Takes an object from the pool

:clear()

Clears all objects in the pool (destroys)

Property
Description

.free

All free objects in the pool (ready to be used)

.busy

All the objects that were taken with :take() and not given back

.expansion

If :take() is called and there are no free objects, it will :expand(expansion)

Last updated