Exemplo n.º 1
0
	void ZombieGame::loadTerrain() {
		auto entry = ZombieEntry(zombieEntry_.getDeepChildEntry("settings map").getString());
		entry = entry.getDeepChildEntry("map objects object");
		while (entry.hasData()) {
			std::string geom(entry.getChildEntry("geom").getString());
			if (entry.isAttributeEqual("type", "building")) {
				auto v = loadPolygon(geom);
				Building* b = buildings_.emplaceBack(v[0], v[1], v[2], v[3], wall_, wall_, wall_);
				engine_.add(b);
				b->setActive(true);
				b->setAwake(true);
			} else if (entry.isAttributeEqual("type", "water")) {
				auto triangle = loadPolygon(geom);
				water_.addTriangle(triangle[0], triangle[1], triangle[2]);
			} else if (entry.isAttributeEqual("type", "grass")) {
				auto triangle = loadPolygon(geom);
				terrain_.addGrass(triangle[0], triangle[1], triangle[2]);
			} else if (entry.isAttributeEqual("type", "tilepoint")) {
				terrain_.addRoad(entry);
			} else if (entry.isAttributeEqual("type", "tree")) {
				engine_.add(new Tree2D(loadPoint(geom), tree_));
			} else if (entry.isAttributeEqual("type", "spawningpoint")) {
				spawningPoints_.push_back(loadPoint(geom));
			} else if (entry.isAttributeEqual("type", "carSpawningpoint")) {
				//carSpawningPoints_.push_back(loadPoint(geom));
			}
			entry = entry.getSibling("object");
		}
	}
Exemplo n.º 2
0
	void Terrain2D::addRoad(ZombieEntry tileEntry) {
		Position position = loadPoint(tileEntry.getChildEntry("geom").getString());
		std::string tileId = tileEntry.getChildEntry("tile_id").getString();
		int deg = tileEntry.getChildEntry("rotation").getInt();
		float size = tileEntry.getChildEntry("size").getFloat();
		mw::Sprite sprite;
		if (tileId == "turn") {
			switch (deg) {
				case 0:
					sprite = turn0_;
					break;
				case 90:
					sprite = turn90_;
					break;
				case 180:
					sprite = turn180_;
					break;
				case 270:
					sprite = turn270_;
					break;
			}
		} else if (tileId == "straight") {
			switch (deg) {
				case 0:
					sprite = straight0_;
					break;
				case 90:
					sprite = straight90_;
					break;
			}
		} else if (tileId == "tintersection") {
			switch (deg) {
				case 0:
					sprite = tintersection0_;
					break;
				case 90:
					sprite = tintersection90_;
					break;
				case 180:
					sprite = tintersection180_;
					break;
				case 270:
					sprite = tintersection270_;
					break;
			}
		} else { //if (tileId == "intersection") {
			sprite = intersection_;
		}
		
		// 4 float/vertices * 6 vertices.
		std::array<GLfloat, 4 * 6> data_;

		int index = 0;
		addSquare(data_.data(), index, position.x - size*0.5f, position.y - size*0.5f, size, size, sprite);
		roads_.insert(roads_.end(), data_.begin(), data_.end());
		numberVerticesRoads_ += 6;
	}
