venerdì 11 dicembre 2015

Day 96: Scenes 2

Today I managed to make everything work, and it was quite a painful job, but I learned tons of stuff on how memory works in c++, when destructors are called, how are called and so on.

The solution I adopted is the use of a typed custom pointer called New. Each object is created through this pointer. Each gameobject is therefore created as a New ptr, and so each of his components. However references to these objects are passed around the engine by their true pointer.

Now, when a scene is switched, the old one is deleted. Each New ptr calls its destructor, and the job is done.

To thest this out I removed most of the stuff from the scene, and I just left there the skybox, a cone mesh and a directional light. In scene 2 everything is identical, except that the second cube is thinner and a little on the right.  As you can see from the picture the switching works perfectly: the old mesh is no more visible (that you can't see, sorry)and the light has the same intensity (which means that there aren't two of them).

The last thing that needs to be done is to reset correclty all the managers in the game: audio, textures, meshes and so on, being careful to not reset lifetime resources. And now that I have a custom pointer I could probably add support for others allocators as well.




Nessun commento:

Posta un commento