Exemple #1
0
    //-------------------------------------------------------------------------
    //                      _ i n i t F i l e S y s t e m s
    //-------------------------------------------------------------------------
    int CApplication::_initFileSystems()
    {
        IAttributes* pa = m_config->getSection("filesystems");
        u32 count = pa->getAttributeCount();

        stringc fs="",fn="";
        for(u32 i=0;i<count;i++)
        {
            fn = pa->getAttributeName(i);
            fs = pa->getAttributeAsString(i);
            if(fn.equals_ignore_case("folder"))
            {
                fs = m_fileSystem->getAbsolutePath(fs);
                fs = m_fileSystem->flattenFilename(fs);
                if(!m_fileSystem->addFolderFileArchive(fs.c_str(), false, false))
                {
                    stringc msg = "Error Adding FileSystem: ";
                    msg += fs;
                    logMessage(msg.c_str());
                }
            }
            else if(fn.equals_ignore_case("zipfile"))
            {
                if(!m_fileSystem->addZipFileArchive(fs.c_str()))
                {
                    stringc msg = "Error Adding FileSystem: ";
                    msg += fs;
                    logMessage(msg.c_str());
                }
            }
            else if(fn.equals_ignore_case("pakfile"))
            {
                if(!m_fileSystem->addPakFileArchive(fs.c_str()))
                {
                    stringc msg = "Error Adding FileSystem: ";
                    msg += fs;
                    logMessage(msg.c_str());
                }
            }
            else 
            {
                stringc msg = "Unknown FileSystem Type: ";
                msg += fn;
                logMessage(msg.c_str());
            }

        }
        return 0;
    }
	bool CSLevel::savePrefab(CSObject* obj, stringc filename)
	{
		CS_LOG(CSLOGTYPE::CSL_DEBUG, "Saving prefab to file %s", filename.c_str());

		CS_CHECK_BOOL(obj, CSLOGTYPE::CSL_WARNING, "Warning unable to save prefab. obj is not valid");

		_chdir(getApplication()->getDirectory("PrefabDirectory").c_str());

		IXMLWriter* writer = getDevice()->getFileSystem()->createXMLWriter(filename);
		if (!writer) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to create prefab file %s", filename.c_str()); return false; }

		writer->writeXMLHeader();

		stringw name("CSOBJECT");
		writer->writeElement(name.c_str(), false, L"TYPE", stringw(obj->getInfo()->getName()).c_str());
		writer->writeLineBreak();

		IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver());
		SAttributeReadWriteOptions options;
		obj->serializeAttributes(attr, &options);

		if (attr->getAttributeCount() != 0)
		{
			attr->write(writer);
			writer->writeLineBreak();
		}

		attr->drop();

		writer->writeClosingTag(name.c_str());
		writer->writeLineBreak();
		writer->writeLineBreak();

		writer->drop();
		return true;
	}
	// save the level objects to disk file
	bool CSLevel::saveToDisk(stringc filename)
	{
		// log this event
		CS_LOG(CSLOGTYPE::CSL_DEBUG, "Saving game data - %s", filename.c_str());

		// creat ethe xml writer
		IXMLWriter* writer = getDevice()->getFileSystem()->createXMLWriter(filename);
		if (!writer) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to create save file %s", filename.c_str()); return false; }

		// write the xml header
		writer->writeXMLHeader();

		vector3df pos(0, 0, 0);
		vector3df tar(0, 0, 0);
		if (getCamera())
		{
			pos = getCamera()->getPosition();
			tar = getCamera()->getTarget();
		}

		// write the camera position and target
		writer->writeLineBreak();
		writer->writeElement(L"CAMERA", false,
			L"POSITION", stringw(vector3dfToStringc(pos)).c_str(),
			L"TARGET", stringw(vector3dfToStringc(tar)).c_str()
			);
		writer->writeLineBreak();
		writer->writeLineBreak();

		// run through thte list of objects
		CSObject* obj = getObjectFactory()->getObjectManager()->getNextObject(true);
		while (obj)
		{
			// if this is not a debug object, then save it to disk
			if (!obj->getDebugObject())
			{
				// write the node type
				stringw name("CSOBJECT");
				writer->writeElement(name.c_str(), false, L"TYPE", stringw(obj->getInfo()->getName()).c_str());
				writer->writeLineBreak();

				// let the object serialize itself into our attributes structure
				IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver());
				SAttributeReadWriteOptions options;
				obj->serializeAttributes(attr, &options);

				// if there are attributes
				if (attr->getAttributeCount() != 0)
				{
					// write the attributes to the xml file
					attr->write(writer);

					// make the file pretty
					writer->writeLineBreak();
				}

				// drop the pointer
				attr->drop();

				// finish writing the xml header / footer
				writer->writeClosingTag(name.c_str());
				writer->writeLineBreak();
				writer->writeLineBreak();
			}
			// get the next object
			obj = getObjectFactory()->getObjectManager()->getNextObject(false);
		}

		// drop the pointer
		writer->drop();

		// everything went fine
		return true;
	}