Core. Pool

Pool Is the object pool class used for object storage and reuse.

The rational use of object pooling can effectively reduce the overhead of object creation and avoid frequent garbage collection, thus optimizing the game fluency.

Constructor

new Pool()

Methods

clearBySign(sign)

Objects that clear the object pool.
Parameters:
Name Type Description
sign String Object type identifier character.

getItem(sign) → {Object}

Identifies characters based on an incoming object type, gets an object of this type that has been stored in the object pool, and returns NULL if there is no object of this type in the object pool.
Parameters:
Name Type Description
sign String Object type identifier character.
Returns:
Type:
Object
An object of this type in the object pool, which returns NULL if there is no object of this type in the object pool.

getItemByClass(sign, cls) → {Object}

Identifies characters based on incoming object types, and gets an object instance of this type identifier in the object pool.

When an object without this type is identified in the object pool, a new object is returned based on the incoming type.

Parameters:
Name Type Description
sign String Object type identifier character.
cls Class The class used to create the type object.
Returns:
Type:
Object
An object that is identified by this type.

getItemByCreateFun(sign, createFun) → {Object}

Identifies characters based on incoming object types, and gets an object instance of this type identifier in the object pool.

When an object without this type is identified in the object pool, a new object is returned by using the function of the incoming creation of this type object.

Parameters:
Name Type Description
sign String Object type identifier character.
createFun function Method for creating the type object.
Returns:
Type:
Object
An object that is identified by this type.

getPoolBySign(sign) → {Array}

Gets the object pool by identifying characters based on the object type.
Parameters:
Name Type Description
sign String Object type identifier character.
Returns:
Type:
Array
Object pooling.

recover(sign, item)

Objects are placed in the object pool of the corresponding type identifier.
Parameters:
Name Type Description
sign String Object type identifier character.
item Object Object.