Automatically removes the oldest Chunk in the game memory.
Retrieves amount of loaded chunks.
Calculates a percentage based on the amount of loaded chunks & the max amount of chunks in the game world.
If total chunks is 50 and amount of loaded chunks is 25, 50% of chunks are full.
Based on this percentage, a scheduled task is generated:
If 75% of chunks are full, next chunk GC will be in 30 seconds and will remove 10 chunks.
If 15-25% chunks are full, next chunk GC will be in 120 seconds and will remove 5 chunks.
I had to balance between high frequency of chunk GC calls and amount of chunks to remove per GC call.
For example:
The max amount of chunks on a large map is approximately 288 chunks.
If the amount of chunks is 80% full, then proceeding to remove 50 chunks in one chunk GC call could potentially result in a noticeable game pause.
Please let me know if I took the right approach or if there is a better way this could be done? Please also let me know on any improvements that can be made?
The potential next step, would be to implement a check so that ONLY chunks that have not been accessed in the last 'x' seconds/minutes are eligible for removal. Please let me know, what you think?
Automatically removes the oldest Chunk in the game memory. Retrieves amount of loaded chunks. Calculates a percentage based on the amount of loaded chunks & the max amount of chunks in the game world. If total chunks is 50 and amount of loaded chunks is 25, 50% of chunks are full. Based on this percentage, a scheduled task is generated: If 75% of chunks are full, next chunk GC will be in 30 seconds and will remove 10 chunks. If 15-25% chunks are full, next chunk GC will be in 120 seconds and will remove 5 chunks.
I had to balance between high frequency of chunk GC calls and amount of chunks to remove per GC call. For example: The max amount of chunks on a large map is approximately 288 chunks.
If the amount of chunks is 80% full, then proceeding to remove 50 chunks in one chunk GC call could potentially result in a noticeable game pause.
Please let me know if I took the right approach or if there is a better way this could be done? Please also let me know on any improvements that can be made?
The potential next step, would be to implement a check so that ONLY chunks that have not been accessed in the last 'x' seconds/minutes are eligible for removal. Please let me know, what you think?
Thanks