Exemple #1
0
bool CGWIC_Cell::LoadObjectStates()
{
	path filenm = GWIC_CELLSTORE_DIR;
	filenm += GetCellFileSuffix();
	filenm += ".xml";
	IXMLReader* xml = graphics->getFileSystem()->createXMLReader(filenm);
	if (!xml) {
		std::cerr << "LoadObjectStates(): can't create xml reader for " << filenm.c_str() << std::endl;
		return false;
	}
	const stringw tg_obj(L"object");
	const stringw tg_pos(L"position");
	const stringw tg_opt(L"options");
	stringw cur_tag;
	path cfile;
	CIrrStrParser pos,rot,scl;
	CGWIC_GameObject* optr = NULL;
	while (xml->read()) {
		switch (xml->getNodeType()) {
		case EXN_ELEMENT:
			if ((cur_tag.empty()) && (tg_obj.equals_ignore_case(xml->getNodeName()))) {
				cur_tag = tg_obj;
				cfile = xml->getAttributeValueSafe(L"file");
				optr = new CGWIC_GameObject(cfile,GetCoord(),graphics,physics);
				if (!optr)
					std::cerr << "Failed to create object from " << cfile.c_str() << std::endl;
				else
					objects.push_back(optr);
			} else if ((cur_tag == tg_obj) && (optr)) {
				if (tg_pos.equals_ignore_case(xml->getNodeName())) {
					pos = xml->getAttributeValueSafe(L"pos");
					rot = xml->getAttributeValueSafe(L"rot");
					scl = xml->getAttributeValueSafe(L"scale");
					optr->SetPos(pos.ToVector3f());
					optr->SetScale(scl.ToVector3f());
					optr->SetRot(rot.ToVector3f());
				} else if (tg_pos.equals_ignore_case(xml->getNodeName())) {
					optr->SetPhysical(xml->getAttributeValueAsInt(L"physical"));
					optr->SetEnabled(xml->getAttributeValueAsInt(L"enabled"));
				}
			}
			break;
		case EXN_ELEMENT_END:
			cur_tag = L"";
			optr = NULL;
			break;
		default: break;
		}
	}
	xml->drop();
	return false;
}
Exemple #2
0
void World::readWalkableObjectIndex() {

	//std::cout << "Loaidng objects that are walkable: " << endl;

	//filepath for the object file
	stringw path = WALK_OBJECT_INDEX;
	//the only tag in this file is the object tag to define a new object
	const stringw object("objectWalkable");
	//initialize an XML reader
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(path);

	//start the reading loop
	while (reader->read()) {
		switch (reader->getNodeType()) {
			//we found a new element
		case irr::io::EXN_ELEMENT:
			//new <object> tag
			if (object.equals_ignore_case(reader->getNodeName())) {
				u16 id = reader->getAttributeValueAsInt(L"id");
				u16 x = reader->getAttributeValueAsInt(L"x");
				u16 y = reader->getAttributeValueAsInt(L"y");
				u16 f = reader->getAttributeValueAsInt(L"f");
				u16 h = reader->getAttributeValueAsInt(L"h");
				object_walkable_index.push_back(ObjectWalkableData(id, x, y, f, h));
				//cout << "object loaded: " << id << " " << x << " " << y << " " << f << endl;
			}
			break;
		}
	}

	//drop the xml reader
	reader->drop();
}
Exemple #3
0
// ----------------------------------------------------------------------------
void Editor::writeResAndExePathIntoConfig()
{
    stringc p;
    IFileSystem* file_system = m_device->getFileSystem();
    IXMLReader*  xml_reader = file_system->createXMLReader(m_config_loc + "/config.xml");
    if (xml_reader)
    {
        const stringw node_name(L"data_dir");
        while (xml_reader->read())
        {
            if (xml_reader->getNodeType() == EXN_ELEMENT
                && node_name.equals_ignore_case(xml_reader->getNodeName()))
            {
                p = xml_reader->getAttributeValueSafe(L"path");
            }
        }
        xml_reader->drop();
    }

    std::ofstream f;
    f.open((m_config_loc + "/config.xml").c_str());
    f << "<config>\n";
    f << "  <data_dir path=\"" << p.c_str() << "\" />\n";

    if (!m_exe_loc.empty())
        f << "  <exe path=\"" << m_exe_loc.c_str() << "\" />\n";

    f << "  <res x=\"" << m_screen_size.Width << "\" y=\"";
    f << m_screen_size.Height << "\" />\n";
    f << "</config>\n";
    f.close();

} // writeResAndExePathIntoConfig
Exemple #4
0
void World::readWaterIndex() {
	//filepath for the object file
	stringw path = WATER_INDEX;
	//the only tag in this file is the object tag to define a new object
	const stringw object("water");
	//initialize an XML reader
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(path);

	//start the reading loop
	while (reader->read()) {
		  switch (reader->getNodeType()) {
			  //we found a new element
              case irr::io::EXN_ELEMENT:
				  //new <object> tag
				  if (object.equals_ignore_case(reader->getNodeName())) {
					  u16 id = reader->getAttributeValueAsInt(L"id");
					  u16 x = reader->getAttributeValueAsInt(L"x");
					  u16 y = reader->getAttributeValueAsInt(L"y");
					  u16 w = reader->getAttributeValueAsInt(L"w");
					  u16 l = reader->getAttributeValueAsInt(L"l");
					  float h = reader->getAttributeValueAsFloat(L"height");
					  water_index.push_back(WaterData(id, x, y,  w, l, h));
					  cout << "Water loaded " << id << " " << x << " " << y << " " << w << " " << l << " " << h << endl;
				  }
				  break;
		  }
	}

	//drop the xml reader
	reader->drop();
}
Exemple #5
0
// ----------------------------------------------------------------------------
void Editor::readConfigFile(IFileSystem* file_system)
{
    IXMLReader* xml_reader = file_system->createXMLReader(path(PHYSFS_getBaseDir())
                                                                    + "config.xml");

    if (!xml_reader)
    {
        path dir = PHYSFS_getUserDir();
        m_config_loc = dir + "/.stk-te";
        xml_reader = file_system->createXMLReader(m_config_loc + "/config.xml");
        if (!xml_reader)
        {
            PHYSFS_setWriteDir(dir.c_str());
            PHYSFS_mkdir(".stk-te");
            return;
        }
    }
    else m_config_loc = PHYSFS_getBaseDir();

    const stringw node_name(L"data_dir");
    const stringw res(L"res");
    const stringw exe(L"exe");
    while (xml_reader->read())
    {
        if (xml_reader->getNodeType() == EXN_ELEMENT)
        {
            if (res.equals_ignore_case(xml_reader->getNodeName()))
            {
                m_screen_size = dimension2du(
                    atol(((stringc)xml_reader->getAttributeValueSafe(L"x")).c_str()),
                    atol(((stringc)xml_reader->getAttributeValueSafe(L"y")).c_str()));
            }
            else  if (node_name.equals_ignore_case(xml_reader->getNodeName()))
            {
                m_data_loc = xml_reader->getAttributeValueSafe(L"path");
                m_icons_loc = m_data_loc + "editor/icons/";
            }
            else if (exe.equals_ignore_case(xml_reader->getNodeName()))
            {
                m_exe_loc = xml_reader->getAttributeValueSafe(L"path");
            }
        }
    }
    xml_reader->drop();
} // readConfigFile
void ZoneSoundLoader::readZonesFromFile(){

	m_firstRun = true; // dont remove this :) in here for good execution flow

	// clear the zone_index vector
	m_zone_index.clear();

	// read from .dat file which contains zone boundaries
	stringw reader_path = SOUND_INDEX;
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(reader_path);

	const stringw zone("zone");

	// read through the zones
	while (reader->read()){

		switch (reader->getNodeType()) {
			// if new zone is found..
		case irr::io::EXN_ELEMENT:
			//new <object> tag
			if (zone.equals_ignore_case(reader->getNodeName())) {
				u16 id = reader->getAttributeValueAsInt(L"id");
				u16 x = reader->getAttributeValueAsInt(L"x");
				u16 z = reader->getAttributeValueAsInt(L"z");
				u16 tox = reader->getAttributeValueAsInt(L"tox");
				u16 toz = reader->getAttributeValueAsInt(L"toz");
				//stringw name = reader->getAttributeValue(L"name");
				const wchar_t* songName = reader->getAttributeValue(L"songName");
				const wchar_t* name = reader->getAttributeValue(L"name");
				wstring sN(songName);
				//std::cout << "Song name:" << endl;
				//std::wcout << sN.c_str() << endl;
				// push the object to a vector
				m_zone_index.push_back(ZoneData(id, x, z, tox, toz, name, songName));
			}
			break;
		}

	}
}
Exemple #7
0
// ----------------------------------------------------------------------------
std::list<stringc> Editor::readRecentlyOpenedList()
{
    std::list<stringc> list;

    IFileSystem* file_system = m_device->getFileSystem();
    IXMLReader*  xml_reader = file_system->createXMLReader(m_config_loc + "/recent.xml");

    stringc s;
    if (xml_reader)
    {
        const stringw file(L"file");
        while (xml_reader->read())
        {
            if (xml_reader->getNodeType() == EXN_ELEMENT
                && file.equals_ignore_case(xml_reader->getNodeName()))
            {
                s  = xml_reader->getAttributeValueSafe(L"name");
                list.push_back(s);
            }
        }
        xml_reader->drop();
    }
    return list;
} // readRecentlyOpenedList
Exemple #8
0
void World::readClickableObjectIndex() {
	ObjectClickable oc;
	//filepath for the objects that are clickable file
	stringw path = CLICK_OBJECT_INDEX;
	//the only tag in this file is the object tag to define a new object
	const stringw object("object");
	//initialize an XML reader
	io::IXMLReader* reader = Client::device->getFileSystem()->createXMLReader(path);

	//start the reading loop
	while (reader->read()) {
		switch (reader->getNodeType()) {
			//we found a new element
		case irr::io::EXN_ELEMENT:
			//new <object> tag
			if (object.equals_ignore_case(reader->getNodeName())) {
				u16 id = reader->getAttributeValueAsInt(L"id");
				u16 x = reader->getAttributeValueAsInt(L"x");
				u16 y = reader->getAttributeValueAsInt(L"y");
				u16 f = reader->getAttributeValueAsInt(L"f");
				stringw m = oc.getMenuItemsList(id);

				//oc.addTriangleSelector();

				object_clickable_index.push_back(ObjectClickableData(id, x, y, f, m));
				cout << "CLICKABLE object loaded: " << id << " " << x << " " << y << " " << f << endl;
				//u16 height = reader->getAttributeValueAsInt(L"h");
				//object_walkable_index.push_back(ObjectWalkableData(id, x, y, f, height));
			}
			break;
		}
	}

	//drop the xml reader
	reader->drop();
}
Exemple #9
0
	/*
	Load xml from disk, overwrite default settings
	The xml we are trying to load has the following structure
	settings nested in sections nested in the root node, like so
	<pre>
		<?xml version="1.0"?>
		<mygame>
			<video>
				<setting name="driver" value="Direct3D9" />
				<setting name="fullscreen" value="0" />
				<setting name="resolution" value="1024x768" />
			</video>
		</mygame>
	</pre>
	*/
	bool load()
	{
		//if not able to create device don't attempt to load
		if (!NullDevice)
			return false;

		irr::io::IXMLReader* xml = NullDevice->getFileSystem()->createXMLReader(SettingsFile);	//create xml reader
		if (!xml)
			return false;

		const stringw settingTag(L"setting"); //we'll be looking for this tag in the xml
		stringw currentSection; //keep track of our current section
		const stringw videoTag(L"video"); //constant for videotag

		//while there is more to read
		while (xml->read())
		{
			//check the node type
			switch (xml->getNodeType())
			{
				//we found a new element
				case irr::io::EXN_ELEMENT:
				{
					//we currently are in the empty or mygame section and find the video tag so we set our current section to video
					if (currentSection.empty() && videoTag.equals_ignore_case(xml->getNodeName()))
					{
						currentSection = videoTag;
					}
					//we are in the video section and we find a setting to parse
					else if (currentSection.equals_ignore_case(videoTag) && settingTag.equals_ignore_case(xml->getNodeName() ))
					{
						//read in the key
						stringw key = xml->getAttributeValueSafe(L"name");
						//if there actually is a key to set
						if (!key.empty())
						{
							//set the setting in the map to the value,
							//the [] operator overrides values if they already exist or inserts a new key value
							//pair into the settings map if it was not defined yet
							SettingMap[key] = xml->getAttributeValueSafe(L"value");
						}
					}

					//..
					// You can add your own sections and tags to read in here
					//..
				}
				break;

				//we found the end of an element
				case irr::io::EXN_ELEMENT_END:
					//we were at the end of the video section so we reset our tag
					currentSection=L"";
				break;
			}
		}

		// don't forget to delete the xml reader
		xml->drop();

		return true;
	}
