void AudioScriptLoader::parseScript(Ogre::DataStreamPtr& dataStream, const Ogre::String& groupName)
{
	Ogre::String line;
	bool nextIsOpenBrace = false;

	mScriptContext.mSection = ASS_NONE;
	mScriptContext.mSection= ASS_NONE;
	mScriptContext.mSound.setNull();
	mScriptContext.mLineNo = 0;
	mScriptContext.mFileName=dataStream->getName();
	mScriptContext.mGroupName=groupName;

	Logger::getInstance()->log("About to start parsing sound script "+dataStream->getName());

	while(!dataStream->eof())
	{
		line = dataStream->getLine();
		mScriptContext.mLineNo++;

		// DEBUG LINE
		//Logger::getInstance()->log("About to attempt line(#" +
		//	Ogre::StringConverter::toString(mScriptContext.mLineNo) + "): " + line);

		// Ignore comments & blanks
		if (!(line.length() == 0 || line.substr(0,2) == "//"))
		{
			if (nextIsOpenBrace)
			{
				// NB, parser will have changed context already
				if (line != "{")
				{
					logParseError("Expecting '{' but got " +
						line + " instead.", mScriptContext);
				}
				nextIsOpenBrace = false;
			}
			else
			{
				nextIsOpenBrace = parseLine(line);
			}

		}
	}

	// Check all braces were closed
	if (mScriptContext.mSection != ASS_NONE)
	{
		logParseError("Unexpected end of file.", mScriptContext);
	}

	// Make sure we invalidate our context shared pointer (don't wanna hold on)
	mScriptContext.mSound.setNull();
}
Exemplo n.º 2
0
bool XMLHelper::Load(TiXmlDocument& xmlDoc, Ogre::DataStreamPtr stream)
{
	size_t length(stream->size());

	if ( length )
	{
		// If we have a file, assume it is all one big XML file, and read it in.
		// The document parser may decide the document ends sooner than the entire file, however.
		std::string data(stream->getAsString());

		xmlDoc.Parse( data.c_str());

		if (xmlDoc.Error() ) {
			std::string errorDesc = xmlDoc.ErrorDesc();
			int errorLine =  xmlDoc.ErrorRow();
			int errorColumn =  xmlDoc.ErrorCol();
			std::stringstream ss;
			ss << "Failed to load xml file '" << stream->getName() << "'! Error at column: " << errorColumn << " line: " << errorLine << ". Error message: " << errorDesc;
			S_LOG_FAILURE(ss.str());
			return false;
		} else {
            return true;
		}
	}
	return false;
}
	void LodConfigSerializer::exportLodConfig(Ogre::LodConfig& config, Ogre::DataStreamPtr stream, Endian endianMode /*= ENDIAN_NATIVE*/ )
	{
		Ogre::LogManager::getSingleton().logMessage("MeshSerializer writing mesh data to stream " + stream->getName() + "...");

		// Decide on endian mode
		determineEndianness(endianMode);
		mLodConfig = &config;
		mStream = stream;
		if (!stream->isWriteable())
		{
			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
				"Unable to use stream " + stream->getName() + " for writing",
				"LodConfigSerializer::export");
		}

		writeFileHeader();
		LogManager::getSingleton().logMessage("File header written.");


		LogManager::getSingleton().logMessage("Writing Lod Config...");
		pushInnerChunk(mStream);
		writeLodConfig();
		popInnerChunk(mStream);
		LogManager::getSingleton().logMessage("LodConfigSerializer export successful.");
	}
Exemplo n.º 4
0
void EmberEntityMappingManager::parseScript (Ogre::DataStreamPtr &stream, const Ogre::String &groupName)
{
	TiXmlDocument xmlDoc;
	XMLHelper xmlHelper;
	if (!xmlHelper.Load(xmlDoc, stream)) {
		return;
	}

	mXmlSerializer.parseScript(xmlDoc, stream->getName());
}
    void SaveGameManager::parseScript(Ogre::DataStreamPtr &stream, const Ogre::String &groupName)
    {
        Ogre::String name = stream->getName();
        name = name.substr(0, name.length()-5); //delete ".save" at the and of the name
        int pointpos = name.find_last_of(".");
        name = name.substr(0, pointpos);

        if(Ogre::StringConverter::isNumber(name))
        {
            mHighestSaveGameNumber = std::max(mHighestSaveGameNumber, Ogre::StringConverter::parseInt(name));

            SaveGameFile* file = new SaveGameFile("", Ogre::StringConverter::parseInt(name));        
            
            LOG_MESSAGE(Logger::RULES, "Parsing header of save game: " + name + ".save");
            SaveGameFileReader reader;
            reader.parseSaveGameFileHeader(stream, groupName, file);
            
            if(file->getProperty(SaveGameFile::PROPERTY_MODULEID) != "") // broken save game
                mSaveGames[Ogre::StringConverter::parseInt(name)] = file;
        }
    }
Exemplo n.º 6
0
void VEffectManager::parseScript(Ogre::DataStreamPtr& stream, const Ogre::String& groupName)
{
	mParsingFilename = stream->getName();
	mParsingLineNumber = 0;

	if (Ogre::StringUtil::endsWith(mParsingFilename, ".effect", false))
	{
		// 解析特效文件
		_parseEffectFile(stream);
	}
	else if (Ogre::StringUtil::endsWith(mParsingFilename, ".skill", false))
	{
		// 解析技能文件
		_parseSkillFile(stream);
	}
	else
	{
		OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
			"wrong file name " + mParsingFilename, "VEffectManager::parseScript");
	}
}
Exemplo n.º 7
0
		bool xmlDocument::open(const Ogre::DataStreamPtr& stream)
		{
			clear();

			mLastErrorFile = stream->getName();
			// это текущая строка для разбора
			std::string line;
			// это строка из файла
			std::string read;
			// текущий узел для разбора
			xmlNodePtr currentNode = 0;

			while (false == stream->eof()) {
				// берем новую строку
				read = stream->getLine (false);
				mLine ++;
				mCol = 0; // потом проверить на многострочных тэгах

				if (read.empty()) continue;

				// текущая строка для разбора и то что еще прочитали
				line += read;

				// крутимся пока в строке есть теги
				while (true) {

					// сначала ищем по угловым скобкам
					size_t start = find(line, '<');
					if (start == line.npos) break;

					size_t end = find(line, '>', start+1);
					if (end == line.npos) break;

					// проверяем на наличее тела
					size_t body = line.find_first_not_of(" \t<");
					if (body < start) {

						std::string body_str = line.substr(0, start);
						// текущий символ
						mCol = body_str.find_first_not_of(" \t");
						utility::trim(body_str);

						if (currentNode != 0) 	currentNode->addBody(body_str);

					}

					// вырезаем наш тэг и парсим
					if (false == parseTag(currentNode, line.substr(start+1, end-start-1))) {
						// ошибка установится внутри
						return false;
					}

					// и обрезаем текущую строку разбора
					line = line.substr(end+1);

				}; // while (true)

			}; // while (!stream.eof())

			if (currentNode) {
				mLastError = xml::errors::XML_ERROR_NON_CLOSE_ALL_TAGS;
				return false;
			}

			return true;
		}