//----------------------------------------------------------------------- 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::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 SkeletonSerializer::importSkeleton(DataStreamPtr& stream, Skeleton* pSkel) { // Determine endianness (must be the first thing we do!) determineEndianness(stream); // Check header readFileHeader(stream); unsigned short streamID; while(!stream->eof()) { streamID = readChunk(stream); switch (streamID) { case SKELETON_BONE: readBone(stream, pSkel); break; case SKELETON_BONE_PARENT: readBoneParent(stream, pSkel); break; case SKELETON_ANIMATION: readAnimation(stream, pSkel); break; case SKELETON_ANIMATION_LINK: readSkeletonAnimationLink(stream, pSkel); break; } } // Assume bones are stored in the binding pose pSkel->setBindingPose(); }
//----------------------------------------------------------------------- void OverlayManager::skipToNextOpenBrace(DataStreamPtr& stream) { String line; while (!stream->eof() && line != "{") { line = stream->getLine(); } }
//----------------------------------------------------------------------- void ParticleSystemManager::skipToNextCloseBrace(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 Serializer::backpedalChunkHeader(DataStreamPtr& stream) { if (!stream->eof()){ stream->skip(-(int)calcChunkHeaderSize()); } #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE mChunkSizeStack.back() = stream->tell(); #endif }
//----------------------------------------------------------------------- void CGUIParticleSystemManager::skipToNextOpenBrace(DataStreamPtr& stream) { CGUIString line; while (!stream->eof() && line != "{") { line = stream->getLine(); } }
void SoundScriptManager::skipToNextOpenBrace(DataStreamPtr& stream) { String 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 Serializer::popInnerChunk(const DataStreamPtr& stream) { #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE if (!mChunkSizeStack.empty()){ size_t pos = stream->tell(); if (pos != static_cast<size_t>(mChunkSizeStack.back()) && !stream->eof() && mReportChunkErrors){ LogManager::getSingleton().logMessage("Corrupted chunk detected! Stream name: " + stream->getName()); } mChunkSizeStack.pop_back(); } #endif }
//----------------------------------------------------------------------- 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 SkeletonSerializer::readAnimationTrack(DataStreamPtr& stream, Animation* anim, Skeleton* pSkel) { // unsigned short boneIndex : Index of bone to apply to unsigned short boneHandle; readShorts(stream, &boneHandle, 1); // Find bone Bone *targetBone = pSkel->getBone(boneHandle); // Create track NodeAnimationTrack* pTrack = anim->createNodeTrack(boneHandle, targetBone); // Keep looking for nested keyframes if (!stream->eof()) { pushInnerChunk(stream); unsigned short streamID = readChunk(stream); while(streamID == SKELETON_ANIMATION_TRACK_KEYFRAME && !stream->eof()) { readKeyFrame(stream, pTrack, pSkel); if (!stream->eof()) { // Get next stream streamID = readChunk(stream); } } if (!stream->eof()) { // Backpedal back to start of this stream if we've found a non-keyframe backpedalChunkHeader(stream); } popInnerChunk(stream); } }
//----------------------------------------------------------------------- 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 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 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 SkeletonSerializer::readAnimation(DataStreamPtr& stream, Skeleton* pSkel) { // char* name : Name of the animation String name; name = readString(stream); // float length : Length of the animation in seconds float len; readFloats(stream, &len, 1); Animation *pAnim = pSkel->createAnimation(name, len); // Read all tracks if (!stream->eof()) { unsigned short streamID = readChunk(stream); while(streamID == SKELETON_ANIMATION_TRACK && !stream->eof()) { readAnimationTrack(stream, pAnim, pSkel); if (!stream->eof()) { // Get next stream streamID = readChunk(stream); } } if (!stream->eof()) { // Backpedal back to start of this stream if we've found a non-track stream->skip(-STREAM_OVERHEAD_SIZE); } } }
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 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; }
//--------------------------------------------------------------------- void SkeletonSerializer::importSkeleton(DataStreamPtr& stream, Skeleton* pSkel) { // Determine endianness (must be the first thing we do!) determineEndianness(stream); // Check header readFileHeader(stream); pushInnerChunk(stream); unsigned short streamID = readChunk(stream); while(!stream->eof()) { switch (streamID) { case SKELETON_BLENDMODE: { // Optional blend mode uint16 blendMode; readShorts(stream, &blendMode, 1); pSkel->setBlendMode(static_cast<SkeletonAnimationBlendMode>(blendMode)); break; } case SKELETON_BONE: readBone(stream, pSkel); break; case SKELETON_BONE_PARENT: readBoneParent(stream, pSkel); break; case SKELETON_ANIMATION: readAnimation(stream, pSkel); break; case SKELETON_ANIMATION_LINK: readSkeletonAnimationLink(stream, pSkel); break; default: break; } streamID = readChunk(stream); } // Assume bones are stored in the binding pose pSkel->setBindingPose(); popInnerChunk(stream); }
//--------------------------------------------------------------------- unsigned short Serializer::readChunk(DataStreamPtr& stream) { #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE size_t pos = stream->tell(); #endif unsigned short id; readShorts(stream, &id, 1); readInts(stream, &mCurrentstreamLen, 1); #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE if (!mChunkSizeStack.empty() && !stream->eof()){ if (pos != static_cast<size_t>(mChunkSizeStack.back()) && mReportChunkErrors){ LogManager::getSingleton().logMessage("Corrupted chunk detected! Stream name: '" + stream->getName() + "' Chunk id: " + StringConverter::toString(id)); } mChunkSizeStack.back() = pos + mCurrentstreamLen; } #endif return id; }
//----------------------------------------------------------------------- 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); } } } } }
//--------------------------------------------------------------------- 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()); }
// if terrain is set, we operate on the already loaded terrain void TerrainGeometryManager::loadLayers(int x, int z, Terrain *terrain) { if (pageConfigFormat.empty()) return; DataStreamPtr ds = getPageConfig(x, z); if (ds.isNull()) return; char line[4096]; ds->readLine(line, 4096); String heightmapImage = String(line); ds->readLine(line, 4096); terrainLayers = PARSEINT(String(line)); if (terrainLayers == 0) return; Ogre::Terrain::ImportData &defaultimp = mTerrainGroup->getDefaultImportSettings(); if (!terrain) defaultimp.layerList.resize(terrainLayers); blendInfo.clear(); blendInfo.resize(terrainLayers); int layer = 0; while (!ds->eof()) { size_t ll = ds->readLine(line, 4096); if (ll==0 || line[0]=='/' || line[0]==';') continue; StringVector args = StringUtil::split(String(line), ","); if (args.size() < 3) { LOG("invalid page config line: '" + String(line) + "'"); continue; } StringUtil::trim(args[1]); StringUtil::trim(args[2]); float worldSize = PARSEREAL(args[0]); if (!terrain) { defaultimp.layerList[layer].worldSize = worldSize; defaultimp.layerList[layer].textureNames.push_back(args[1]); defaultimp.layerList[layer].textureNames.push_back(args[2]); } else { terrain->setLayerWorldSize(layer, worldSize); terrain->setLayerTextureName(layer, 0, args[1]); terrain->setLayerTextureName(layer, 1, args[2]); } blendLayerInfo_t &bi = blendInfo[layer]; bi.blendMode = 'R'; bi.alpha = 'R'; if (args.size() > 3) { StringUtil::trim(args[3]); bi.blendMapTextureFilename = args[3]; } if (args.size() > 4) { StringUtil::trim(args[4]); bi.blendMode = args[4][0]; } if (args.size() > 5) bi.alpha = PARSEREAL(args[5]); layer++; if (layer >= terrainLayers) break; } LOG("done loading page: loaded " + TOSTRING(layer) + " layers"); }
Airfoil::Airfoil(Ogre::String const& fname) { for (int i = 0; i < 3601; i++) //init in case of bad things { cl[i] = 0; cd[i] = 0; cm[i] = 0; } char line[1024]; //we load directly X-Plane AFL file format!!! bool process = false; bool neg = true; int lastia = -1; ResourceGroupManager& rgm = ResourceGroupManager::getSingleton(); String group = ""; try { group = rgm.findGroupContainingResource(fname); } catch (...) { } if (group == "") { LOG(String("Airfoil error: could not load airfoil ")+fname); return; } DataStreamPtr ds = rgm.openResource(fname, group); while (!ds->eof()) { size_t ll = ds->readLine(line, 1023); if (ll == 0) continue; // fscanf(fd," %[^\n\r]",line); if (!strncmp("alpha", line, 5)) { process = true; continue; }; if (process) { float l, d, m; int a, b; sscanf(line, "%i.%i %f %f %f", &a, &b, &l, &d, &m); if (neg) b = -b; if (a == 0 && b == 0) neg = false; int ia = (a * 10 + b) + 1800; if (ia == 3600) { process = false; }; cl[ia] = l; cd[ia] = d; cm[ia] = m; if (lastia != -1 && ia - lastia > 1) { //we have to interpolate previous elements (linear interpolation) int i; for (i = 0; i < ia - lastia - 1; i++) { cl[lastia + 1 + i] = cl[lastia] + (float)(i + 1) * (cl[ia] - cl[lastia]) / (float)(ia - lastia); cd[lastia + 1 + i] = cd[lastia] + (float)(i + 1) * (cd[ia] - cd[lastia]) / (float)(ia - lastia); cm[lastia + 1 + i] = cm[lastia] + (float)(i + 1) * (cm[ia] - cm[lastia]) / (float)(ia - lastia); } } lastia = ia; } } }
//----------------------------------------------------------------------- void RenderSystemCapabilitiesSerializer::parseScript(DataStreamPtr& stream) { // reset parsing data to NULL mCurrentLineNumber = 0; mCurrentLine = 0; mCurrentStream.reset(); mCurrentCapabilities = 0; mCurrentStream = stream; // parser operating data String line; ParseAction parseAction = PARSE_HEADER; StringVector tokens; bool parsedAtLeastOneRSC = false; // collect capabilities lines (i.e. everything that is not header, "{", "}", // comment or empty line) for further processing CapabilitiesLinesList capabilitiesLines; // for reading data char tmpBuf[OGRE_STREAM_TEMP_SIZE]; // TODO: build a smarter tokenizer so that "{" and "}" // don't need separate lines while (!stream->eof()) { stream->readLine(tmpBuf, OGRE_STREAM_TEMP_SIZE-1); line = String(tmpBuf); StringUtil::trim(line); // keep track of parse position mCurrentLine = &line; mCurrentLineNumber++; tokens = StringUtil::split(line); // skip empty and comment lines // TODO: handle end of line comments if (tokens[0] == "" || tokens[0].substr(0,2) == "//") continue; switch (parseAction) { // header line must look like this: // render_system_capabilities "Vendor Card Name Version xx.xxx" case PARSE_HEADER: if(tokens[0] != "render_system_capabilities") { logParseError("The first keyword must be render_system_capabilities. RenderSystemCapabilities NOT created!"); return; } else { // the rest of the tokens are irrevelant, beause everything between "..." is one name String rscName = line.substr(tokens[0].size()); StringUtil::trim(rscName); // the second argument must be a "" delimited string if (!StringUtil::match(rscName, "\"*\"")) { logParseError("The argument to render_system_capabilities must be a quote delimited (\"...\") string. RenderSystemCapabilities NOT created!"); return; } else { // we have a valid header // remove quotes rscName = rscName.substr(1); rscName = rscName.substr(0, rscName.size() - 1); // create RSC mCurrentCapabilities = OGRE_NEW RenderSystemCapabilities(); // RSCManager is responsible for deleting mCurrentCapabilities RenderSystemCapabilitiesManager::getSingleton()._addRenderSystemCapabilities(rscName, mCurrentCapabilities); LogManager::getSingleton().logMessage("Created RenderSystemCapabilities" + rscName); // do next action parseAction = FIND_OPEN_BRACE; parsedAtLeastOneRSC = true; } } break; case FIND_OPEN_BRACE: if (tokens[0] != "{" || tokens.size() != 1) { logParseError("Expected '{' got: " + line + ". Continuing to next line."); } else { parseAction = COLLECT_LINES; } break; case COLLECT_LINES: if (tokens[0] == "}") { // this render_system_capabilities section is over // let's process the data and look for the next one parseCapabilitiesLines(capabilitiesLines); capabilitiesLines.clear(); parseAction = PARSE_HEADER; } else capabilitiesLines.push_back(CapabilitiesLinesList::value_type(line, mCurrentLineNumber)); break; } } // Datastream is empty // if we are still looking for header, this means that we have either // finished reading one, or this is an empty file if(parseAction == PARSE_HEADER && parsedAtLeastOneRSC == false) { logParseError ("The file is empty"); } if(parseAction == FIND_OPEN_BRACE) { logParseError ("Bad .rendercaps file. Were not able to find a '{'"); } if(parseAction == COLLECT_LINES) { logParseError ("Bad .rendercaps file. Were not able to find a '}'"); } }
//----------------------------------------------------------------------- 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 }