예제 #1
0
 CSimulator::~CSimulator() {
    if(IsProfiling()) {
       delete m_pcProfiler;
    }
    /* Delete the visualization */
    if(m_pcVisualization != NULL) delete m_pcVisualization;
    /* Delete all the media */
    for(CMedium::TMap::iterator it = m_mapMedia.begin();
        it != m_mapMedia.end(); ++it) {
       delete it->second;
    }
    m_mapMedia.clear();
    m_vecMedia.clear();
    /* Delete all the physics engines */
    for(CPhysicsEngine::TMap::iterator it = m_mapPhysicsEngines.begin();
        it != m_mapPhysicsEngines.end(); ++it) {
       delete it->second;
    }
    m_mapPhysicsEngines.clear();
    m_vecPhysicsEngines.clear();
    /* Delete the space and the dynamic linking manager */
    if(m_pcSpace != NULL) {
       delete m_pcSpace;
    }
    /* Get rid of all libraries */
    CDynamicLoading::UnloadAllLibraries();
 }
예제 #2
0
const bool DB::Open(const std::string &filename)
{
    if(IsOpen()==true)
    {
        Close();
    }
    if(IsOpen()==false)
    {
        m_lastresult=sqlite3_open(filename.c_str(),&m_db);
        if(m_lastresult==SQLITE_OK)
        {
            if(IsProfiling())
            {
                StartProfiling();
            }
            return true;
        }
        else
        {
            std::string errmsg("");
            int err=GetLastExtendedError(errmsg);
            HandleError(err,errmsg,"DB::Open");
            return false;
        }
    }
    else
    {
        return false;
    }
}
예제 #3
0
 void CSimulator::Destroy() {
    /* Call user destroy function */
    if (m_pcLoopFunctions != NULL) {
       m_pcLoopFunctions->Destroy();
       delete m_pcLoopFunctions;
       m_pcLoopFunctions = NULL;
    }
    /* Destroy the visualization */
    if(m_pcVisualization != NULL) {
       m_pcVisualization->Destroy();
    }
    /* Destroy simulated space */
    if(m_pcSpace != NULL) {
       m_pcSpace->Destroy();
    }
    /* Destroy media */
    for(CMedium::TMap::iterator it = m_mapMedia.begin();
        it != m_mapMedia.end(); ++it) {
       it->second->Destroy();
       delete it->second;
    }
    m_mapMedia.clear();
    m_vecMedia.clear();
    /* Destroy physics engines */
    for(CPhysicsEngine::TMap::iterator it = m_mapPhysicsEngines.begin();
        it != m_mapPhysicsEngines.end(); ++it) {
       it->second->Destroy();
       delete it->second;
    }
    m_mapPhysicsEngines.clear();
    m_vecPhysicsEngines.clear();
    /* Get rid of ARGoS category */
    if(CRandom::ExistsCategory("argos")) {
       CRandom::RemoveCategory("argos");
    }
    /* Free up factory data */
    CFactory<CMedium>::Destroy();
    CFactory<CPhysicsEngine>::Destroy();
    CFactory<CVisualization>::Destroy();
    CFactory<CSimulatedActuator>::Destroy();
    CFactory<CSimulatedSensor>::Destroy();
    CFactory<CCI_Controller>::Destroy();
    CFactory<CEntity>::Destroy();
    CFactory<CLoopFunctions>::Destroy();
    /* Stop profiling and flush the data */
    if(IsProfiling()) {
       m_pcProfiler->Stop();
       m_pcProfiler->Flush(m_bHumanReadableProfile);
    }
    LOG.Flush();
    LOGERR.Flush();
 }
예제 #4
0
 void CSimulator::Init() {
    /* General configuration */
    InitFramework(GetNode(m_tConfigurationRoot, "framework"));
    /* Initialize controllers */
    InitControllers(GetNode(m_tConfigurationRoot, "controllers"));
    /* Create loop functions */
    if(NodeExists(m_tConfigurationRoot, "loop_functions")) {
       /* User specified a loop_functions section in the XML */
       InitLoopFunctions(GetNode(m_tConfigurationRoot, "loop_functions"));
    }
    else {
       /* No loop_functions in the XML */
       m_pcLoopFunctions = new CLoopFunctions;
    }
    /* Physics engines */
    InitPhysics(GetNode(m_tConfigurationRoot, "physics_engines"));
    /* Media */
    InitMedia(GetNode(m_tConfigurationRoot, "media"));
    /* Space */
    InitSpace(GetNode(m_tConfigurationRoot, "arena"));
    /* Call user init function */
    if(NodeExists(m_tConfigurationRoot, "loop_functions")) {
       m_pcLoopFunctions->Init(GetNode(m_tConfigurationRoot, "loop_functions"));
    }
    /* Physics engines */
    InitPhysics2();
    /* Media */
    InitMedia2();
    /* Initialise visualization */
    TConfigurationNodeIterator itVisualization;
    if(NodeExists(m_tConfigurationRoot, "visualization") &&
       ((itVisualization = itVisualization.begin(&GetNode(m_tConfigurationRoot, "visualization"))) != itVisualization.end())) {
       InitVisualization(GetNode(m_tConfigurationRoot, "visualization"));
    }
    else {
       LOG << "[INFO] No visualization selected." << std::endl;
       m_pcVisualization = new CDefaultVisualization();
    }
    /* Start profiling, if needed */
    if(IsProfiling()) {
       m_pcProfiler->Start();
    }
 }