Ejemplo n.º 1
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);
        }
    }
}
Ejemplo n.º 2
0
bool TerrainArea::parseArea()
{
	if (!mEntity.hasAttr("area")) {
		S_LOG_FAILURE("TerrainArea created for entity with no area attribute");
		return false;
	}

	const Atlas::Message::Element areaElem(mEntity.valueOfAttr("area"));

	if (!areaElem.isMap()) {
		S_LOG_FAILURE("TerrainArea element ('area') must be of map type.");
		return false;
	}

	const Atlas::Message::MapType& areaData(areaElem.asMap());

	int layer = 0;
	WFMath::Polygon<2> poly;
	TerrainAreaParser parser;
	if (parser.parseArea(areaData, poly, layer)) {
		if (!mArea) {
			mArea = new Mercator::Area(layer, false);
		} else {
			//A bit of an ugly hack here since the Mercator system doesn't support changing the layer. We need to swap the old area for a new one if the layer has changed.
			if (mArea->getLayer() != layer) {
				mOldArea = mArea;
				mArea = new Mercator::Area(layer, false);
			}
		}
		// transform polygon into terrain coords
		WFMath::Vector<3> xVec = WFMath::Vector<3>(1.0, 0.0, 0.0).rotate(mEntity.getOrientation());
		double theta = atan2(xVec.y(), xVec.x()); // rotation about Z

		WFMath::RotMatrix<2> rm;
		poly.rotatePoint(rm.rotation(theta), WFMath::Point<2>(0, 0));
		poly.shift(WFMath::Vector<2>(mEntity.getPosition().x(), mEntity.getPosition().y()));

		mArea->setShape(poly);

		return true;
	} else {
		return false;
	}
}
void OutfitMatch::testAttribute(const Atlas::Message::Element& attribute, bool triggerEvaluation)
{
	if (attribute.isMap()) {
		Eris::Entity* entity(0);
		const auto& tmap = attribute.asMap();
		auto I = tmap.find(mOutfitName);
		if (I != tmap.end() && I->second.isString()) {
			entity = mView->getEntity(I->second.asString());
			//the entity might not be available yet, so we need to create an observer for it
			if (!entity) {
				if (mEntityObserver.get()) {
					mEntityObserver->observeCreation(mView, I->second.asString());
				}
			} else {
				testEntity(entity);
			}
		} else {
			testEntity(entity);
		}
	}
	if (triggerEvaluation) {
		evaluateChanges();
	}
}
Ejemplo n.º 4
0
int main()
{
    Eris::Logged.connect(sigc::ptr_fun(writeLog));
    Eris::setLogLevel(Eris::LOG_DEBUG);
    {
        TestConnection con("name", "localhost",
                                                    6767, true);

        TestAccount acc(&con);
        
        std::string fake_char_id("1");
        TestAvatar ea(&acc, fake_char_id);
        acc.setup_insertActiveCharacters(&ea);
        TestEntity* char_ent = new TestEntity(fake_char_id, 0, ea.getView());
        ea.setup_setEntity(char_ent);
        
        typedef std::map<std::string, Atlas::Message::Element> ElementStore;
        ElementStore modTypes;
        ElementStore shapes;
        
        ElementStore levelMods;
        Atlas::Message::MapType levelMod1;
        levelMod1["type"] = Atlas::Message::Element("levelmod");
        levelMods["1"] = levelMod1;
        Atlas::Message::MapType levelMod2(levelMod1);
        levelMod2["height"] = 20;
        levelMods["2"] = levelMod2;
        Atlas::Message::MapType levelMod3(levelMod1);
        levelMod2["heightoffset"] = 30;
        levelMods["3"] = levelMod3;
        
        
        ElementStore adjustMods;
        Atlas::Message::MapType adjustMod1;
        adjustMod1["type"] = Atlas::Message::Element("adjustmod");
        adjustMods["1"] = levelMod1;
        Atlas::Message::MapType adjustMod2(adjustMod1);
        adjustMod2["height"] = 20;
        adjustMods["2"] = adjustMod2;
        Atlas::Message::MapType adjustMod3(adjustMod1);
        adjustMod2["heightoffset"] = 30;
        adjustMods["3"] = adjustMod3;
        
        Atlas::Message::MapType craterMod1;
        craterMod1["type"] = Atlas::Message::Element("cratermod");
        
        ElementStore slopeMods;
        Atlas::Message::MapType slopeMod1;
        slopeMod1["type"] = Atlas::Message::Element("slopemod");
        Atlas::Message::ListType slopes;
        slopes.push_back(10);
        slopes.push_back(20);
        slopeMod1["slopes"] = slopes;
        slopeMods["1"] = slopeMod1;
        
        
        Atlas::Message::MapType shapeCircle;
        shapeCircle["radius"] = 15;
        shapeCircle["position"] = Atlas::Message::ListType(2, 0.);
        shapeCircle["type"] = "ball";
        shapes["ball"] = shapeCircle;
        
        Atlas::Message::MapType shapePolygon;
        Atlas::Message::ListType points;
        points.push_back(WFMath::Point<2>(0,0).toAtlas());
        points.push_back(WFMath::Point<2>(10,0).toAtlas());
        points.push_back(WFMath::Point<2>(10,10).toAtlas());
        points.push_back(WFMath::Point<2>(0,10).toAtlas());
        shapePolygon["points"] = points;
        shapePolygon["type"] = "polygon";
        shapes["polygon"] = shapePolygon;
        
        shapes["empty"] = Atlas::Message::MapType();
        
        //no terrain mod info
        {
            Atlas::Message::MapType emptyElement;
            TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
            mod_ent->setup_setAttr("terrainmod", emptyElement);
            
            Eris::TerrainModObserver mod(mod_ent);
            assert(!mod.init());
            
        }
        
        //no shape
        {
            Atlas::Message::MapType modElement = levelMod1;
            TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
            mod_ent->setup_setAttr("terrainmod", modElement);
            
            Eris::TerrainModObserver mod(mod_ent);
            assert(!mod.init());
            
        }       
         
        //test level mod
        for (ElementStore::iterator I = levelMods.begin(); I != levelMods.end(); ++I) {
            for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) {
                std::cout << "Testing level mod " << I->first << " with " << J->first << std::endl;
                Atlas::Message::Element modElement = I->second;
                modElement.asMap()["shape"] = J->second;
                TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
                mod_ent->setup_setAttr("terrainmod", modElement);
                
                Eris::TerrainModObserver mod(mod_ent);
                if (J->first == "empty") {
                    assert(!mod.init());
                } else {
                    assert(mod.init());
                }
            }
        }        
        
        //test adjust mod
        for (ElementStore::iterator I = adjustMods.begin(); I != adjustMods.end(); ++I) {
            for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) {
                std::cout << "Testing adjust mod " << I->first << " with " << J->first << std::endl;
                Atlas::Message::Element modElement = I->second;
                modElement.asMap()["shape"] = J->second;
                TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
                mod_ent->setup_setAttr("terrainmod", modElement);
                
                Eris::TerrainModObserver mod(mod_ent);
                if (J->first == "empty") {
                    assert(!mod.init());
                } else {
                    assert(mod.init());
                }
            }
        }
                
        //test slope mod
        for (ElementStore::iterator I = slopeMods.begin(); I != slopeMods.end(); ++I) {
            for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) {
                std::cout << "Testing slope mod " << I->first << " with " << J->first << std::endl;
                Atlas::Message::Element modElement = I->second;
                modElement.asMap()["shape"] = J->second;
                TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
                mod_ent->setup_setAttr("terrainmod", modElement);
                
                Eris::TerrainModObserver mod(mod_ent);
                if (J->first == "empty") {
                    assert(!mod.init());
                } else {
                    assert(mod.init());
                }
            }
        }
        
        Atlas::Message::MapType shapeBall;
        shapeBall["radius"] = 15;
        shapeBall["position"] = Atlas::Message::ListType(3, 0.);
        shapeBall["type"] = "ball";
        
        //test crater mod
        {
            Atlas::Message::MapType modElement = craterMod1;
            modElement["shape"] = shapeCircle;
            TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
            mod_ent->setup_setAttr("terrainmod", modElement);
            
            Eris::TerrainModObserver mod(mod_ent);
            assert(mod.init());
            
        }
    }
    return 0;
}
Ejemplo n.º 5
0
MapAdapter::MapAdapter(const ::Atlas::Message::Element& element, CEGUI::Window* childContainer)
:  AdapterBase(element), mChildContainer(childContainer),
mAttributes(element.asMap())
{
}