void CEntity::Init(TConfigurationNode& t_tree) { try { /* * Set the id of the entity from XML or type description */ /* Was an id specified explicitly? */ if(NodeAttributeExists(t_tree, "id")) { /* Yes, use that */ GetNodeAttribute(t_tree, "id", m_strId); } else { /* No, derive it from the parent */ if(m_pcParent != NULL) { UInt32 unIdCount = 0; while(GetParent().HasComponent(GetTypeDescription() + "[" + GetTypeDescription() + "_" + ToString(unIdCount) + "]")) { ++unIdCount; } m_strId = GetTypeDescription() + "_" + ToString(unIdCount); } else { THROW_ARGOSEXCEPTION("Root entities must provide the identifier tag"); } } } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize an entity.", ex); } }
void CRABMedium::Init(TConfigurationNode& t_tree) { try { CMedium::Init(t_tree); /* Check occlusions? */ GetNodeAttributeOrDefault(t_tree, "check_occlusions", m_bCheckOcclusions, m_bCheckOcclusions); /* Get the positional index method */ std::string strPosIndexMethod("grid"); GetNodeAttributeOrDefault(t_tree, "index", strPosIndexMethod, strPosIndexMethod); /* Get the arena center and size */ CVector3 cArenaCenter; CVector3 cArenaSize; TConfigurationNode& tArena = GetNode(CSimulator::GetInstance().GetConfigurationRoot(), "arena"); GetNodeAttribute(tArena, "size", cArenaSize); GetNodeAttributeOrDefault(tArena, "center", cArenaCenter, cArenaCenter); /* Create the positional index for embodied entities */ if(strPosIndexMethod == "grid") { size_t punGridSize[3]; if(!NodeAttributeExists(t_tree, "grid_size")) { punGridSize[0] = cArenaSize.GetX(); punGridSize[1] = cArenaSize.GetY(); punGridSize[2] = cArenaSize.GetZ(); } else { std::string strPosGridSize; GetNodeAttribute(t_tree, "grid_size", strPosGridSize); ParseValues<size_t>(strPosGridSize, 3, punGridSize, ','); } CGrid<CRABEquippedEntity>* pcGrid = new CGrid<CRABEquippedEntity>( cArenaCenter - cArenaSize * 0.5f, cArenaCenter + cArenaSize * 0.5f, punGridSize[0], punGridSize[1], punGridSize[2]); m_pcRABEquippedEntityGridUpdateOperation = new CRABEquippedEntityGridEntityUpdater(*pcGrid); pcGrid->SetUpdateEntityOperation(m_pcRABEquippedEntityGridUpdateOperation); m_pcRABEquippedEntityIndex = pcGrid; } else { THROW_ARGOSEXCEPTION("Unknown method \"" << strPosIndexMethod << "\" for the positional index."); } } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Error in initialization of the range-and-bearing medium", ex); } }
void CSimulator::InitControllers(TConfigurationNode& t_tree) { /* * Go through controllers, loading the library of each of them * and storing type, id and XML tree of each of them for later use */ if(! t_tree.NoChildren()) { try { std::string strLibrary; std::string strId; TConfigurationNodeIterator it; for(it = it.begin(&t_tree); it != it.end(); ++it) { /* Get controller id */ try { GetNodeAttribute(*it, "id", strId); } catch(CARGoSException& ex) { std::string strValue; it->GetValue(&strValue); THROW_ARGOSEXCEPTION_NESTED("Controller type \"" << strValue << "\" has no assigned id.", ex); } /* Bomb out if id is already in map */ if(m_mapControllerConfig.find(strId) != m_mapControllerConfig.end()) { THROW_ARGOSEXCEPTION("Controller id \"" << strId << "\" duplicated"); } /* Optionally, process "library" attribute if present */ if(NodeAttributeExists(*it, "library")) { /* Get library name */ GetNodeAttribute(*it, "library", strLibrary); /* Load library */ CDynamicLoading::LoadLibrary(strLibrary); } /* Store XML info in map by id */ m_mapControllerConfig.insert(std::pair<std::string, TConfigurationNode*>(strId, &(*it))); } } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Error initializing controllers", ex); } } }