G
GrandFree
Guest
I've got a room with about 3000 objects that are marked as optimizable (par_optimize).
So I've divided my room into chunks by creating a "chunk" object for each chunk (obj_optimize_chunk). Each chunk size is the same size as a view.
Each chunk object populates its lists of data for optimizable objects (par_optimize) that are within the chunk, and then if a view comes into contact with the chunk, it's considered active.
If a chunk object is active, it loops through its list of optimizable instances. If any of the instances are within any view and are currently deactivated, then they're set to active, if any of them aren't in any views and are currently activated, then they're set to deactive. I'm also making sure duplicates that cross paths with multiple chunks aren't being processed if they were already processed in the same frame.
It's **technically** working in the sense that it's deactivating/activating the correct number of instances. But it's not working in the sense that the FPS is dropping to extremely low levels. It's even worse when there's 4 views active and they're all near a large number of optimizable objects or if they're spread over entirely separate chunks.
If I leave all optimizable objects deactivated, I'll get around 1000 - 2000 FPS.
If I use this method and I only have 1 view active and only 300 objects are active, my FPS drops to around 80.
If I use this method and I have 4 views active and only 300 objects are active, my FPS drops to around 20. It gets to around 10 if the views are all in completely different chunks spaced far apart.
So yeah I'm honestly not sure what's slowing it down seeing as there aren't that many par_optimize objects even active.
Here's where I populate the chunk list data (cornerX and cornerY refer to the topleft of par_optimize's sprite to ensure any part of the sprite is checked if it's inside a chunk or view):
obj_optimize_chunk Create Event:
obj_optimize_chunk Begin Step Event:
par_controller Create Event:
par_controller End Step Event:
Why is my FPS dropping to such low levels despite the fact that there are a small number of objects (par_optimize) instances?
So I've divided my room into chunks by creating a "chunk" object for each chunk (obj_optimize_chunk). Each chunk size is the same size as a view.
Each chunk object populates its lists of data for optimizable objects (par_optimize) that are within the chunk, and then if a view comes into contact with the chunk, it's considered active.
If a chunk object is active, it loops through its list of optimizable instances. If any of the instances are within any view and are currently deactivated, then they're set to active, if any of them aren't in any views and are currently activated, then they're set to deactive. I'm also making sure duplicates that cross paths with multiple chunks aren't being processed if they were already processed in the same frame.
It's **technically** working in the sense that it's deactivating/activating the correct number of instances. But it's not working in the sense that the FPS is dropping to extremely low levels. It's even worse when there's 4 views active and they're all near a large number of optimizable objects or if they're spread over entirely separate chunks.
If I leave all optimizable objects deactivated, I'll get around 1000 - 2000 FPS.
If I use this method and I only have 1 view active and only 300 objects are active, my FPS drops to around 80.
If I use this method and I have 4 views active and only 300 objects are active, my FPS drops to around 20. It gets to around 10 if the views are all in completely different chunks spaced far apart.
So yeah I'm honestly not sure what's slowing it down seeing as there aren't that many par_optimize objects even active.
Here's where I populate the chunk list data (cornerX and cornerY refer to the topleft of par_optimize's sprite to ensure any part of the sprite is checked if it's inside a chunk or view):
obj_optimize_chunk Create Event:
Code:
// List of par_optimize objects in the chunk to avoid duplicates
optimizesID = ds_list_create();
optimizesDeactivated = ds_list_create();
optimizesRealX = ds_list_create();
optimizesRealY = ds_list_create();
optimizesWidth = ds_list_create();
optimizesHeight = ds_list_create();
checkAnyChunks = true; // Used to deactivate currently active par_optimize instances on first frame incase they aren't within the active chunk or any views
var thisChunk = id;
// Go through all par_optimize instances
with(par_optimize) {
var optimizeID = id;
// If the sprite rectangle is inside of the chunk then we add its data to the relevant chunk lists
if(rectangle_in_rectangle(cornerX, cornerY, cornerX+abs(sprite_width), cornerY+abs(sprite_height), thisChunk.x, thisChunk.y, thisChunk.x+thisChunk.width, thisChunk.y+thisChunk.height) > 0) {
ds_list_add(thisChunk.optimizesID, optimizeID); // add its ID
ds_list_add(thisChunk.optimizesDeactivated, false); // add whether or not it's deactivated
ds_list_add(thisChunk.optimizesRealX, cornerX); // add the top left corner of its sprite x value
ds_list_add(thisChunk.optimizesRealY, cornerY); // add the top left corner of its sprite y value
ds_list_add(thisChunk.optimizesWidth, abs(sprite_width)); // add its sprite width
ds_list_add(thisChunk.optimizesHeight, abs(sprite_height)); // add its sprite height
}
}
Code:
activeChunk = false;
for(var v = 0; v < global.split_screens; v++) {
// If this chunk object crosses any views, set it to active
if(!activeChunk && rectangle_in_view(x, y, x+width, y+height, v, 0)) {
activeChunk = true;
break;
}
}
// checkAnyChunks is set to true initially and then set to false here
// to deactivate objects outside the view(s), or else they won't ever be deactivated
// until you reach those chunks in your view(s)
if(activeChunk || checkAnyChunks) {
checkAnyChunks = false;
var optimizesSize = ds_list_size(optimizesID);
// Loop through the instance data for this chunk
for(var i = 0; i < optimizesSize; i++) {
var opID = ds_list_find_value(optimizesID, i);
var handledAlready = false;
// Check if the optimized instance ID is already in a handled list in par_controller
with(par_controller) {
handledAlready = (ds_list_find_index(optimizerHandled, opID) != -1);
}
// Another chunk has already processed this instance data for this frame, move on to the next
if(handledAlready) continue;
// Get the instance data
var deactivated = ds_list_find_value(optimizesDeactivated, i);
var opX = ds_list_find_value(optimizesRealX, i);
var opY = ds_list_find_value(optimizesRealY, i);
var opW = ds_list_find_value(optimizesWidth, i);
var opH = ds_list_find_value(optimizesHeight, i);
var inAnyView = false;
// Check if the instance's rectangle (x,y, x+width, y+height) is inside any views
for(var v = 0; v < global.split_screens; v++) {
if(rectangle_in_view(opX, opY, opX+opW, opY+opH, v, 0)) {
inAnyView = true;
v = global.split_screens;
}
}
// If the instance is in any views...
if(inAnyView) {
// If it's deactivated and inside any view, reactivate it
if(deactivated) {
instance_activate_object(opID);
ds_list_replace(optimizesDeactivated, i, false);
}
}
// If the instance is not in any views...
else {
// If the instance is activated, deactivate it
if(!deactivated) {
instance_deactivate_object(opID);
ds_list_replace(optimizesDeactivated, i, true);
}
}
// Mark this instance data as handled for this frame
// par_controller clears its optimizerHandled list in the End Step event
with(par_controller) {ds_list_add(optimizerHandled, opID);}
}
}
Code:
optimizerHandled = ds_list_create(); // Temporary list containing handled optimized instances for a frame
Code:
ds_list_clear(optimizerHandled); // Clear the list, gets reset on every new frame
Why is my FPS dropping to such low levels despite the fact that there are a small number of objects (par_optimize) instances?