void ZipArchiveTests::testFileRead() { ZipArchive arch(testPath, "Zip"); arch.load(); DataStreamPtr stream = arch.open("rootfile.txt"); CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 1"), stream->getLine()); CPPUNIT_ASSERT(stream->eof()); }
void FileSystemArchiveTests::testFileRead() { FileSystemArchive arch(testPath, "FileSystem"); arch.load(); DataStreamPtr stream = arch.open("rootfile.txt"); CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 1"), stream->getLine()); CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, stream->getLine()); // blank at end of file CPPUNIT_ASSERT(stream->eof()); }
//----------------------------------------------------------------------- void ParticleSystemManager::parseNewAffector(const String& type, DataStreamPtr& stream, ParticleSystem* sys) { // Create new affector ParticleAffector* pAff = sys->addAffector(type); // Parse affector details String line; while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (line == "}") { // Finished affector break; } else { // Attribute StringUtil::toLowerCase(line); parseAffectorAttrib(line, pAff); } } } }
//----------------------------------------------------------------------- void OldMaterialReader::parseNewTextureLayer(DataStreamPtr& stream, MaterialPtr& pMat) { String line; TextureUnitState* pLayer; pLayer = pMat->getTechnique(0)->getPass(0)->createTextureUnitState(""); while (!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (line.length() != 0 && !(line.substr(0,2) == "//")) { if (line == "}") { // end of layer return; } else { parseLayerAttrib(line, pMat, pLayer); } } } }
//----------------------------------------------------------------------- void CGUIParticleSystemManager::parseNewEmitter(const CGUIString& type, DataStreamPtr& stream, CGUIParticleSystem* sys) { // Create new emitter CGUIParticleEmitter* pEmit = sys->addEmitter(type); // Parse emitter details CGUIString line; while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (line == "}") { // Finished emitter break; } else { // Attribute StringUtil::toLowerCase(line); parseEmitterAttrib(line, pEmit); } } } }
//----------------------------------------------------------------------- void ParticleSystemManager::skipToNextCloseBrace(DataStreamPtr& stream) { String line; while (!stream->eof() && line != "}") { line = stream->getLine(); } }
void SoundScriptManager::skipToNextOpenBrace(DataStreamPtr& stream) { String line = ""; while (!stream->eof() && line != "{") { line = stream->getLine(); } }
//----------------------------------------------------------------------- void OverlayManager::skipToNextOpenBrace(DataStreamPtr& stream) { String line; while (!stream->eof() && line != "{") { line = stream->getLine(); } }
//----------------------------------------------------------------------- void ConfigFile::load(const DataStreamPtr& stream, const String& separators, bool trimWhitespace) { /* Clear current settings map */ clear(); String currentSection = StringUtil::BLANK; SettingsMultiMap* currentSettings = OGRE_NEW_T(SettingsMultiMap, MEMCATEGORY_GENERAL)(); mSettings[currentSection] = currentSettings; /* Process the file line for line */ String line, optName, optVal; while (!stream->eof()) { line = stream->getLine(); /* Ignore comments & blanks */ if (line.length() > 0 && line.at(0) != '#' && line.at(0) != '@') { if (line.at(0) == '[' && line.at(line.length()-1) == ']') { // Section currentSection = line.substr(1, line.length() - 2); SettingsBySection::const_iterator seci = mSettings.find(currentSection); if (seci == mSettings.end()) { currentSettings = OGRE_NEW_T(SettingsMultiMap, MEMCATEGORY_GENERAL)(); mSettings[currentSection] = currentSettings; } else { currentSettings = seci->second; } } else { /* Find the first seperator character and split the string there */ Ogre::String::size_type separator_pos = line.find_first_of(separators, 0); if (separator_pos != Ogre::String::npos) { optName = line.substr(0, separator_pos); /* Find the first non-seperator character following the name */ Ogre::String::size_type nonseparator_pos = line.find_first_not_of(separators, separator_pos); /* ... and extract the value */ /* Make sure we don't crash on an empty setting (it might be a valid value) */ optVal = (nonseparator_pos == Ogre::String::npos) ? "" : line.substr(nonseparator_pos); if (trimWhitespace) { StringUtil::trim(optVal); StringUtil::trim(optName); } currentSettings->insert(SettingsMultiMap::value_type(optName, optVal)); } } } } }
//----------------------------------------------------------------------- void CGUIParticleSystemManager::skipToNextOpenBrace(DataStreamPtr& stream) { CGUIString line; while (!stream->eof() && line != "{") { line = stream->getLine(); } }
void SoundScriptManager::parseScript(DataStreamPtr& stream, const String& groupName) { SoundScriptTemplate* sst = 0; String line = ""; std::vector<String> vecparams; LOG("SoundScriptManager: Parsing script "+stream->getName()); while (!stream->eof()) { line = RoR::Utils::SanitizeUtf8String(stream->getLine()); // ignore comments & blanks if (!(line.length() == 0 || line.substr(0, 2) == "//")) { if (sst == 0) { // no current SoundScript // so first valid data should be a SoundScript name LOG("SoundScriptManager: creating template "+line); sst = createTemplate(line, groupName, stream->getName()); if (!sst) { // there is a name collision for this Sound Script LOG("SoundScriptManager: Error, this sound script is already defined: "+line); skipToNextOpenBrace(stream); skipToNextCloseBrace(stream); continue; } // skip to and over next { skipToNextOpenBrace(stream); } else { // already in a ss if (line == "}") { // finished ss sst = 0; } else { // attribute // split params on space Ogre::StringVector veclineparams = StringUtil::split(line, "\t ", 0); if (!sst->setParameter(veclineparams)) { LOG("Bad SoundScript attribute line: '" + line + "' in " + stream->getName()); } } } } } }
void SkinManager::parseScript(DataStreamPtr& stream, const String& groupName) { try { String line = ""; Skin *pSkin = 0; while(!stream->eof()) { line = stream->getLine(); // Ignore blanks & comments if (!line.length() || line.substr(0, 2) == "//") { continue; } if (!pSkin) { // No current skin // So first valid data should be skin name #ifdef ROR_USE_OGRE_1_9 pSkin = (Skin *)createResource(line, groupName).getPointer(); #else pSkin = (Skin *)create(line, groupName).getPointer(); #endif if (pSkin) { pSkin->_notifyOrigin(stream->getName()); stream->skipLine("{"); } } else { // Already in skin if (line == "}") { // Finished //addImpl((Ogre::ResourcePtr)pSkin); pSkin = 0; // NB skin isn't loaded until required } else { ParseSkinAttribute(line, pSkin); } } } } catch(Ogre::ItemIdentityException e) { // this catches duplicates -> to be ignored // this happens since we load the full skin data off the cache, so we don't need // to re-add it to the SkinManager return; } }
//----------------------------------------------------------------------- void Quake3ShaderManager::parseNewShaderPass(DataStreamPtr& stream, Quake3Shader* pShader) { String line; int passIdx; passIdx = pShader->numPasses; pShader->numPasses++; pShader->pass.resize(pShader->numPasses); // Default pass details pShader->pass[passIdx].animNumFrames = 0; pShader->pass[passIdx].blend = LBO_REPLACE; pShader->pass[passIdx].blendDest = SBF_ZERO; pShader->pass[passIdx].blendSrc = SBF_ONE; pShader->pass[passIdx].depthFunc = CMPF_LESS_EQUAL; pShader->pass[passIdx].flags = 0; pShader->pass[passIdx].rgbGenFunc = SHADER_GEN_IDENTITY; pShader->pass[passIdx].tcModRotate = 0; pShader->pass[passIdx].tcModScale[0] = pShader->pass[passIdx].tcModScale[1] = 1.0; pShader->pass[passIdx].tcModScroll[0] = pShader->pass[passIdx].tcModScroll[1] = 0; pShader->pass[passIdx].tcModStretchWave = SHADER_FUNC_NONE; pShader->pass[passIdx].tcModTransform[0] = pShader->pass[passIdx].tcModTransform[1] = 0; pShader->pass[passIdx].tcModTurbOn = false; pShader->pass[passIdx].tcModTurb[0] = pShader->pass[passIdx].tcModTurb[1] = pShader->pass[passIdx].tcModTurb[2] = pShader->pass[passIdx].tcModTurb[3] = 0; pShader->pass[passIdx].texGen = TEXGEN_BASE; pShader->pass[passIdx].addressMode = TextureUnitState::TAM_WRAP; pShader->pass[passIdx].customBlend = false; pShader->pass[passIdx].alphaVal = 0; pShader->pass[passIdx].alphaFunc = CMPF_ALWAYS_PASS; while (!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (line.length() != 0 && line.substr(0,2) != "//") { if (line == "}") { // end of shader return; } else { parseShaderPassAttrib(line, pShader, &pShader->pass[passIdx]); } } } }
//----------------------------------------------------------------------- void OldMaterialReader::parseScript(DataStreamPtr& stream) { String line; MaterialPtr pMat; char tempBuf[512]; while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (pMat.isNull()) { // No current material // So first valid data should be a material name pMat = MaterialManager::getSingleton().create(line, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // Skip to and over next { stream->readLine(tempBuf, 511, "{"); } else { // Already in a material if (line == "}") { // Finished material pMat.setNull(); } else if (line == "{") { // new pass parseNewTextureLayer(stream, pMat); } else { // Attribute StringUtil::toLowerCase(line); parseAttrib(line, pMat); } } } } }
//--------------------------------------------------------------------- void OverlayManager::parseNewElement( DataStreamPtr& stream, String& elemType, String& elemName, bool isContainer, Overlay* pOverlay, bool isATemplate, String templateName, OverlayContainer* container) { String line; OverlayElement* newElement = NULL; newElement = OverlayManager::getSingleton().createOverlayElementFromTemplate(templateName, elemType, elemName, isATemplate); // do not add a template to an overlay // add new element to parent if (container) { // Attach to container container->addChild(newElement); } // do not add a template to the overlay. For templates overlay = 0 else if (pOverlay) { pOverlay->add2D((OverlayContainer*)newElement); } while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (line == "}") { // Finished element break; } else { if (isContainer && parseChildren(stream,line, pOverlay, isATemplate, static_cast<OverlayContainer*>(newElement))) { // nested children... don't reparse it } else { // Attribute parseElementAttrib(line, pOverlay, newElement); } } } } }
//--------------------------------------------------------------------- void FontManager::parseScript(DataStreamPtr& stream, const String& groupName) { String line; FontPtr pFont; while( !stream->eof() ) { line = stream->getLine(); // Ignore blanks & comments if( !line.length() || line.substr( 0, 2 ) == "//" ) { continue; } else { if (pFont.isNull()) { // No current font // So first valid data should be font name if (StringUtil::startsWith(line, "font ")) { // chop off the 'particle_system ' needed by new compilers line = line.substr(5); } pFont = create(line, groupName); pFont->_notifyOrigin(stream->getName()); // Skip to and over next { stream->skipLine("{"); } else { // Already in font if (line == "}") { // Finished pFont.setNull(); // NB font isn't loaded until required } else { parseAttribute(line, pFont); } } } } }
int SkidmarkManager::loadDefaultModels() { LOG("SkidmarkManager loading default models"); // check if we have a config file String group = ""; try { group = ResourceGroupManager::getSingleton().findGroupContainingResource("skidmarks.cfg"); } catch(...) { } // emit a warning if we did not found the file if (group.empty()) { LOG("skidmarks| skidmarks.cfg not found"); return 1; } // open the file for reading DataStreamPtr ds = ResourceGroupManager::getSingleton().openResource("skidmarks.cfg", group); String line = ""; String currentModel = ""; while (!ds->eof()) { line = RoR::Utils::SanitizeUtf8String(ds->getLine()); StringUtil::trim(line); if (line.empty() || line[0]==';') continue; StringVector args = StringUtil::split(line, ","); if (args.size() == 1) { currentModel = line; continue; } // process the line if we got a model if (!currentModel.empty()) processLine(args, currentModel); } return 0; }
//--------------------------------------------------------------------- String Serializer::readString(DataStreamPtr& stream) { return stream->getLine(false); }
//--------------------------------------------------------------------- void OverlayManager::parseScript(DataStreamPtr& stream, const String& groupName) { // check if we've seen this script before (can happen if included // multiple times) if (!stream->getName().empty() && mLoadedScripts.find(stream->getName()) != mLoadedScripts.end()) { LogManager::getSingleton().logMessage( "Skipping loading overlay include: '" + stream->getName() + " as it is already loaded."); return; } String line; Overlay* pOverlay = 0; bool skipLine; while(!stream->eof()) { bool isATemplate = false; skipLine = false; line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (line.substr(0,8) == "#include") { vector<String>::type params = StringUtil::split(line, "\t\n ()<>"); DataStreamPtr includeStream = ResourceGroupManager::getSingleton().openResource( params[1], groupName); parseScript(includeStream, groupName); continue; } if (!pOverlay) { // No current overlay // check to see if there is a template if (line.substr(0,8) == "template") { isATemplate = true; } else { // So first valid data should be overlay name if (StringUtil::startsWith(line, "overlay ")) { // chop off the 'particle_system ' needed by new compilers line = line.substr(8); } pOverlay = create(line); pOverlay->_notifyOrigin(stream->getName()); // Skip to and over next { skipToNextOpenBrace(stream); skipLine = true; } } if ((pOverlay && !skipLine) || isATemplate) { // Already in overlay vector<String>::type params = StringUtil::split(line, "\t\n ()"); if (line == "}") { // Finished overlay pOverlay = 0; } else if (parseChildren(stream,line, pOverlay, isATemplate, NULL)) { } else { // Attribute if (!isATemplate) { parseAttrib(line, pOverlay); } } } } } // record as parsed mLoadedScripts.insert(stream->getName()); }
//----------------------------------------------------------------------- void ParticleSystemManager::parseScript(DataStreamPtr& stream, const String& groupName) { #if OGRE_USE_NEW_COMPILERS == 1 ScriptCompilerManager::getSingleton().parseScript(stream, groupName); #else // OGRE_USE_NEW_COMPILERS String line; ParticleSystem* pSys; std::vector<String> vecparams; pSys = 0; while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (pSys == 0) { // No current system // So first valid data should be a system name if (StringUtil::startsWith(line, "particle_system ")) { // chop off the 'particle_system ' needed by new compilers line = line.substr(16); } pSys = createTemplate(line, groupName); pSys->_notifyOrigin(stream->getName()); // Skip to and over next { skipToNextOpenBrace(stream); } else { // Already in a system if (line == "}") { // Finished system pSys = 0; } else if (line.substr(0,7) == "emitter") { // new emitter // Get typename vecparams = StringUtil::split(line, "\t "); if (vecparams.size() < 2) { // Oops, bad emitter LogManager::getSingleton().logMessage("Bad particle system emitter line: '" + line + "' in " + pSys->getName()); skipToNextCloseBrace(stream); } skipToNextOpenBrace(stream); parseNewEmitter(vecparams[1], stream, pSys); } else if (line.substr(0,8) == "affector") { // new affector // Get typename vecparams = StringUtil::split(line, "\t "); if (vecparams.size() < 2) { // Oops, bad affector LogManager::getSingleton().logMessage("Bad particle system affector line: '" + line + "' in " + pSys->getName()); skipToNextCloseBrace(stream); } skipToNextOpenBrace(stream); parseNewAffector(vecparams[1],stream, pSys); } else { // Attribute parseAttrib(line, pSys); } } } } #endif // OGRE_USE_NEW_COMPILERS }
//----------------------------------------------------------------------- void Quake3ShaderManager::parseScript(DataStreamPtr& stream, const String& group) { String line; Quake3Shader* pShader; char tempBuf[512]; pShader = 0; bool dummy = false; while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (pShader == 0) { // No current shader if (getByName(line) == 0) { dummy = false; } else { // Defined before, parse but ignore // Q3A has duplicates in shaders, doh dummy = true; } // So first valid data should be a shader name pShader = create(line); // Skip to and over next { stream->readLine(tempBuf, 511, "{"); } else { // Already in a shader if (line == "}") { // Finished shader if (dummy && pShader) { OGRE_DELETE pShader; } pShader = 0; } else if (line == "{") { // new pass parseNewShaderPass(stream, pShader); } else { // Attribute StringUtil::toLowerCase(line); parseShaderAttrib(line, pShader); } } } } }