]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
eat unsupported tokens from framegroups file
[xonotic/darkplaces.git] / model_shared.c
index 40e7b278512194b6dd8d3957ee061e9499e29d2e..3188e60793c99b9de74662256106f5cffdc48aff 100644 (file)
@@ -234,7 +234,7 @@ void R_Model_Null_Draw(entity_render_t *ent)
 }
 
 
-typedef void (*mod_framegroupify_parsegroups_t) (unsigned int i, int start, int len, float fps, qboolean loop, void *pass);
+typedef void (*mod_framegroupify_parsegroups_t) (unsigned int i, int start, int len, float fps, qboolean loop, const char *name, void *pass);
 
 int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups_t cb, void *pass)
 {
@@ -243,18 +243,23 @@ int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups
        float fps;
        unsigned int i;
        qboolean loop;
+       char name[64];
 
        bufptr = buf;
        i = 0;
        for(;;)
        {
                // an anim scene!
-               if (!COM_ParseToken_Simple(&bufptr, true, false))
+
+               // REQUIRED: fetch start
+               if (!COM_ParseToken_Simple(&bufptr, true, false, true))
                        break;
                if (!strcmp(com_token, "\n"))
                        continue; // empty line
                start = atoi(com_token);
-               if (!COM_ParseToken_Simple(&bufptr, true, false))
+
+               // REQUIRED: fetch length
+               if (!COM_ParseToken_Simple(&bufptr, true, false, true))
                        break;
                if (!strcmp(com_token, "\n"))
                {
@@ -262,44 +267,68 @@ int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups
                        continue;
                }
                len = atoi(com_token);
-               if (!COM_ParseToken_Simple(&bufptr, true, false))
+
+               // OPTIONAL args start
+               if (!COM_ParseToken_Simple(&bufptr, true, false, true))
                        break;
-               // we default to looping as it's usually wanted, so to NOT loop you append a 0
+
+               // OPTIONAL: fetch fps
+               fps = 20;
                if (strcmp(com_token, "\n"))
                {
                        fps = atof(com_token);
-                       if (!COM_ParseToken_Simple(&bufptr, true, false))
+                       if (!COM_ParseToken_Simple(&bufptr, true, false, true))
                                break;
-                       if (strcmp(com_token, "\n"))
-                               loop = atoi(com_token) != 0;
-                       else
-                               loop = true;
                }
-               else
+
+               // OPTIONAL: fetch loopflag
+               loop = true;
+               if (strcmp(com_token, "\n"))
+               {
+                       loop = (atoi(com_token) != 0);
+                       if (!COM_ParseToken_Simple(&bufptr, true, false, true))
+                               break;
+               }
+
+               // OPTIONAL: fetch name
+               name[0] = 0;
+               if (strcmp(com_token, "\n"))
                {
-                       fps = 20;
-                       loop = true;
+                       strlcpy(name, com_token, sizeof(name));
+                       if (!COM_ParseToken_Simple(&bufptr, true, false, true))
+                               break;
                }
 
+               // OPTIONAL: remaining unsupported tokens (eat them)
+               while (strcmp(com_token, "\n"))
+               {
+                       if (!COM_ParseToken_Simple(&bufptr, true, false, true))
+                       {
+                               bufptr = NULL;
+                               break;
+                       }
+               }
+               if(!bufptr)
+                       break;
+
+               //Con_Printf("data: %d %d %d %f %d (%s)\n", i, start, len, fps, loop, name);
+
                if(cb)
-                       cb(i, start, len, fps, loop, pass);
+                       cb(i, start, len, fps, loop, (name[0] ? name : NULL), pass);
                ++i;
        }
 
        return i;
 }
 
-void Mod_FrameGroupify_ParseGroups_Count (unsigned int i, int start, int len, float fps, qboolean loop, void *pass)
-{
-       unsigned int *cnt = (unsigned int *) pass;
-       ++*cnt;
-}
-
-void Mod_FrameGroupify_ParseGroups_Store (unsigned int i, int start, int len, float fps, qboolean loop, void *pass)
+static void Mod_FrameGroupify_ParseGroups_Store (unsigned int i, int start, int len, float fps, qboolean loop, const char *name, void *pass)
 {
        dp_model_t *mod = (dp_model_t *) pass;
        animscene_t *anim = &mod->animscenes[i];
-       dpsnprintf(anim->name, sizeof(anim[i].name), "groupified_%d_anim", i);
+       if(name)
+               strlcpy(anim->name, name, sizeof(anim[i].name));
+       else
+               dpsnprintf(anim->name, sizeof(anim[i].name), "groupified_%d_anim", i);
        anim->firstframe = bound(0, start, mod->num_poses - 1);
        anim->framecount = bound(1, len, mod->num_poses - anim->firstframe);
        anim->framerate = max(1, fps);
@@ -1627,6 +1656,7 @@ extern cvar_t mod_q3shader_default_offsetmapping_scale;
 extern cvar_t mod_q3shader_default_offsetmapping_bias;
 extern cvar_t mod_q3shader_default_polygonoffset;
 extern cvar_t mod_q3shader_default_polygonfactor;
+extern cvar_t mod_q3shader_force_addalpha;
 void Mod_LoadQ3Shaders(void)
 {
        int j;
@@ -1789,6 +1819,11 @@ void Mod_LoadQ3Shaders(void)
                                                                        layer->blendfunc[0] = GL_ONE;
                                                                        layer->blendfunc[1] = GL_ONE;
                                                                }
+                                                               else if (!strcasecmp(parameter[1], "addalpha"))
+                                                               {
+                                                                       layer->blendfunc[0] = GL_SRC_ALPHA;
+                                                                       layer->blendfunc[1] = GL_ONE;
+                                                               }
                                                                else if (!strcasecmp(parameter[1], "filter"))
                                                                {
                                                                        layer->blendfunc[0] = GL_DST_COLOR;
@@ -1816,7 +1851,7 @@ void Mod_LoadQ3Shaders(void)
                                                                        else if (!strcasecmp(parameter[k+1], "GL_DST_COLOR"))
                                                                                layer->blendfunc[k] = GL_DST_COLOR;
                                                                        else if (!strcasecmp(parameter[k+1], "GL_DST_ALPHA"))
-                                                                               layer->blendfunc[k] = GL_ONE_MINUS_DST_ALPHA;
+                                                                               layer->blendfunc[k] = GL_DST_ALPHA;
                                                                        else if (!strcasecmp(parameter[k+1], "GL_ONE_MINUS_SRC_COLOR"))
                                                                                layer->blendfunc[k] = GL_ONE_MINUS_SRC_COLOR;
                                                                        else if (!strcasecmp(parameter[k+1], "GL_ONE_MINUS_SRC_ALPHA"))
@@ -1970,6 +2005,15 @@ void Mod_LoadQ3Shaders(void)
                                                        shader.textureblendalpha = true;
                                                }
                                        }
+
+                                       if(mod_q3shader_force_addalpha.integer)
+                                       {
+                                               // for a long while, DP treated GL_ONE GL_ONE as GL_SRC_ALPHA GL_ONE
+                                               // this cvar brings back this behaviour
+                                               if(layer->blendfunc[0] == GL_ONE && layer->blendfunc[1] == GL_ONE)
+                                                       layer->blendfunc[0] = GL_SRC_ALPHA;
+                                       }
+
                                        layer->texflags = 0;
                                        if (layer->alphatest)
                                                layer->texflags |= TEXF_ALPHA;