do some smol cleanup r_skins
mostly style fixes, some minor caching for some things
This commit is contained in:
1 parent
4fccb48d2a
commit
aeb172f2ab
1 file changed
+124
-104
+124
-104
@@ -33,7 +33,7 @@
|
||||
|
||||
#include "qs22j.h"
|
||||
|
||||
CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2];
|
||||
CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2]; // huehuehuehuehue
|
||||
|
||||
#include "discord.h"
|
||||
|
||||
@@ -41,6 +41,7 @@ INT32 numskins = 0;
|
||||
INT32 numallskins = 0;
|
||||
INT32 numlocalskins = 0;
|
||||
skin_t skins[MAXSKINS];
|
||||
|
||||
UINT8 skinstats[9][9][MAXSKINS];
|
||||
UINT8 skinstatscount[9][9] = {
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
@@ -53,6 +54,7 @@ UINT8 skinstatscount[9][9] = {
|
||||
{0, 1, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
UINT8 skinsorted[MAXSKINS];
|
||||
skin_t localskins[MAXLOCALSKINS];
|
||||
skin_t allskins[MAXSKINS+MAXLOCALSKINS];
|
||||
@@ -71,12 +73,13 @@ static void Sk_SetDefaultValue(skin_t *skin, boolean local)
|
||||
// set default skin values
|
||||
//
|
||||
memset(skin, 0, sizeof (skin_t));
|
||||
|
||||
snprintf(skin->name, sizeof skin->name, "skin %u", K_GetMobjSkinNum(skin, local));
|
||||
skin->name[sizeof skin->name - 1] = '\0';
|
||||
skin->wadnum = INT16_MAX;
|
||||
strcpy(skin->sprite, "");
|
||||
|
||||
skin->flags = 0;
|
||||
skin->wadnum = INT16_MAX;
|
||||
|
||||
strcpy(skin->sprite, "");
|
||||
|
||||
strcpy(skin->realname, "Someone");
|
||||
strcpy(skin->hudname, "???");
|
||||
@@ -95,8 +98,12 @@ static void Sk_SetDefaultValue(skin_t *skin, boolean local)
|
||||
skin->highresscale = FRACUNIT>>1;
|
||||
|
||||
for (i = 0; i < sfx_skinsoundslot0; i++)
|
||||
if (S_sfx[i].skinsound != -1)
|
||||
skin->soundsid[S_sfx[i].skinsound] = i;
|
||||
{
|
||||
const INT32 skinsound = S_sfx[i].skinsound;
|
||||
|
||||
if (skinsound != -1)
|
||||
skin->soundsid[skinsound] = i;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -124,6 +131,7 @@ void R_InitSkins(void)
|
||||
skin = &skins[0];
|
||||
numskins = 1;
|
||||
Sk_SetDefaultValue(skin, false);
|
||||
|
||||
memset(skinstats, 0, sizeof(skinstats));
|
||||
memset(skinsorted, 0, sizeof(skinsorted));
|
||||
|
||||
@@ -132,13 +140,16 @@ void R_InitSkins(void)
|
||||
#ifdef SKINVALUES
|
||||
skin_cons_t[0].strvalue = skins[0].name;
|
||||
#endif
|
||||
skin->flags = 0;
|
||||
|
||||
strcpy(skin->realname, "Sonic");
|
||||
strcpy(skin->hudname, "SONIC");
|
||||
|
||||
strncpy(skin->facerank, "PLAYRANK", 9);
|
||||
strncpy(skin->facewant, "PLAYWANT", 9);
|
||||
strncpy(skin->facemmap, "PLAYMMAP", 9);
|
||||
|
||||
skin->flags = 0;
|
||||
|
||||
skin->wadnum = 0; // god what have you brought to this world
|
||||
skin->prefcolor = SKINCOLOR_BLUE;
|
||||
skin->localskin = false;
|
||||
@@ -177,9 +188,10 @@ INT32 R_SkinAvailable(const char *name)
|
||||
|
||||
for (i = 0; i < numskins; i++)
|
||||
{
|
||||
if (stricmp(skins[i].name,name) == 0)
|
||||
if (stricmp(skins[i].name, name) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -191,9 +203,10 @@ INT32 R_AnySkinAvailable(const char *name)
|
||||
|
||||
for (i = 0; i < numallskins; i++)
|
||||
{
|
||||
if (stricmp(allskins[i].name,name) == 0)
|
||||
if (stricmp(allskins[i].name, name) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -205,20 +218,20 @@ INT32 R_LocalSkinAvailable(const char *name, boolean local)
|
||||
{
|
||||
for (i = 0; i < numlocalskins; i++)
|
||||
{
|
||||
if (stricmp(localskins[i].name,name) == 0)
|
||||
if (stricmp(localskins[i].name, name) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return R_SkinAvailable(name);
|
||||
|
||||
return R_SkinAvailable(name);
|
||||
}
|
||||
|
||||
// network code calls this when a 'skin change' is received
|
||||
boolean SetPlayerSkin(INT32 playernum, const char *skinname)
|
||||
{
|
||||
INT32 i;
|
||||
player_t *player = &players[playernum];
|
||||
|
||||
for (i = 0; i < numskins; i++)
|
||||
{
|
||||
@@ -230,7 +243,7 @@ boolean SetPlayerSkin(INT32 playernum, const char *skinname)
|
||||
}
|
||||
}
|
||||
|
||||
if (P_IsLocalPlayer(player))
|
||||
if (P_IsLocalPlayer(&players[playernum]))
|
||||
CONS_Alert(CONS_WARNING, M_GetText("Skin '%s' not found.\n"), skinname);
|
||||
else if (server || IsPlayerAdmin(consoleplayer))
|
||||
CONS_Alert(CONS_WARNING, M_GetText("Player %d (%s) skin '%s' not found\n"), playernum, player_names[playernum], skinname);
|
||||
@@ -253,6 +266,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar)
|
||||
{
|
||||
player->localskin = 1 + i;
|
||||
player->skinlocal = true;
|
||||
|
||||
if (player->mo)
|
||||
{
|
||||
player->mo->localskin = &localskins[i];
|
||||
@@ -270,6 +284,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar)
|
||||
{
|
||||
player->localskin = 1 + i;
|
||||
player->skinlocal = false;
|
||||
|
||||
if (player->mo)
|
||||
{
|
||||
player->mo->localskin = &skins[i];
|
||||
@@ -284,6 +299,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar)
|
||||
{
|
||||
player->localskin = 0;
|
||||
player->skinlocal = false;
|
||||
|
||||
if (player->mo)
|
||||
{
|
||||
player->mo->localskin = 0;
|
||||
@@ -318,6 +334,7 @@ void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum)
|
||||
if (skinnum >= 0 && skinnum < numskins) // Make sure it exists!
|
||||
{
|
||||
player->skin = skinnum;
|
||||
|
||||
if (player->mo)
|
||||
player->mo->skin = skin;
|
||||
|
||||
@@ -360,117 +377,97 @@ void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum)
|
||||
static UINT16 W_CheckForSkinMarkerInPwad(UINT16 wadid, UINT16 startlump)
|
||||
{
|
||||
UINT16 i;
|
||||
const char *S_SKIN = "S_SKIN";
|
||||
lumpinfo_t *lump_p;
|
||||
|
||||
// scan forward, start at <startlump>
|
||||
if (startlump < wadfiles[wadid]->numlumps)
|
||||
{
|
||||
lump_p = wadfiles[wadid]->lumpinfo + startlump;
|
||||
|
||||
for (i = startlump; i < wadfiles[wadid]->numlumps; i++, lump_p++)
|
||||
if (memcmp(lump_p->name,S_SKIN,6)==0)
|
||||
{
|
||||
if (memcmp(lump_p->name, "S_SKIN", 6) == 0)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return INT16_MAX; // not found
|
||||
}
|
||||
|
||||
//sort function for sorting skin names
|
||||
static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what the naming conventions for local functions are
|
||||
static int skinSortFunc(const void *a, const void *b) // tbh i have no clue what the naming conventions for local functions are
|
||||
{
|
||||
const skin_t *in1 = &skins[*(const UINT8 *)a];
|
||||
const skin_t *in2 = &skins[*(const UINT8 *)b];
|
||||
INT32 temp = 0;
|
||||
const UINT8 val_a = *((const UINT8 *)a);
|
||||
const UINT8 val_b = *((const UINT8 *)b);
|
||||
int diff = 0;
|
||||
const UINT8 val_a = *(const UINT8 *)a;
|
||||
const UINT8 val_b = *(const UINT8 *)b;
|
||||
const skin_t *in1 = &skins[val_a];
|
||||
const skin_t *in2 = &skins[val_b];
|
||||
|
||||
//return (strcmp(in1->realname, in2->realname) < 0) || (strcmp(in1->realname, in2->realname) ==);
|
||||
// return (strcmp(in1->realname, in2->realname) < 0) || (strcmp(in1->realname, in2->realname) ==);
|
||||
|
||||
switch (cv_skinselectgridsort.value)
|
||||
{
|
||||
case SKINMENUSORT_REALNAME:
|
||||
//CONS_Printf("Sorting by realname\n");
|
||||
// CONS_Printf("Sorting by realname\n");
|
||||
// check name
|
||||
if ((temp = strcmp(in1->realname, in2->realname)))
|
||||
return temp;
|
||||
// sort by internal name
|
||||
return strcmp(in1->name, in2->name);
|
||||
break;
|
||||
diff = strcmp(in1->realname, in2->realname);
|
||||
if (diff != 0) return diff;
|
||||
|
||||
case SKINMENUSORT_NAME:
|
||||
//CONS_Printf("Sorting by name\n");
|
||||
return strcmp(in1->name, in2->name);
|
||||
break;
|
||||
|
||||
case SKINMENUSORT_SPEED:
|
||||
//CONS_Printf("Sorting by speed\n");
|
||||
// CONS_Printf("Sorting by speed\n");
|
||||
// check speed
|
||||
if (in1->kartspeed < in2->kartspeed)
|
||||
return -1;
|
||||
else if (in2->kartspeed < in1->kartspeed)
|
||||
return 1;
|
||||
diff = in1->kartspeed - in2->kartspeed;
|
||||
if (diff != 0) return diff;
|
||||
|
||||
// then check weight
|
||||
if (in1->kartweight < in2->kartweight)
|
||||
return -1;
|
||||
else if (in2->kartweight < in1->kartweight)
|
||||
return 1;
|
||||
// then check name
|
||||
if ((temp = strcmp(in1->realname, in2->realname)))
|
||||
return temp;
|
||||
// sort by internal name
|
||||
return strcmp(in1->name, in2->name);
|
||||
break;
|
||||
diff = in1->kartweight - in2->kartweight;
|
||||
if (diff != 0) return diff;
|
||||
|
||||
// then check name
|
||||
diff = strcmp(in1->realname, in2->realname);
|
||||
if (diff != 0) return diff;
|
||||
|
||||
break;
|
||||
case SKINMENUSORT_WEIGHT:
|
||||
//CONS_Printf("Sorting by weight\n");
|
||||
// CONS_Printf("Sorting by weight\n");
|
||||
// check weight
|
||||
if (in1->kartweight < in2->kartweight)
|
||||
return -1;
|
||||
else if (in2->kartweight < in1->kartweight)
|
||||
return 1;
|
||||
diff = in1->kartweight - in2->kartweight;
|
||||
if (diff != 0) return diff;
|
||||
|
||||
// then check speed
|
||||
if (in1->kartspeed < in2->kartspeed)
|
||||
return -1;
|
||||
else if (in2->kartspeed < in1->kartspeed)
|
||||
return 1;
|
||||
// then check name
|
||||
if ((temp = strcmp(in1->realname, in2->realname)))
|
||||
return temp;
|
||||
// sort by internal name
|
||||
return strcmp(in1->name, in2->name);
|
||||
break;
|
||||
diff = in1->kartspeed - in2->kartspeed;
|
||||
if (diff != 0) return diff;
|
||||
|
||||
// then check name
|
||||
diff = strcmp(in1->realname, in2->realname);
|
||||
if (diff != 0) return diff;
|
||||
|
||||
break;
|
||||
case SKINMENUSORT_PREFCOLOR:
|
||||
//CONS_Printf("Sorting by prefcolor\n");
|
||||
// CONS_Printf("Sorting by prefcolor\n");
|
||||
// check prefcolor
|
||||
if (in1->prefcolor < in2->prefcolor)
|
||||
return -1;
|
||||
else if (in2->prefcolor < in1->prefcolor)
|
||||
return 1;
|
||||
diff = in1->prefcolor - in2->prefcolor;
|
||||
if (diff != 0) return diff;
|
||||
|
||||
// then check name
|
||||
if ((temp = strcmp(in1->realname, in2->realname)))
|
||||
return temp;
|
||||
// sort by internal name
|
||||
return strcmp(in1->name, in2->name);
|
||||
diff = strcmp(in1->realname, in2->realname);
|
||||
if (diff != 0) return diff;
|
||||
|
||||
break;
|
||||
|
||||
case SKINMENUSORT_ID:
|
||||
//CONS_Printf("Sorting by id\n");
|
||||
//how do i do by ID?????
|
||||
//wait why dont i just convert the inputs to UINT32s
|
||||
//please tell me im allowed to define variables in here since its a block
|
||||
|
||||
if (val_a == val_b)
|
||||
return 0;
|
||||
else if (val_a < val_b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
|
||||
// CONS_Printf("Sorting by id\n");
|
||||
// how do i do by ID?????
|
||||
// wait why dont i just convert the inputs to UINT32s
|
||||
// please tell me im allowed to define variables in here since its a block
|
||||
return (int)val_a - (int)val_b;
|
||||
case SKINMENUSORT_NAME:
|
||||
default:
|
||||
return strcmp(in1->name, in2->name);
|
||||
break;
|
||||
}
|
||||
//im scared this somehow will sometimes end up here so im gonna add this here just to be safe
|
||||
|
||||
// im scared this somehow will sometimes end up here so im gonna add this here just to be safe
|
||||
// now it will often end up here >:3
|
||||
return strcmp(in1->name, in2->name);
|
||||
}
|
||||
|
||||
@@ -531,6 +528,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
Sk_SetDefaultValue(skin, local);
|
||||
skin->wadnum = wadnum;
|
||||
hudname = realname = false;
|
||||
|
||||
// parse
|
||||
stoken = strtok (buf2, "\r\n= ");
|
||||
while (stoken)
|
||||
@@ -562,18 +560,18 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
// using the default skin name's number set above
|
||||
else
|
||||
{
|
||||
const size_t stringspace =
|
||||
strlen(value) + sizeof lnumskins + 1;
|
||||
const size_t stringspace = strlen(value) + sizeof lnumskins + 1;
|
||||
char *value2 = Z_Malloc(stringspace, PU_STATIC, NULL);
|
||||
snprintf(value2, stringspace,
|
||||
"%s%d", value, lnumskins);
|
||||
|
||||
snprintf(value2, stringspace, "%s%d", value, lnumskins);
|
||||
value2[stringspace - 1] = '\0';
|
||||
|
||||
if (R_LocalSkinAvailable(value2, local) == -1)
|
||||
{
|
||||
STRBUFCPY(skin->name,
|
||||
value2);
|
||||
STRBUFCPY(skin->name, value2);
|
||||
strlwr(skin->name);
|
||||
}
|
||||
|
||||
Z_Free(value2);
|
||||
}
|
||||
|
||||
@@ -589,6 +587,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
{
|
||||
STRBUFCPY(skin->hudname, skin->name);
|
||||
strupr(skin->hudname);
|
||||
|
||||
for (value = skin->hudname; *value; value++)
|
||||
if (*value == '_') *value = ' '; // turn _ into spaces.
|
||||
}
|
||||
@@ -597,8 +596,10 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
{ // Display name (eg. "Knuckles")
|
||||
realname = true;
|
||||
STRBUFCPY(skin->realname, value);
|
||||
|
||||
for (value = skin->realname; *value; value++)
|
||||
if (*value == '_') *value = ' '; // turn _ into spaces.
|
||||
|
||||
if (!hudname)
|
||||
STRBUFCPY(skin->hudname, skin->realname);
|
||||
}
|
||||
@@ -606,12 +607,13 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
{ // Life icon name (eg. "K.T.E")
|
||||
hudname = true;
|
||||
STRBUFCPY(skin->hudname, value);
|
||||
|
||||
for (value = skin->hudname; *value; value++)
|
||||
if (*value == '_') *value = ' '; // turn _ into spaces.
|
||||
|
||||
if (!realname)
|
||||
STRBUFCPY(skin->realname, skin->hudname);
|
||||
}
|
||||
|
||||
else if (!stricmp(stoken, "sprite"))
|
||||
{
|
||||
strupr(value);
|
||||
@@ -642,6 +644,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
else if (!stricmp(stoken, "kartspeed"))
|
||||
{
|
||||
skin->kartspeed = atoi(value);
|
||||
|
||||
if (skin->kartspeed < 1)
|
||||
skin->kartspeed = 1;
|
||||
if (skin->kartspeed > 9)
|
||||
@@ -650,6 +653,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
else if (!stricmp(stoken, "kartweight"))
|
||||
{
|
||||
skin->kartweight = atoi(value);
|
||||
|
||||
if (skin->kartweight < 1)
|
||||
skin->kartweight = 1;
|
||||
if (skin->kartweight > 9)
|
||||
@@ -657,47 +661,60 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
}
|
||||
// custom translation table
|
||||
else if (!stricmp(stoken, "startcolor"))
|
||||
{
|
||||
skin->starttranscolor = atoi(value);
|
||||
}
|
||||
else if (!stricmp(stoken, "prefcolor"))
|
||||
{
|
||||
skin->prefcolor = K_GetKartColorByName(value);
|
||||
}
|
||||
else if (!stricmp(stoken, "highresscale"))
|
||||
{
|
||||
skin->highresscale = FLOAT_TO_FIXED(atof(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
INT32 found = false;
|
||||
sfxenum_t i;
|
||||
|
||||
// copy name of sounds that are remapped
|
||||
// for this skin
|
||||
for (i = 0; i < sfx_skinsoundslot0; i++)
|
||||
{
|
||||
if (!S_sfx[i].name)
|
||||
const sfxinfo_t *sfx = &S_sfx[i];
|
||||
|
||||
if (!sfx->name)
|
||||
continue;
|
||||
if (S_sfx[i].skinsound != -1
|
||||
&& !stricmp(S_sfx[i].name,
|
||||
stoken + 2))
|
||||
|
||||
if (sfx->skinsound != -1
|
||||
&& !stricmp(sfx->name, stoken + 2))
|
||||
{
|
||||
skin->soundsid[S_sfx[i].skinsound] =
|
||||
S_AddSoundFx(value+2, S_sfx[i].singularity, S_sfx[i].pitch, true);
|
||||
skin->soundsid[sfx->skinsound] = S_AddSoundFx(value+2, sfx->singularity, sfx->pitch, true);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
CONS_Debug(DBG_SETUP, "R_AddSkins: Unknown keyword '%s' in S_SKIN lump# %d (WAD %s)\n", stoken, lump, wadfiles[wadnum]->filename);
|
||||
}
|
||||
|
||||
stoken = strtok(NULL, "\r\n= ");
|
||||
}
|
||||
|
||||
free(buf2);
|
||||
|
||||
lump++; // if no sprite defined use spirte just after this one
|
||||
|
||||
if (skin->sprite[0] == '\0')
|
||||
{
|
||||
const char *csprname = W_CheckNameForNumPwad(wadnum, lump);
|
||||
|
||||
// skip to end of this skin's frames
|
||||
lastlump = lump;
|
||||
|
||||
while (W_CheckNameForNumPwad(wadnum, lastlump) && memcmp(W_CheckNameForNumPwad(wadnum, lastlump), csprname,4)==0)
|
||||
lastlump++;
|
||||
|
||||
// allocate (or replace) sprite frames, and set spritedef
|
||||
R_AddSingleSpriteDef(csprname, &skin->spritedef, wadnum, lump, lastlump);
|
||||
}
|
||||
@@ -707,12 +724,15 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
size_t name;
|
||||
boolean found = false;
|
||||
const char *sprname = skin->sprite;
|
||||
for (name = 0;sprnames[name][0] != '\0';name++)
|
||||
|
||||
for (name = 0; sprnames[name][0] != '\0'; name++)
|
||||
{
|
||||
if (strncmp(sprnames[name], sprname, 4) == 0)
|
||||
{
|
||||
found = true;
|
||||
skin->spritedef = sprites[name];
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// not found so make a new one
|
||||
// go through the entire current wad looking for our sprite
|
||||
@@ -726,7 +746,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
while ((lname = W_CheckNameForNumPwad(wadnum, localllump)))
|
||||
{
|
||||
// If this is a valid sprite...
|
||||
if (!memcmp(lname, sprname,4) && lname[4] && lname[5] && lname[5] >= '0' && lname[5] <= '8')
|
||||
if (!memcmp(lname, sprname, 4) && lname[4] && lname[5] && lname[5] >= '0' && lname[5] <= '8')
|
||||
{
|
||||
if (lstart == UINT16_MAX)
|
||||
lstart = localllump;
|
||||
@@ -741,6 +761,7 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
}
|
||||
// If not already set do nothing
|
||||
}
|
||||
|
||||
++localllump;
|
||||
}
|
||||
|
||||
@@ -760,7 +781,6 @@ void R_AddSkins(UINT16 wadnum, boolean local)
|
||||
(local ? localskin_cons_t : skin_cons_t)[lnumskins].value = lnumskins;
|
||||
(local ? localskin_cons_t : skin_cons_t)[lnumskins].strvalue = skin->name;
|
||||
#endif
|
||||
|
||||
if (!local)
|
||||
{
|
||||
// Update the forceskin possiblevalues
|
||||
|
||||
Reference in new issue
Block a user