Can someone help me with Arrays and Structures?

I have no idea how to make Arrays and Structures work… id really appreciate some help, iv been doing some reading and i cant work this out in my brain :frowning:

Im trying to improve performance on my Minecraft style game by doing Object culling.

My idea is to delete objects that are off screen and recreate them if their position is almost in view.

My idea was to check if an object is out of view from the camera, then store their X Position into an Array and the same for their Y, into a different Array.

So far so good…

Then run a check if the X and Y value of the arrays are within the camera borders, if so then create the object using those values and remove the variables from the arrays…

The issue is how the heck do i check for those values inside the Arrays?

…or how do i tell GDevelop to remove those specific values it just used from the index?

Maybe im just being slow because its getting late, but i cant seem to find the expression i need to use, or maybe im just going about this all wrong…

Can someone help me understand all this? Any ideas how i can do this?

I almost got it working…

Theres something missing and im not sure what…

Its deleting all blocks out of view at the same time, but only building one at a time when in view… theres something funky i cant work out

Its kinda working… the issue is that its placing the tiles are the wrong values, no idea why…

Its lining up the tiles now, making chunks of them where originally there were no dirt tiles… this is driving me nutts lol

Culling is usually to avoid to iterate over everything. if you iterate over everything to do the culling, you’ll likely not see any benefit.
It’s not something that can be done with events.

1 Like

Yeah, i get it…

I went trough that with trying to disable the Platform behavior, the events were more expensive than leaving it on…

I figured the whole thing out anyways :slight_smile:

I can still do some testing to see how the whole thing goes.

At least i learned how to work with Arrays which is always a bonus :slight_smile:

Turns out what was missing was pairing the 2 arrays by checking their index and picking the 2 that have the same number!

I feel kinda smart now :stuck_out_tongue:

Just did some testing and the results are as Davy says, its bad…

Its always better to have all objects in the scene then it is to cull them with events…

On a small scale, no culling results in about 10ms, with the culling on only one set of tiles, its 12ms, so… no dice on the culling…

On a bigger scale, the events went up to 21ms, and again, thats just checking for one tile type, if i had made it check for all types im sure the game wouldnt even load lol

Oh well, this was a fun learning experience anyways, now i know how arrays work and can probably do some cool stuff with them!