LorenzoGatti said:
Are you sure you aren't simply doing unnecessary allocations of unnecessarily complex objects? Arrays of vectors of stuff should be long-lived and consolidated
I could reduce the number of allocations by using a larger block size, e.g. like Minecraft divides the world into large chunks of voxels. It would require only one mesh data structure containing those 3 vectors you mention later.
But i better use small blocks, having many small meshes for the space of a single Minecraft chunk.
The advantage is, if the level designer edits the scene, e.g. moving a wall or door, there is less space to update than with using large blocks, so the waiting to play test the changes is a shorter duration.
My primary goal is to minimize waiting time on local changes. If you change a whole mountain it might take an hour, but if you only move a door it should take just 20 seconds, for example. And for this goal small blocks are better than large blocks, while for many other objectives it would be the opposite.
It's a balancing act to find the best compromise and settings, and it seems my ideal settings cause terrible memory fragmentation over time.
Processing the same scene at the same detail with larger blocks does not cause the slowdown. At least not that much. But to a small degree it does. If my scene would be bigger, and for an open world game it would be much bigger, the slowdown would become again unacceptable pretty quickly i guess.
If i quit my application and restart it, it's fast again. But i need to reload everything from disk, causing another wait.
After i quit my application, it takes minutes until all memory is freed, which is suspicious. I often kill the process to speed this up.
LorenzoGatti said:
In case of modifications it should be possible to recycle deleted polygons, half-edges and vertices by maintaining free lists, without fragmentation.
I will use freelists to manage my memory, but i can do so only after current work to implement it is done.
Currently the most mesh editing happens due to stitching the boundaries of adjacent mesh blocks. For that i just add the edits to the back of the vectors, and the deleted mesh elements remain disconnected in memory. That's ok because only few polygons are affected form stitching, if at all. Mostly the boundaries match.
But i need four iterations of the stitching process, and i need to store each intermediate result in memory and on disk, so future local edits have minimal workloads. So i have 4 copies of almost the same mesh around, which i could compress using a diff algorithm as used to compare two files of source code.
In fact, the final mesh is only 5% of my data or even less. But i need to keep all the intermediate results. If i would not, you would need to recompute all the data for the whole world after each subtle change, and making games with this would not be possible.
Sorry for the long text, but my stuff is very unusual, crazy, and it might fail. I'm aware of that. ; )