From: vortex Date: Sun, 6 Jun 2010 16:33:45 +0000 (+0000) Subject: support for q3map2's custinfoparms.txt in Mod_LoadQ3Shaders, so now you can create... X-Git-Tag: xonotic-v0.1.0preview~230^2~251 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cfa39fe98ca9b6ffb70434980802cafb4ace63d6;p=xonotic%2Fdarkplaces.git support for q3map2's custinfoparms.txt in Mod_LoadQ3Shaders, so now you can create custom surfaceparms that works with BIH. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10227 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/model_shared.c b/model_shared.c index 40c49dbf..9c7e2c38 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1603,6 +1603,9 @@ void Mod_LoadQ3Shaders(void) q3shaderinfo_layer_t *layer; int numparameters; char parameter[TEXTURE_MAXFRAMES + 4][Q3PATHLENGTH]; + char *custsurfaceparmnames[256]; // VorteX: q3map2 has 64 but well, someone will need more + unsigned long custsurfaceparms[256]; + int numcustsurfaceparms; Mod_FreeQ3Shaders(); @@ -1614,6 +1617,49 @@ void Mod_LoadQ3Shaders(void) Mem_ExpandableArray_NewArray (&q3shader_data->char_ptrs, q3shaders_mem, sizeof (char**), 256); + // parse custinfoparms.txt + numcustsurfaceparms = 0; + if (text = f = (char *)FS_LoadFile("scripts/custinfoparms.txt", tempmempool, false, NULL)) + { + if (!COM_ParseToken_QuakeC(&text, false) || strcasecmp(com_token, "{")) + Con_DPrintf("scripts/custinfoparms.txt: contentflags section parsing error - expected \"{\", found \"%s\"\n", com_token); + else + { + while (COM_ParseToken_QuakeC(&text, false)) + if (!strcasecmp(com_token, "}")) + break; + // custom surfaceflags section + if (!COM_ParseToken_QuakeC(&text, false) || strcasecmp(com_token, "{")) + Con_DPrintf("scripts/custinfoparms.txt: surfaceflags section parsing error - expected \"{\", found \"%s\"\n", com_token); + else + { + while(COM_ParseToken_QuakeC(&text, false)) + { + if (!strcasecmp(com_token, "}")) + break; + // register surfaceflag + if (numcustsurfaceparms >= 256) + { + Con_Printf("scripts/custinfoparms.txt: surfaceflags section parsing error - max 256 surfaceflags exceeded\n"); + break; + } + // name + j = strlen(com_token)+1; + custsurfaceparmnames[numcustsurfaceparms] = (char *)Mem_Alloc(tempmempool, j); + strlcpy(custsurfaceparmnames[numcustsurfaceparms], com_token, j+1); + // value + if (COM_ParseToken_QuakeC(&text, false)) + custsurfaceparms[numcustsurfaceparms] = strtol(com_token, NULL, 0); + else + custsurfaceparms[numcustsurfaceparms] = 0; + numcustsurfaceparms++; + } + } + } + Mem_Free(f); + } + + // parse shaders search = FS_Search("scripts/*.shader", true, false); if (!search) return; @@ -1989,7 +2035,20 @@ void Mod_LoadQ3Shaders(void) else if (!strcasecmp(parameter[1], "antiportal")) shader.surfaceparms |= Q3SURFACEPARM_ANTIPORTAL; else - Con_DPrintf("%s parsing warning: unknown surfaceparm \"%s\"\n", search->filenames[fileindex], parameter[1]); + { + // try custom surfaceparms + for (j = 0; j < numcustsurfaceparms; j++) + { + if (!strcasecmp(custsurfaceparmnames[j], parameter[1])) + { + shader.surfaceparms |= custsurfaceparms[j]; + break; + } + } + // failed all + if (j == numcustsurfaceparms) + Con_DPrintf("%s parsing warning: unknown surfaceparm \"%s\"\n", search->filenames[fileindex], parameter[1]); + } } else if (!strcasecmp(parameter[0], "dpshadow")) shader.dpshadow = true; @@ -2143,6 +2202,9 @@ void Mod_LoadQ3Shaders(void) Mem_Free(f); } FS_FreeSearch(search); + // free custinfoparm values + for (j = 0; j < numcustsurfaceparms; j++) + Mem_Free(custsurfaceparmnames[j]); } q3shaderinfo_t *Mod_LookupQ3Shader(const char *name)