/* ================ 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
/* ================ LoadMapFile ================ */ void Q2_LoadMapFile(char *filename) { int i; script_t *script; Log_Print("-- Q2_LoadMapFile --\n"); #ifdef ME //loaded map type loadedmaptype = MAPTYPE_QUAKE2; //reset the map loading ResetMapLoading(); #endif //ME script = LoadScriptFile(filename); if (!script) { Log_Print("couldn't open %s\n", filename); return; } //end if //white spaces and escape characters inside a string are not allowed SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS | SCFL_PRIMITIVE); nummapbrushsides = 0; num_entities = 0; while (Q2_ParseMapEntity(script)) { } ClearBounds(map_mins, map_maxs); for (i = 0 ; i < entities[0].numbrushes ; i++) { if (mapbrushes[i].mins[0] > 4096) { continue; // no valid points } AddPointToBounds(mapbrushes[i].mins, map_mins, map_maxs); AddPointToBounds(mapbrushes[i].maxs, map_mins, map_maxs); } //end for PrintMapInfo(); //free the script FreeScript(script); // TestExpandBrushes (); // Q2_CreateMapTexinfo(); } //end of the function Q2_LoadMapFile
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_ParseBSPEntities( void ) { script_t *script; token_t token; bsp_entity_t *ent; bsp_epair_t *epair; byte *buffer, *buftrav; int bufsize; // RF, modified this, so that it first gathers up memory requirements, then allocates a single chunk, // and places the strings all in there bspworld.ebuffer = NULL; script = LoadScriptMemory( bspworld.dentdata, bspworld.entdatasize, "entdata" ); SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); //SCFL_PRIMITIVE); bufsize = 0; while ( PS_ReadToken( script, &token ) ) { if ( strcmp( token.string, "{" ) ) { ScriptError( script, "invalid %s\n", token.string ); AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if if ( bspworld.numentities >= MAX_BSPENTITIES ) { botimport.Print( PRT_MESSAGE, "too many entities in BSP file\n" ); break; } //end if while ( PS_ReadToken( script, &token ) ) { if ( !strcmp( token.string, "}" ) ) { break; } bufsize += sizeof( bsp_epair_t ); if ( token.type != TT_STRING ) { ScriptError( script, "invalid %s\n", token.string ); AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if StripDoubleQuotes( token.string ); bufsize += strlen( token.string ) + 1; if ( !PS_ExpectTokenType( script, TT_STRING, 0, &token ) ) { AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if StripDoubleQuotes( token.string ); bufsize += strlen( token.string ) + 1; } //end while if ( strcmp( token.string, "}" ) ) { ScriptError( script, "missing }\n" ); AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if } //end while FreeScript( script ); buffer = (byte *)GetClearedHunkMemory( bufsize ); buftrav = buffer; bspworld.ebuffer = buffer; // RF, now parse the entities into memory // RF, NOTE: removed error checks for speed, no need to do them twice script = LoadScriptMemory( bspworld.dentdata, bspworld.entdatasize, "entdata" ); SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); //SCFL_PRIMITIVE); bspworld.numentities = 1; while ( PS_ReadToken( script, &token ) ) { ent = &bspworld.entities[bspworld.numentities]; bspworld.numentities++; ent->epairs = NULL; while ( PS_ReadToken( script, &token ) ) { if ( !strcmp( token.string, "}" ) ) { break; } epair = (bsp_epair_t *) buftrav; buftrav += sizeof( bsp_epair_t ); epair->next = ent->epairs; ent->epairs = epair; StripDoubleQuotes( token.string ); epair->key = (char *) buftrav; buftrav += ( strlen( token.string ) + 1 ); strcpy( epair->key, token.string ); if ( !PS_ExpectTokenType( script, TT_STRING, 0, &token ) ) { AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if StripDoubleQuotes( token.string ); epair->value = (char *) buftrav; buftrav += ( strlen( token.string ) + 1 ); strcpy( epair->value, token.string ); } //end while } //end while FreeScript( script ); } //end of the function AAS_ParseBSPEntities
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_ParseBSPEntities(void) { script_t *script; token_t token; bsp_entity_t *ent; bsp_epair_t *epair; script = LoadScriptMemory(bspworld.dentdata, bspworld.entdatasize, "entdata"); SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES|SCFL_NOSTRINGESCAPECHARS);//SCFL_PRIMITIVE); bspworld.numentities = 1; while(PS_ReadToken(script, &token)) { if (strcmp(token.string, "{")) { ScriptError(script, "invalid %s", token.string); AAS_FreeBSPEntities(); FreeScript(script); return; } //end if if (bspworld.numentities >= MAX_BSPENTITIES) { botimport.Print(PRT_MESSAGE, "too many entities in BSP file\n"); break; } //end if ent = &bspworld.entities[bspworld.numentities]; bspworld.numentities++; ent->epairs = NULL; while(PS_ReadToken(script, &token)) { if (!strcmp(token.string, "}")) break; epair = (bsp_epair_t *) GetClearedHunkMemory(sizeof(bsp_epair_t)); epair->next = ent->epairs; ent->epairs = epair; if (token.type != TT_STRING) { ScriptError(script, "invalid %s", token.string); AAS_FreeBSPEntities(); FreeScript(script); return; } //end if StripDoubleQuotes(token.string); epair->key = (char *) GetHunkMemory(strlen(token.string) + 1); strcpy(epair->key, token.string); if (!PS_ExpectTokenType(script, TT_STRING, 0, &token)) { AAS_FreeBSPEntities(); FreeScript(script); return; } //end if StripDoubleQuotes(token.string); epair->value = (char *) GetHunkMemory(strlen(token.string) + 1); strcpy(epair->value, token.string); } //end while if (strcmp(token.string, "}")) { ScriptError(script, "missing }"); AAS_FreeBSPEntities(); FreeScript(script); return; } //end if } //end while FreeScript(script); } //end of the function AAS_ParseBSPEntities