implemented QW skin support, it's broken on skins that are not the same
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 30 Apr 2007 05:39:56 +0000 (05:39 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 30 Apr 2007 05:39:56 +0000 (05:39 +0000)
size as the model skin though

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7213 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
client.h
gl_rmain.c
gl_rsurf.c
model_alias.c
model_brush.c
model_sprite.c
render.h

index c001ad4..84d93e8 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -817,6 +817,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
        e->render.flags = e->state_current.flags;
        e->render.effects = e->state_current.effects;
        VectorScale(e->state_current.colormod, (1.0f / 32.0f), e->render.colormod);
+       e->render.entitynumber = e - cl.entities;
        if (e->state_current.flags & RENDER_COLORMAPPED)
        {
                int cb;
index 8578e8d..9d98fa7 100644 (file)
--- a/client.h
+++ b/client.h
@@ -245,6 +245,8 @@ typedef struct entity_render_s
        model_t *model;
        // current uninterpolated animation frame (for things which do not use interpolation)
        int frame;
+       // number of the entity represents, or 0 for non-network entities
+       int entitynumber;
        // entity shirt and pants colors (-1 if not colormapped)
        int colormap;
        // literal colors for renderer
index 088e3bf..5d69317 100644 (file)
@@ -149,6 +149,9 @@ r_glsl_permutation_t r_glsl_permutations[SHADERPERMUTATION_MAX];
 // currently selected permutation
 r_glsl_permutation_t *r_glsl_permutation;
 
+char r_qwskincache[MAX_SCOREBOARD][MAX_QPATH];
+skinframe_t *r_qwskincache_skinframe[MAX_SCOREBOARD];
+
 // vertex coordinates for a quad that covers the screen exactly
 const static float r_screenvertex3f[12] =
 {
@@ -1119,7 +1122,7 @@ skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewid
        return item;
 }
 
-skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags)
+skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboolean complain)
 {
        // FIXME: it should be possible to disable loading various layers using
        // cvars, to prevent wasted loading time and memory usage if the user does
@@ -1146,7 +1149,7 @@ skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags)
        if (skinframe && skinframe->base)
                return skinframe;
 
-       basepixels = loadimagepixels(name, false, 0, 0);
+       basepixels = loadimagepixels(name, complain, 0, 0);
        if (basepixels == NULL)
                return NULL;
 
@@ -1375,6 +1378,9 @@ void gl_main_start(void)
                r_refdef.fogmasktable[x] = bound(0, alpha, 1);
        }
 
+       memset(r_qwskincache, 0, sizeof(r_qwskincache));
+       memset(r_qwskincache_skinframe, 0, sizeof(r_qwskincache_skinframe));
+
        // set up r_skinframe loading system for textures
        memset(&r_skinframe, 0, sizeof(r_skinframe));
        r_skinframe.loadsequence = 1;
@@ -1396,6 +1402,9 @@ void gl_main_start(void)
 
 void gl_main_shutdown(void)
 {
+       memset(r_qwskincache, 0, sizeof(r_qwskincache));
+       memset(r_qwskincache_skinframe, 0, sizeof(r_qwskincache_skinframe));
+
        // clear out the r_skinframe state
        Mem_ExpandableArray_FreeArray(&r_skinframe.array);
        memset(&r_skinframe, 0, sizeof(r_skinframe));
@@ -3076,6 +3085,7 @@ static void R_Texture_AddLayer(texture_t *t, qboolean depthmask, int blendfunc1,
 
 void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
 {
+       int i;
        model_t *model = ent->model;
 
        // switch to an alternate material if this is a q1bsp animated material
@@ -3105,8 +3115,20 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                texture->currentframe = t;
        }
 
-       // pick a new currentskinframe if the material is animated
-       if (t->numskinframes >= 2)
+       // update currentskinframe to be a qw skin or animation frame
+       if ((i = ent->entitynumber - 1) >= 0 && i < cl.maxclients)
+       {
+               if (strcmp(r_qwskincache[i], cl.scores[i].qw_skin))
+               {
+                       strlcpy(r_qwskincache[i], cl.scores[i].qw_skin, sizeof(r_qwskincache[i]));
+                       Con_DPrintf("loading skins/%s\n", r_qwskincache[i]);
+                       r_qwskincache_skinframe[i] = R_SkinFrame_LoadExternal(va("skins/%s", r_qwskincache[i]), TEXF_PRECACHE | (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_PICMIP, developer.integer > 0);
+               }
+               t->currentskinframe = r_qwskincache_skinframe[i];
+               if (t->currentskinframe == NULL)
+                       t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->frame2time)) % t->numskinframes];
+       }
+       else if (t->numskinframes >= 2)
                t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->frame2time)) % t->numskinframes];
        if (t->backgroundnumskinframes >= 2)
                t->backgroundcurrentskinframe = t->backgroundskinframes[(int)(t->backgroundskinframerate * (cl.time - ent->frame2time)) % t->backgroundnumskinframes];
