Example #1
0
// adds menu support for TGA and JPG skins
static qboolean IsValidSkin (char **filelist, int numFiles, int index)
{
	int		len = strlen(filelist[index]);

	if (	!strcmp (filelist[index]+max(len-4,0), ".pcx")
		||  !strcmp (filelist[index]+max(len-4,0), ".tga")
#ifdef PNG_SUPPORT
		||  !strcmp (filelist[index]+max(len-4,0), ".png")
#endif // PNG_SUPPORT
		||	!strcmp (filelist[index]+max(len-4,0), ".jpg") )
	{
		if (	strcmp (filelist[index]+max(len-6,0), "_i.pcx")
			&&  strcmp (filelist[index]+max(len-6,0), "_i.tga")
#ifdef PNG_SUPPORT
			&&  strcmp (filelist[index]+max(len-6,0), "_i.png")
#endif // PNG_SUPPORT
			&&  strcmp (filelist[index]+max(len-6,0), "_i.jpg") )

			if (	IconOfSkinExists (filelist[index], filelist, numFiles-1 , "_i.pcx")
				||	IconOfSkinExists (filelist[index], filelist, numFiles-1 , "_i.tga")
#ifdef PNG_SUPPORT
				||	IconOfSkinExists (filelist[index], filelist, numFiles-1 , "_i.png")
#endif // PNG_SUPPORT
				||	IconOfSkinExists (filelist[index], filelist, numFiles-1 , "_i.jpg"))
				return true;
	}
	return false;
}
Example #2
0
void PlayerModel_Load(void)
{
    char scratch[MAX_QPATH];
    size_t len;
    int ndirs = 0;
    char *dirnames[MAX_PLAYERMODELS];
    int i, j;
    char **list;
    char *s, *p;
    int numFiles;
    playerModelInfo_t *pmi;

    uis.numPlayerModels = 0;

    // get a list of directories
    if (!(list = (char **)FS_ListFiles(NULL, "players/*/tris.md2", FS_SEARCH_BYFILTER | FS_SEARCH_SAVEPATH, &numFiles))) {
        return;
    }

    for (i = 0; i < numFiles; i++) {
        len = Q_strlcpy(scratch, list[i], sizeof(scratch));
        if (len >= sizeof(scratch))
            continue;

        // make short name for the model
        if (!(s = strchr(scratch, '/')))
            continue;
        s++;

        if (!(p = strchr(s, '/')))
            continue;
        *p = 0;

        for (j = 0; j < ndirs; j++) {
            if (!strcmp(dirnames[j], s)) {
                break;
            }
        }

        if (j != ndirs) {
            continue;
        }

        dirnames[ndirs++] = UI_CopyString(s);
        if (ndirs == MAX_PLAYERMODELS) {
            break;
        }
    }

    FS_FreeList((void **)list);

    if (!ndirs) {
        return;
    }

    // go through the subdirectories
    for (i = 0; i < ndirs; i++) {
        int k, s;
        char **pcxnames;
        char **skinnames;
        int npcxfiles;
        int nskins = 0;

        // verify the existence of tris.md2
        Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], "/tris.md2", NULL);
        if (!FS_FileExists(scratch)) {
            goto skip;
        }

        // verify the existence of at least one pcx skin
        Q_concat(scratch, sizeof(scratch), "players/", dirnames[i], NULL);
        pcxnames = (char **)FS_ListFiles(scratch, ".pcx", 0, &npcxfiles);
        if (!pcxnames) {
            goto skip;
        }

        // count valid skins, which consist of a skin with a matching "_i" icon
        for (k = 0; k < npcxfiles; k++) {
            if (!strstr(pcxnames[k], "_i.pcx")) {
                if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) {
                    nskins++;
                }
            }
        }

        if (!nskins) {
            FS_FreeList((void **)pcxnames);
            goto skip;
        }

        skinnames = UI_Malloc(sizeof(char *) * (nskins + 1));
        skinnames[nskins] = NULL;

        // copy the valid skins
        for (s = 0, k = 0; k < npcxfiles; k++) {
            if (!strstr(pcxnames[k], "_i.pcx")) {
                if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) {
                    COM_StripExtension(scratch, pcxnames[k], sizeof(scratch));
                    skinnames[s++] = UI_CopyString(scratch);
                }
            }
        }

        FS_FreeList((void **)pcxnames);

        // at this point we have a valid player model
        pmi = &uis.pmi[uis.numPlayerModels++];
        pmi->nskins = nskins;
        pmi->skindisplaynames = skinnames;
        pmi->directory = dirnames[i];
        continue;

skip:
        Z_Free(dirnames[i]);
    }

    qsort(uis.pmi, uis.numPlayerModels, sizeof(uis.pmi[0]), pmicmpfnc);
}