Packagecitrus.datastructures
Classpublic class PoolObject
InheritancePoolObject Inheritance DoublyLinkedList Inheritance Object
Subclasses Box2DObjectPool, CitrusObjectPool, CitrusSpritePool, NapeObjectPool

Object pooling is a data structure based on a simple observation : the ‘new’ operator is costly, memory allocation necessary for the object creation is a slow process. And Garbage Collection too! So object pooling idea is really simple : - create lots of object at the beginning of your level, if there is FPS reduction it shouldn't be a big problem. - if you need more objects during the game create many of them that can be use later. - destroy your object if you don’t need it anymore, but keep a link to it! So it will be reassign! - destroy all your objects and set them to null at the end of your level (garbage collector will work).



Public Properties
 PropertyDefined By
  allSize : uint
[read-only] returns the amount of free objects and objects in use.
PoolObject
 Inheritedhead : DoublyLinkedListNode
DoublyLinkedList
  isCitrusObjectPool : Boolean
[read-only] return true if the Pool is composed of Physics/CitrusSprite, false for SpriteArt/StarlingArt
PoolObject
  length : uint
[override] [read-only] returns the amount of objects currently in use.
PoolObject
  onCreate : Signal
dispatches a Signal with a newly created object of type _pooType.
PoolObject
  onDestroy : Signal
dispatches a Signal with an object of type _pooType before its destruction.
PoolObject
  onDispose : Signal
dispatches a Signal with the disposed object of type _pooType.
PoolObject
  onRecycle : Signal
dispatches a Signal with a recycled object of type _pooType.
PoolObject
  poolSize : uint
[read-only] returns the amount of free objects.
PoolObject
  recycledSize : uint
[read-only] returns the amount of objects currently in use.
PoolObject
 Inheritedtail : DoublyLinkedListNode
DoublyLinkedList
Protected Properties
 PropertyDefined By
 Inherited_count : uint
DoublyLinkedList
  _defaultParams : Object
PoolObject
  _freeCount : uint = 0
PoolObject
  _freeListHead : DoublyLinkedListNode = null
PoolObject
  gc : Vector.<DoublyLinkedListNode>
PoolObject
  _isCitrusObjectPool : Boolean
PoolObject
  _poolGrowthRate : uint = 0
PoolObject
  _poolSize : uint = 0
PoolObject
  _poolType : Class
PoolObject
Public Methods
 MethodDefined By
  
PoolObject(pooledType:Class, defaultParams:Object, poolGrowthRate:uint, isCitrusObjectPool:Boolean)
An implementation of an object Pool to limit instantiation for better performances.
PoolObject
 Inherited
Append an object to the list.
DoublyLinkedList
 Inherited
Append a node to the list.
DoublyLinkedList
  
clear():void
Completely destroy all the content of the pool (the free objects) and "unlink" from recycled object.
PoolObject
 Inherited
content():String
DoublyLinkedList
  
destroy():void
after clearing, just get rid of signals etc...
PoolObject
  
disposeAll():void
Discard all currently used objects and send them all back to the free list
PoolObject
  
dispose of data object to the pool.
PoolObject
  
Discard a now useless object to be stored in the free list.
PoolObject
  
foreach(callback:Function):Boolean
loops through all nodes and applies callback (both recycled and free objects will be affected)
PoolObject
  
foreachDisposed(callback:Function):Boolean
loops through all disposed nodes and applies callback (only free objects will be affected)
PoolObject
  
foreachRecycled(callback:Function):Boolean
loops through all recycled nodes and applies callback (only objects currently in use will be affected)
PoolObject
  
get(params:Object = null):DoublyLinkedListNode
Get an object from the free list and returns the node holding it in its data property.
PoolObject
  
Get a node from its data
PoolObject
  
initializePool(poolSize:uint = 1):void
Call initializePool to create a pool of size _poolSize.
PoolObject
  
isDataDisposed(data:*):Boolean
check if object is free
PoolObject
  
killAll():void
PoolObject
 Inherited
Prepend an object to the list.
DoublyLinkedList
 Inherited
Prepend a node to the list.
DoublyLinkedList
 Inherited
