In these days I tried to figure out how to correctly handle memory, but in the end I found out that I just had an enormous confusion about that because I never really studied in depth how cpp handles that... One of the things that I learned is that I shouldn't try to create and destruct an object with an allocator, I should just allocate memory, and the destruction should be done with custom pointers: instead of instantiating new objects, I should create special pointers with a destructor that holds the pointers to the data.
Now that this is clear, I understood that I can just create my scene system WITHOUT the stack allocator, and I don't even need to keep track of the objects, they will eventually be detroyed when the special pointer goes out of scope.
I will implement the special allocators, but only once I get this working with mallocs and frees.
Today I wrote the entire scene management cycle, and the ways that the game uses to change scene.
To test it out I created two scenes, identical except for a cone which is one of them. I switch between them by calling a function defined in the main game class. The switching is done correctly, and the start, update and handle_inputs are correctly called.
As you can see from the picture, since I've not created the special pointers yet, all the previously created geometry are still visible in the scene. I'll hopefully fix that tomorrow.

Nessun commento:
Posta un commento