/** Get the value of the current element. */ char *ReadElementValue(const char *line, const char *file, int *lineNumber) { char *buffer; char ch; int len, max; int x; len = 0; max = BLOCK_SIZE; buffer = Allocate(max + 1); for(x = 0; !IsValueEnd(line[x]); x++) { if(line[x] == '&') { x += ParseEntity(line + x, &ch, file, *lineNumber) - 1; if(ch) { buffer[len] = ch; } else { buffer[len] = line[x]; } } else { if(line[x] == '\n') { ++*lineNumber; } buffer[len] = line[x]; } ++len; if(len >= max) { max += BLOCK_SIZE; buffer = Reallocate(buffer, max + 1); } } buffer[len] = 0; Trim(buffer); return buffer; }
/* ================ ParseEntities Parses the dentdata string into entities ================ */ void ParseEntities( void ) { num_entities = 0; ParseFromMemory( dentdata, entdatasize ); while ( ParseEntity () ) { } }
/* ================ LoadMapFile ================ */ void LoadMapFile (char *filename) { char *buf; Message (MSGVERBOSE, "------ LoadMapFile ------"); LoadFile (filename, (void **)&buf); StartTokenParsing (buf); num_entities = 0; while (ParseEntity ()) { } FreeOther (buf); if (num_entities == 0) Message(MSGERR, "No entities in map"); if (PlayerStarts == 0) Message (MSGWARNCRIT, "No info_player_start entity in level"); if (strlen(MapTitle) != 0) Message (MSGALWAYS, "Title: \"%s\"", MapTitle); Message (MSGVERBOSE, "%6i faces", nummapfaces); Message (MSGVERBOSE, "%6i brushes", nummapbrushes); Message (MSGVERBOSE, "%6i entities", num_entities); Message (MSGVERBOSE, "%6i miptex", nummiptex); Message (MSGVERBOSE, "%6i texinfo", numtexinfo); }
/* ================ LoadMapFile ================ */ void LoadMapFile (char *filename) { void *buf; num_entities = 0; nummapbrushfaces = 0; nummapbrushes = 0; nummapplanes = 0; nummiptex = 0; mapversion = 0; LoadFile (filename, &buf); StartTokenParsing (buf); while (ParseEntity ()); qfree (buf); qprintf ("--- LoadMapFile ---\n"); qprintf ("%s\n", filename); qprintf ("%5i faces\n", nummapbrushfaces); qprintf ("%5i brushes\n", nummapbrushes); qprintf ("%5i entities\n", num_entities); qprintf ("%5i textures\n", nummiptex); qprintf ("%5i texinfo\n", numtexinfo); }
OgreNewtonMesh::OgreNewtonMesh (dNewton* const world, SceneNode* const sceneNode) :dNewtonMesh (world) ,m_materialMap() { Vector3 rootPos (Vector3::ZERO); Vector3 rootScale = sceneNode->getScale(); Quaternion rootOrient = Quaternion::IDENTITY; // parse the entire node adding all static mesh to the collision tree int stack = 1; SceneNode* stackNode[32]; Vector3 scale[32]; Vector3 posit[32]; Quaternion orientation[32]; stackNode[0] = sceneNode; posit[0] = Vector3::ZERO; scale[0] = Vector3 (1.0f, 1.0f, 1.0f); orientation[0] = Quaternion::IDENTITY; BeginPolygon(); while (stack) { stack --; Vector3 curScale (scale[stack]); Vector3 curPosit (posit[stack]); Quaternion curOrient (orientation[stack]); SceneNode* const node = stackNode[stack]; // parse this scene node. Quaternion thisOrient (curOrient * node->getOrientation()); Vector3 thisPos (curPosit + (curOrient * (node->getPosition() * curScale))); Vector3 thisScale (curScale * node->getScale()); Matrix4 matrix; matrix.makeTransform(thisPos, thisScale, thisOrient); // now add the polys from this node. unsigned int num_obj = node->numAttachedObjects(); for (unsigned int co = 0; co < num_obj; co++) { MovableObject* const obj = node->getAttachedObject(short(co)); if (obj->getMovableType() == "Entity") { ParseEntity (((Entity*) obj)->getMesh(), matrix); } } SceneNode::ChildNodeIterator child_it = node->getChildIterator(); while (child_it.hasMoreElements()) { stackNode[stack] = sceneNode; scale[stack] = thisScale; posit[stack] = thisPos; orientation[stack] = thisOrient; stack ++; dAssert (stack < int (sizeof (stackNode[stack]) / sizeof (stackNode[0]))); } } EndPolygon(); }
void ParseEntities( void ){ numEntities = 0; ParseFromMemory( bspEntData, bspEntDataSize ); while ( ParseEntity() ) ; /* ydnar: set number of bsp entities in case a map is loaded on top */ numBSPEntities = numEntities; }
OgreNewtonMesh::OgreNewtonMesh (dNewton* const world, const MeshPtr mesh, const Matrix4& matrix) :dNewtonMesh (world) ,m_materialMap() { BeginPolygon(); ParseEntity (mesh, matrix); EndPolygon(); }
/** * @brief Parses the curTile->entdata string into entities * @sa UnparseEntities * @sa ParseEntity */ void ParseEntities (void) { num_entities = 0; ParseFromMemory(curTile->entdata, curTile->entdatasize); while (ParseEntity() != nullptr) { } }
OgreNewtonMesh::OgreNewtonMesh (dNewton* const world, const Entity* const entity) :dNewtonMesh (world) ,m_materialMap() { BeginPolygon(); ParseEntity (entity->getMesh(), Matrix4::IDENTITY); EndPolygon(); }
/* ================ ParseEntities Parses the sin_dentdata string into entities ================ */ void Sin_ParseEntities( void ) { script_t *script; num_entities = 0; script = LoadScriptMemory( sin_dentdata, sin_entdatasize, "*sin bsp file" ); SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); while ( ParseEntity( script ) ) { } //end while FreeScript( script ); } //end of the function Sin_ParseEntities
void LoadMapFile (char *filename) { char *buf; LoadFile (filename, (void **)&buf); StartTokenParsing (buf); num_entities = 0; while (ParseEntity ()) { } free (buf); logprint ("--- LoadMapFile ---\n"); logprint ("%s\n", filename); logprint ("%5i brushes\n", nummapbrushes); logprint ("%5i entities\n", num_entities); logprint ("%5i miptex\n", nummiptex); logprint ("%5i texinfo\n", numtexinfo); }
/** Read the value of an element or attribute. */ char *ReadValue(const char *line, const char *file, char (*IsEnd)(char), unsigned int *offset, unsigned int *lineNumber) { char *buffer; char ch; unsigned int len, max; unsigned int x; len = 0; max = BLOCK_SIZE; buffer = Allocate(max + 1); for(x = 0; !(IsEnd)(line[x]); x++) { if(line[x] == '&') { x += ParseEntity(line + x, &ch, file, *lineNumber) - 1; if(ch) { buffer[len] = ch; } else { buffer[len] = line[x]; } } else { if(line[x] == '\n') { *lineNumber += 1; } buffer[len] = line[x]; } len += 1; if(len >= max) { max += BLOCK_SIZE; buffer = Reallocate(buffer, max + 1); if(JUNLIKELY(buffer == NULL)) { FatalError(_("out of memory")); } } } buffer[len] = 0; Trim(buffer); *offset = x; return buffer; }
static bool ParseXmlData(char*& s, char*& dst, char until) { while (*s && *s != until) { if (*s == '&') { ParseEntity(++s, dst); } if (*s == ' ') { *dst++ = *s++; //if (!m_bPreserveWhitespace) SkipWhitespace(s); } else { *dst++ = *s++; } } // Make sure that MapAttributes() works correctly when it parses // over a value that has been transformed. char* sfill = dst + 1; while (sfill < s) *sfill++ = ' '; return true; }
//----------------------------------------------------------------------------- // Purpose: Only called on BSP load. Parses and spawns all the entities in the BSP. // Input : pMapData - Pointer to the entity data block to parse. //----------------------------------------------------------------------------- void C_PhysPropClientside::ParseAllEntities(const char *pMapData) { int nEntities = 0; char szTokenBuffer[MAPKEY_MAXLENGTH]; // // Loop through all entities in the map data, creating each. // for ( ; true; pMapData = MapEntity_SkipToNextEntity(pMapData, szTokenBuffer) ) { // // Parse the opening brace. // char token[MAPKEY_MAXLENGTH]; pMapData = MapEntity_ParseToken( pMapData, token ); // // Check to see if we've finished or not. // if (!pMapData) break; if (token[0] != '{') { Error( "MapEntity_ParseAllEntities: found %s when expecting {", token); continue; } // // Parse the entity and add it to the spawn list. // pMapData = ParseEntity( pMapData ); nEntities++; } }
void XmlSettingsDialog::ParsePage (const QDomElement& page) { Titles_ << GetLabel (page); QStringList icons; if (page.hasAttribute ("icon")) icons << page.attribute ("icon"); auto iconElem = page .firstChildElement ("icons") .firstChildElement ("icon"); while (!iconElem.isNull ()) { icons << iconElem.text (); iconElem = iconElem.nextSiblingElement ("icon"); } IconNames_ << icons; const auto baseWidget = new QWidget; Pages_->addWidget (baseWidget); const auto lay = new QGridLayout; lay->setContentsMargins (0, 0, 0, 0); baseWidget->setLayout (lay); ParseEntity (page, baseWidget); bool foundExpanding = false; for (const auto w : baseWidget->findChildren<QWidget*> ()) if (w->sizePolicy ().verticalPolicy () & QSizePolicy::ExpandFlag) { foundExpanding = true; break; } if (!foundExpanding) lay->addItem (new QSpacerItem (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), lay->rowCount (), 0, 1, 2); }
bool FarXMLScanner::ParseAttribute (FarXMLNode *node) { FarString attrName = NextName(); if (attrName.IsEmpty()) return false; SkipWhitespace(); if (!NextExpectedChar ('=')) return false; SkipWhitespace(); char valueDelimiter = NextChar(); if (valueDelimiter != '\'' && valueDelimiter != '\"') { ReportError ("\" or \'"); return false; } FarString attrValue; while (1) { char c = NextChar(); if (c == valueDelimiter) break; else if (c == '&') { int entityValue = ParseEntity(); if (entityValue == -1) return false; attrValue += (char) entityValue; } else attrValue += c; } node->AddAttr (attrName, attrValue); return true; }
void LoadMapFile(void) { parser_t parser; char *buf; int i, j, length, cAxis; void *pTemp; struct lumpdata *texinfo; mapentity_t *ent; mapbrush_t *brush; mapface_t *face, *face2; Message(msgProgress, "LoadMapFile"); length = LoadFile(options.szMapName, &buf, true); PreParseFile(buf); ParserInit(&parser, buf); map.numfaces = map.numbrushes = map.numentities = 0; ent = map.entities; while (ParseEntity(&parser, ent)) { /* Allocate memory for the bmodel, if needed. */ const char *classname = ValueForKey(ent, "classname"); if (strcmp(classname, "func_detail") && ent->nummapbrushes) { ent->lumps[BSPMODEL].data = AllocMem(BSPMODEL, 1, true); ent->lumps[BSPMODEL].count = 1; } map.numentities++; ent++; } /* Double check the entity count matches our pre-parse count */ if (map.numentities != map.maxentities) Error(errLowEntCount); FreeMem(buf, OTHER, length + 1); // Print out warnings for entities if (!(rgfStartSpots & info_player_start)) Message(msgWarning, warnNoPlayerStart); if (!(rgfStartSpots & info_player_deathmatch)) Message(msgWarning, warnNoPlayerDeathmatch); // if (!(rgfStartSpots & info_player_coop)) // Message(msgWarning, warnNoPlayerCoop); // Clean up texture memory if (map.nummiptex > map.maxfaces) Error(errLowMiptexCount); else if (map.nummiptex < map.maxfaces) { // For stuff in AddAnimatingTex, make room available pTemp = map.miptex; map.maxmiptex = map.nummiptex + cAnimtex * 20; map.miptex = AllocMem(MIPTEX, map.maxmiptex, true); memcpy(map.miptex, pTemp, map.nummiptex * rgcMemSize[MIPTEX]); FreeMem(pTemp, MIPTEX, map.maxfaces); } texinfo = &pWorldEnt->lumps[BSPTEXINFO]; if (texinfo->index > texinfo->count) Error(errLowTexinfoCount); else if (texinfo->index < texinfo->count) { pTemp = texinfo->data; texinfo->data = AllocMem(BSPTEXINFO, texinfo->index, true); memcpy(texinfo->data, pTemp, texinfo->index * rgcMemSize[BSPTEXINFO]); FreeMem(pTemp, BSPTEXINFO, texinfo->count); texinfo->count = texinfo->index; } // One plane per face + 6 for portals map.maxplanes = map.numfaces + 6; // Count # of unique planes in all of the faces for (i = 0, face = map.faces; i < map.numfaces; i++, face++) { face->fUnique = true; for (j = 0, face2 = map.faces; j < i; j++, face2++) { if (face2->fUnique && VectorCompare(face->plane.normal, face2->plane.normal) && fabs(face->plane.dist - face2->plane.dist) < EQUAL_EPSILON) { face->fUnique = false; map.maxplanes--; break; } } } /* * Now iterate through brushes, add one plane for each face below 6 axis * aligned faces. This compensates for planes added in ExpandBrush. */ for (i = 0, brush = map.brushes; i < map.numbrushes; i++, brush++) { cAxis = 0; for (j = 0, face = brush->faces; j < brush->numfaces; j++, face++) { if (fabs(face->plane.normal[0]) > 1 - NORMAL_EPSILON || fabs(face->plane.normal[1]) > 1 - NORMAL_EPSILON || fabs(face->plane.normal[2]) > 1 - NORMAL_EPSILON) cAxis++; } if (6 - cAxis > 0) map.maxplanes += 6 - cAxis; } /* * map.maxplanes*3 because of 3 hulls, then add 20% as a fudge factor for * hull edge bevel planes */ map.maxplanes = 3 * map.maxplanes + map.maxplanes / 5; map.planes = AllocMem(PLANE, map.maxplanes, true); Message(msgStat, "%5i faces", map.numfaces); Message(msgStat, "%5i brushes", map.numbrushes); Message(msgStat, "%5i entities", map.numentities); Message(msgStat, "%5i unique texnames", map.nummiptex); Message(msgStat, "%5i texinfo", texinfo->count); Message(msgLiteral, "\n"); }
void XmlSettingsDialog::ParseEntity (const QDomElement& entity, QWidget *baseWidget) { QDomElement item = entity.firstChildElement ("item"); while (!item.isNull ()) { ParseItem (item, baseWidget); item = item.nextSiblingElement ("item"); } auto gbox = entity.firstChildElement ("groupbox"); while (!gbox.isNull ()) { const auto box = new QGroupBox (GetLabel (gbox)); box->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred); const auto groupLayout = new QGridLayout (); groupLayout->setContentsMargins (2, 2, 2, 2); box->setLayout (groupLayout); ParseEntity (gbox, box); const auto lay = qobject_cast<QGridLayout*> (baseWidget->layout ()); lay->addWidget (box, lay->rowCount (), 0, 1, 2); gbox = gbox.nextSiblingElement ("groupbox"); } auto scroll = entity.firstChildElement ("scrollarea"); while (!scroll.isNull ()) { const auto area = new QScrollArea (); if (scroll.hasAttribute ("horizontalScroll")) { const auto& attr = scroll.attribute ("horizontalScroll"); if (attr == "on") area->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); else if (attr == "off") area->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); } if (scroll.hasAttribute ("verticalScroll")) { const auto& attr = scroll.attribute ("verticalScroll"); if (attr == "on") area->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); else if (attr == "off") area->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); } area->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); const auto areaWidget = new QFrame; areaWidget->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); const auto areaLayout = new QGridLayout; areaWidget->setLayout (areaLayout); ParseEntity (scroll, areaWidget); area->setWidget (areaWidget); area->setWidgetResizable (true); areaWidget->show (); const auto lay = qobject_cast<QGridLayout*> (baseWidget->layout ()); const auto thisRow = lay->rowCount (); lay->addWidget (area, thisRow, 0, 1, 2); lay->setRowStretch (thisRow, 1); scroll = scroll.nextSiblingElement ("scrollarea"); } auto tab = entity.firstChildElement ("tab"); if (!tab.isNull ()) { const auto tabs = new QTabWidget; const auto lay = qobject_cast<QGridLayout*> (baseWidget->layout ()); lay->addWidget (tabs, lay->rowCount (), 0, 1, 2); while (!tab.isNull ()) { const auto page = new QWidget; const auto widgetLay = new QGridLayout; widgetLay->setContentsMargins (0, 0, 0, 0); page->setLayout (widgetLay); tabs->addTab (page, GetLabel (tab)); ParseEntity (tab, page); tab = tab.nextSiblingElement ("tab"); widgetLay->addItem (new QSpacerItem (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), widgetLay->rowCount (), 0, 1, 1); } } }
void LoadMapFile(void) { char *buf; int i, j, length; void *pTemp; struct lumpdata *texinfo; Message(msgProgress, "LoadMapFile"); length = LoadFile(options.szMapName, (void *)&buf, true); PreParseFile(buf); ParserInit(buf); // Faces are loaded in reverse order, to be compatible with origqbsp. // Brushes too. map.iFaces = map.cFaces - 1; map.iBrushes = map.cBrushes - 1; map.iEntities = 0; pCurEnt = &map.rgEntities[0]; while (ParseEntity(pCurEnt)) { map.iEntities++; pCurEnt++; } FreeMem(buf, OTHER, length + 1); // Print out warnings for entities if (!(rgfStartSpots & info_player_start)) Message(msgWarning, warnNoPlayerStart); if (!(rgfStartSpots & info_player_deathmatch)) Message(msgWarning, warnNoPlayerDeathmatch); // if (!(rgfStartSpots & info_player_coop)) // Message(msgWarning, warnNoPlayerCoop); // Clean up texture memory if (cMiptex > map.cFaces) Message(msgError, errLowMiptexCount); else if (cMiptex < map.cFaces) { // For stuff in AddAnimatingTex, make room available pTemp = (void *)rgszMiptex; rgszMiptex = AllocMem(MIPTEX, cMiptex + cAnimtex * 20, true); memcpy(rgszMiptex, pTemp, cMiptex * rgcMemSize[MIPTEX]); FreeMem(pTemp, MIPTEX, map.cFaces); } texinfo = &pWorldEnt->lumps[BSPTEXINFO]; if (texinfo->index > texinfo->count) Message(msgError, errLowTexinfoCount); else if (texinfo->index < texinfo->count) { pTemp = texinfo->data; texinfo->data = AllocMem(BSPTEXINFO, texinfo->index, true); memcpy(texinfo->data, pTemp, texinfo->index * rgcMemSize[BSPTEXINFO]); FreeMem(pTemp, BSPTEXINFO, texinfo->count); texinfo->count = texinfo->index; } // One plane per face + 6 for portals cPlanes = map.cFaces + 6; // Count # of unique planes for (i = 0; i < map.cFaces; i++) { map.rgFaces[i].fUnique = true; for (j = 0; j < i; j++) if (map.rgFaces[j].fUnique && VectorCompare(map.rgFaces[i].plane.normal, map.rgFaces[j].plane.normal) && fabs(map.rgFaces[i].plane.dist - map.rgFaces[j].plane.dist) < EQUAL_EPSILON) { map.rgFaces[i].fUnique = false; cPlanes--; break; } } // Now iterate through brushes, add one plane for each face below 6 axis aligned faces. // This compensates for planes added in ExpandBrush. int cAxis; for (i = 0; i < map.cBrushes; i++) { cAxis = 0; for (j = map.rgBrushes[i].iFaceStart; j < map.rgBrushes[i].iFaceEnd; j++) { if (fabs(map.rgFaces[j].plane.normal[0]) > 1 - NORMAL_EPSILON || fabs(map.rgFaces[j].plane.normal[1]) > 1 - NORMAL_EPSILON || fabs(map.rgFaces[j].plane.normal[2]) > 1 - NORMAL_EPSILON) cAxis++; } if (6 - cAxis > 0) cPlanes += 6 - cAxis; } // cPlanes*3 because of 3 hulls, then add 20% as a fudge factor for hull edge bevel planes cPlanes = 3 * cPlanes + cPlanes / 5; pPlanes = AllocMem(PLANE, cPlanes, true); Message(msgStat, "%5i faces", map.cFaces); Message(msgStat, "%5i brushes", map.cBrushes); Message(msgStat, "%5i entities", map.cEntities); Message(msgStat, "%5i unique texnames", cMiptex); Message(msgStat, "%5i texinfo", texinfo->count); Message(msgLiteral, "\n"); }