Exemple #10
0
bool CGWIC_BodyPart::LoadModelFile(irr::io::path fname)
{
	IXMLReader* mio = irDevice->getFileSystem()->createXMLReader(fname);
	if (!mio) return false;
	std::cout << "Reading model XML: " << fname.c_str() << std::endl;
	const stringw mt_model(L"Model");
	const stringw mt_inslot(L"InSlot");
	const stringw mt_outslot(L"OutSlot");
	const stringw mt_collision(L"Collision");
	const stringw mt_colbox(L"StandardBox");
	const stringw mt_colsph(L"StandardSphere");
	const stringw mt_coltri(L"TriMeshShape");
	const stringw mt_colcvx(L"ConvexHull");
	const stringw mt_colgim(L"GImpact");
	GWIC_BPSlot cslot;
	CIrrStrParser strparse;
	nocollision = true; //in case we can't load or found collision shape model
	while (mio->read()) {
		if (mt_model.equals_ignore_case(mio->getNodeName())) {
			mesh = scManager->getMesh(GWIC_BPARTS_DIR+mio->getAttributeValueSafe(L"file"));
			if (mesh) root = scManager->addAnimatedMeshSceneNode(
					mesh,parent,GWIC_PICKABLE_MASK | GWIC_ACTOR_MASK);
			if (root) {
				root->updateAbsolutePosition();
				root->setMaterialFlag(EMF_NORMALIZE_NORMALS,true);
				ITriangleSelector* sel = scManager->createTriangleSelector(mesh,root);
				root->setTriangleSelector(sel);
				sel->drop();
			}
			//TODO: texturing
		} else if (mt_inslot.equals_ignore_case(mio->getNodeName())) {
			strparse = mio->getAttributeValueSafe(L"position");
			slot_in.posit = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"rotation");
			slot_in.rotat = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"axis");
			slot_in.axis = strparse.ToVector3f();
		} else if (mt_outslot.equals_ignore_case(mio->getNodeName())) {
			cslot.ID = mio->getAttributeValueAsInt(L"ID");
			strparse = mio->getAttributeValueSafe(L"position");
			cslot.posit = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"rotation");
			cslot.rotat = strparse.ToVector3f();
			strparse = mio->getAttributeValueSafe(L"axis");
			cslot.axis = strparse.ToVector3f();
			slot_outs.push_back(cslot);
		} else if (mt_collision.equals_substring_ignore_case(mio->getNodeName())) {
			mass = mio->getAttributeValueAsFloat(L"mass");
			stringw data = mio->getAttributeValueSafe(L"type");
			nocollision = false;
			if (data.equals_substring_ignore_case(mt_colbox))
				coltype = ECST_BOX;
			else if (data.equals_substring_ignore_case(mt_colsph))
				coltype = ECST_SPHERE;
			else if (data.equals_substring_ignore_case(mt_coltri))
				coltype = ECST_BVHTRIMESH;
			else if (data.equals_substring_ignore_case(mt_colcvx))
				coltype = ECST_CONVEXHULL;
			else if (data.equals_substring_ignore_case(mt_colgim))
				coltype = ECST_GIMPACT;
			else {
				std::cerr << "Collision model unknown: " << data.c_str() << std::endl;
				nocollision = true;
			}
			//colmesh = scManager->getMesh(mio->getAttributeValueSafe(L"file"));
		}
	}
	mio->drop();
	return true;
}