This commit is contained in:
Mikulas Florek 2016-07-24 15:44:37 +02:00
parent 98cf5640cc
commit 7fe0deb057
13 changed files with 105 additions and 131 deletions

View file

@ -78,12 +78,13 @@ struct AnimationSceneImpl : public AnimationScene
}
~AnimationSceneImpl()
void clear() override
{
for (Animable& animable : m_animables)
{
unloadAnimation(animable.animation);
}
m_animables.clear();
}
@ -171,12 +172,7 @@ struct AnimationSceneImpl : public AnimationScene
{
int32 count;
serializer.read(count);
for (Animable& animable : m_animables)
{
unloadAnimation(animable.animation);
}
m_animables.clear();
m_animables.reserve(count);
for (int i = 0; i < count; ++i)
{
Animable animable;

View file

@ -89,9 +89,16 @@ struct AudioSceneImpl : public AudioScene
}
~AudioSceneImpl()
void clear() override
{
clearClips();
for (auto* clip : m_clips)
{
clip->clip->getResourceManager().get(CLIP_RESOURCE_HASH)->unload(*clip->clip);
LUMIX_DELETE(m_allocator, clip);
}
m_clips.clear();
m_ambient_sounds.clear();
m_echo_zones.clear();
}
@ -334,20 +341,9 @@ struct AudioSceneImpl : public AudioScene
}
void clearClips()
{
for (auto* clip : m_clips)
{
clip->clip->getResourceManager().get(CLIP_RESOURCE_HASH)->unload(*clip->clip);
LUMIX_DELETE(m_allocator, clip);
}
m_clips.clear();
}
void deserialize(InputBlob& serializer, int version) override
{
clearClips();
clear();
serializer.read(m_listener.entity);
if (m_listener.entity != INVALID_ENTITY)
@ -383,7 +379,6 @@ struct AudioSceneImpl : public AudioScene
ComponentHandle dummy_cmp;
if (version <= (int)AudioSceneVersion::REFACTOR) serializer.read(dummy_cmp);
serializer.read(count);
m_ambient_sounds.clear();
for (int i = 0; i < count; ++i)
{
AmbientSound sound;
@ -401,7 +396,6 @@ struct AudioSceneImpl : public AudioScene
if (version > (int)AudioSceneVersion::ECHO_ZONES)
{
serializer.read(count);
m_echo_zones.clear();
for (int i = 0; i < count; ++i)
{

View file

@ -2069,6 +2069,7 @@ public:
if (reload)
{
m_game_mode_file->seek(FS::SeekMode::BEGIN, 0);
m_universe->resetScenes();
load(*m_game_mode_file);
}
m_engine->getFileSystem().close(*m_game_mode_file);

View file

@ -702,6 +702,7 @@ public:
{
auto* scene = scenes[i];
scenes.pop();
scene->clear();
scene->getPlugin().destroyScene(scene);
}
LUMIX_DELETE(m_allocator, &universe);

View file

@ -30,6 +30,7 @@ namespace Lumix
virtual void startGame() {}
virtual void stopGame() {}
virtual int getVersion() const { return -1; }
virtual void clear() = 0;
};

View file

@ -35,7 +35,7 @@ public:
}
~HierarchyImpl()
void clear() override
{
auto iter = m_children.begin(), end = m_children.end();
while (iter != end)
@ -43,6 +43,8 @@ public:
LUMIX_DELETE(m_allocator, iter.value());
++iter;
}
m_children.clear();
m_parents.clear();
}

View file

@ -64,6 +64,15 @@ Array<IScene*>& Universe::getScenes()
}
void Universe::resetScenes()
{
for (auto* scene : m_scenes)
{
scene->clear();
}
}
void Universe::addScene(IScene* scene)
{
m_scenes.push(scene);

View file

@ -86,6 +86,7 @@ public:
IScene* getScene(uint32 hash) const;
Array<IScene*>& getScenes();
void addScene(IScene* scene);
void resetScenes();
private:
struct Transformation

View file

@ -431,13 +431,7 @@ namespace Lumix
}
~LuaScriptSceneImpl()
{
unloadAllScripts();
}
void unloadAllScripts()
void clear() override
{
Path invalid_path;
for (auto* script_cmp : m_scripts)
@ -1223,7 +1217,6 @@ namespace Lumix
}
int len = serializer.read<int>();
unloadAllScripts();
m_scripts.rehash(len);
for (int i = 0; i < len; ++i)
{
@ -1269,7 +1262,6 @@ namespace Lumix
void deserializeOld(InputBlob& serializer)
{
int len = serializer.read<int>();
unloadAllScripts();
m_scripts.rehash(len);
for (int i = 0; i < len; ++i)
{

View file

@ -146,7 +146,12 @@ struct NavigationSceneImpl : public NavigationScene
~NavigationSceneImpl()
{
m_universe.entityTransformed().unbind<NavigationSceneImpl, &NavigationSceneImpl::onEntityMoved>(this);
clear();
clearNavmesh();
}
void clear() override
{
m_agents.clear();
}
@ -169,7 +174,7 @@ struct NavigationSceneImpl : public NavigationScene
int getVersion() const override { return (int)Version::LATEST; }
void clear()
void clearNavmesh()
{
rcFreePolyMeshDetail(m_detail_mesh);
rcFreePolyMesh(m_polymesh);
@ -478,7 +483,7 @@ struct NavigationSceneImpl : public NavigationScene
bool load(const char* path) override
{
clear();
clearNavmesh();
FS::OsFile file;
if (!file.open(path, FS::Mode::OPEN_AND_READ, m_allocator)) return false;
@ -982,7 +987,7 @@ struct NavigationSceneImpl : public NavigationScene
bool generateNavmesh() override
{
PROFILE_FUNCTION();
clear();
clearNavmesh();
if (!initNavmesh()) return false;
@ -1089,22 +1094,21 @@ struct NavigationSceneImpl : public NavigationScene
void deserialize(InputBlob& serializer, int version) override
{
m_agents.clear();
if (version > (int)Version::AGENTS)
if (version <= (int)Version::AGENTS) return;
int count = 0;
serializer.read(count);
m_agents.rehash(count);
for (int i = 0; i < count; ++i)
{
int count = 0;
serializer.read(count);
for (int i = 0; i < count; ++i)
{
Agent agent;
serializer.read(agent.entity);
serializer.read(agent.radius);
serializer.read(agent.height);
agent.agent = -1;
m_agents.insert(agent.entity, agent);
ComponentHandle cmp = {agent.entity.index};
m_universe.addComponent(agent.entity, NAVMESH_AGENT_TYPE, this, cmp);
}
Agent agent;
serializer.read(agent.entity);
serializer.read(agent.radius);
serializer.read(agent.height);
agent.agent = -1;
m_agents.insert(agent.entity, agent);
ComponentHandle cmp = {agent.entity.index};
m_universe.addComponent(agent.entity, NAVMESH_AGENT_TYPE, this, cmp);
}
}

View file

@ -311,10 +311,41 @@ struct PhysicsSceneImpl : public PhysicsScene
~PhysicsSceneImpl()
{
ASSERT(m_controllers.size() == 0);
ASSERT(m_ragdolls.size() == 0);
ASSERT(m_actors.size() == 0);
ASSERT(m_terrains.size() == 0);
m_controller_manager->release();
m_default_material->release();
m_dummy_actor->release();
m_scene->release();
}
void clear() override
{
for (auto& controller : m_controllers)
{
controller.m_controller->release();
}
m_controllers.clear();
for (auto& ragdoll : m_ragdolls)
{
destroySkeleton(ragdoll.root);
}
m_ragdolls.clear();
for (auto& joint : m_joints)
{
joint.physx->release();
}
m_joints.clear();
for (auto* actor : m_actors)
{
LUMIX_DELETE(m_allocator, actor);
}
m_actors.clear();
m_dynamic_actors.clear();
m_terrains.clear();
}
@ -3030,7 +3061,6 @@ struct PhysicsSceneImpl : public PhysicsScene
void deserializeActors(InputBlob& serializer, int version)
{
int32 count;
m_dynamic_actors.clear();
serializer.read(count);
for (auto* actor : m_actors)
{
@ -3060,11 +3090,6 @@ struct PhysicsSceneImpl : public PhysicsScene
{
int32 count;
serializer.read(count);
for (auto& controller : m_controllers)
{
controller.m_controller->release();
}
m_controllers.clear();
for (int i = 0; i < count; ++i)
{
Entity entity;
@ -3119,12 +3144,6 @@ struct PhysicsSceneImpl : public PhysicsScene
{
if (version <= int(PhysicsSceneVersion::RAGDOLLS)) return;
for (auto& ragdoll : m_ragdolls)
{
destroySkeleton(ragdoll.root);
}
m_ragdolls.clear();
int count;
serializer.read(count);
m_ragdolls.reserve(count);
@ -3150,8 +3169,6 @@ struct PhysicsSceneImpl : public PhysicsScene
int count;
serializer.read(count);
for (int i = 0; i < m_joints.size(); ++i) m_joints.at(i).physx->release();
m_joints.clear();
m_joints.reserve(count);
for (int i = 0; i < count; ++i)
{
@ -3267,7 +3284,6 @@ struct PhysicsSceneImpl : public PhysicsScene
{
int32 count;
serializer.read(count);
m_terrains.clear();
for (int i = 0; i < count; ++i)
{
bool exists = true;
@ -3472,27 +3488,7 @@ PhysicsScene* PhysicsScene::create(PhysicsSystem& system, Universe& context, Eng
void PhysicsScene::destroy(PhysicsScene* scene)
{
PhysicsSceneImpl* impl = static_cast<PhysicsSceneImpl*>(scene);
for (auto& controller : impl->m_controllers)
{
controller.m_controller->release();
}
impl->m_controllers.clear();
for (auto& ragdoll : impl->m_ragdolls)
{
impl->destroySkeleton(ragdoll.root);
}
impl->m_ragdolls.clear();
for (auto* actor : impl->m_actors)
{
LUMIX_DELETE(impl->m_allocator, actor);
}
impl->m_actors.clear();
impl->m_terrains.clear();
impl->m_controller_manager->release();
impl->m_default_material->release();
impl->m_dummy_actor->release();
impl->m_scene->release();
LUMIX_DELETE(impl->m_allocator, scene);
}

View file

@ -124,9 +124,6 @@ public:
}
~CullingSystemImpl() {}
void clear() override
{
m_spheres.clear();

View file

@ -192,31 +192,40 @@ public:
~RenderSceneImpl()
{
auto& rm = m_engine.getResourceManager();
auto* material_manager = static_cast<MaterialManager*>(rm.get(MATERIAL_HASH));
m_universe.entityTransformed().unbind<RenderSceneImpl, &RenderSceneImpl::onEntityMoved>(this);
m_universe.entityDestroyed().unbind<RenderSceneImpl, &RenderSceneImpl::onEntityDestroyed>(this);
CullingSystem::destroy(*m_culling_system);
}
void clear() override
{
auto& rm = m_engine.getResourceManager();
auto* material_manager = static_cast<MaterialManager*>(rm.get(MATERIAL_HASH));
for (int i = 0; i < m_model_loaded_callbacks.size(); ++i)
{
LUMIX_DELETE(m_allocator, m_model_loaded_callbacks[i]);
}
m_model_loaded_callbacks.clear();
for (Decal& decal : m_decals)
{
if(decal.material) material_manager->unload(*decal.material);
if (decal.material) material_manager->unload(*decal.material);
}
m_decals.clear();
for (auto* terrain : m_terrains)
{
LUMIX_DELETE(m_allocator, terrain);
}
m_terrains.clear();
for (auto* emitter : m_particle_emitters)
{
LUMIX_DELETE(m_allocator, emitter);
}
m_particle_emitters.clear();
for (auto& i : m_renderables)
{
@ -228,13 +237,14 @@ public:
LUMIX_DELETE(m_allocator, i.pose);
}
}
m_renderables.clear();
m_culling_system->clear();
for (auto& probe : m_environment_probes)
{
if (probe.texture) probe.texture->getResourceManager().get(TEXTURE_HASH)->unload(*probe.texture);
}
CullingSystem::destroy(*m_culling_system);
m_environment_probes.clear();
}
@ -687,7 +697,6 @@ public:
ResourceManagerBase* material_manager = m_engine.getResourceManager().get(MATERIAL_HASH);
int count;
serializer.read(count);
m_decals.clear();
m_decals.reserve(count);
for (int i = 0; i < count; ++i)
{
@ -732,16 +741,6 @@ public:
{
int32 count;
serializer.read(count);
for (int i = 0, c = m_environment_probes.size(); i < c; ++i)
{
auto& probe = m_environment_probes.at(i);
if (probe.texture)
{
probe.texture->getResourceManager().get(TEXTURE_HASH)->unload(*probe.texture);
}
}
m_environment_probes.clear();
m_environment_probes.reserve(count);
auto* texture_manager = m_engine.getResourceManager().get(TEXTURE_HASH);
uint64 universe_guid = m_universe.getPath().getHash();
@ -785,8 +784,6 @@ public:
{
int count;
serializer.read(count);
for (auto* emitter : m_particle_emitters) LUMIX_DELETE(m_allocator, emitter);
m_particle_emitters.clear();
m_particle_emitters.reserve(count);
for(int i = 0; i < count; ++i)
{
@ -904,7 +901,6 @@ public:
{
int32 size;
serializer.read(size);
m_cameras.clear();
m_cameras.rehash(size);
for (int i = 0; i < size; ++i)
{
@ -943,15 +939,6 @@ public:
{
int32 size = 0;
serializer.read(size);
for (int i = 0; i < m_renderables.size(); ++i)
{
if (m_renderables[i].entity != INVALID_ENTITY)
{
setModel({i}, nullptr);
}
}
m_culling_system->clear();
m_renderables.clear();
m_renderables.reserve(size);
for (int i = 0; i < size; ++i)
{
@ -1006,9 +993,7 @@ public:
{
int32 size = 0;
serializer.read(size);
m_point_lights_map.clear();
m_point_lights.resize(size);
m_light_influenced_geometry.clear();
for (int i = 0; i < size; ++i)
{
m_light_influenced_geometry.push(Array<ComponentHandle>(m_allocator));
@ -1073,11 +1058,6 @@ public:
void deserializeTerrains(InputBlob& serializer, RenderSceneVersion version)
{
for (auto* terrain : m_terrains)
{
LUMIX_DELETE(m_allocator, terrain);
}
m_terrains.clear();
int32 size = 0;
serializer.read(size);
for (int i = 0; i < size; ++i)