Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Supporting Infinite Maps #1635
In progress PR for #260.
Currently I've added a class
Can you move the
16 to some constant at some place. Currently it is a magic number which occurs in many many places.
I really like where this is going and already in its current form it can mean a huge reduction in memory usage for people using many tile layers with little content.
At the moment this patch leaves many operations that iterate the entire area and that will even allocate the entire layer as huge array again, like the resize and offset operations. In each case we should consider ways to perform those operations more efficiently.
In any case, good start and let's see where we can take this!
The simplest solution I can think of is just like the previous one. Creating a
I think this was good approach! Noticed a few issues.
Btw, I noticed the main reason for the slow load times is due to the following lines in
if (_chunk.isEmpty()) mChunks.remove(chunkCoordinates(x, y));
In particular, it is slow because setting an empty cell at a location that is already entirely empty will cause the chunk to get allocated and then immediately de-allocated again, and this will happen for each cell of an empty tile layer.
While this confirms that your idea to avoid setting empty cells in the map reader would resolve that particular slowness, I think instead it may be good to avoid the allocation and de-allocation in general by inserting the following check at the top:
if (cell.isEmpty() && !findChunk(x, y)) return;
Additionally, we could not bother with de-allocating chunks at all. I think it's a bit dubious whether we really need to free up memory there, because the main point of the chunks is to avoid massive memory allocation. In contrast, the user is probably not going to erase large areas and then care about whether that frees up some memory. If we don't bother with de-allocation, then there is also no need for keeping track of