From: divverent Date: Sat, 20 Aug 2011 15:41:23 +0000 (+0000) Subject: dpshaderkill enhancements X-Git-Tag: xonotic-v0.5.0~35 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9a53b119b2aa8c9d0913e0936e4d9938cd44bec5;p=xonotic%2Fdarkplaces.git dpshaderkill enhancements "Kill" current shader: dpshaderkillifcvar r_foo == 42 dpshaderkillifcvar r_foo != 42 dpshaderkillifcvar r_foo < 42 dpshaderkillifcvar r_foo > 42 dpshaderkillifcvar r_foo <= 42 dpshaderkillifcvar r_foo >= 42 "Un-kill" current shader (unsets the kill flag): dpnoshaderkillifcvar r_foo == 42 dpnoshaderkillifcvar r_foo != 42 dpnoshaderkillifcvar r_foo < 42 dpnoshaderkillifcvar r_foo > 42 dpnoshaderkillifcvar r_foo <= 42 dpnoshaderkillifcvar r_foo >= 42 Also, shader override logic is modified so killed shaders can be used to make alternatives, e.g. switching between two shader definitions based on cvars: - killed shaders never override other shaders, but show no warning - non-killed shaders override killed shaders - non-killed shaders still do not override other non-killed shaders git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11287 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=4434beb3c023ef9f97f772f3944b5800065a8e15 --- diff --git a/model_shared.c b/model_shared.c index 46768288..a7a57690 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1573,15 +1573,31 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader) { if (strcasecmp (entry->shader.name, shader->name) == 0) { - unsigned char *start, *end, *start2; - start = (unsigned char *) (&shader->Q3SHADERINFO_COMPARE_START); - end = ((unsigned char *) (&shader->Q3SHADERINFO_COMPARE_END)) + sizeof(shader->Q3SHADERINFO_COMPARE_END); - start2 = (unsigned char *) (&entry->shader.Q3SHADERINFO_COMPARE_START); - if(memcmp(start, start2, end - start)) - Con_DPrintf("Shader '%s' already defined, ignoring mismatching redeclaration\n", shader->name); + // redeclaration + if(shader->dpshaderkill) + { + // killed shader is a redeclarion? we can safely ignore it + return; + } + else if(entry->shader.dpshaderkill) + { + // replace the old shader! + // this will skip the entry allocating part + // below and just replace the shader + break; + } else - Con_DPrintf("Shader '%s' already defined\n", shader->name); - return; + { + unsigned char *start, *end, *start2; + start = (unsigned char *) (&shader->Q3SHADERINFO_COMPARE_START); + end = ((unsigned char *) (&shader->Q3SHADERINFO_COMPARE_END)) + sizeof(shader->Q3SHADERINFO_COMPARE_END); + start2 = (unsigned char *) (&entry->shader.Q3SHADERINFO_COMPARE_START); + if(memcmp(start, start2, end - start)) + Con_DPrintf("Shader '%s' already defined, ignoring mismatching redeclaration\n", shader->name); + else + Con_DPrintf("Shader '%s' already defined\n", shader->name); + return; + } } lastEntry = entry; entry = entry->chain; @@ -1623,6 +1639,7 @@ void Mod_LoadQ3Shaders(void) char *custsurfaceparmnames[256]; // VorteX: q3map2 has 64 but well, someone will need more unsigned long custsurfaceparms[256]; int numcustsurfaceparms; + qboolean dpshaderkill; Mod_FreeQ3Shaders(); @@ -2079,15 +2096,57 @@ void Mod_LoadQ3Shaders(void) strlcpy(shader.dpreflectcube, parameter[1], sizeof(shader.dpreflectcube)); else if (!strcasecmp(parameter[0], "dpmeshcollisions")) shader.dpmeshcollisions = true; - else if (!strcasecmp(parameter[0], "dpshaderkillifcvarzero") && numparameters >= 2) + // this sets dpshaderkill to true if dpshaderkillifcvarzero was used, and to false if dpnoshaderkillifcvarzero was used + else if (((dpshaderkill = !strcasecmp(parameter[0], "dpshaderkillifcvarzero")) || !strcasecmp(parameter[0], "dpnoshaderkillifcvarzero")) && numparameters >= 2) { if (Cvar_VariableValue(parameter[1]) == 0.0f) - shader.dpshaderkill = true; + shader.dpshaderkill = dpshaderkill; } - else if (!strcasecmp(parameter[0], "dpshaderkillifcvar") && numparameters >= 2) + // this sets dpshaderkill to true if dpshaderkillifcvar was used, and to false if dpnoshaderkillifcvar was used + else if (((dpshaderkill = !strcasecmp(parameter[0], "dpshaderkillifcvar")) || !strcasecmp(parameter[0], "dpnoshaderkillifcvar")) && numparameters >= 2) { - if (Cvar_VariableValue(parameter[1]) != 0.0f) - shader.dpshaderkill = true; + const char *operator = NULL; + if (numparameters >= 3) + operator = parameter[2]; + if(!operator) + { + if (Cvar_VariableValue(parameter[1]) != 0.0f) + shader.dpshaderkill = dpshaderkill; + } + else if (numparameters >= 4 && !strcmp(operator, "==")) + { + if (Cvar_VariableValue(parameter[1]) == atof(parameter[3])) + shader.dpshaderkill = dpshaderkill; + } + else if (numparameters >= 4 && !strcmp(operator, "!=")) + { + if (Cvar_VariableValue(parameter[1]) != atof(parameter[3])) + shader.dpshaderkill = dpshaderkill; + } + else if (numparameters >= 4 && !strcmp(operator, ">")) + { + if (Cvar_VariableValue(parameter[1]) > atof(parameter[3])) + shader.dpshaderkill = dpshaderkill; + } + else if (numparameters >= 4 && !strcmp(operator, "<")) + { + if (Cvar_VariableValue(parameter[1]) < atof(parameter[3])) + shader.dpshaderkill = dpshaderkill; + } + else if (numparameters >= 4 && !strcmp(operator, ">=")) + { + if (Cvar_VariableValue(parameter[1]) >= atof(parameter[3])) + shader.dpshaderkill = dpshaderkill; + } + else if (numparameters >= 4 && !strcmp(operator, "<=")) + { + if (Cvar_VariableValue(parameter[1]) <= atof(parameter[3])) + shader.dpshaderkill = dpshaderkill; + } + else + { + Con_DPrintf("%s parsing warning: unknown dpshaderkillifcvar operator \"%s\", or not enough arguments\n", search->filenames[fileindex], operator); + } } else if (!strcasecmp(parameter[0], "sky") && numparameters >= 2) {