« first day (2999 days earlier)      last day (2011 days later) » 

user92578
3:20 PM
oh no, all the easy smart-pointer conversions are done :(
 
user92578
gotta bite the bullet and get into the entity management
 
user92578
CLevelScene::~CLevelScene()
{
	// Deletes all the non-entity owned boundings, since entities delete their own boundings.
	for (auto bounding : m_Boundings)
	{
		if (bounding && !bounding->GetEntity()) delete bounding;
	}
}
 
user92578
It's this stuff that is hella scary
 
user92578
really makes me scratch my head thinking "how the fuck am I gonna do this"
 
user92578
Okay, so my Level class owns all entities in the level
 
user92578
3:29 PM
Currently, if an entity wants to spawn another entity, it can simply new one, add it to the level, and keep a pointer to the entity it allocated.
 
user92578
Now, I want to replace that allocation with std::unique_ptr
 
user92578
But if I pass the entity that was std::make_uniqued to the level, it will of course std::move it into a std::vector, and the variable that was initialized in the caller's code won't be valid anymore.
 
user92578
Is there a common way to fix this? Do I make Level::AddEntity return a raw pointer to the entity that is moved into the container in Level?
 
user92578
m_Child = new CEntity();
level->AddEntity(child);
m_Child->DoStuff();
 
user92578
VS
 
user92578
3:36 PM
m_Child = std::make_unique<CEntity>();
level->AddEntity(std::move(m_Child));
m_Child->DoStuff(); // WHOOOPS, RUNTIME ERROR (hopefully)
 
5:05 PM
Yay! Finally got Daggerfall to work!
 

« first day (2999 days earlier)      last day (2011 days later) »