DoublyLinkedList
 Inherited
Remove a node from the list and return its data.
DoublyLinkedList
 Inherited
DoublyLinkedList
  
updateArt(stateView:ACitrusView):void
PoolObject
  
updatePhysics(timeDelta:Number):void
PoolObject
Protected Methods
 MethodDefined By
  
_create(node:DoublyLinkedListNode, params:Object = null):void
override to create your custom pooled object differently.
PoolObject
  
override to destroy your custom pooled object differently.
PoolObject
  
override to dispose your custom pooled object differently.
PoolObject
  
_recycle(node:DoublyLinkedListNode, params:Object = null):void
override to recycle your custom pooled object differently.
PoolObject
  
increasePoolSize(sizeIncrease:uint, params:Object = null):void
Create new objects of the _poolType type and dispose them instantly in the free list for future needs.
PoolObject
  
mergeParams(newParams:Object):Object
returns a new params object where newParams adds or overwrites parameters to the default params object defined in the constructor.
PoolObject
Property Detail
_defaultParamsproperty
protected var _defaultParams:Object

_freeCountproperty 
protected var _freeCount:uint = 0

_freeListHeadproperty 
protected var _freeListHead:DoublyLinkedListNode = null

_isCitrusObjectPoolproperty 
protected var _isCitrusObjectPool:Boolean

_poolGrowthRateproperty 
protected var _poolGrowthRate:uint = 0

_poolSizeproperty 
protected var _poolSize:uint = 0

_poolTypeproperty 
protected var _poolType:Class

allSizeproperty 
allSize:uint  [read-only]

returns the amount of free objects and objects in use.


Implementation
    public function get allSize():uint
gcproperty 
protected var gc:Vector.<DoublyLinkedListNode>

isCitrusObjectPoolproperty 
isCitrusObjectPool:Boolean  [read-only]

return true if the Pool is composed of Physics/CitrusSprite, false for SpriteArt/StarlingArt


Implementation
    public function get isCitrusObjectPool():Boolean
lengthproperty 
length:uint  [read-only] [override]

returns the amount of objects currently in use.


Implementation
    public function get length():uint
onCreateproperty 
public var onCreate:Signal

dispatches a Signal with a newly created object of type _pooType.

onDestroyproperty 
public var onDestroy:Signal

dispatches a Signal with an object of type _pooType before its destruction.

onDisposeproperty 
public var onDispose:Signal

dispatches a Signal with the disposed object of type _pooType.

onRecycleproperty 
public var onRecycle:Signal

dispatches a Signal with a recycled object of type _pooType.

poolSizeproperty 
poolSize:uint  [read-only]

returns the amount of free objects.


Implementation
    public function get poolSize():uint
recycledSizeproperty 
recycledSize:uint  [read-only]

returns the amount of objects currently in use.


Implementation
    public function get recycledSize():uint
stateproperty 
citrus_internal var state:IState

Constructor Detail
PoolObject()Constructor
public function PoolObject(pooledType:Class, defaultParams:Object, poolGrowthRate:uint, isCitrusObjectPool:Boolean)

An implementation of an object Pool to limit instantiation for better performances. Though you pass the Class as a parameter at the pool creation, there's no way for it to send you back your object correctly typed If you want that, reimplement the Pool class and the DoublyLinkedListNode for each of your pool or port these files to Haxe with Generics ! WARNING : Be sure to design your pooled objects with NO constructor parameters and an 'init' method of some kind that will reinitialized all necessary properties each time your objects are 'recycled'. WARNING : Remember to cast your objects in the correct type before using them each time you get one from a DoublyLinkedListNode.data !!!

Parameters
pooledType:Class — the Class Object of the type you want to store in this pool
 
defaultParams:Object — default params applied to newly created objects (important for physics)
 
poolGrowthRate:uint — the number of object to instantiate each time a new one is needed and the free list is empty
 
isCitrusObjectPool:Boolean — a boolean, set it to true if the Pool is composed of Physics/CitrusSprite, set it to false for SpriteArt/StarlingArt
Method Detail
_create()method
protected function _create(node:DoublyLinkedListNode, params:Object = null):void

