saffeine
Member
no prefix for this one because it's more of a general question than anything ( for what it might matter, i AM using GMS2.3+ ), but i'm in the process of developing a game and a development level editor / chunk builder, which is less important than the game itself but will help a lot further down the line. in advance, i want to make sure it's pretty well optimised from start to finish, but can't for the life of me figure out how to make a canvas that can be expanded in every direction, and i'm also interested in hearing how other people would approach the chunk handling functions.
my current plan is something along the lines of:
it's a very rough idea of what i'm aiming for, i'm sure it has room for optimisation but that isn't the main point here.
is there a better way of keeping the unloaded chunks in memory so the disk isn't being read/written to every time chunks are loaded/saved?
although i'm not making a sandbox game ( minecraft / terraria / etc. ), how would i handle generating chunks at a negative index, seeing as arrays don't allow it?
- i did consider using an offset value but i dismissed it when i realised it'd potentially mean having to shift the whole array across the further back the player moves.
- another thought is using four different arrays where the index is multiplied by different values when loaded in as a chunk. ( negative x/y would multiply the chunk index by -1 for both to find the chunk position, for example ).
i've never really used chunks before and i've tried looking into methods of achieving it but i can't seem to find a decent answer to those questions. maybe i'm just missing something, it's entirely possible.
my current plan is something along the lines of:
Code:
1. create a new 2D array that holds a string for each chunk, or populate it with externally loaded strings, we'll call it chunkList.
- if the level doesn't exist, the array starts with a size of ( 1, 1 ) and resizes as the level is built.
- if the level does exist, the array either reads the size from the file or just expands as it's loaded.
2. find the camera bounds, calculate which chunks should be loaded, and run a for loop from the top-left to the bottom-right.
3. ( 2.3+ specific ) for each index of chunkList calculated from the previous step, create a new constructor instance of Chunk() and decode the string into it.
4. add each loaded chunk to a new array that is looped through to update the contents during the step event, we'll call this loadedChunks.
5. periodically check each index of loadedChunks, and if it's outside the view, remove it from the list.
6. when the chunk is unloaded, save all the information to a buffer, encode the buffer, then update its index in chunkList.
7. when the game is saved ( or on a cycle ), encode chunkList to a file and save it to a file for later reading.
- i know i could save each chunk to its own file but i'd rather avoid the clutter.
8. you get the idea by now.
is there a better way of keeping the unloaded chunks in memory so the disk isn't being read/written to every time chunks are loaded/saved?
although i'm not making a sandbox game ( minecraft / terraria / etc. ), how would i handle generating chunks at a negative index, seeing as arrays don't allow it?
- i did consider using an offset value but i dismissed it when i realised it'd potentially mean having to shift the whole array across the further back the player moves.
- another thought is using four different arrays where the index is multiplied by different values when loaded in as a chunk. ( negative x/y would multiply the chunk index by -1 for both to find the chunk position, for example ).
i've never really used chunks before and i've tried looking into methods of achieving it but i can't seem to find a decent answer to those questions. maybe i'm just missing something, it's entirely possible.
Last edited: