Skip to content

Commit

Permalink
pooling_object_set_reload_callback fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersonJales committed Sep 26, 2021
1 parent 5378b71 commit 924b698
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions objects/obj_pooling_objects/Other_4.gml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ var _pool = global.obj_pool_map[? room];

if(_pool == undefined){
_pool = ds_map_create();
ds_map_add(_pool, POOL_MAP_KEYS_ARR, []);
ds_map_add(_pool, POOL_MAP_KEYS_RELOAD, false);
ds_map_add(_pool, POOLING_OBJECTS_MAP_KEYS_ARR, []);
ds_map_add(_pool, POOLING_OBJECTS_MAP_KEYS_RELOAD, false);
ds_map_add_map(global.obj_pool_map, room, _pool);
}
else if(_pool[? POOL_MAP_KEYS_RELOAD]) {
_pool[? POOL_MAP_KEYS_RELOAD] = false;
var _keys_arr = _pool[? POOL_MAP_KEYS_ARR];
else if(_pool[? POOLING_OBJECTS_MAP_KEYS_RELOAD]) {
_pool[? POOLING_OBJECTS_MAP_KEYS_RELOAD] = false;
var _keys_arr = _pool[? POOLING_OBJECTS_MAP_KEYS_ARR];

var _per_obj_struct;
for(var _i = 0; _i < array_length(_keys_arr); _i++){
Expand Down
4 changes: 2 additions & 2 deletions objects/obj_pooling_objects/Other_5.gml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
/// Case the room is persistent,
/// we want to preserve the instances that are deactive
/// So, reactive all the instances, before room transition
var _keys = global.obj_pool_current[? POOL_MAP_KEYS_ARR];
var _keys = global.obj_pool_current[? POOLING_OBJECTS_MAP_KEYS_ARR];

if(room_persistent){
global.obj_pool_current[? POOL_MAP_KEYS_RELOAD] = true;
global.obj_pool_current[? POOLING_OBJECTS_MAP_KEYS_RELOAD] = true;

var _i = 0, _f = 0;
repeat(array_length(_keys)){
Expand Down
6 changes: 3 additions & 3 deletions scripts/__pooling_objects_system/__pooling_objects_system.gml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Made by @jalesjefferson
/// Github link -> https://github.com/JeffersonJales/pooling_objects

#macro POOL_MAP_KEYS_ARR "__keys_arr"
#macro POOL_MAP_KEYS_RELOAD "__reload_on_room_start"
#macro POOLING_OBJECTS_MAP_KEYS_ARR "__keys_arr"
#macro POOLING_OBJECTS_MAP_KEYS_RELOAD "__reload_on_room_start"
#macro POOLING_OBJECT_RELOAD_FUNC_VAR_NAME "__pooling_objects_reload_callback"

global.obj_pool_map = ds_map_create(); // The pool map, every object needing to be here, have a reference
Expand Down Expand Up @@ -45,7 +45,7 @@ function __pooling_objects_struct_by_object(obj_ind) constructor {

with(instance){
if(variable_instance_exists(id, POOLING_OBJECT_RELOAD_FUNC_VAR_NAME))
__pooling_objects_reload_func(); // The callback function set with pooling_object_set_reload_callback
__pooling_objects_reload_callback(); // The callback function set with pooling_object_set_reload_callback
else
event_perform(ev_create, 0); // Default reload from pool
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/scr_pooling_objects/scr_pooling_objects.gml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function pooling_objects_get_instance(obj_index){
/// Set up a callback function when getting an instance from the pool - Default is create_event
/// @param callback - Expects a function. Will be called on the instance scope.
/// @param instance - The instance
function pooling_object_set_reload_callback(callback, instance = self){
function pooling_object_set_reload_callback(callback){
if(is_method(callback)){
with(instance)
with(other)
variable_instance_set(id,
POOLING_OBJECT_RELOAD_FUNC_VAR_NAME,
method(id, callback));
Expand Down

0 comments on commit 924b698

Please sign in to comment.