Move to object_ptr
This commit is contained in:
@@ -8,8 +8,6 @@ World::World(GameInstance& game_instance) : game_instance(game_instance)
|
||||
|
||||
World::~World()
|
||||
{
|
||||
for (auto& actor : actors)
|
||||
delete actor;
|
||||
actors.clear();
|
||||
}
|
||||
|
||||
@@ -28,13 +26,13 @@ void World::Tick(double delta_time)
|
||||
std::shared_ptr<SaveMap> World::save()
|
||||
{
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("World");
|
||||
save->SaveListObject("Actors", std::move(reinterpret_cast<std::list<ISave*>&>(actors)));
|
||||
save->SaveListObject("Actors", std::move(reinterpret_cast<std::list<UType::object_ptr<ISave>>&>(actors)));
|
||||
return save;
|
||||
}
|
||||
|
||||
void World::load(std::shared_ptr<SaveMap> save)
|
||||
{
|
||||
actors = std::move(reinterpret_cast<std::list<Actor*>&>(save->GetListObject("Actors")));
|
||||
actors = std::move(reinterpret_cast<std::list<UType::object_ptr<Actor>>&>(save->GetListObject("Actors")));
|
||||
|
||||
for (auto& i : actors)
|
||||
i->world_ = this;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "RTTI.h"
|
||||
#include "Game/Actors/Actor.hpp"
|
||||
#include "Game/Actors/Mesh/Mesh.hpp"
|
||||
#include "Types/object_ptr.hpp"
|
||||
|
||||
class GameInstance;
|
||||
|
||||
@@ -16,7 +17,7 @@ class World : public ISave
|
||||
GameInstance& game_instance;
|
||||
|
||||
// Actors only
|
||||
std::list<Actor*> actors;
|
||||
std::list<UType::object_ptr<Actor>> actors;
|
||||
|
||||
public:
|
||||
World(GameInstance& game_instance);
|
||||
@@ -38,7 +39,7 @@ public:
|
||||
Container list;
|
||||
for (auto i = actors.cbegin(); i != actors.cend(); ++i)
|
||||
{
|
||||
if (T* cast_object = RTTI::dyn_cast<T>(*i))
|
||||
if (T* cast_object = RTTI::dyn_cast<T, Actor>((*i).get()))
|
||||
list.push_back(cast_object);
|
||||
}
|
||||
return list;
|
||||
|
||||
Reference in New Issue
Block a user