TypeNode * Inheritance::addChild(const Root & obj) { const std::string & child = obj->getId(); const std::string & parent = obj->getParents().front(); if (atlasObjects.find(child) != atlasObjects.end()) { std::cerr << String::compose("Installing type \"%1\"(\"%2\") " "which was already installed", child, parent) << std::endl; return 0; } TypeNodeDict::iterator I = atlasObjects.find(parent); if (I == atlasObjects.end()) { std::cerr << String::compose("Installing type \"%1\" " "which has unknown parent \"%2\".", child, parent) << std::endl; return 0; } Element children(ListType(1, child)); if (I->second->description()->copyAttr("children", children) == 0) { assert(children.isList()); children.asList().push_back(child); } I->second->description()->setAttr("children", children); TypeNode * type = new TypeNode(child, obj); type->setParent(I->second); atlasObjects[child] = type; return type; }
TypeNode * Inheritance::addChild(const Root & obj) { const std::string & child = obj->getId(); const std::string & parent = obj->getParents().front(); assert(atlasObjects.find(child) == atlasObjects.end()); TypeNodeDict::iterator I = atlasObjects.find(parent); assert(I != atlasObjects.end()); Element children(ListType(1, child)); if (I->second->description()->copyAttr("children", children) == 0) { assert(children.isList()); children.asList().push_back(child); } I->second->description()->setAttr("children", children); TypeNode * type = new TypeNode(child, obj); type->setParent(I->second); atlasObjects[child] = type; return type; }
TypeNode * Inheritance::addChild(const Root & obj) { assert(obj->getParents().size() > 0); const std::string & child = obj->getId(); const std::string & parent = obj->getParents().front(); TypeNodeDict::const_iterator I = atlasObjects.find(child); TypeNodeDict::const_iterator Iend = atlasObjects.end(); if (I != Iend) { const TypeNode * existing = I->second->parent(); log(ERROR, String::compose("Installing %1 \"%2\"(\"%3\") " "which was already installed as %4 (\"%5\")", obj->getObjtype(), child, parent, I->second->description()->getObjtype(), existing ? existing->name() : "NON")); return 0; } I = atlasObjects.find(parent); if (I == Iend) { log(ERROR, String::compose("Installing %1 \"%2\" " "which has unknown parent \"%3\".", obj->getObjtype(), child, parent));; return 0; } Element children(ListType(1, child)); if (I->second->description()->copyAttr("children", children) == 0) { assert(children.isList()); children.asList().push_back(child); } I->second->description()->setAttr("children", children); TypeNode * type = new TypeNode(child, obj); type->setParent(I->second); atlasObjects.insert(std::make_pair(child, type)); return type; }
void setup() { m_inheritance = new Inheritance(); //Set up testing environment for Type/Soft properties m_b1 = new TestEntity("1", 1); add_entity(m_b1); m_thingType = new TypeNode("thing"); types["thing"] = m_thingType; m_barrelType = new TypeNode("barrel"); m_barrelType->setParent(m_thingType); types["barrel"] = m_barrelType; m_b1->setType(m_barrelType); m_b1->setProperty("mass", new SoftProperty(Element(30))); m_b1->setProperty("burn_speed", new SoftProperty(Element(0.3))); m_b1->setProperty("isVisible", new SoftProperty(Element(true))); m_b2 = new Entity("2", 2); add_entity(m_b2); m_b2->setProperty("mass", new SoftProperty(Element(20))); m_b2->setProperty("burn_speed", new SoftProperty(0.25)); m_b2->setType(m_barrelType); m_b2->setProperty("isVisible", new SoftProperty(Element(false))); m_b3 = new Entity("3", 3); add_entity(m_b3); m_b3->setProperty("mass", new SoftProperty(Element(25))); m_b3->setProperty("burn_speed", new SoftProperty(Element(0.25))); m_b3->setType(m_barrelType); m_boulderType = new TypeNode("boulder"); types["boulder"] = m_boulderType; m_bl1 = new Entity("4", 4); add_entity(m_bl1); m_bl1->setProperty("mass", new SoftProperty(Element(25))); m_bl1->setType(m_boulderType); SoftProperty* prop1 = new SoftProperty(); prop1->set(std::vector<Element>{25.0, 20.0}); m_bl1->setProperty("float_list", prop1); SoftProperty* list_prop2 = new SoftProperty(); list_prop2->set(std::vector<Element>{"foo", "bar"}); m_bl1->setProperty("string_list", list_prop2); // Create an entity-related memory map Atlas::Message::MapType entity_memory_map{{"disposition", 25}}; m_memory.emplace("1", entity_memory_map); //b1 contains bl1 which contains b3 m_b1_container = new LocatedEntitySet; m_b1_container->insert(m_bl1); m_bl1->m_location.m_parent = m_b1; m_b1->m_contains = m_b1_container; m_b1->test_setDomain(new TestDomain(*m_b1)); m_bl1_container = new LocatedEntitySet; m_bl1_container->insert(m_b3); m_b3->m_location.m_parent = m_bl1; m_bl1->m_contains = m_bl1_container; //Set up testing environment for Outfit property m_glovesType = new TypeNode("gloves"); types["gloves"] = m_glovesType; m_bootsType = new TypeNode("boots"); m_characterType = new TypeNode("character"); types["character"] = m_characterType; TypeNode* m_clothType = new TypeNode("cloth"); types["cloth"] = m_clothType; TypeNode* m_leatherType = new TypeNode("leather"); m_glovesEntity = new Entity("5", 5); add_entity(m_glovesEntity); m_glovesEntity->setType(m_glovesType); m_glovesEntity->setProperty("color", new SoftProperty("brown")); m_glovesEntity->setProperty("mass", new SoftProperty(5)); //Mark it with a "reach" so we can use it in the "can_reach ... with" tests auto reachProp = new Property<double>(); reachProp->data() = 10.0f; m_glovesEntity->setProperty("reach", reachProp); m_bootsEntity = new Entity("6", 6); add_entity(m_bootsEntity); m_bootsEntity->setType(m_bootsType); m_bootsEntity->setProperty("color", new SoftProperty("black")); m_bootsEntity->setProperty("mass", new SoftProperty(10)); m_cloth = new Entity("8", 8); add_entity(m_cloth); m_cloth->setType(m_clothType); m_cloth->setProperty("color", new SoftProperty("green")); m_leather = new Entity("9", 9); add_entity(m_leather); m_leather->setType(m_leatherType); m_leather->setProperty("color", new SoftProperty("pink")); //The m_cloth entity is attached to the gloves by the "thumb" attachment { auto attachedProp = new SoftProperty(); attachedProp->data() = Atlas::Message::MapType{{"$eid", m_cloth->getId()}}; m_glovesEntity->setProperty("attached_thumb", attachedProp); auto plantedOnProp = new PlantedOnProperty(); plantedOnProp->data().entity = WeakEntityRef(m_glovesEntity.get()); m_cloth->setProperty("planted_on", plantedOnProp); } m_ch1 = new Entity("7", 7); add_entity(m_ch1); m_ch1->setType(m_characterType); //The m_glovesEntity entity is attached to the m_ch1 by the "hand_primary" attachment { auto attachedHandPrimaryProp = new SoftProperty(); attachedHandPrimaryProp->data() = Atlas::Message::MapType{{"$eid", m_glovesEntity->getId()}}; m_ch1->setProperty("attached_hand_primary", attachedHandPrimaryProp); } { auto plantedOnProp = new PlantedOnProperty(); plantedOnProp->data().entity = WeakEntityRef(m_ch1.get()); m_glovesEntity->setProperty("planted_on", plantedOnProp); } BBoxProperty* bbox1 = new BBoxProperty; bbox1->set((std::vector<Element>{-1, -3, -2, 1, 3, 2})); m_b1->setProperty("bbox", bbox1); BBoxProperty* bbox2 = new BBoxProperty; bbox2->set(std::vector<Element>{-3, -2, -1, 1, 3, 2}); m_bl1->setProperty("bbox", bbox2); m_cloth->setProperty("bbox", bbox1->copy()); }