I may have missed something, but is there a reason to keep the Background object as a pointer?
Then you don't have much control over memory. I could call the Unload function to drop a texture but the object and its data will still be there till
out of scope or game end, which is pretty much a waste. Why remain the object till game loop ends when it is no useless anymore (sprite without texture in this case) and you could drop it from memory.
std:make_unique is awesome, although i use MinGW not Visual Studio's compiler.
I guess i will stick with
int* a = new int;
delete a;
a = nullptr;
delete a; // <-- OK
if its totally safe.
bool useless () const {return isUseless;}
static void clean_up () {
for (/*every object in MasterVector*/)
if (object->useless()) {
vec.erase(/*object*/);
delete /*object*/;
}
}
static void clean_up (std::vector vec*) {
for (/*every object in vec*/)
if ( object->useless() ) {
vec->erase(/*object*/);
delete /*object*/;
}
}
void update () {
/*do anything it needs to do*/
if (/*something very very sad happened*/)
isUseless = true;
}
dejaime im i missing a point or you i dont know. I dont understand your solution pretty much.
You keep objects in dynamic array and check for their state if they are not useless then you delete them.
This isUseless is only checked in clean_up() function
As far as i understood you remove the object from the array when it is useless but you are not deleting it till cleanup, which pretty much can be called within game loop or end game. And again if you call clean_up() in game loop you need to make sure to call it in the end game if object is not useless, which again leads back to my problem.
But if you only assign isUseless in the game logic and do clean_up() in the end it basically means that the object with its data except the texture will still remain in memory till endgame. I want to free things from memory since they are not usable anymore. Probably i miss something i don't know and your solution may be efficient enough, but it does not seem to be structured well as you know that in game you don't deal with specific objects only. So keeping structured attaching same logic for everything helps readability and not getting frustrated when things go complex.