HTEXTURE hgeResourceManager::GetTexture(const char *name, int resgroup) { HTEXTURE reshandle; RTexture *resource; ResDesc *Res=FindRes(this, RES_TEXTURE, name); if(Res) return (HTEXTURE)Res->Get(this); else { reshandle=hge->Texture_Load(name); if(reshandle) { resource=new RTexture(); resource->handle=reshandle; resource->resgroup=resgroup; resource->mipmap=false; strcpy(resource->name, name); strcpy(resource->filename, name); AddRes(this, RES_TEXTURE, resource); return reshandle; } } return 0; }
void ScriptParseFileResource(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename, ResDesc *rr, int restype) { RResource *rc=(RResource *)rr, *base; base = (RResource *)FindRes(rm, restype, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->filename[0]=0; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp,false)) { switch(sp->tokentype) { case TTPAR_FILENAME: sp->get_token(); sp->get_token(); strcpy(rc->filename, sp->tkn_string()); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; default: ScriptSkipToNextParameter(sp,true); break; } } AddRes(rm, restype, rc); }
void* hgeResourceManager::GetResource(const char *name, int resgroup) { void *reshandle; RResource *resource; ResDesc *Res=FindRes(this, RES_RESOURCE, name); if(Res) return (void *)Res->Get(this); else { reshandle=hge->Resource_Load(name); if(reshandle) { resource=new RResource(); resource->handle=(DWORD)reshandle; resource->resgroup=resgroup; strcpy(resource->name, name); strcpy(resource->filename, name); AddRes(this, RES_RESOURCE, resource); return reshandle; } } return 0; }
VOID* hgeResourceManager::GetResource(CONST TCHAR *name, INT resgroup) { VOID *reshandle; RResource *resource; ResDesc *Res=FindRes(this, RES_RESOURCE, name); if(Res) return (VOID *)Res->Get(this); else { reshandle=hge->Resource_Load(name); if(reshandle) { resource=new RResource(); resource->handle=(DWORD)reshandle; resource->resgroup=resgroup; _tcscpy(resource->name, name); _tcscpy(resource->filename, name); AddRes(this, RES_RESOURCE, resource); return reshandle; } } return 0; }
HTEXTURE hgeResourceManager::GetTexture(CONST TCHAR *name, INT resgroup) { HTEXTURE reshandle; RTexture *resource; ResDesc *Res=FindRes(this, RES_TEXTURE, name); if(Res) return (HTEXTURE)Res->Get(this); else { reshandle=hge->Texture_Load(name); if(reshandle) { resource=new RTexture(); resource->handle=reshandle; resource->resgroup=resgroup; resource->mipmap=FALSE; _tcscpy(resource->name, name); _tcscpy(resource->filename, name); AddRes(this, RES_TEXTURE, resource); return reshandle; } } return 0; }
void RSprite::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RSprite *rc, *base; rc = new RSprite(); base = (RSprite *)FindRes(rm, RES_SPRITE, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->texname[0]=0; rc->tx=rc->ty=0; rc->w=rc->h=0; rc->hotx=rc->hoty=0; rc->blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE; rc->color=0xFFFFFFFF; rc->z=0.5f; rc->bXFlip=false; rc->bYFlip=false; // rc->x=rc->y=0; // rc->scale=1.0f; // rc->rotation=0.0f; // rc->collision=HGECOL_RECT; } rc->handle=0; strcpy(rc->name, name); ScriptParseSpriteAnim(sp, rc, false); AddRes(rm, RES_SPRITE, rc); }
void RAnimation::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RAnimation *rc, *base; rc = new RAnimation(); base = (RAnimation *)FindRes(rm, RES_ANIMATION, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->texname[0]=0; rc->tx=rc->ty=0; rc->w=rc->h=0; rc->hotx=rc->hoty=0; rc->blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE; rc->color=0xFFFFFFFF; rc->z=0.5f; rc->bXFlip=false; rc->bYFlip=false; // rc->x=rc->y=0; // rc->scale=1.0f; // rc->rotation=0.0f; // rc->collision=HGECOL_RECT; rc->frames=1; rc->fps=12.0f; rc->mode=HGEANIM_FWD | HGEANIM_LOOP; } rc->handle=0; strcpy(rc->name, name); ScriptParseSpriteAnim(sp, rc, true); AddRes(rm, RES_ANIMATION, rc); }
void RESGen::AddWad(const std::string &wadlist, size_t start, size_t len) { std::string wadfile = wadlist.substr(start, len); replaceCharAll(wadfile, '\\', '/'); // strip folders wadfile = wadfile.substr(wadfile.rfind('/') + 1); // Add file to reslist AddRes(wadfile); }
void RTarget::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RTarget *rc, *base; rc = new RTarget(); base = (RTarget *)FindRes(rm, RES_TARGET, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->width=256; rc->height=256; rc->zbuffer=false; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp, false)) { switch(sp->tokentype) { case TTPAR_SIZE: sp->get_token(); sp->get_token(); rc->width=sp->tkn_int(); sp->get_token(); sp->get_token(); rc->height=sp->tkn_int(); break; case TTPAR_ZBUFFER: sp->get_token(); sp->get_token(); rc->zbuffer=sp->tkn_bool(); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; default: ScriptSkipToNextParameter(sp, true); break; } } AddRes(rm, RES_TARGET, rc); }
void RMusic::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { // ScriptParseFileResource(rm, sp, name, basename, new RMusic(), RES_MUSIC); RMusic *rc, *base; rc=new RMusic(); base = (RMusic *)FindRes(rm, RES_MUSIC, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->amplify=50; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp,false)) { switch(sp->tokentype) { case TTPAR_FILENAME: sp->get_token(); sp->get_token(); strcpy(rc->filename, sp->tkn_string()); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; case TTPAR_AMPLIFY: sp->get_token(); sp->get_token(); rc->amplify=sp->tkn_int(); break; default: ScriptSkipToNextParameter(sp,true); break; } } AddRes(rm, RES_MUSIC, rc); }
void RParticle::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RParticle *rc, *base; rc = new RParticle(); base = (RParticle *)FindRes(rm, RES_PARTICLE, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->filename[0]=0; rc->spritename[0]=0; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp, false)) { switch(sp->tokentype) { case TTPAR_FILENAME: sp->get_token(); sp->get_token(); strcpy(rc->filename, sp->tkn_string()); break; case TTPAR_SPRITE: sp->get_token(); sp->get_token(); strcpy(rc->spritename, sp->tkn_string()); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; default: ScriptSkipToNextParameter(sp, true); break; } } AddRes(rm, RES_PARTICLE, rc); }
void RTexture::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RTexture *rc, *base; rc=new RTexture(); base = (RTexture *)FindRes(rm, RES_TEXTURE, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->mipmap=false; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp,false)) { switch(sp->tokentype) { case TTPAR_FILENAME: sp->get_token(); sp->get_token(); strcpy(rc->filename, sp->tkn_string()); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; case TTPAR_MIPMAP: sp->get_token(); sp->get_token(); rc->mipmap=sp->tkn_bool(); break; default: ScriptSkipToNextParameter(sp,true); break; } } AddRes(rm, RES_TEXTURE, rc); }
hgeStringTable *hgeResourceManager::GetStringTable(const char *name, int resgroup) { hgeStringTable *strtable; RStringTable *resource; ResDesc *Res = FindRes(this, RES_STRTABLE, name); if (Res) { return (hgeStringTable *)Res->Get(this); } else { strtable = new hgeStringTable(name); resource = new RStringTable(); resource->handle = strtable; resource->resgroup = resgroup; strcpy(resource->name, name); strcpy(resource->filename, name); AddRes(this, RES_STRTABLE, resource); return strtable; } return 0; }
hgeStringTable* hgeResourceManager::GetStringTable(CONST TCHAR *name, INT resgroup) { hgeStringTable *strtable; RStringTable *resource; ResDesc *Res=FindRes(this, RES_STRTABLE, name); if(Res) return (hgeStringTable*)Res->Get(this); else { strtable=new hgeStringTable(name); if(strtable) { resource=new RStringTable(); resource->handle=(DWORD)strtable; resource->resgroup=resgroup; _tcscpy(resource->name, name); _tcscpy(resource->filename, name); AddRes(this, RES_STRTABLE, resource); return strtable; } } return 0; }
HSTREAM hgeResourceManager::GetStream(CONST TCHAR *name, INT resgroup) { HSTREAM reshandle; RStream *resource; ResDesc *Res=FindRes(this, RES_STREAM, name); if(Res) return (HSTREAM)Res->Get(this); else { reshandle=hge->Stream_Load(name); if(reshandle) { resource=new RStream(); resource->handle=reshandle; resource->resgroup=resgroup; _tcscpy(resource->name, name); _tcscpy(resource->filename, name); AddRes(this, RES_STREAM, resource); return reshandle; } } return 0; }
HMUSIC hgeResourceManager::GetMusic(CONST TCHAR *name, INT resgroup) { HMUSIC reshandle; RMusic *resource; ResDesc *Res=FindRes(this, RES_MUSIC, name); if(Res) return (HMUSIC)Res->Get(this); else { reshandle=hge->Music_Load(name); if(reshandle) { resource=new RMusic(); resource->handle=reshandle; resource->resgroup=resgroup; _tcscpy(resource->name, name); _tcscpy(resource->filename, name); AddRes(this, RES_MUSIC, resource); return reshandle; } } return 0; }
HEFFECT hgeResourceManager::GetEffect(CONST TCHAR *name, INT resgroup) { HEFFECT reshandle; REffect *resource; ResDesc *Res=FindRes(this, RES_EFFECT, name); if(Res) return (HEFFECT)Res->Get(this); else { reshandle=hge->Effect_Load(name); if(reshandle) { resource=new REffect(); resource->handle=reshandle; resource->resgroup=resgroup; _tcscpy(resource->name, name); _tcscpy(resource->filename, name); AddRes(this, RES_EFFECT, resource); return reshandle; } } return 0; }
void RESGen::ParseSentence(const char* const sentence) { // Not so performance critical here std::string sentenceLower(sentence); strToLower(sentenceLower); if( (sentenceLower.length() > 0) // References string in sentences.txt && (sentenceLower[0] != '!') // References string in Titles.txt && (sentenceLower[0] != '#') ) { // See if value references a wav file if( // Only one word (sentenceLower.find(' ') == std::string::npos) && !CompareStrEnd(sentenceLower, ".wav") ) { // TODO: Check that specifying a wav actually // works, and not that people are just misusing // this entity std::string resource = sentenceLower; std::string soundPrefix("sound/"); // Add sound/ to start if it isn't already if(resource.compare(0, soundPrefix.length(), soundPrefix)) { resource.insert(0, soundPrefix); } AddRes(resource); } else { // Everything between parentheses is for intonation // Ignore unbalanced parentheses - we'll just fail to find a // resource for that token (probably an emoticon) stripParentheses(sentenceLower); const size_t slashIndex = sentenceLower.find('/'); std::string soundPrefix("sound/"); // Is an announcer specified? if(slashIndex != std::string::npos) { soundPrefix += sentenceLower.substr(0, slashIndex + 1); sentenceLower.erase(0, slashIndex + 1); } else { // Default announcer soundPrefix += "vox/"; } // These get converted into comma and period sounds which definitely exist replaceCharAll(sentenceLower, ',', ' '); replaceCharAll(sentenceLower, '.', ' '); removeSubstring(sentenceLower, "\\n"); removeSubstring(sentenceLower, "\\r"); // Ignore any other illegal characters left over replaceCharAll(sentenceLower, '\\', ' '); Tokenizer<' '> tokenizer(sentenceLower); // while(true) incorrectly triggers MSVC C4127 for(;;) { const char* token = tokenizer.Next(); if(token == NULL) { break; } AddRes(token, soundPrefix.c_str(), ".wav"); } } } }
void RDistort::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RDistort *rc, *base; rc = new RDistort(); base = (RDistort *)FindRes(rm, RES_DISTORT, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->texname[0]=0; rc->tx=rc->ty=0; rc->w=rc->h=0; rc->cols=rc->rows=2; rc->blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE; rc->color=0xFFFFFFFF; rc->z=0.5f; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp, false)) { switch(sp->tokentype) { case TTPAR_TEXTURE: sp->get_token(); sp->get_token(); strcpy(rc->texname, sp->tkn_string()); break; case TTPAR_RECT: sp->get_token(); sp->get_token(); rc->tx=sp->tkn_float(); sp->get_token(); sp->get_token(); rc->ty=sp->tkn_float(); sp->get_token(); sp->get_token(); rc->w=sp->tkn_float(); sp->get_token(); sp->get_token(); rc->h=sp->tkn_float(); break; case TTPAR_MESH: sp->get_token(); sp->get_token(); rc->cols=sp->tkn_int(); sp->get_token(); sp->get_token(); rc->rows=sp->tkn_int(); break; case TTPAR_BLENDMODE: ScriptParseBlendMode(sp, &rc->blend); break; case TTPAR_COLOR: sp->get_token(); sp->get_token(); rc->color=sp->tkn_hex(); break; case TTPAR_ZORDER: sp->get_token(); sp->get_token(); rc->z=sp->tkn_float(); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; default: ScriptSkipToNextParameter(sp, true); break; } } AddRes(rm, RES_DISTORT, rc); }
void RFont::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *name, const char *basename) { RFont *rc, *base; rc = new RFont(); base = (RFont *)FindRes(rm, RES_FONT, basename); if(base) *rc=*base; else { rc->resgroup=0; rc->mipmap=false; rc->filename[0]=0; rc->blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE; rc->color=0xFFFFFFFF; rc->z=0.5f; rc->scale=1.0f; rc->proportion=1.0f; rc->tracking=0.0f; rc->spacing=1.0f; rc->rotation=0.0f; } rc->handle=0; strcpy(rc->name, name); while(ScriptSkipToNextParameter(sp,false)) { switch(sp->tokentype) { case TTPAR_FILENAME: sp->get_token(); sp->get_token(); strcpy(rc->filename, sp->tkn_string()); break; case TTPAR_BLENDMODE: ScriptParseBlendMode(sp, &rc->blend); break; case TTPAR_COLOR: sp->get_token(); sp->get_token(); rc->color=sp->tkn_hex(); break; case TTPAR_ZORDER: sp->get_token(); sp->get_token(); rc->z=sp->tkn_float(); break; case TTPAR_SCALE: sp->get_token(); sp->get_token(); rc->scale=sp->tkn_float(); break; case TTPAR_PROPORTION: sp->get_token(); sp->get_token(); rc->proportion=sp->tkn_float(); break; case TTPAR_ROTATION: sp->get_token(); sp->get_token(); rc->rotation=sp->tkn_float(); break; case TTPAR_TRACKING: sp->get_token(); sp->get_token(); rc->tracking=sp->tkn_float(); break; case TTPAR_SPACING: sp->get_token(); sp->get_token(); rc->spacing=sp->tkn_float(); break; case TTPAR_RESGROUP: sp->get_token(); sp->get_token(); rc->resgroup=sp->tkn_int(); break; case TTPAR_MIPMAP: sp->get_token(); sp->get_token(); rc->mipmap=sp->tkn_bool(); break; default: ScriptSkipToNextParameter(sp, true); break; } } AddRes(rm, RES_FONT, rc); }
void RScript::Parse(hgeResourceManager *rm, RScriptParser *sp, const char *sname, const char *sbasename) { RScriptParser *np; RScript *res_script; void *data; hgeU32 size; char *script, name[MAXRESCHARS], basename[MAXRESCHARS]; int restype; if(!FindRes(rm, RES_SCRIPT, sname)) { res_script = new RScript(); // hack! we need an instance of RScript to access hge // if all ok, this object is used later to keep the script data=hge->Resource_Load(sname, &size); if(!data) { if(sp) sp->ScriptPostError("Script "," not found."); else hge->System_Log("Script '%s' not found.",sname); delete res_script; return; } else { script= new char[size+1]; memcpy(script, data, size); script[size]=0; hge->Resource_Free(data); strcpy(res_script->name, sname); AddRes(rm, RES_SCRIPT, res_script); np = new RScriptParser(res_script->name, script); for(;;) { np->get_token(); if(np->tokentype == TTEND) break; else if(np->tokentype == TTRES_INCLUDE) { np->get_token(); RScript::Parse(rm, np, np->tkn_string(), NULL); } else if(np->tokentype > TTRES__FIRST && np->tokentype < TTRES__LAST) { restype=np->tokentype-TTRES__FIRST-1; name[0]=basename[0]=0; np->get_token(); if(FindRes(rm, restype, np->tkn_string())) { np->ScriptPostError("Resource "," of the same type already has been defined."); while((np->tokentype <= TTRES__FIRST || np->tokentype >= TTRES__LAST) && np->tokentype != TTEND) np->get_token(); np->put_back(); continue; } strcpy(name, np->tkn_string()); np->get_token(); if(np->tokentype == TTBASED) { np->get_token(); if(!FindRes(rm, restype, np->tkn_string())) np->ScriptPostError("Base resource "," is not defined."); else strcpy(basename, np->tkn_string()); np->get_token(); } if(np->tokentype == TTOPENBLOCK) { switch(restype) { case RES_RESOURCE: RResource::Parse(rm, np, name, basename); break; case RES_TEXTURE: RTexture::Parse(rm, np, name, basename); break; case RES_EFFECT: REffect::Parse(rm, np, name, basename); break; case RES_MUSIC: RMusic::Parse(rm, np, name, basename); break; case RES_STREAM: RStream::Parse(rm, np, name, basename); break; case RES_TARGET: RTarget::Parse(rm, np, name, basename); break; case RES_SPRITE: RSprite::Parse(rm, np, name, basename); break; case RES_ANIMATION: RAnimation::Parse(rm, np, name, basename); break; case RES_FONT: RFont::Parse(rm, np, name, basename); break; case RES_PARTICLE: RParticle::Parse(rm, np, name, basename); break; case RES_DISTORT: RDistort::Parse(rm, np, name, basename); break; case RES_STRTABLE: RStringTable::Parse(rm, np, name, basename); break; } } else { np->ScriptPostError("Illegal resource syntax, "," found; '{' expected."); while((np->tokentype <= TTRES__FIRST || np->tokentype >= TTRES__LAST) && np->tokentype != TTEND) np->get_token(); np->put_back(); } } else { np->ScriptPostError("Unrecognized resource specificator ","."); while((np->tokentype <= TTRES__FIRST || np->tokentype >= TTRES__LAST) && np->tokentype != TTEND) np->get_token(); np->put_back(); } } delete np; delete[] script; } } else sp->ScriptPostError("Script "," already has been parsed."); }
int RESGen::MakeRES(std::string &map, int fileindex, size_t filecount, const StringMap &resources, std::vector<std::string> &resourcePaths_) { resourcePaths = resourcePaths_; std::string basefolder; std::string basefilename; splitPath(map, basefolder, basefilename); const std::string resName = basefolder + basefilename + ".res"; if (verbal) { printf("Creating .res file %s [%d/" SIZE_T_SPECIFIER "].\n", resName.c_str(), fileindex, filecount); } // Check if resfile doesn't already exist const bool fileexists = fileExists(resName); if (!overwrite && fileexists) { // File found, but we don't want to overwrite. printf("%s already exists. Skipping file.\n", resName.c_str()); return 1; } // Clear the resfile list to be sure (SHOULD be empty) resfile.clear(); // Clear the texture list to be sure (SHOULD be empty) texturelist.clear(); // first, get the enity data std::string entdata; if(!LoadBSPData(map, entdata, texturelist)) { // error. return return 1; } statcount = STAT_MAX; // make statbar print at once EntTokenizer entDataTokenizer(entdata); try { const EntTokenizer::KeyValuePair* kv = entDataTokenizer.NextPair(); // Note that we reparse the mapinfo. if(!kv) { printf("Error parsing \"%s\".\n", map.c_str()); return 1; } while (kv && (entDataTokenizer.GetNumBlocksRead() == 0)) { if (!strcmp(kv->first, "wad")) { std::string value(kv->second); if (!value.empty()) // Don't try to parse an empty listing { // seperate the WAD files and save size_t i = 0; size_t seppos; while ((seppos = value.find(';', i)) != std::string::npos) { AddWad(value, i, seppos - i); // Add wad to reslist i = seppos + 1; } // There might be a wad file left in the list, check for it if (i < value.length()) { // it should be equal, there is a wadfile left! AddWad(value, i, value.length() - i); } } } else if (!strcmp(kv->first, "skyname")) { std::string value(kv->second); // Add al 6 sky textures here AddRes(value, "gfx/env/", "up.tga"); AddRes(value, "gfx/env/", "dn.tga"); AddRes(value, "gfx/env/", "lf.tga"); AddRes(value, "gfx/env/", "rt.tga"); AddRes(value, "gfx/env/", "ft.tga"); AddRes(value, "gfx/env/", "bk.tga"); } kv = entDataTokenizer.NextPair(); } while (kv) { const ptrdiff_t keyLength = entDataTokenizer.GetLatestKeyLength(); const ptrdiff_t valueLength = entDataTokenizer.GetLatestValueLength(); // Early out - check if key ends in 'speak' if( (keyLength >= 5) && !strcmp(kv->first + keyLength - 5, "speak") ) { // Guessing which keys have spoken sentences is too likely to // cause false positives - instead use a whitelist of keys // known to contain sentences // TODO: This can still cause false positives if used on a different entity/mod // TODO: Ideally parse FGD corresponding to map if( !strcmp(kv->first, "AP_speak") || !strcmp(kv->first, "non_owners_team_speak") || !strcmp(kv->first, "non_team_speak") || !strcmp(kv->first, "owners_team_speak") || !strcmp(kv->first, "speak") || !strcmp(kv->first, "team_speak") ) { ParseSentence(kv->second); } } const char *token = kv->second; // TODO: This is fast, but should be made more robust if possible // Need at least 5 chars, assuming filename is: // [alpha][.][alpha]{3} if(valueLength >= 5) { if(token[valueLength - 4] == '.') { const int c1 = ::tolower(token[valueLength - 3]); const int c2 = ::tolower(token[valueLength - 2]); const int c3 = ::tolower(token[valueLength - 1]); if(c1 == 'm' && c2 == 'd' && c3 == 'l') { // mdl file AddRes(token); } if(c1 == 'w' && c2 == 'a' && c3 == 'v') { // wave file AddRes(token, "sound/"); } if(c1 == 's' && c2 == 'p' && c3 == 'r') { // sprite file AddRes(token); } if(c1 == 'b' && c2 == 'm' && c3 == 'p') { // bitmap file AddRes(token); } if(c1 == 't' && c2 == 'g' && c3 == 'a') { // targa file AddRes(token); } } } // update statbar if (statusline && statcount == STAT_MAX) { // Reset the statcount statcount = 0; // Calculate the percentage completed of the current file. size_t progress = static_cast<size_t>(token - &entdata[0]); size_t percentage = ((progress + 1) * 101) / entdata.length(); // Make the length one too long. if (percentage > 100) { // Make sure we don;t go over 100% percentage = 100; } printf("\r(" SIZE_T_SPECIFIER "%%) [%d/" SIZE_T_SPECIFIER "]", percentage, fileindex, filecount); } else { statcount++; } kv = entDataTokenizer.NextPair(); } } catch(ParseException &parseException) { if(parseException.GetCharNum() >= 0) { printf("Failed to parse '%s': %s (char: %d)\n", map.c_str(), parseException.what(), parseException.GetCharNum()); } else { printf("Failed to parse '%s': %s\n", map.c_str(), parseException.what()); } return 1; } if (statusline) { // erase statusline printf("\r%-21s\r", ""); // easier to adjust length this way } entdata.clear(); // Try to find info txt and overview data std::string overviewPath = basefolder + ".." + PATH_SEPARATOR + "overviews" + PATH_SEPARATOR + basefilename; if(fileExists(overviewPath + ".txt")) { // file found, but we need the tga or bmp too if(fileExists(overviewPath + ".tga")) { // txt found too, add both files to res list AddRes(basefilename, "overviews/", ".tga"); AddRes(basefilename, "overviews/", ".txt"); } else if(fileExists(overviewPath + ".bmp")) { // txt found too, add both files to res list AddRes(basefilename, "overviews/", ".bmp"); AddRes(basefilename, "overviews/", ".txt"); } } // Resource list has been made. int status = 0; // RES status, 0 means ok, 2 means missing resource std::vector<std::string> extraResources; // Check for resources on disk if (!resourcePaths.empty()) { //printf("\nStarting resource check:\n"); StringMap::iterator it = resfile.begin(); while(it != resfile.end()) { bool bErase = false; StringMap::const_iterator resourceIt = resources.find(it->first); if(resourceIt == resources.end()) { // file not found - maybe it's excluded? if(excludelist.find(it->first) != excludelist.end()) { // file found - it's an exclude if (contentdisp) { printf("Resource is excluded: %s\n", it->second.c_str()); } } else if (CompareStrEnd(it->first, ".wad")) { // not a wad file if (verbal) { printf("Resource file not found: %s\n", it->second.c_str()); } status = 2; // res file might not be complete } else { // wad file is not critical, so no status change if (contentdisp) { printf("Resource file not found: %s\n", it->second.c_str()); } } bErase = true; } else { if (matchcase) { // match case it->second = resourceIt->second; } if (parseresource) { if (!CompareStrEnd(it->first, ".wad")) { // Check if wad file is used if (!CheckWadUse(resourceIt)) // We MUST have the right file { // Wad is NOT being used if (contentdisp) { printf("WAD file not used: %s\n", it->second.c_str()); } if(!preservewads) { bErase = true; } } } else if (!CompareStrEnd(it->first, ".mdl")) { // Check model for external texture if (CheckModelExtTexture(resourceIt->second)) { // Uses external texture, add std::string extmdltex = it->second.substr(0, it->second.length() - 4); // strip extention extmdltex += "T.mdl"; // add T and extention if( (resfile.find(strToLowerCopy(extmdltex)) == resfile.end()) && (findStringNoCase(extraResources, extmdltex) == extraResources.end()) ) { extraResources.push_back(extmdltex); if (contentdisp) { printf("MDL texture file added: %s\n", extmdltex.c_str()); } } } } } } if(bErase) { it = resfile.erase(it); } else { ++it; } } for(std::vector<std::string>::const_iterator extraIt = extraResources.begin(); extraIt != extraResources.end(); ++extraIt) { resfile[strToLowerCopy(*extraIt)] = *extraIt; } } // Check if resource has to be excluded if (checkforexcludes) { //printf("\nStarting exclude check:\n"); StringMap::iterator it = resfile.begin(); while(it != resfile.end()) { if(excludelist.find(it->first) != excludelist.end()) { // file found if (contentdisp) { printf("Resource is excluded: %s\n", it->second.c_str()); } it = resfile.erase(it); } else { ++it; } } } // Give a list of missing textures if (parseresource && !resourcePaths.empty() && verbal) { if (!texturelist.empty()) { status = 2; // res file might not be complete for(StringMap::const_iterator it = texturelist.begin(); it != texturelist.end(); ++it) { printf("Texture not found in wad files: %s\n", it->second.c_str()); } } } if (resfile.empty() && rfastring.empty()) { // no resources! if (verbal) { printf("No resources were found for \"%s.res\".", basefilename.c_str()); } if (fileexists) { // File exists, delete it. // WHAT? No check for overwrite? No! // Think of it, if the file exists we MUST be in overwrite mode to even get to this point! remove(resName.c_str()); if (verbal) { printf(" Deleting existing res file.\n"); } } else { // File doesn't exist, so we don't have to delete it. if (verbal) { printf(" Skipping file.\n"); } } return status; } // Collecting resfile entries is done, now write the res file. if (!WriteRes(basefolder, basefilename)) { return 1; } // File written successfully. We can safely erase the resfile and texture list resfile.clear(); texturelist.clear(); return status; }