index c245edb..1927aa2 100644 (file)
@@ -1133,7 +1133,7 @@ void R_ReplaceWorldTexture (void)
        {
                if(t->width && !strcasecmp(t->name, r))
                {
-                       if ((skinframe = R_SkinFrame_LoadExternal((char*)newt, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP)))
+                       if ((skinframe = R_SkinFrame_LoadExternal((char*)newt, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, true)))
                        {
                                t->skinframes[0] = skinframe;
                                Con_Printf("%s replaced with %s\n", r, newt);
index 5503283..4cecaaf 100644 (file)
@@ -711,7 +711,7 @@ static void Mod_BuildAliasSkinsFromSkinFiles(texture_t *skin, skinfile_t *skinfi
                                // leave the skin unitialized (nodraw) if the replacement is "common/nodraw" or "textures/common/nodraw"
                                if (!strcmp(skinfileitem->name, meshname) && strcmp(skinfileitem->replacement, "common/nodraw") && strcmp(skinfileitem->replacement, "textures/common/nodraw"))
                                {
-                                       tempskinframe = R_SkinFrame_LoadExternal(skinfileitem->replacement, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP);
+                                       tempskinframe = R_SkinFrame_LoadExternal(skinfileitem->replacement, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false);
                                        if (!tempskinframe)
                                                if (cls.state != ca_dedicated)
                                                        Con_DPrintf("mesh \"%s\": failed to load skin #%i \"%s\"\n", meshname, i, skinfileitem->replacement);
@@ -723,7 +723,7 @@ static void Mod_BuildAliasSkinsFromSkinFiles(texture_t *skin, skinfile_t *skinfi
        }
        else
        {
-               tempskinframe = R_SkinFrame_LoadExternal(shadername, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP);
+               tempskinframe = R_SkinFrame_LoadExternal(shadername, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false);
                if (!tempskinframe)
                        if (cls.state != ca_dedicated)
                                Con_Printf("Can't find texture \"%s\" for mesh \"%s\", using grey checkerboard\n", shadername, meshname);
@@ -995,7 +995,7 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
                                        sprintf (name, "%s_%i_%i", loadmodel->name, i, j);
                                else
                                        sprintf (name, "%s_%i", loadmodel->name, i);
-                               tempskinframe = R_SkinFrame_LoadExternal(name, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PICMIP);
+                               tempskinframe = R_SkinFrame_LoadExternal(name, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PICMIP, false);
                                if (!tempskinframe)
                                        tempskinframe = R_SkinFrame_LoadInternal(name, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_PICMIP, true, r_fullbrights.integer, (unsigned char *)datapointer, skinwidth, skinheight, 8, NULL, NULL);
                                Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + totalskins * loadmodel->num_surfaces, tempskinframe);
@@ -1005,7 +1005,7 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
                }
                // check for skins that don't exist in the model, but do exist as external images
                // (this was added because yummyluv kept pestering me about support for it)
-               while ((tempskinframe = R_SkinFrame_LoadExternal(va("%s_%i", loadmodel->name, loadmodel->numskins), (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PICMIP)))
+               while ((tempskinframe = R_SkinFrame_LoadExternal(va("%s_%i", loadmodel->name, loadmodel->numskins), (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PICMIP, false)))
                {
                        // expand the arrays to make room
                        tempskinscenes = loadmodel->skinscenes;
@@ -1149,7 +1149,7 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
                loadmodel->data_textures = (texture_t *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t));
                for (i = 0;i < loadmodel->numskins;i++, inskin += MD2_SKINNAME)
                {
-                       tempskinframe = R_SkinFrame_LoadExternal(inskin, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP);
+                       tempskinframe = R_SkinFrame_LoadExternal(inskin, (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false);
                        if (!tempskinframe)
                                Con_Printf("%s is missing skin \"%s\"\n", loadmodel->name, inskin);
                        Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + i * loadmodel->num_surfaces, tempskinframe);
index 76219a6..f7bd00c 100644 (file)
@@ -1483,9 +1483,9 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                        }
                        else
                        {
-                               skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s/%s", mapname, tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP);
+                               skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s/%s", mapname, tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false);
                                if (!skinframe)
-                                       skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP);
+                                       skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false);
                                if (!skinframe)
                                {
                                        // did not find external texture, load it from the bsp or wad3
@@ -4566,7 +4566,7 @@ Q3 shader blendfuncs actually used in the game (* = supported by DP)
                                out->numskinframes = shader->primarylayer->numframes;
                                out->skinframerate = shader->primarylayer->framerate;
                                for (j = 0;j < shader->primarylayer->numframes;j++)
-                                       if (!(out->skinframes[j] = R_SkinFrame_LoadExternal(shader->primarylayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP ? 0 : TEXF_PICMIP) | (shader->primarylayer->clampmap ? TEXF_CLAMP : 0))))
+                                       if (!(out->skinframes[j] = R_SkinFrame_LoadExternal(shader->primarylayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP ? 0 : TEXF_PICMIP) | (shader->primarylayer->clampmap ? TEXF_CLAMP : 0), false)))
                                                Con_DPrintf("%s: could not load texture \"%s\" (frame %i) for shader \"%s\"\n", loadmodel->name, shader->primarylayer->texturename[j], j, out->name);
                        }
                        if (shader->backgroundlayer)
@@ -4576,7 +4576,7 @@ Q3 shader blendfuncs actually used in the game (* = supported by DP)
                                out->backgroundskinframerate = shader->backgroundlayer->framerate;
                                for (j = 0;j < shader->backgroundlayer->numframes;j++)
                                {
-                                       if (!(out->backgroundskinframes[j] = R_SkinFrame_LoadExternal(shader->backgroundlayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP ? 0 : TEXF_PICMIP) | (shader->backgroundlayer->clampmap ? TEXF_CLAMP : 0))))
+                                       if (!(out->backgroundskinframes[j] = R_SkinFrame_LoadExternal(shader->backgroundlayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP ? 0 : TEXF_PICMIP) | (shader->backgroundlayer->clampmap ? TEXF_CLAMP : 0), false)))
                                        {
                                                Con_DPrintf("%s: could not load texture \"%s\" (frame %i) for shader \"%s\"\n", loadmodel->name, shader->backgroundlayer->texturename[j], j, out->name);
                                                out->backgroundskinframes[j] = R_SkinFrame_LoadMissing();
@@ -4606,7 +4606,7 @@ Q3 shader blendfuncs actually used in the game (* = supported by DP)
                        //if (R_TextureHasAlpha(out->skinframes[0].base))
                        //      out->surfaceparms |= Q3SURFACEPARM_TRANS;
                        out->numskinframes = 1;
-                       if (!(out->skinframes[0] = R_SkinFrame_LoadExternal(out->name, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP)))
+                       if (!(out->skinframes[0] = R_SkinFrame_LoadExternal(out->name, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP, false)))
                                Con_DPrintf("%s: could not load texture for missing shader \"%s\"\n", loadmodel->name, out->name);
                }
                // init the animation variables
index 8ef4357..6e4bf45 100644 (file)
@@ -177,7 +177,7 @@ static void Mod_Sprite_SharedSetup(const unsigned char *datapointer, int version
                                        sprintf (name, "%s_%i_%i", loadmodel->name, i, j);
                                else
                                        sprintf (name, "%s_%i", loadmodel->name, i);
-                               if (!(skinframe = R_SkinFrame_LoadExternal(name, texflags)))
+                               if (!(skinframe = R_SkinFrame_LoadExternal(name, texflags, false)))
                                {
                                        if (groupframes > 1)
                                                sprintf (fogname, "%s_%i_%ifog", loadmodel->name, i, j);
@@ -405,7 +405,7 @@ void Mod_IDS2_Load(model_t *mod, void *buffer, void *bufferend)
                {
                        const dsprite2frame_t *pinframe;
                        pinframe = &pinqsprite->frames[i];
-                       if (!(skinframe = R_SkinFrame_LoadExternal(pinframe->name, texflags)))
+                       if (!(skinframe = R_SkinFrame_LoadExternal(pinframe->name, texflags, false)))
                        {
                                Con_Printf("Mod_IDS2_Load: failed to load %s", pinframe->name);
                                skinframe = R_SkinFrame_LoadMissing();
index 96469b1..4ae53eb 100644 (file)
--- a/render.h
+++ b/render.h
@@ -132,7 +132,7 @@ void R_SkinFrame_PrepareForPurge(void);
 void R_SkinFrame_MarkUsed(skinframe_t *skinframe);
 void R_SkinFrame_Purge(void);
 skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewidth, int compareheight, int comparecrc, qboolean add);
-skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags);
+skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboolean complain);
 skinframe_t *R_SkinFrame_LoadInternal(const char *name, int textureflags, int loadpantsandshirt, int loadglowtexture, const unsigned char *skindata, int width, int height, int bitsperpixel, const unsigned int *palette, const unsigned int *alphapalette);
 skinframe_t *R_SkinFrame_LoadMissing(void);