Exemplo n.º 3
0
bool Exif2GPX::loadGPX(const QString& filename, 
		       bool useTracks, bool useWaypoints) {
  QDomDocument qdd;
  QFile file(filename);
  qdd.setContent(&file);
  QDomNode node, node2, node3, node4, node5;
  node = qdd.namedItem("gpx");
  if (node.isNull()) {
    std::cerr<<"Could not load "<<filename<<std::endl;
    return false;
  }
  
  node2 = node.firstChild();
  while (!node2.isNull()) {
    if (node2.nodeName() == "wpt" && useWaypoints)
      loadPoint(node2);
    else if (node2.nodeName() == "trk" && useTracks) {
      node3 = node2.firstChild();
      while (!node3.isNull()) {
	if (node3.nodeName() == "trkseg") {
	  node4 = node3.firstChild();
	  while (!node4.isNull()) {
	    if (node4.nodeName() == "trkpt")
	      loadPoint(node4);
	    node4 = node4.nextSibling();
	  }
	}
	node3 = node3.nextSibling();
      }
    }
    node2 = node2.nextSibling();
  }
  
  // did we get any points?
  if (points.size() == 0) {
    std::cerr<<"No timestamped points found in "<<filename<<std::endl;
    return false;
  }
  
  return true;
}
Exemplo n.º 4
0
void UpdateScene::update(float diff) {
    if(!updateYet) {
        updateYet = true;
	    //不需要更新文件
        CCUserDefault *def = CCUserDefault::sharedUserDefault();
        if(def->getStringForKey("update") != "0")
            ap->updateFiles();
        else  {
            progress = 200;
        }
    } else {
        localcount = localcount+1;
		CCLog("progress to load main %d", progress);
        if(progress == 200 && localcount >= 50) {
            CCUserDefault *def = CCUserDefault::sharedUserDefault();
            if(def->getStringForKey("update") != "0") {
                if(publicAssets != NULL) {
                    publicAssets->updateVersion();
                }
            }
            /*
			CCDictionary *dict = CCDictionary::create();
			CCDictionary *ads = CCDictionary::create();
			ads->setObject(CCString::create("AdsAdmob"), "name");
			dict->setObject(ads, "ads");
			MyPlugins::getInstance()->loadPlugins(dict);
            */
		
			CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();

			std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("main.lua");
			pEngine->executeScriptFile(path.c_str());
		}else {
			loadPoint(progress);
		}
	}
}
Exemplo n.º 5
0
int XMIResource::processElement(xmlTextReaderPtr reader)
{
    const xmlChar *name = xmlTextReaderConstLocalName(reader);
    parent = NB_XCOS_NAMES;

    // lookup for known node names
    // thanks to the string intern-ing, the pointer comparison could be used
    auto found = std::find(constXcosNames.begin(), constXcosNames.end(), name);
    enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
    switch (current)
    {
        case e_Diagram:
        {
            // the root diagram should be decoded
            model::BaseObject o(root, DIAGRAM);

            processed.push_back(o);
            return loadDiagram(reader, o);
        }
        case e_child:
        {
            // this is a child of a diagram, resolve the type and call the loaders
            // iterate on attributes to lookup for EMF type

            // iterate on attributes
            for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
            {
                const xmlChar* nsURI  = xmlTextReaderConstNamespaceUri(reader);
                if (nsURI != xsiNamespaceUri)
                {
                    continue;
                }

                auto foundName = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstLocalName(reader));
                enum xcosNames currentName = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), foundName));
                if (currentName != e_type)
                {
                    continue;
                }

                const xmlChar* value = xmlTextReaderConstValue(reader);
                const xmlChar* valueWithoutPrefix = BAD_CAST(std::strchr((const char*) value, ':'));
                if (valueWithoutPrefix == nullptr)
                {
                    valueWithoutPrefix = value;
                }
                else
                {
                    // remove the leading ':'
                    valueWithoutPrefix = valueWithoutPrefix + 1;
                }
                const xmlChar* interned = xmlTextReaderConstString(reader, valueWithoutPrefix);

                auto found = std::find(constXcosNames.begin(), constXcosNames.end(), interned);
                enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
                switch (current)
                {
                    case e_Block:
                    {
                        ScicosID o = controller.createObject(BLOCK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, BLOCK);
                        processed.push_back(child);
                        return loadBlock(reader, child);
                    }
                    case e_Link:
                    {
                        ScicosID o = controller.createObject(LINK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, LINK);
                        processed.push_back(child);
                        return loadLink(reader, child);
                    }
                    case e_Annotation:
                    {
                        ScicosID o = controller.createObject(ANNOTATION);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, ANNOTATION);
                        return loadAnnotation(reader, child);
                    }
                    default:
                        sciprint("Not handled child type=%s at line %d\n", *found,
                                 xmlTextReaderGetParserLineNumber(reader) - 1);
                        return -1;
                }
            }
            break;
        }
        case e_in: // no break on purpose
        case e_out: // no break on purpose
        case e_ein: // no break on purpose
        case e_eout:
        {
            ScicosID o = controller.createObject(PORT);

            enum object_properties_t p;
            switch (current)
            {
                case e_in:
                    p = INPUTS;
                    break;
                case e_out:
                    p = OUTPUTS;
                    break;
                case e_ein:
                    p = EVENT_INPUTS;
                    break;
                case e_eout:
                    p = EVENT_OUTPUTS;
                    break;
                default:
                    return -1;
            }

            model::BaseObject parent = processed.back();
            // add the port them to the parent
            std::vector<ScicosID> ports;
            controller.getObjectProperty(parent.id(), parent.kind(), p, ports);
            ports.push_back(o);
            controller.setObjectProperty(parent.id(), parent.kind(), p, ports);

            // decode content
            model::BaseObject child(o, PORT);
            return loadPort(reader, child);
        }
        case e_geometry:
            // geometry is used for rectangle coordinates of its parent
            return loadGeometry(reader, processed.back());
        case e_nzcross:
            // nzcross is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_nmode:
            // nmode is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_rpar:
            // rpar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_ipar:
            // ipar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_opar:
            // ipar is a Block property
            return loadBase64(reader, OPAR, processed.back());
        case e_state:
            // state is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_dstate:
            // dstate is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_odstate:
            // odstate is a Block property
            return loadBase64(reader, ODSTATE, processed.back());
        case e_equations:
            // equation is a Block property
            return loadBase64(reader, EQUATIONS, processed.back());
        case e_expression:
            // expression is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_exprs:
            // exprs is a Block property
            return loadBase64(reader, EXPRS, processed.back());
        case e_controlPoint:
            // controlPoint is a link property
            return loadPoint(reader, processed.back());
        case e_context:
            // context is a Layer property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_properties:
            // properties is a Diagram property
            return loadSimulationConfig(reader, processed.back());
        case e_datatype:
            // datatype is a Port property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        default:
            sciprint("Unknown \"%s\" element name at line %d\n", name, xmlTextReaderGetParserLineNumber(reader) - 1);
            return -1;
    }

    return 1;
}
Exemplo n.º 6
0
void NamedPoint::load(Common::SeekableReadStream &stream) {
	_namedPointId = stream.readUint32LE();
	loadPoint(stream, _pt);
}