override to create your custom pooled object differently.

Parameters

node:DoublyLinkedListNode
 
params:Object (default = null)

_destroy()method 
protected function _destroy(node:DoublyLinkedListNode):void

override to destroy your custom pooled object differently.

Parameters

node:DoublyLinkedListNode

_dispose()method 
protected function _dispose(node:DoublyLinkedListNode):void

override to dispose your custom pooled object differently.

Parameters

node:DoublyLinkedListNode

_recycle()method 
protected function _recycle(node:DoublyLinkedListNode, params:Object = null):void

override to recycle your custom pooled object differently.

Parameters

node:DoublyLinkedListNode
 
params:Object (default = null)

clear()method 
public function clear():void

Completely destroy all the content of the pool (the free objects) and "unlink" from recycled object. (called automatically by the state)

destroy()method 
public function destroy():void

after clearing, just get rid of signals etc...

disposeAll()method 
public function disposeAll():void

Discard all currently used objects and send them all back to the free list

disposeFromData()method 
public function disposeFromData(data:*):DoublyLinkedListNode

dispose of data object to the pool.

Parameters

data:*

Returns
DoublyLinkedListNode
disposeNode()method 
public function disposeNode(node:DoublyLinkedListNode):DoublyLinkedListNode

Discard a now useless object to be stored in the free list.

Parameters

node:DoublyLinkedListNode — the node holding the object to discard

Returns
DoublyLinkedListNode
foreach()method 
public function foreach(callback:Function):Boolean

loops through all nodes and applies callback (both recycled and free objects will be affected)

Parameters

callback:Function — gets node.data for argument.

Returns
Boolean
foreachDisposed()method 
public function foreachDisposed(callback:Function):Boolean

loops through all disposed nodes and applies callback (only free objects will be affected)

Parameters

callback:Function — gets node.data for argument.

Returns
Boolean
foreachRecycled()method 
public function foreachRecycled(callback:Function):Boolean

loops through all recycled nodes and applies callback (only objects currently in use will be affected)

Parameters

callback:Function — gets node.data for argument.

Returns
Boolean
get()method 
public function get(params:Object = null):DoublyLinkedListNode

Get an object from the free list and returns the node holding it in its data property. It will be reinitialize inside this function. You may need to cast it.

Parameters

params:Object (default = null) — It calls an initialize method. If the pool _isCitrusObjectPool is true, it calls the CitrusObject initialize method.

Returns
DoublyLinkedListNode — A node holding the newly 'recycled' object
getNodeFromData()method 
public function getNodeFromData(data:*):DoublyLinkedListNode

Get a node from its data

Parameters

data:* — node's data

Returns
DoublyLinkedListNode — the node
increasePoolSize()method 
protected function increasePoolSize(sizeIncrease:uint, params:Object = null):void

Create new objects of the _poolType type and dispose them instantly in the free list for future needs. Called once at the pool creation with _poolSize as a parameter, and once with _poolGrowthRate each time a new Object is needed and the free list is empty.

Parameters

sizeIncrease:uint — the number of objects to instantiate and store in the free list
 
params:Object (default = null)

initializePool()method 
public function initializePool(poolSize:uint = 1):void

Call initializePool to create a pool of size _poolSize. all objects will instantly be created and disposed, ready to be recycled with get(). you have the option of not initializing the pool in which case the first get will return a new object and will grow the pool size according to the growth rate.

Parameters

poolSize:uint (default = 1)

isDataDisposed()method 
public function isDataDisposed(data:*):Boolean

check if object is free

Parameters

data:*

Returns
Boolean
killAll()method 
public function killAll():void

mergeParams()method 
protected function mergeParams(newParams:Object):Object

returns a new params object where newParams adds or overwrites parameters to the default params object defined in the constructor.

Parameters

newParams:Object

Returns
Object — Object
updateArt()method 
public function updateArt(stateView:ACitrusView):void

Parameters

stateView:ACitrusView

updatePhysics()method 
public function updatePhysics(timeDelta:Number):void

Parameters

timeDelta:Number