예제 #1
0
void TasksProperty::set(const Atlas::Message::Element & val)
{
    if (!val.isList())
    {
        log(ERROR, "Task property must be a list.");
        return;
    }

    if (m_task == 0) {
        log(ERROR, "No task in ::set");
        return;
    }

    ListType tasks = val.asList();
    ListType::const_iterator I = tasks.begin();
    ListType::const_iterator Iend = tasks.end();
    for (; I != Iend; ++I) {
        if (!I->isMap()) {
            log(ERROR, "Task must be a map.");
            return;
        }
        const MapType & task = I->asMap();
        MapType::const_iterator J = task.begin();
        MapType::const_iterator Jend = task.end();
        for (J = task.begin(); J != Jend; ++J) {
            m_task->setAttr(J->first, J->second);
        }
    }
}
예제 #2
0
void SizeAdapter::updateGui(const ::Atlas::Message::Element& element)
{
	SelfUpdateContext context(*this);
	
	WFMath::AxisBox<3> axisBox;
	try {
		axisBox.fromAtlas(element.asList());
	} catch (...) {
		axisBox = WFMath::AxisBox<3>(WFMath::Point<3>(-0.5, -0.5, -0.5), WFMath::Point<3>(0.5, 0.5, 0.5));
	}
	if (mWidgets.lowerXWindow) {
		mWidgets.lowerXWindow->setText(ValueTypeHelper<float, std::string>::convert(axisBox.lowCorner().x()));
	}
	if (mWidgets.lowerYWindow) {
		mWidgets.lowerYWindow->setText(ValueTypeHelper<float, std::string>::convert(axisBox.lowCorner().y()));
	}
	if (mWidgets.lowerZWindow) {
		mWidgets.lowerZWindow->setText(ValueTypeHelper<float, std::string>::convert(axisBox.lowCorner().z()));
	}
	if (mWidgets.upperXWindow) {
		mWidgets.upperXWindow->setText(ValueTypeHelper<float, std::string>::convert(axisBox.highCorner().x()));
	}
	if (mWidgets.upperYWindow) {
		mWidgets.upperYWindow->setText(ValueTypeHelper<float, std::string>::convert(axisBox.highCorner().y()));
	}
	if (mWidgets.upperZWindow) {
		mWidgets.upperZWindow->setText(ValueTypeHelper<float, std::string>::convert(axisBox.highCorner().z()));
	}

	updateInfo();

}
예제 #3
0
void SizeAdapter::updateGui(const ::Atlas::Message::Element& element)
{
	AdapterSelfUpdateContext context(*this);
	WFMath::AxisBox<3> axisBox;
	try {
		axisBox.fromAtlas(element.asList());
	} catch (...) {
		axisBox = WFMath::AxisBox<3>(WFMath::Point<3>(-0.5, -0.5, -0.5), WFMath::Point<3>(0.5, 0.5, 0.5));
	}
	if (mLowerXWindow) {
		mLowerXWindow->setText(toString(axisBox.lowCorner().x()));
	}
	if (mLowerYWindow) {
		mLowerYWindow->setText(toString(axisBox.lowCorner().y()));
	}
	if (mLowerZWindow) {
		mLowerZWindow->setText(toString(axisBox.lowCorner().z()));
	}
	if (mUpperXWindow) {
		mUpperXWindow->setText(toString(axisBox.highCorner().x()));
	}
	if (mUpperYWindow) {
		mUpperYWindow->setText(toString(axisBox.highCorner().y()));
	}
	if (mUpperZWindow) {
		mUpperZWindow->setText(toString(axisBox.highCorner().z()));
	}

	updateInfo();

}
예제 #4
0
파일: Container.cpp 프로젝트: 9cat/cyphesis
void StdContainer::addToEntity(const std::string & key,
                               const Atlas::Objects::Entity::RootEntity & ent) const
{
    Atlas::Message::Element v = Atlas::Message::ListType();
    Atlas::Message::ListType & contlist = v.asList();
    EntitySet::const_iterator Iend = m_entities.end();
    for (EntitySet::const_iterator I = m_entities.begin(); I != Iend; ++I) {
        contlist.push_back((*I)->getId());
    }
    ent->setAttr(key, v);
}
예제 #5
0
void RuleTreeAdapter::extractChildren(const Root& op, std::list<std::string>& children)
{
	Atlas::Message::Element childElem;
	if (op->copyAttr("children", childElem) == 0) {
		if (childElem.isList()) {
			for (auto child : childElem.asList()) {
				if (child.isString()) {
					children.push_back(child.asString());
				}
			}
		}
	}
}
예제 #6
0
void TerrainShaderParser::createShaders(const Atlas::Message::Element& surfaces)
{
  Terrain::TerrainLayerDefinitionManager& terrainManager = Terrain::TerrainLayerDefinitionManager::getSingleton();
  bool isValid = false;
  if (surfaces.isList()) {
    const Atlas::Message::ListType & slist(surfaces.asList());
    for (Atlas::Message::ListType::const_iterator I = slist.begin(); I != slist.end(); ++I) {
      if (I->isMap()) {
        std::string name;
        std::string pattern;
        const Atlas::Message::MapType& surfaceMap(I->asMap());

        Mercator::Shader::Parameters params;
        if (surfaceMap.count("params")) {
          const Atlas::Message::Element& paramsElem(surfaceMap.find("params")->second);
          if (paramsElem.isMap()) {
            for (Atlas::Message::MapType::const_iterator J = paramsElem.asMap().begin(); J != paramsElem.asMap().end(); ++J) {
              if (J->second.isNum()) {
                params[J->first] = J->second.asNum();
              }
            }
          }
        }

        if (surfaceMap.count("name")) {
          const Atlas::Message::Element& nameElem(surfaceMap.find("name")->second);
          if (nameElem.isString()) {
            const std::string& name = nameElem.asString();
            Terrain::TerrainLayerDefinition* def(terrainManager.getDefinitionForShader(name));
            if (def) {
              if (surfaceMap.count("pattern")) {
                const Atlas::Message::Element& patternElem(surfaceMap.find("pattern")->second);
                if (patternElem.isString()) {
                  const std::string& pattern = patternElem.asString();
                  Mercator::Shader* shader = Mercator::ShaderFactories::instance().newShader(pattern, params);
                  if (shader) {
                    isValid = true;
                    mTerrainHandler.createShader(def, shader);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (!isValid) {
    createDefaultShaders();
  }
}
예제 #7
0
void EntityImporterBase::resolveEntityReferences(Atlas::Message::Element& element)
{
    if (element.isMap()) {
        auto entityRefI = element.asMap().find("$eid");
        if (entityRefI != element.asMap().end() && entityRefI->second.isString()) {
            auto I = mEntityIdMap.find(entityRefI->second.asString());
            if (I != mEntityIdMap.end()) {
                entityRefI->second = I->second;
            }
        }
        //If it's a map we need to process all child elements too
        for (auto& I : element.asMap()) {
            resolveEntityReferences(I.second);
        }
    } else if (element.isList()) {
        //If it's a list we need to process all child elements too
        for (auto& I : element.asList()) {
            resolveEntityReferences(I);
        }
    }
}
예제 #8
0
void EntityImporterBase::start(const std::string& filename)
{
    S_LOG_VERBOSE("Starting import from " << filename);
    auto factories = Atlas::Objects::Factories::instance();

    auto rootObj = loadFromFile(filename);

    if (!rootObj.isValid()) {
        EventCompleted.emit();
        return;
    }
    Atlas::Message::Element metaElem;
    Atlas::Message::Element entitiesElem;
    Atlas::Message::Element mindsElem;
    Atlas::Message::Element rulesElem;
    rootObj->copyAttr("meta", metaElem);
    rootObj->copyAttr("entities", entitiesElem);
    rootObj->copyAttr("minds", mindsElem);
    if (rootObj->copyAttr("rules", rulesElem) == 0) {
        if (!rulesElem.isList()) {
            S_LOG_WARNING("Rules element is not list.");
            EventCompleted.emit();
            return;
        } else {
            for (auto& ruleMessage : rulesElem.asList()) {
                if (ruleMessage.isMap()) {
                    auto object = factories->createObject(ruleMessage.asMap());
                    if (object.isValid()) {
                        if (!object->isDefaultId()) {
                            mPersistedRules.insert(std::make_pair(object->getId(), object));
                        }
                    }
                }
            }

        }
    }

    if (!entitiesElem.isNone() && !entitiesElem.isList()) {
        S_LOG_WARNING("Entities element is not list.");
        EventCompleted.emit();
        return;
    }
    if (!mindsElem.isNone() && !mindsElem.isList()) {
        S_LOG_WARNING("Minds element is not list.");
        EventCompleted.emit();
        return;
    }

    if (!entitiesElem.isNone()) {
        for (auto& entityMessage : entitiesElem.asList()) {
            if (entityMessage.isMap()) {
                auto& entityMap = entityMessage.asMap();
                auto object = factories->createObject(entityMap);
                if (object.isValid()) {
                    if (!object->isDefaultId()) {
                        registerEntityReferences(object->getId(), entityMap);
                        mPersistedEntities.insert(std::make_pair(object->getId(), object));
                    }
                }
            }
        }
    }

    //If we should resume the world, check if the world has a "suspended" property,
    //and disable it if so.
    if (mResumeWorld) {
        auto I = mPersistedEntities.find("0");
        if (I != mPersistedEntities.end()) {
            if (I->second->hasAttr("suspended")) {
                I->second->setAttr("suspended", 0);
                S_LOG_INFO("Resuming suspended world.");
            }
        }
    }
    if (!mindsElem.isNone()) {
        for (auto& mindMessage : mindsElem.asList()) {
            if (mindMessage.isMap()) {
                auto object = factories->createObject(mindMessage.asMap());
                if (object.isValid()) {
                    if (!object->isDefaultId()) {
                        mPersistedMinds.insert(std::make_pair(object->getId(), object));
                    }
                }
            }
        }
    }

    S_LOG_INFO("Starting loading of world. Number of entities: " << mPersistedEntities.size() << " Number of minds: " << mPersistedMinds.size() << " Number of rules: " << mPersistedRules.size());
    mStats.entitiesCount = static_cast<unsigned int>(mPersistedEntities.size());
    mStats.mindsCount = static_cast<unsigned int>(mPersistedMinds.size());
    mStats.rulesCount = static_cast<unsigned int>(mPersistedRules.size());

    EventProgress.emit();

    if (mPersistedRules.empty()) {
        startEntityWalking();
    } else {
        startRuleWalking();
    }

}
예제 #9
0
ListAdapter::ListAdapter(const ::Atlas::Message::Element& element, CEGUI::Window* childContainer)
    :  AdapterBase(element), mChildContainer(childContainer), mAttributes(element.asList())
{
}