Search code examples
c#multidimensional-arraysimulationgame-developmentmonogame

Divide a 2d array into another 2d arrays


I am trying make a falling sand simulation game something like Noita.

and I need to figure out how they divided Noita's world into chunks 'since that's what the devs said in theyr gdc talk for optimizing the world' and I am not sure on how they did that.

I also found this person called "MARF" on youtube:

https://www.youtube.com/watch?v=5Ka3tbbT-9E&list=PLn0iQu83pjfaNwbpEGbn0orKQHbKeD81p&index=2&t=1140s&ab_channel=MARF

in "17:35" he says that he divided the world into chunks and He didn't even show how he did it.

so does someone know how to do this?

I thought of using the Array.copy function to copy every 16 x 16 bit into a new array and then I add it into a List of 2d arrays and then Updating everychunk needed. but this method is supported for only 1d arrays. :/

I alsow tried making 16 x 16 worlds as chunks and then offsetting them.. I couldn't offset the arrays properly and it would be a nightmare to figure out how to move elements between chunks.


Solution

  • You are asking the wrong questions.

    Please look up "quad trees" on google.

    Not great for moving objects, but good for static 2D worlds.


    The idea of a chunk is to divide the word into smaller parts.

    By dividing the screen into smaller units as an array for moving objects, collisions can be limited to those array values near the object in question.


    A chunk is simply an array where the dimensions are reduced by a fixed value. For example, 32x32 pixels is represented by a single element in the array.