//! creates/loads an animated mesh from the file. //! \return Pointer to the created mesh. Returns 0 if loading failed. //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). //! See IReferenceCounted::drop() for more information. IAnimatedMesh* CIrrMeshFileLoader::createMesh(io::IReadFile* file) { io::IXMLReader* reader = FileSystem->createXMLReader(file); if (!reader) return 0; // read until mesh section, skip other parts const core::stringc meshTagName = "mesh"; IAnimatedMesh* mesh = 0; while(reader->read()) { if (reader->getNodeType() == io::EXN_ELEMENT) { if (meshTagName == reader->getNodeName()) { mesh = readMesh(reader); break; } else skipSection(reader, true); // unknown section } } reader->drop(); return mesh; }
modelPort *parseOutport() { modelPort *ret = new modelPort(); ret->type = OUTPORT; QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); strLine = getLine(); QString name = getValue(strLine, TOKNAME); strLine = getLine(); QString coupledport = getValue(strLine, TOKCOUPLEDPORT); strLine = getLine(); QString description = getValue(strLine, TOKDESCRIPTION); strLine = getLine(); checkEqual(strLine, TOKGRAPHIC); skipSection(); strLine = getLine(); checkEqual(strLine, TOKCBRACE); ret->name = name; ret->coupledPort = coupledport.trimmed().toInt(); return ret; }
modelAtomic *parseAtomic() { int inPorts, outPorts; bool ok; QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); strLine = getLine(); QString name = getValue(strLine, TOKNAME); strLine = getLine(); QString ports = getValue(strLine, TOKPORTS); QStringList slports = ports.split(TOKCOLON, QString::SkipEmptyParts); inPorts = slports.first().toInt(&ok); outPorts = slports.last().toInt(&ok); //printf("Atomic %s has %d inports and %d outports\n",name.toAscii().constData(),inPorts,outPorts); strLine = getLine(); QString path = getValue(strLine, TOKPATH); path = path.replace("Continuous","continuous"); path = path.replace("Discrete","discrete"); path = path.replace("Hybrid","hybrid"); path = path.replace("Qss","qss"); path = path.replace("Realtime","realtime"); path = path.replace("Sources","sources"); path = path.replace("Source","source"); path = path.replace("Sinks","sinks"); path = path.replace("Sink","sink"); strLine = getLine(); QString desc = getValue(strLine, TOKDESCRIPTION); strLine = getLine(); checkEqual(strLine, TOKGRAPHIC); skipSection(); strLine = getLine(); checkEqual(strLine, TOKPARAMETERS); QList < modelParameter * >params = parseParameters(); strLine = getLine(); modelAtomic *ret = new modelAtomic(); if (strLine == TOKEXTRA) { ret->extra = parseExtra(); strLine = getLine(); } checkEqual(strLine, TOKCBRACE); ret->inPorts = inPorts; ret->outPorts = outPorts; ret->name = name; ret->path = path; ret->desc = desc; ret->params = params; return ret; }
//! reads a mesh sections and creates a mesh from it IAnimatedMesh* CIrrMeshFileLoader::readMesh(io::IXMLReader* reader) { SAnimatedMesh* animatedmesh = new SAnimatedMesh(); SMesh* mesh = new SMesh(); animatedmesh->addMesh(mesh); mesh->drop(); core::stringc bbSectionName = "boundingBox"; core::stringc bufferSectionName = "buffer"; core::stringc meshSectionName = "mesh"; if (!reader->isEmptyElement()) while(reader->read()) { if (reader->getNodeType() == io::EXN_ELEMENT) { const wchar_t* nodeName = reader->getNodeName(); if (bbSectionName == nodeName) { // inside a bounding box, ignore it for now because // we are calculating this anyway ourselves later. } else if (bufferSectionName == nodeName) { // we've got a mesh buffer IMeshBuffer* buffer = readMeshBuffer(reader); if (buffer) { mesh->addMeshBuffer(buffer); buffer->drop(); } } else skipSection(reader, true); // unknown section } // end if node type is element else if (reader->getNodeType() == io::EXN_ELEMENT_END) { if (meshSectionName == reader->getNodeName()) { // end of mesh section reached, cancel out break; } } } // end while reader->read(); mesh->recalculateBoundingBox(); animatedmesh->recalculateBoundingBox(); return animatedmesh; }
bool PgnStream::nextGame() { char c; while ((c = readChar()) != 0) { if (c == '[') { rewindChar(); m_phase = InTags; return true; } else skipSection(this, c); } return false; }
modelCoupled *parseCoupled() { bool ok; int inPorts, outPorts; modelCoupled *ret = new modelCoupled(); QList < modelChild * >childs; QList < modelPoint * >points; QList < modelLine * >lines; QList < modelPort * >lsPorts; QString strLine = getLine(); checkEqual(strLine, TOKOBRACE); strLine = getLine(); QString type = getValue(strLine, TOKTYPE); strLine = getLine(); QString name = getValue(strLine, TOKNAME); //printf("Parsing a coupled named:%s\n", QSTR(name)); strLine = getLine(); QString ports = getValue(strLine, TOKPORTS); QStringList slports = ports.split(TOKCOLON, QString::SkipEmptyParts); inPorts = slports.first().toInt(&ok); outPorts = slports.last().toInt(&ok); strLine = getLine(); QString desc = getValue(strLine, TOKDESCRIPTION); strLine = getLine(); checkEqual(strLine, TOKGRAPHIC); skipSection(); strLine = getLine(); checkEqual(strLine, TOKPARAMETERS); QList < modelParameter * >params = parseParameters(); strLine = getLine(); checkEqual(strLine, TOKSYSTEM); strLine = getLine(); checkEqual(strLine, TOKOBRACE); do { strLine = getLine(); if (strLine == TOKATOMIC) { modelChild *c = new modelChild(); c->childType = ATOMIC; c->atomic = parseAtomic(); c->atomic->father = ret; childs.append(c); } if (strLine == TOKCOUPLED) { modelChild *c = new modelChild(); c->childType = COUPLED; c->coupled = parseCoupled(); c->coupled->father = ret; childs.append(c); } if (strLine == TOKINPORT) { lsPorts.append(parseInport()); } if (strLine == TOKOUTPORT) { lsPorts.append(parseOutport()); } if (strLine == TOKPOINT) { points.append(parsePoint()); } if (strLine == TOKLINE) { lines.append(parseLine()); } if (strLine == TOKEXTRA) { ret->extra = parseExtra(); } } while (strLine != TOKCBRACE); strLine = getLine(); checkEqual(strLine, TOKCBRACE); ret->name = name; ret->type = type; ret->lsPorts = lsPorts; ret->params = params; ret->childs = childs; ret->points = points; ret->lines = lines; checkLinesWithPoints(ret); return ret; }
void HPJReader::parseFile() { HCStartFile( _scanner.name() ); int length = _scanner.getLine(); // Get the first line. char section[15]; int i; while( length != 0 ){ // The first line had better be the beginning of a section. if( _scanner[0] != '[' ){ HCWarning( HPJ_NOTSECTION, _scanner.lineNum(), _scanner.name() ); length = skipSection(); continue; } // Read in the name of the section. for( i=1; i < length ; i++ ){ if( _scanner[i] == ']' ) break; section[i-1] = (char) toupper( _scanner[i] ); } // If the section name wasn't terminated properly, skip the section. if( i == length ){ HCWarning( HPJ_BADSECTION, _scanner.lineNum(), _scanner.name() ); length = skipSection(); continue; } section[i-1] = '\0'; // Pass control to the appropriate "section handler". if( strcmp( section, SBaggage ) == 0 ){ length = handleBaggage(); } else if( strcmp( section, SOptions ) == 0 ){ length = handleOptions(); } else if( strcmp( section, SConfig ) == 0 ){ length = handleConfig(); } else if( strcmp( section, SFiles ) == 0 ){ length = handleFiles(); } else if( strcmp( section, SMap ) == 0 ){ length = handleMap(); } else if( strcmp( section, SBitmaps ) == 0 ){ length = handleBitmaps(); } else if( strcmp( section, SWindows ) == 0 ){ length = handleWindows(); } else { HCWarning( HPJ_BADSECTION, _scanner.lineNum(), _scanner.name() ); length = skipSection(); } } if( _rtfFiles == NULL ){ HCError( HPJ_NOFILES ); } // Now parse individual RTF files. StrNode *curfile = _rtfFiles; StrNode *curdir; InFile source; // First, implement phrase replacement if desired. if( _theFiles->_sysFile->isCompressed() ){ _topFile = _rtfFiles; _firstDir = _root; _startDir = _homeDir; _theFiles->_phrFile = new HFPhrases( _dir, &firstFile, &nextFile ); char full_path[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _fullpath( full_path, _scanner.name(), _MAX_PATH ); _splitpath( full_path, drive, dir, fname, ext ); _makepath( full_path, drive, dir, fname, PhExt ); if( !_oldPhrases || !_theFiles->_phrFile->oldTable(full_path) ){ _theFiles->_phrFile->readPhrases(); _theFiles->_phrFile->createQueue( full_path ); } } _theFiles->_topFile = new HFTopic( _dir, _theFiles->_phrFile ); // For each file, search the ROOT path, and create a RTFparser // to deal with it. curfile = _rtfFiles; while( curfile != NULL ){ curdir = _root; if( curdir == NULL ){ source.open( curfile->_name ); } else while( curdir != NULL ){ chdir( curdir->_name ); source.open( curfile->_name ); chdir( _homeDir ); if( !source.bad() ) break; curdir = curdir->_next; } if( source.bad() ){ HCWarning( FILE_ERR, curfile->_name ); } else { RTFparser rtfhandler( _theFiles, &source ); rtfhandler.Go(); source.close(); } curfile = curfile->_next; } }