Exemplo n.º 1
0
 void ComponentPluginManager::UnloadAllPlugins(EntityManager& em)
 {
    for(PluginFactoryMap::iterator i = mFactories.begin(); i != mFactories.end(); ++i)
    {
       ComponentType ctype = i->first;
       if(em.HasEntitySystem(ctype))
       {
          dtEntity::EntitySystem* es = em.GetEntitySystem(ctype);
          if(es == NULL || !em.RemoveEntitySystem(*es))
          {
             LOG_ERROR("Could not cleanly remove entity system " << GetStringFromSID(ctype));
          }
          else
          {
             delete es;
          }
       }
    }
 }
Exemplo n.º 2
0
   bool ComponentPluginManager::StartEntitySystem(EntityManager& em, ComponentType ctype)
   {
      if(em.HasEntitySystem(ctype))
      {
         return true;
      }
      LOG_DEBUG("Starting entity system " << GetStringFromSID(ctype));
      ComponentPluginFactory* factory = GetPluginFactory(ctype);

      if(factory == NULL)
      {
         LOG_DEBUG("Cannot start entity system "
            << dtEntity::GetStringFromSID(ctype) << ": no factory found");
         return false;
      }
      // start all plugins this plugin depends on
      std::list<ComponentType> deps;
      factory->GetDependencies(deps);

      while(!deps.empty())
      {
         ComponentType dependency = deps.front();
         deps.pop_front();

         if(em.HasEntitySystem(dependency))
         {
            continue;
         }
         // check if dependency can be fulfilled
         if(!FactoryExists(dependency))
         {
            LOG_ERROR("Cannot start plugin " << dtEntity::GetStringFromSID(ctype) << ": It depends on plugin "
             << GetStringFromSID(dependency) << " which was not found.");
            return false;
         }

         // only start dependency if it is not running now
         if(!em.HasEntitySystem(dependency))
         {
            StartEntitySystem(em, dependency);
         }
      }

      // use factory to create the plugin

      EntitySystem* es;
      bool success = factory->Create(&em, es);

      if(success)
      {
         // call, although no properties were set yet
         es->Finished();
         LOG_DEBUG("Created entity system of type " << GetStringFromSID(ctype));
         em.AddEntitySystem(*es);
         return true;
      }
      else
      {
         LOG_ERROR("Error starting entity system " << dtEntity::GetStringFromSID(ctype));
         return false;
      }
   }