-
Notifications
You must be signed in to change notification settings - Fork 1
base_pool
Class Name: COP_Pool
Inherits: Node
Inherited By: pool_global, pool_local
Base class for all the pool object manager.
base_pool is the parent/base class for all the pool object manager. This script uses the pool system to pre-load objects in the memory and later share those pool objects. This saves performance by sharing the same object over and over rather than creating new objects during run time.
The pool object manager is also an update object. This means the pool object manager is updated by the base_update_manager. It is also an auto setup object as well which means certain setup will be done in the editor mode.
The script is designed in a way that every new pooling object manager type will need to extend from base_pool. That way it will be easier to keep the pooling object managers organized and having common parent. This will also help in making sure that new/current pooling object managers can be just dragged and dropped into other scripts and it will work no matter what type of a pooling object manager is used, SOLID principles.
Type | Name | Default Value |
---|---|---|
COP_PoolHelper | _helper | |
COP_FixedBoolVar | _is_enable_at_start | |
Array[Node] | _p_objects | |
Node | _pool_object_holder | |
int | _p_index_object | |
Array[Node] | _requests | |
Node | _object_cur | |
int | _pointer_pool_object | -1 |
bool | _is_active | false |
Return Type | Name |
---|---|
void | _ready() |
void | update( float delta ) |
void | set_active( bool is_enable ) |
bool | is_active() |
void | auto_setup() |
void | add_requests( Node object ) |
void | _p_setup_object_pool() |
bool | _p_is_pool_object( Node object ) |
bool | _p_is_pool_object_available( Node object ) |
Object | _get_pool_object() |
void | _process_request( Node object ) |
void | _add_self_to_manager() |
bool | _is_update_object() |
bool | _is_auto_setup_object() |
bool | _is_pool_manager() |
COP_PoolHelper _helper
This is the property that stores the reference to this pool object manager so that other scripts can use this pool object manager by using the resource reference only. This is helpful in a way that the user do NOT need to go around search for which node object in the scene contains the pool object manager. They can just set the cop_pool_manager_helper resource reference.
Note: Any class that contains the word _helper means it is the script that stores a reference of itself into the _helper properties. Other scripts wanting to use this reference resource should name the property _manager or _manager_somethingelse. This is just my convention.
COP_FixedBoolVar _is_enable_at_start
This flag enables/disables the pool object manager when the scene starts. If true then the pool manager object will start working when the scene starts. If false then the pool manager object will NOT work when the scene starts.
Note: You can also enable/disable the pool object manager during run time by calling the method set_active().
These are the pool objects that will be shared and with other scripts. For an object to be considered as a pool object it MUST be child of Node. This means Node2D, Node3D, Area3D etc. can all be considered as pool object because they all are children of Node.
Node _pool_object_holder
This is the Node from which all the pool objects will be loaded into the _p_objects array. Basically this means that this Node contains all the pool objects for this pool object manager.
int _p_index_object = 0
This index is used for populating the _p_objects array with pool objects.
This property stores all the pooling requests from other scripts. The request is for sending other scripts a pool object. The pool object manager goes through all the requests till this array is empty. See the method add_request() for more details.
Node _object_cur
This property stores a request from the _requests array which is later used for processing. By processing it means other logic will use this property to send back the requested pool object to the correct script object. See the method _process_request() for more details.
int _pointer_pool_object = -1
This is the index which points to the next available pool object. See the method _get_pool_object() for more details.
bool _is_active = false
This flag is used to enable/disable the pool object manager. When the flag is true means the pool object manager is enabled. When the flag is false means the pool object manager is disabled. See the method set_active() for more details.
This is the method where all the setup happens for the pool object manager.
Note: If the child classes requires to use the _ready() method then make sure the child class calls the parent class', super class', _ready() method as well. This is to avoid any unwanted results.
void update ( float delta )
This is the main method where the logic of the pool object manager works. This method is called per frame or depending on the pool object manager setting.
void set_active ( bool is_enable )
This method enables/disables the pool object manager. When a true flag is sent then the pool object manager will be enabled. Whan a false flag is sent then the pool object manager will be disabled. This method can be called during runtime.
bool is_active ()
This method checks if the pool object manager is active or NOT. It is checked by the base_update_manager to see if to call the update() method of the pool object manager.
This method does the auto setup which is done by the Automation logic. In the pool object manager the auto setup will make the Node holding the script base_pool into _pool_object_holder. Then it will try to find all the pool objects in that Node and then add them to the _p_objects array if any pool object exists.
void add_requests ( Node object )
This method adds a pool object request. Scripts that wants to get a pool object must call this method. The requesting object must be a child of Node. The obejct parameter must be the script requesting for the pool object.
This method sets up the pool objects which is it populates the array _p_objects with pool objects.
This method checks if the object is pool object. This method can be overridden by child scripts to give different logic to check if the object is pool object.
Note: This method always returns true for base_pool script.
This method checks if the pool object is available to be shared. True means available to be shared. False means NOT available to be shared. If NOT available to be shared then the pool object manager will skip this pool object and will come back later to check if the object is available or NOT. This method can be overridden by child scripts to give different logic to check if the pool object is available or NOT.
Note: This method always returns true for base_pool script.
Object _get_pool_object ()
This method gets the available pool object. Everytime this method is called the pointer _pointer_pool_object will point to the next pool object to return.
void _process_request ( Node object )
This method process' the request. It will send the first available pool object to the script that requested it first. If a pool object is NOT available then the pool object manager will keep waiting for a pool object to be available for the current request. Basically it uses FIFO process.
This method adds the pool object manager to the update manager.
Note: This method is a stub method and needs to be overridden by the child script if this method is needed by the child script.
bool _is_update_object ()
This method checks if the pool object manager is an update object, which it is, and always returns true. This is needed by the Automation logic to use duck typing to check if the object is an update object.
Note: This method should NOT be overridden or changed because it is used by the Automation logic to check if the object is an update object.
bool _is_auto_setup_object ()
This method checks if the pool object manager is an auto setup object, which it is, and always returns true. This is needed by the Automation logic to use duck typing to check if the object is an auto setup object.
Note: This method should NOT be overridden or changed because it is used by the Automation logic to check if the object is an auto setup object.
bool _is_pool_manager ()
This method checks if the object is a pool object manager, which it is, and always returns true. This method is needed for duck typing check and should NOT be overridden or changed.
- Tutorial Bar
- Tutorial Debug
- Tutorial Instantiate Object
- Tutorial Pool
- Tutorial Timer
- Tutorial Update Manager
- Tutorial Variable Creator
- Bars
- Debugs
- Maths
- Pools
- Resources
- Fixed Vars
- Managers
- Observers
- Vars
- Script Templates
- Timers
- Updates