unsigned int r_numqueries;
unsigned int r_maxqueries;
-char r_qwskincache[MAX_SCOREBOARD][MAX_QPATH];
-skinframe_t *r_qwskincache_skinframe[MAX_SCOREBOARD];
+typedef struct r_qwskincache_s
+{
+ char name[MAX_QPATH];
+ skinframe_t *skinframe;
+}
+r_qwskincache_t;
+
+static r_qwskincache_t *r_qwskincache;
+static int r_qwskincache_size;
/// vertex coordinates for a quad that covers the screen exactly
const float r_screenvertex3f[12] =
int basepixels_height;
skinframe_t *skinframe;
- *has_alpha = false;
+ if (has_alpha)
+ *has_alpha = false;
if (cls.state == ca_dedicated)
return NULL;
if (j < basepixels_width * basepixels_height * 4)
{
// has transparent pixels
- *has_alpha = true;
+ if (has_alpha)
+ *has_alpha = true;
pixels = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
for (j = 0;j < image_width * image_height * 4;j += 4)
{
skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboolean complain)
{
- qboolean has_alpha;
- return R_SkinFrame_LoadExternal_CheckAlpha(name, textureflags, complain, &has_alpha);
+ return R_SkinFrame_LoadExternal_CheckAlpha(name, textureflags, complain, NULL);
}
static rtexture_t *R_SkinFrame_TextureForSkinLayer(const unsigned char *in, int width, int height, const char *name, const unsigned int *palette, int textureflags, qboolean force)
r_maxqueries = 0;
memset(r_queries, 0, sizeof(r_queries));
- memset(r_qwskincache, 0, sizeof(r_qwskincache));
- memset(r_qwskincache_skinframe, 0, sizeof(r_qwskincache_skinframe));
+ r_qwskincache = NULL;
+ r_qwskincache_size = 0;
// set up r_skinframe loading system for textures
memset(&r_skinframe, 0, sizeof(r_skinframe));
r_maxqueries = 0;
memset(r_queries, 0, sizeof(r_queries));
- memset(r_qwskincache, 0, sizeof(r_qwskincache));
- memset(r_qwskincache_skinframe, 0, sizeof(r_qwskincache_skinframe));
+ r_qwskincache = NULL;
+ r_qwskincache_size = 0;
// clear out the r_skinframe state
Mem_ExpandableArray_FreeArray(&r_skinframe.array);
// FIXME: move this code to client
int l;
char *entities, entname[MAX_QPATH];
+ if (r_qwskincache)
+ Mem_Free(r_qwskincache);
+ r_qwskincache = NULL;
+ r_qwskincache_size = 0;
if (cl.worldmodel)
{
strlcpy(entname, cl.worldmodel->name, sizeof(entname));
Matrix4x4_Concat(texmatrix, &matrix, &temp);
}
+void R_LoadQWSkin(r_qwskincache_t *cache, const char *skinname)
+{
+ int textureflags = TEXF_PRECACHE | (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_PICMIP | TEXF_COMPRESS;
+ char name[MAX_QPATH];
+ skinframe_t *skinframe;
+ unsigned char pixels[296*194];
+ strlcpy(cache->name, skinname, sizeof(cache->name));
+ dpsnprintf(name, sizeof(name), "skins/%s.pcx", cache->name);
+ if (developer_loading.integer)
+ Con_Printf("loading %s\n", name);
+ skinframe = R_SkinFrame_Find(name, textureflags, 0, 0, 0, false);
+ if (!skinframe || !skinframe->base)
+ {
+ unsigned char *f;
+ fs_offset_t filesize;
+ skinframe = NULL;
+ f = FS_LoadFile(name, tempmempool, true, &filesize);
+ if (f)
+ {
+ if (LoadPCX_QWSkin(f, filesize, pixels, 296, 194))
+ skinframe = R_SkinFrame_LoadInternalQuake(name, textureflags, true, r_fullbrights.integer, pixels, image_width, image_height);
+ Mem_Free(f);
+ }
+ }
+ cache->skinframe = skinframe;
+}
+
texture_t *R_GetCurrentTexture(texture_t *t)
{
int i;
// update currentskinframe to be a qw skin or animation frame
if ((i = ent->entitynumber - 1) >= 0 && i < cl.maxclients && cls.protocol == PROTOCOL_QUAKEWORLD && cl.scores[i].qw_skin[0] && !strcmp(ent->model->name, "progs/player.mdl"))
{
- if (strcmp(r_qwskincache[i], cl.scores[i].qw_skin))
+ if (!r_qwskincache || r_qwskincache_size != cl.maxclients)
{
- strlcpy(r_qwskincache[i], cl.scores[i].qw_skin, sizeof(r_qwskincache[i]));
- if (developer_loading.integer)
- Con_Printf("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 | TEXF_COMPRESS, developer.integer > 0);
+ r_qwskincache_size = cl.maxclients;
+ if (r_qwskincache)
+ Mem_Free(r_qwskincache);
+ r_qwskincache = Mem_Alloc(r_main_mempool, sizeof(*r_qwskincache) * r_qwskincache_size);
}
- t->currentskinframe = r_qwskincache_skinframe[i];
+ if (strcmp(r_qwskincache[i].name, cl.scores[i].qw_skin))
+ R_LoadQWSkin(&r_qwskincache[i], cl.scores[i].qw_skin);
+ t->currentskinframe = r_qwskincache[i].skinframe;
if (t->currentskinframe == NULL)
t->currentskinframe = t->skinframes[(int)(t->skinframerate * (cl.time - ent->shadertime)) % t->numskinframes];
}
else
a[x++] = dataByte;
}
- fin += pcx.bytes_per_line - image_width; // the number of bytes per line is always forced to an even number
while(x < image_width)
a[x++] = 0;
}
return image_buffer;
}
+/*
+============
+LoadPCX
+============
+*/
+qboolean LoadPCX_QWSkin(const unsigned char *f, int filesize, unsigned char *pixels, int outwidth, int outheight)
+{
+ pcx_t pcx;
+ unsigned char *a;
+ const unsigned char *fin, *enddata;
+ int x, y, x2, dataByte, pcxwidth, pcxheight;
+
+ if (filesize < (int)sizeof(pcx) + 768)
+ return false;
+
+ image_width = outwidth;
+ image_height = outheight;
+ fin = f;
+
+ memcpy(&pcx, fin, sizeof(pcx));
+ fin += sizeof(pcx);
+
+ // LordHavoc: big-endian support ported from QF newtree
+ pcx.xmax = LittleShort (pcx.xmax);
+ pcx.xmin = LittleShort (pcx.xmin);
+ pcx.ymax = LittleShort (pcx.ymax);
+ pcx.ymin = LittleShort (pcx.ymin);
+ pcx.hres = LittleShort (pcx.hres);
+ pcx.vres = LittleShort (pcx.vres);
+ pcx.bytes_per_line = LittleShort (pcx.bytes_per_line);
+ pcx.palette_type = LittleShort (pcx.palette_type);
+
+ pcxwidth = pcx.xmax + 1 - pcx.xmin;
+ pcxheight = pcx.ymax + 1 - pcx.ymin;
+ if (pcx.manufacturer != 0x0a || pcx.version != 5 || pcx.encoding != 1 || pcx.bits_per_pixel != 8 || pcxwidth > 4096 || pcxheight > 4096 || pcxwidth <= 0 || pcxheight <= 0)
+ return false;
+
+ enddata = f + filesize - 768;
+
+ for (y = 0;y < outheight && fin < enddata;y++)
+ {
+ a = pixels + y * outwidth;
+ // pad the output with blank lines if needed
+ if (y >= pcxheight)
+ {
+ memset(a, 0, outwidth);
+ continue;
+ }
+ for (x = 0;x < pcxwidth;)
+ {
+ if (fin >= enddata)
+ return false;
+ dataByte = *fin++;
+ if(dataByte >= 0xC0)
+ {
+ x2 = x + (dataByte & 0x3F);
+ if (fin >= enddata)
+ return false;
+ if (x2 > pcxwidth)
+ return false;
+ dataByte = *fin++;
+ for (;x < x2;x++)
+ if (x < outwidth)
+ a[x] = dataByte;
+ }
+ else
+ {
+ if (x < outwidth) // truncate to destination width
+ a[x] = dataByte;
+ x++;
+ }
+ }
+ while(x < outwidth)
+ a[x++] = 0;
+ }
+
+ return true;
+}
+
/*
=========================================================