domenica 6 dicembre 2015

Day 92: Destructors

Today I decided to start working on a scene management system.

This requires me to handle the memory correcly when I'm switching scenes, and the amount of things I need to change in order to achieve this is pretty huge...

Today I started by modifying a few classes, for example the audio manager, the profiler and the texture manager. Each one of them now has a reset method that removes everything unnecessary, including gpu memory in case of the texture manager.

The first big problem was the MeshManager, because some of the meshes are loaded by the engine, and should not be freed. So I created a little hacky system to understand if a mesh is for the engine or not without storing the information in the mesh itself.

Now I need to proceed with the most difficult part, which is deleting everything created from within the game. I need to keep track of models, emitters, lights and so on, basically everything I created until now... Deleting only the GameObjects is not an option, even if the components are recursively deleted, because some components could not be attached to anything.

So I guess that for each instantiable class I ever created I will add a static field which holds a list of pointers to the instances, and then I'll just call a Free on each element.

Calling free on a gameobject is usally a bad practice, because all the pointers it holds will not be freed, however if every model, every light and every other thing are also freed, this SHOULD not be a problem.

In absence or more clever ideas, I'll proceed down this road

Nessun commento:

Posta un commento