From 6b00b2948ffafe138cab65c0ca64ca736bcf15ee Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 6 Jun 2025 23:13:33 +0200 Subject: [PATCH] split skin stuff from r_things into r_skins what a mess --- src/Sourcefile | 1 + src/lua_baselib.c | 1 + src/lua_hooklib.c | 1 + src/lua_mobjlib.c | 1 + src/lua_playerlib.c | 1 + src/lua_skinlib.c | 3 +- src/m_menu.h | 1 + src/p_enemy.c | 1 + src/p_mobj.c | 1 + src/p_saveg.c | 1 + src/r_draw.h | 1 + src/r_patch.c | 1 + src/r_skins.c | 791 ++++++++++++++++++++++++++++++++++++++++++ src/r_skins.h | 152 ++++++++ src/r_things.c | 827 ++------------------------------------------ src/r_things.h | 140 +------- 16 files changed, 998 insertions(+), 926 deletions(-) create mode 100644 src/r_skins.c create mode 100644 src/r_skins.h diff --git a/src/Sourcefile b/src/Sourcefile index 4d117111d..1161ce994 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -54,6 +54,7 @@ r_patch.c r_patchrotation.c r_plane.c r_segs.c +r_skins.c r_sky.c r_splats.c r_things.c diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 88a5b6314..5b877e7ba 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -16,6 +16,7 @@ #include "p_slopes.h" // P_GetZAt #include "z_zone.h" #include "r_main.h" +#include "r_skins.h" #include "r_things.h" #include "m_random.h" #include "s_sound.h" diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 1ef02b886..54c39d560 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -14,6 +14,7 @@ #include "doomstat.h" #include "p_mobj.h" #include "g_game.h" +#include "r_skins.h" #include "r_things.h" #include "b_bot.h" #include "z_zone.h" diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index a0aff8484..4a297a654 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -15,6 +15,7 @@ #include "doomdef.h" #include "fastcmp.h" #include "r_things.h" +#include "r_skins.h" #include "r_main.h" #include "p_local.h" #include "g_game.h" diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 710b5d340..94c1f8fea 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -13,6 +13,7 @@ #include "doomdef.h" #include "fastcmp.h" #include "r_main.h" +#include "r_skins.h" #include "r_things.h" #include "p_mobj.h" #include "d_player.h" diff --git a/src/lua_skinlib.c b/src/lua_skinlib.c index 403ac834e..4425f125c 100644 --- a/src/lua_skinlib.c +++ b/src/lua_skinlib.c @@ -12,6 +12,7 @@ #include "doomdef.h" #include "fastcmp.h" +#include "r_skins.h" #include "r_things.h" #include "sounds.h" @@ -277,4 +278,4 @@ int LUA_SkinLib(lua_State *L) lua_setglobal(L, "skins"); return 0; -} \ No newline at end of file +} diff --git a/src/m_menu.h b/src/m_menu.h index 126d59e1b..d14d05cbe 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -15,6 +15,7 @@ #ifndef __X_MENU__ #define __X_MENU__ +#include "r_skins.h" #include "d_event.h" #include "command.h" #include "i_threads.h" diff --git a/src/p_enemy.c b/src/p_enemy.c index 042e0cec3..68d4c3430 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -16,6 +16,7 @@ #include "g_game.h" #include "p_local.h" #include "r_main.h" +#include "r_skins.h" #include "r_state.h" #include "s_sound.h" #include "m_random.h" diff --git a/src/p_mobj.c b/src/p_mobj.c index 59ad7f1d2..4a9641156 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -20,6 +20,7 @@ #include "p_setup.h" #include "r_fps.h" #include "r_main.h" +#include "r_skins.h" #include "r_things.h" #include "r_sky.h" #include "r_splats.h" diff --git a/src/p_saveg.c b/src/p_saveg.c index 6ca8fd90f..954a6e03f 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -24,6 +24,7 @@ #include "r_fps.h" #include "r_things.h" #include "r_state.h" +#include "r_skins.h" #include "w_wad.h" #include "y_inter.h" #include "z_zone.h" diff --git a/src/r_draw.h b/src/r_draw.h index 12ab3f584..a61ce33e3 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -20,6 +20,7 @@ extern "C" { #include "r_defs.h" #include "r_things.h" +#include "r_skins.h" // ------------------------------- // COMMON STUFF FOR 8bpp AND 16bpp diff --git a/src/r_patch.c b/src/r_patch.c index 21f59401c..f48996ea4 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -16,6 +16,7 @@ #include "doomdef.h" #include "r_patch.h" #include "r_things.h" +#include "r_skins.h" #include "z_zone.h" #include "w_wad.h" diff --git a/src/r_skins.c b/src/r_skins.c new file mode 100644 index 000000000..6bda9e263 --- /dev/null +++ b/src/r_skins.c @@ -0,0 +1,791 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Vivian "toastergrl" Grannell. +// Copyright (C) 2025 by Kart Krew. +// Copyright (C) 2020 by Sonic Team Junior. +// Copyright (C) 2000 by DooM Legacy Team. +// Copyright (C) 1996 by id Software, Inc. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_skins.c +/// \brief Loading skins + +#include "dehacked.h" // get_number (for thok) +#include "doomdef.h" +#include "console.h" +#include "r_draw.h" +#include "r_things.h" +#include "r_skins.h" +#include "g_game.h" +#include "k_kart.h" // SRB2kart +#include "p_local.h" +#include "st_stuff.h" +#include "i_video.h" // rendermode +#include "w_wad.h" +#include "z_zone.h" + +#ifdef HWRENDER +#include "hardware/hw_md2.h" +#endif + +#include "qs22j.h" + +CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2]; + +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}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {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]; + +// FIXTHIS: don't work because it must be inistilised before the config load +//#define SKINVALUES +#ifdef SKINVALUES +CV_PossibleValue_t skin_cons_t[MAXSKINS+1]; +CV_PossibleValue_t localskin_cons_t[MAXLOCALSKINS+1]; +#endif + +static void Sk_SetDefaultValue(skin_t *skin, boolean local) +{ + INT32 i; + // + // 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; + + strcpy(skin->realname, "Someone"); + strcpy(skin->hudname, "???"); + strncpy(skin->facerank, "PLAYRANK", 9); + strncpy(skin->facewant, "PLAYWANT", 9); + strncpy(skin->facemmap, "PLAYMMAP", 9); + + skin->starttranscolor = 160; + skin->prefcolor = SKINCOLOR_GREEN; + + // SRB2kart + skin->kartspeed = 5; + skin->kartweight = 5; + // + + skin->highresscale = FRACUNIT>>1; + + for (i = 0; i < sfx_skinsoundslot0; i++) + if (S_sfx[i].skinsound != -1) + skin->soundsid[S_sfx[i].skinsound] = i; +} + +// +// Initialize the basic skins +// +void R_InitSkins(void) +{ + skin_t *skin; +#ifdef SKINVALUES + INT32 i; + + for (i = 0; i <= MAXSKINS; i++) + { + skin_cons_t[i].value = 0; + skin_cons_t[i].strvalue = NULL; + } + for (i = 0; i <= MAXLOCALSKINS; i++) + { + localskin_cons_t[i].value = 0; + localskin_cons_t[i].strvalue = NULL; + } +#endif + + // skin[0] = Sonic skin + skin = &skins[0]; + numskins = 1; + Sk_SetDefaultValue(skin, false); + memset(skinstats, 0, sizeof(skinstats)); + memset(skinsorted, 0, sizeof(skinsorted)); + + // Hardcoded S_SKIN customizations for Sonic. + strcpy(skin->name, DEFAULTSKIN); +#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->wadnum = 0; // god what have you brought to this world + skin->prefcolor = SKINCOLOR_BLUE; + skin->localskin = false; + skin->localnum = 0; + + // SRB2kart + skin->kartspeed = 8; + skin->kartweight = 2; + // + + skin->spritedef.numframes = sprites[SPR_PLAY].numframes; + skin->spritedef.spriteframes = sprites[SPR_PLAY].spriteframes; + skin->sprinfo = spriteinfo[SPR_PLAY]; + ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, 0); + + // Set values for Sonic skin + Forceskin_cons_t[1].value = 0; + Forceskin_cons_t[1].strvalue = skin->name; + + //MD2 for sonic doesn't want to load in Linux. +#ifdef HWRENDER + if (rendermode == render_opengl) + HWR_AddPlayerMD2(0, false); +#endif + + // lets set it + allskins[0] = skins[0]; + numallskins = 1; +} + +// returns true if the skin name is found (loaded from pwad) +// warning return -1 if not found +INT32 R_SkinAvailable(const char *name) +{ + INT32 i; + + for (i = 0; i < numskins; i++) + { + if (stricmp(skins[i].name,name) == 0) + return i; + } + return -1; +} + +// returns true if the skin name is found (loaded from pwad) +// warning return -1 if not found +INT32 R_AnySkinAvailable(const char *name) +{ + INT32 i; + + for (i = 0; i < numallskins; i++) + { + if (stricmp(allskins[i].name,name) == 0) + return i; + } + return -1; +} + +INT32 R_LocalSkinAvailable(const char *name, boolean local) +{ + INT32 i; + + if (local) + { + for (i = 0; i < numlocalskins; i++) + { + if (stricmp(localskins[i].name,name) == 0) + return i; + } + return -1; + } + else + 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++) + { + // search in the skin list + if (stricmp(skins[i].name, skinname) == 0) + { + SetPlayerSkinByNum(playernum, i); + return true; + } + } + + if (P_IsLocalPlayer(player)) + 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); + + SetPlayerSkinByNum(playernum, 0); + return false; +} + +void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) +{ + INT32 i; + player_t *player = &players[playernum]; + + if (stricmp(skinname, "none")) + { + for (i = 0; i < numlocalskins; i++) + { + // search in the localskin list + if (stricmp(localskins[i].name, skinname) == 0) + { + player->localskin = 1 + i; + player->skinlocal = true; + if (player->mo) + { + player->mo->localskin = &localskins[i]; + player->mo->skinlocal = true; + } + + goto setcvar; + } + } + + for (i = 0; i < numskins; i++) + { + // search in the skin list + if (stricmp(skins[i].name, skinname) == 0) + { + player->localskin = 1 + i; + player->skinlocal = false; + if (player->mo) + { + player->mo->localskin = &skins[i]; + player->mo->skinlocal = false; + } + + goto setcvar; + } + } + } + else + { + player->localskin = 0; + player->skinlocal = false; + if (player->mo) + { + player->mo->localskin = 0; + player->mo->skinlocal = false; + } + } + +setcvar: + if (cvar != NULL) + { + if (player->localskin > 0) + { + CV_StealthSet(&cv_fakelocalskin, K_GetSkinArray(player->skinlocal)[player->localskin-1].name); + CV_StealthSet(cvar, K_GetSkinArray(player->skinlocal)[player->localskin-1].name); + + } + else + { + CV_StealthSet(&cv_fakelocalskin, "none"); + CV_StealthSet(cvar, "none"); + } + } +} + +// Same as SetPlayerSkin, but uses the skin #. +// network code calls this when a 'skin change' is received +void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum) +{ + player_t *player = &players[playernum]; + skin_t *skin = &skins[skinnum]; + + if (skinnum >= 0 && skinnum < numskins) // Make sure it exists! + { + player->skin = skinnum; + if (player->mo) + player->mo->skin = skin; + + player->charflags = (UINT32)skin->flags; + + // SRB2kart + player->kartspeed = skin->kartspeed; + player->kartweight = skin->kartweight; + + if (player->mo) + P_SetScale(player->mo, player->mo->scale); + + demo_extradata[playernum] |= DXD_SKIN; + + return; + } + + if (P_IsLocalPlayer(player)) + CONS_Alert(CONS_WARNING, M_GetText("Skin %d not found\n"), skinnum); + else if(server || IsPlayerAdmin(consoleplayer)) + CONS_Alert(CONS_WARNING, "Player %d (%s) skin %d not found\n", playernum, player_names[playernum], skinnum); + + SetPlayerSkinByNum(playernum, 0); // not found put the sonic skin +} + +// +// Add skins from a pwad, each skin preceded by 'S_SKIN' marker +// + +// Does the same is in w_wad, but check only for +// the first 6 characters (this is so we can have S_SKIN1, S_SKIN2.. +// for wad editors that don't like multiple resources of the same name) +// +static UINT16 W_CheckForSkinMarkerInPwad(UINT16 wadid, UINT16 startlump) +{ + UINT16 i; + const char *S_SKIN = "S_SKIN"; + lumpinfo_t *lump_p; + + // scan forward, start at + 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) + 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 +{ + 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); + + //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"); + // check name + if ((temp = strcmp(in1->realname, in2->realname))) + return temp; + // sort by internal name + return strcmp(in1->name, in2->name); + break; + + 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"); + // check speed + if (in1->kartspeed < in2->kartspeed) + return -1; + else if (in2->kartspeed < in1->kartspeed) + return 1; + // 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; + + case SKINMENUSORT_WEIGHT: + //CONS_Printf("Sorting by weight\n"); + // check weight + if (in1->kartweight < in2->kartweight) + return -1; + else if (in2->kartweight < in1->kartweight) + return 1; + // 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; + + case SKINMENUSORT_PREFCOLOR: + //CONS_Printf("Sorting by prefcolor\n"); + // check prefcolor + if (in1->prefcolor < in2->prefcolor) + return -1; + else if (in2->prefcolor < in1->prefcolor) + 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; + + 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; + + 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 + return strcmp(in1->name, in2->name); +} + +void sortSkinGrid(void) +{ + //CONS_Printf("Sorting skin list (%d)...\n", cv_skinselectgridsort.value); + qs22j(skinsorted, numskins, sizeof(UINT8), skinSortFunc); +} + +// +// Find skin sprites, sounds & optional status bar face, & add them +// +void R_AddSkins(UINT16 wadnum, boolean local) +{ + UINT16 lump, lastlump = 0; + char *buf; + char *buf2; + char *stoken; + char *value; + size_t size; + skin_t *skin; + boolean hudname, realname; + +#define lnumskins (local ? numlocalskins : numskins) + + // + // search for all skin markers in pwad + // + + while ((lump = W_CheckForSkinMarkerInPwad(wadnum, lastlump)) != INT16_MAX) + { + // advance by default + lastlump = lump + 1; + + if (!local && numskins >= MAXSKINS) + { + CONS_Alert(CONS_WARNING, M_GetText("Unable to add skin, too many characters are loaded (%d maximum)\n"), MAXSKINS); + continue; // so we know how many skins couldn't be added + } + if (local && numlocalskins >= MAXLOCALSKINS) + { + CONS_Alert(CONS_WARNING, M_GetText("Unable to add localskin, too many localskins are loaded (%d maximum)\n"), MAXLOCALSKINS); + continue; // so we know how many skins couldn't be added + } + + buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); + size = W_LumpLengthPwad(wadnum, lump); + + // for strtok + buf2 = malloc(size+1); + if (!buf2) + I_Error("R_AddSkins: No more free memory\n"); + M_Memcpy(buf2,buf,size); + buf2[size] = '\0'; + + // set defaults + skin = &K_GetSkinArray(local)[lnumskins]; + Sk_SetDefaultValue(skin, local); + skin->wadnum = wadnum; + hudname = realname = false; + // parse + stoken = strtok (buf2, "\r\n= "); + while (stoken) + { + if ((stoken[0] == '/' && stoken[1] == '/') + || (stoken[0] == '#'))// skip comments + { + stoken = strtok(NULL, "\r\n"); // skip end of line + goto next_token; // find the real next token + } + + value = strtok(NULL, "\r\n= "); + + if (!value) + I_Error("R_AddSkins: syntax error in S_SKIN lump# %d(%s) in WAD %s\n", lump, W_CheckNameForNumPwad(wadnum,lump), wadfiles[wadnum]->filename); + + if (!stricmp(stoken, "name")) + { + // the skin name must uniquely identify a single skin + // I'm lazy so if name is already used I leave the 'skin x' + // default skin name set in Sk_SetDefaultValue + if (R_LocalSkinAvailable(value, local) == -1) + { + STRBUFCPY(skin->name, value); + strlwr(skin->name); + } + // I'm not lazy, so if the name is already used I make the name 'namex' + // using the default skin name's number set above + else + { + const size_t stringspace = + strlen(value) + sizeof lnumskins + 1; + char *value2 = Z_Malloc(stringspace, PU_STATIC, NULL); + snprintf(value2, stringspace, + "%s%d", value, lnumskins); + value2[stringspace - 1] = '\0'; + if (R_LocalSkinAvailable(value2, local) == -1) + { + STRBUFCPY(skin->name, + value2); + strlwr(skin->name); + } + Z_Free(value2); + } + + // copy to hudname and fullname as a default. + if (!realname) + { + STRBUFCPY(skin->realname, skin->name); + for (value = skin->realname; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + } + if (!hudname) + { + STRBUFCPY(skin->hudname, skin->name); + strupr(skin->hudname); + for (value = skin->hudname; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + } + } + else if (!stricmp(stoken, "realname")) + { // 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); + } + else if (!stricmp(stoken, "hudname")) + { // 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); + memcpy(skin->sprite, value, sizeof skin->sprite); + } + else if (!stricmp(stoken, "facerank")) + { + strupr(value); + memcpy(skin->facerank, value, sizeof(skin->facerank)-1); + skin->facerank[sizeof(skin->facerank)-1] = '\0'; + } + else if (!stricmp(stoken, "facewant")) + { + strupr(value); + memcpy(skin->facewant, value, sizeof(skin->facewant)-1); + skin->facewant[sizeof(skin->facewant)-1] = '\0'; + } + else if (!stricmp(stoken, "facemmap")) + { + strupr(value); + strncpy(skin->facemmap, value, sizeof(skin->facemmap)-1); + skin->facemmap[sizeof(skin->facemmap)-1] = '\0'; + } + +#define FULLPROCESS(field) else if (!stricmp(stoken, #field)) skin->field = get_number(value); + // character type identification + FULLPROCESS(flags) +#undef FULLPROCESS + +#define GETKARTSTAT(field) \ + else if (!stricmp(stoken, #field)) \ + { \ + skin->field = atoi(value); \ + if (skin->field < 1) skin->field = 1; \ + if (skin->field > 9) skin->field = 9; \ + } + GETKARTSTAT(kartspeed) + GETKARTSTAT(kartweight) +#undef GETKARTSTAT + + // 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) + continue; + if (S_sfx[i].skinsound != -1 + && !stricmp(S_sfx[i].name, + stoken + 2)) + { + skin->soundsid[S_sfx[i].skinsound] = + S_AddSoundFx(value+2, S_sfx[i].singularity, S_sfx[i].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); + } +next_token: + 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); + } + else + { + // search in the normal sprite tables + size_t name; + boolean found = false; + const char *sprname = skin->sprite; + for (name = 0;sprnames[name][0] != '\0';name++) + if (strncmp(sprnames[name], sprname, 4) == 0) + { + found = true; + skin->spritedef = sprites[name]; + } + + // not found so make a new one + // go through the entire current wad looking for our sprite + // don't just mass add anything beginning with our four letters. + // "HOODFACE" is not a sprite name. + if (!found) + { + UINT16 localllump = 0, lstart = UINT16_MAX, lend = UINT16_MAX; + const char *lname; + + 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 (lstart == UINT16_MAX) + lstart = localllump; + // If already set do nothing + } + else + { + if (lstart != UINT16_MAX) + { + lend = localllump; + break; + } + // If not already set do nothing + } + ++localllump; + } + + R_AddSingleSpriteDef(sprname, &skin->spritedef, wadnum, lstart, lend); + } + + // I don't particularly care about skipping to the end of the used frames. + // We could be using frames from ANYWHERE in the current WAD file, including + // right before us, which is a terrible idea. + // So just let the function in the while loop take care of it for us. + } + + R_FlushTranslationColormapCache(); + + CONS_Printf(M_GetText("Added skin '%s'\n"), skin->name); +#ifdef SKINVALUES + (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 + Forceskin_cons_t[numskins+1].value = numskins; + Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name; + skin->localskin = false; + skin->localnum = numskins; + ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numskins); + } + else + { + skin->localskin = true; + skin->localnum = numlocalskins; + ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numlocalskins); + } + +#ifdef HWRENDER + if (rendermode == render_opengl) + HWR_AddPlayerMD2(lnumskins, local); +#endif + if (!local) + { + skinstats[skin->kartspeed-1][skin->kartweight-1][skinstatscount[skin->kartspeed-1][skin->kartweight-1]] = numskins; + CONS_Debug(DBG_SETUP, M_GetText("Added %d to %d, %d\n"), numskins, skin->kartweight, skin->kartweight); + skinstatscount[skin->kartspeed-1][skin->kartweight-1]++; + CONS_Debug(DBG_SETUP, M_GetText("Incremented %d, %d to %d\n"), skin->kartspeed, skin->kartweight, skinstatscount[skin->kartspeed - 1][skin->kartweight - 1]); + skinsorted[numskins] = numskins; + } + + allskins[numallskins] = K_GetSkinArray(local)[lnumskins]; + + local ? numlocalskins++ : numskins++; + numallskins++; + } + +#undef lnumskins + //sortSkinGrid(); + + return; +} diff --git a/src/r_skins.h b/src/r_skins.h new file mode 100644 index 000000000..cada396f4 --- /dev/null +++ b/src/r_skins.h @@ -0,0 +1,152 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Vivian "toastergrl" Grannell. +// Copyright (C) 2025 by Kart Krew. +// Copyright (C) 2020 by Sonic Team Junior. +// Copyright (C) 2000 by DooM Legacy Team. +// Copyright (C) 1996 by id Software, Inc. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_skins.h +/// \brief Skins stuff + +#ifndef __R_SKINS__ +#define __R_SKINS__ +#ifdef __cplusplus +extern "C" { +#endif + +#include "d_player.h" +#include "sounds.h" +#include "r_patch.h" + +// "Left" and "Right" character symbols for additional rotation functionality +#define ROT_L ('L' - '0') +#define ROT_R ('R' - '0') + +#define SKINNAMESIZE 16 +// should be all lowercase!! S_SKIN processing does a strlwr +#define DEFAULTSKIN "sonic" +#define DEFAULTSKIN2 "tails" // secondary player +#define DEFAULTSKIN3 "knuckles" // third player +#define DEFAULTSKIN4 "eggman" // fourth player + +typedef struct +{ + char name[SKINNAMESIZE+1]; // INT16 descriptive name of the skin + spritedef_t spritedef; + spriteinfo_t sprinfo; + UINT16 wadnum; + char sprite[4]; // Sprite name, if seperated from S_SKIN. + skinflags_t flags; + + char realname[SKINNAMESIZE+1]; // Display name for level completion. + char hudname[SKINNAMESIZE+1]; // HUD name to display (officially exactly 5 characters long) + char facerank[9], facewant[9], facemmap[9]; // Arbitrarily named patch lumps + + // SRB2kart + UINT8 kartspeed; + UINT8 kartweight; + // + + // Definable color translation table + UINT8 starttranscolor; + UINT8 prefcolor; + fixed_t highresscale; // scale of highres, default is 0.5 + + // specific sounds per skin + sfxenum_t soundsid[NUMSKINSOUNDS]; // sound # in S_sfx table + + boolean localskin; + INT32 localnum; +} skin_t; + +extern CV_PossibleValue_t Forceskin_cons_t[]; + +extern INT32 numskins; +extern INT32 numlocalskins; +extern INT32 numallskins; +extern skin_t skins[MAXSKINS]; +extern UINT8 skinstats[9][9][MAXSKINS]; +extern UINT8 skinstatscount[9][9]; +extern UINT8 skinsorted[MAXSKINS]; + +extern skin_t localskins[MAXLOCALSKINS]; +extern skin_t allskins[MAXSKINS+MAXLOCALSKINS]; + +//faB: find sprites in wadfile, replace existing, add new ones +// (only sprites from namelist are added or replaced) +void R_AddSpriteDefs(UINT16 wadnum); + +void R_InitSkins(void); +void R_AddSkins(UINT16 wadnum, boolean local); + +INT32 R_SkinAvailable(const char *name); +INT32 R_AnySkinAvailable(const char *name); +INT32 R_LocalSkinAvailable(const char *name, boolean local); + +// had to move those here Zzz... +INT32 K_GetSkinNum(player_t *player); +INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local); +skin_t *K_GetPlayerSkin(player_t *player); +skin_t *K_GetMobjSkin(const mobj_t *mobj); +patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); +skin_t *K_GetSkinArray(boolean local); + +void sortSkinGrid(void); + +boolean SetPlayerSkin(INT32 playernum,const char *skinname); +void SetPlayerSkinByNum(INT32 playernum,INT32 skinnum); // Tails 03-16-2002 +void SetLocalPlayerSkin(INT32 playernum,const char *skinname, consvar_t *cvar); + +char *GetPlayerFacePic(INT32 skinnum); + +// Functions to go from sprite character ID to frame number +// for 2.1 compatibility this still uses the old 'A' + frame code +// The use of symbols tends to be painful for wad editors though +// So the future version of this tries to avoid using symbols +// as much as possible while also defining all 64 slots in a sane manner +// 2.1: [[ ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ]] +// Future: [[ ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@ ]] +FUNCMATH FUNCINLINE static ATTRINLINE char R_Frame2Char(UINT8 frame) +{ +#if 1 // 2.1 compat + return 'A' + frame; +#else + if (frame < 26) return 'A' + frame; + if (frame < 36) return '0' + (frame - 26); + if (frame < 62) return 'a' + (frame - 36); + if (frame == 62) return '!'; + if (frame == 63) return '@'; + return '\xFF'; +#endif +} + +FUNCMATH FUNCINLINE static ATTRINLINE UINT8 R_Char2Frame(char cn) +{ +#if 1 // 2.1 compat + if (cn == '+') return '\\' - 'A'; // PK3 can't use backslash, so use + instead + return cn - 'A'; +#else + if (cn >= 'A' && cn <= 'Z') return cn - 'A'; + if (cn >= '0' && cn <= '9') return (cn - '0') + 26; + if (cn >= 'a' && cn <= 'z') return (cn - 'a') + 36; + if (cn == '!') return 62; + if (cn == '@') return 63; + return 255; +#endif +} + +FUNCMATH FUNCINLINE static ATTRINLINE boolean R_ValidSpriteAngle(UINT8 rotation) +{ + return ((rotation <= 8) || (rotation == ROT_L) || (rotation == ROT_R)); +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif //__R_SKINS__ diff --git a/src/r_things.c b/src/r_things.c index b1de37364..601bfa012 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1,4 +1,4 @@ -// SONIC ROBO BLAST 2 +// SONIC ROBO BLAST 2 KART //----------------------------------------------------------------------------- // Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1998-2000 by DooM Legacy Team. @@ -17,20 +17,15 @@ #include "r_plane.h" #include "r_portal.h" #include "r_local.h" - -#include "dehacked.h" // get_number (for thok) #include "doomdef.h" #include "d_netfil.h" // blargh. for nameonly(). #include "console.h" #include "g_game.h" -#include "k_kart.h" // SRB2kart #include "p_tick.h" #include "p_local.h" #include "p_setup.h" #include "p_slopes.h" #include "st_stuff.h" -#include "m_cheat.h" // objectplace -#include "m_misc.h" #include "i_video.h" // rendermode #include "w_wad.h" #include "z_zone.h" @@ -43,12 +38,6 @@ #include "r_patchrotation.h" #endif -#include "qs22j.h" - -CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2]; - -static void R_InitSkins(void); - #define MINZ (FRACUNIT*16) #define BASEYCENTER (BASEVIDHEIGHT/2) @@ -72,20 +61,10 @@ static lighttable_t **spritelights; INT16 *negonearray; INT16 *screenheightarray; -spriteinfo_t spriteinfo[NUMSPRITES]; - // // INITIALIZATION FUNCTIONS // -// variables used to look up and range check thing_t sprites patches -spritedef_t *sprites; -size_t numsprites; - -static spriteframe_t sprtemp[64]; -static size_t maxframe; -static const char *spritename; - // // Clipping against drawsegs optimization, from prboom-plus // @@ -120,6 +99,37 @@ INT32 R_ThingLightLevel(mobj_t* thing) return lightlevel; } +// +// Sprite rotation 0 is facing the viewer, +// rotation 1 is one angle turn CLOCKWISE around the axis. +// This is not the same as the angle, +// which increases counter clockwise (protractor). +// There was a lot of stuff grabbed wrong, so I changed it... +// + +spriteinfo_t spriteinfo[NUMSPRITES]; + +// +// INITIALIZATION FUNCTIONS +// + +// variables used to look up and range check thing_t sprites patches +spritedef_t *sprites; +size_t numsprites; + +static spriteframe_t sprtemp[64]; +static size_t maxframe; +static const char *spritename; + +// +// GAME FUNCTIONS +// +UINT32 visspritecount, numvisiblesprites; + +static UINT32 clippedvissprites; +static vissprite_t *visspritechunks[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {NULL}; + + // ========================================================================== // // Sprite loading routines: support sprites in pwad, dehacked sprite renaming, @@ -252,7 +262,7 @@ static void R_InstallSpriteLump(UINT16 wad, // graphics patch // // Returns true if the sprite was succesfully added // -static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 wadnum, UINT16 startlump, UINT16 endlump) +boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 wadnum, UINT16 startlump, UINT16 endlump) { UINT16 l; UINT8 frame; @@ -476,16 +486,6 @@ void R_AddSpriteDefs(UINT16 wadnum) CONS_Printf(M_GetText("%s added %d frames in %s sprites\n"), wadname, end-start, sizeu1(addsprites)); } - -// -// GAME FUNCTIONS -// -UINT32 visspritecount, numvisiblesprites; - -static UINT32 clippedvissprites; -static vissprite_t *visspritechunks[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {NULL}; - - // // R_InitSprites // Called at program start. @@ -3019,764 +3019,3 @@ void R_DrawMasked(maskcount_t* masks, UINT8 nummasks) R_ClearDrawNodes(&heads[nummasks - 1]); } } - -// ========================================================================== -// -// SKINS CODE -// -// ========================================================================== - -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}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {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]; - -// FIXTHIS: don't work because it must be inistilised before the config load -//#define SKINVALUES -#ifdef SKINVALUES -CV_PossibleValue_t skin_cons_t[MAXSKINS+1]; -CV_PossibleValue_t localskin_cons_t[MAXLOCALSKINS+1]; -#endif - -static void Sk_SetDefaultValue(skin_t *skin, boolean local) -{ - INT32 i; - // - // 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; - - strcpy(skin->realname, "Someone"); - strcpy(skin->hudname, "???"); - strncpy(skin->facerank, "PLAYRANK", 9); - strncpy(skin->facewant, "PLAYWANT", 9); - strncpy(skin->facemmap, "PLAYMMAP", 9); - - skin->starttranscolor = 160; - skin->prefcolor = SKINCOLOR_GREEN; - - // SRB2kart - skin->kartspeed = 5; - skin->kartweight = 5; - // - - skin->highresscale = FRACUNIT>>1; - - for (i = 0; i < sfx_skinsoundslot0; i++) - if (S_sfx[i].skinsound != -1) - skin->soundsid[S_sfx[i].skinsound] = i; -} - -// -// Initialize the basic skins -// -void R_InitSkins(void) -{ - skin_t *skin; -#ifdef SKINVALUES - INT32 i; - - for (i = 0; i <= MAXSKINS; i++) - { - skin_cons_t[i].value = 0; - skin_cons_t[i].strvalue = NULL; - } - for (i = 0; i <= MAXLOCALSKINS; i++) - { - localskin_cons_t[i].value = 0; - localskin_cons_t[i].strvalue = NULL; - } -#endif - - // skin[0] = Sonic skin - skin = &skins[0]; - numskins = 1; - Sk_SetDefaultValue(skin, false); - memset(skinstats, 0, sizeof(skinstats)); - memset(skinsorted, 0, sizeof(skinsorted)); - - // Hardcoded S_SKIN customizations for Sonic. - strcpy(skin->name, DEFAULTSKIN); -#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->wadnum = 0; // god what have you brought to this world - skin->prefcolor = SKINCOLOR_BLUE; - skin->localskin = false; - skin->localnum = 0; - - // SRB2kart - skin->kartspeed = 8; - skin->kartweight = 2; - // - - skin->spritedef.numframes = sprites[SPR_PLAY].numframes; - skin->spritedef.spriteframes = sprites[SPR_PLAY].spriteframes; - skin->sprinfo = spriteinfo[SPR_PLAY]; - ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, 0); - - // Set values for Sonic skin - Forceskin_cons_t[1].value = 0; - Forceskin_cons_t[1].strvalue = skin->name; - - //MD2 for sonic doesn't want to load in Linux. -#ifdef HWRENDER - if (rendermode == render_opengl) - HWR_AddPlayerMD2(0, false); -#endif - - // lets set it - allskins[0] = skins[0]; - numallskins = 1; -} - -// returns true if the skin name is found (loaded from pwad) -// warning return -1 if not found -INT32 R_SkinAvailable(const char *name) -{ - INT32 i; - - for (i = 0; i < numskins; i++) - { - if (stricmp(skins[i].name,name) == 0) - return i; - } - return -1; -} - -// returns true if the skin name is found (loaded from pwad) -// warning return -1 if not found -INT32 R_AnySkinAvailable(const char *name) -{ - INT32 i; - - for (i = 0; i < numallskins; i++) - { - if (stricmp(allskins[i].name,name) == 0) - return i; - } - return -1; -} - -INT32 R_LocalSkinAvailable(const char *name, boolean local) -{ - INT32 i; - - if (local) - { - for (i = 0; i < numlocalskins; i++) - { - if (stricmp(localskins[i].name,name) == 0) - return i; - } - return -1; - } - else - 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++) - { - // search in the skin list - if (stricmp(skins[i].name, skinname) == 0) - { - SetPlayerSkinByNum(playernum, i); - return true; - } - } - - if (P_IsLocalPlayer(player)) - 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); - - SetPlayerSkinByNum(playernum, 0); - return false; -} - -void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) -{ - INT32 i; - player_t *player = &players[playernum]; - - if (stricmp(skinname, "none")) - { - for (i = 0; i < numlocalskins; i++) - { - // search in the localskin list - if (stricmp(localskins[i].name, skinname) == 0) - { - player->localskin = 1 + i; - player->skinlocal = true; - if (player->mo) - { - player->mo->localskin = &localskins[i]; - player->mo->skinlocal = true; - } - - goto setcvar; - } - } - - for (i = 0; i < numskins; i++) - { - // search in the skin list - if (stricmp(skins[i].name, skinname) == 0) - { - player->localskin = 1 + i; - player->skinlocal = false; - if (player->mo) - { - player->mo->localskin = &skins[i]; - player->mo->skinlocal = false; - } - - goto setcvar; - } - } - } - else - { - player->localskin = 0; - player->skinlocal = false; - if (player->mo) - { - player->mo->localskin = 0; - player->mo->skinlocal = false; - } - } - -setcvar: - if (cvar != NULL) - { - if (player->localskin > 0) - { - CV_StealthSet(&cv_fakelocalskin, K_GetSkinArray(player->skinlocal)[player->localskin-1].name); - CV_StealthSet(cvar, K_GetSkinArray(player->skinlocal)[player->localskin-1].name); - - } - else - { - CV_StealthSet(&cv_fakelocalskin, "none"); - CV_StealthSet(cvar, "none"); - } - } -} - -// Same as SetPlayerSkin, but uses the skin #. -// network code calls this when a 'skin change' is received -void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum) -{ - player_t *player = &players[playernum]; - skin_t *skin = &skins[skinnum]; - - if (skinnum >= 0 && skinnum < numskins) // Make sure it exists! - { - player->skin = skinnum; - if (player->mo) - player->mo->skin = skin; - - player->charflags = (UINT32)skin->flags; - - // SRB2kart - player->kartspeed = skin->kartspeed; - player->kartweight = skin->kartweight; - - if (player->mo) - P_SetScale(player->mo, player->mo->scale); - - demo_extradata[playernum] |= DXD_SKIN; - - return; - } - - if (P_IsLocalPlayer(player)) - CONS_Alert(CONS_WARNING, M_GetText("Skin %d not found\n"), skinnum); - else if(server || IsPlayerAdmin(consoleplayer)) - CONS_Alert(CONS_WARNING, "Player %d (%s) skin %d not found\n", playernum, player_names[playernum], skinnum); - - SetPlayerSkinByNum(playernum, 0); // not found put the sonic skin -} - -// -// Add skins from a pwad, each skin preceded by 'S_SKIN' marker -// - -// Does the same is in w_wad, but check only for -// the first 6 characters (this is so we can have S_SKIN1, S_SKIN2.. -// for wad editors that don't like multiple resources of the same name) -// -static UINT16 W_CheckForSkinMarkerInPwad(UINT16 wadid, UINT16 startlump) -{ - UINT16 i; - const char *S_SKIN = "S_SKIN"; - lumpinfo_t *lump_p; - - // scan forward, start at - 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) - 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 -{ - 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); - - //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"); - // check name - if ((temp = strcmp(in1->realname, in2->realname))) - return temp; - // sort by internal name - return strcmp(in1->name, in2->name); - break; - - 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"); - // check speed - if (in1->kartspeed < in2->kartspeed) - return -1; - else if (in2->kartspeed < in1->kartspeed) - return 1; - // 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; - - case SKINMENUSORT_WEIGHT: - //CONS_Printf("Sorting by weight\n"); - // check weight - if (in1->kartweight < in2->kartweight) - return -1; - else if (in2->kartweight < in1->kartweight) - return 1; - // 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; - - case SKINMENUSORT_PREFCOLOR: - //CONS_Printf("Sorting by prefcolor\n"); - // check prefcolor - if (in1->prefcolor < in2->prefcolor) - return -1; - else if (in2->prefcolor < in1->prefcolor) - 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; - - 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; - - 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 - return strcmp(in1->name, in2->name); -} - -void sortSkinGrid(void) -{ - //CONS_Printf("Sorting skin list (%d)...\n", cv_skinselectgridsort.value); - qs22j(skinsorted, numskins, sizeof(UINT8), skinSortFunc); -} - -// -// Find skin sprites, sounds & optional status bar face, & add them -// -void R_AddSkins(UINT16 wadnum, boolean local) -{ - UINT16 lump, lastlump = 0; - char *buf; - char *buf2; - char *stoken; - char *value; - size_t size; - skin_t *skin; - boolean hudname, realname; - -#define lnumskins (local ? numlocalskins : numskins) - - // - // search for all skin markers in pwad - // - - while ((lump = W_CheckForSkinMarkerInPwad(wadnum, lastlump)) != INT16_MAX) - { - // advance by default - lastlump = lump + 1; - - if (!local && numskins >= MAXSKINS) - { - CONS_Alert(CONS_WARNING, M_GetText("Unable to add skin, too many characters are loaded (%d maximum)\n"), MAXSKINS); - continue; // so we know how many skins couldn't be added - } - if (local && numlocalskins >= MAXLOCALSKINS) - { - CONS_Alert(CONS_WARNING, M_GetText("Unable to add localskin, too many localskins are loaded (%d maximum)\n"), MAXLOCALSKINS); - continue; // so we know how many skins couldn't be added - } - - buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); - size = W_LumpLengthPwad(wadnum, lump); - - // for strtok - buf2 = malloc(size+1); - if (!buf2) - I_Error("R_AddSkins: No more free memory\n"); - M_Memcpy(buf2,buf,size); - buf2[size] = '\0'; - - // set defaults - skin = &K_GetSkinArray(local)[lnumskins]; - Sk_SetDefaultValue(skin, local); - skin->wadnum = wadnum; - hudname = realname = false; - // parse - stoken = strtok (buf2, "\r\n= "); - while (stoken) - { - if ((stoken[0] == '/' && stoken[1] == '/') - || (stoken[0] == '#'))// skip comments - { - stoken = strtok(NULL, "\r\n"); // skip end of line - goto next_token; // find the real next token - } - - value = strtok(NULL, "\r\n= "); - - if (!value) - I_Error("R_AddSkins: syntax error in S_SKIN lump# %d(%s) in WAD %s\n", lump, W_CheckNameForNumPwad(wadnum,lump), wadfiles[wadnum]->filename); - - if (!stricmp(stoken, "name")) - { - // the skin name must uniquely identify a single skin - // I'm lazy so if name is already used I leave the 'skin x' - // default skin name set in Sk_SetDefaultValue - if (R_LocalSkinAvailable(value, local) == -1) - { - STRBUFCPY(skin->name, value); - strlwr(skin->name); - } - // I'm not lazy, so if the name is already used I make the name 'namex' - // using the default skin name's number set above - else - { - const size_t stringspace = - strlen(value) + sizeof lnumskins + 1; - char *value2 = Z_Malloc(stringspace, PU_STATIC, NULL); - snprintf(value2, stringspace, - "%s%d", value, lnumskins); - value2[stringspace - 1] = '\0'; - if (R_LocalSkinAvailable(value2, local) == -1) - { - STRBUFCPY(skin->name, - value2); - strlwr(skin->name); - } - Z_Free(value2); - } - - // copy to hudname and fullname as a default. - if (!realname) - { - STRBUFCPY(skin->realname, skin->name); - for (value = skin->realname; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - } - if (!hudname) - { - STRBUFCPY(skin->hudname, skin->name); - strupr(skin->hudname); - for (value = skin->hudname; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - } - } - else if (!stricmp(stoken, "realname")) - { // 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); - } - else if (!stricmp(stoken, "hudname")) - { // 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); - memcpy(skin->sprite, value, sizeof skin->sprite); - } - else if (!stricmp(stoken, "facerank")) - { - strupr(value); - memcpy(skin->facerank, value, sizeof(skin->facerank)-1); - skin->facerank[sizeof(skin->facerank)-1] = '\0'; - } - else if (!stricmp(stoken, "facewant")) - { - strupr(value); - memcpy(skin->facewant, value, sizeof(skin->facewant)-1); - skin->facewant[sizeof(skin->facewant)-1] = '\0'; - } - else if (!stricmp(stoken, "facemmap")) - { - strupr(value); - strncpy(skin->facemmap, value, sizeof(skin->facemmap)-1); - skin->facemmap[sizeof(skin->facemmap)-1] = '\0'; - } - -#define FULLPROCESS(field) else if (!stricmp(stoken, #field)) skin->field = get_number(value); - // character type identification - FULLPROCESS(flags) -#undef FULLPROCESS - -#define GETKARTSTAT(field) \ - else if (!stricmp(stoken, #field)) \ - { \ - skin->field = atoi(value); \ - if (skin->field < 1) skin->field = 1; \ - if (skin->field > 9) skin->field = 9; \ - } - GETKARTSTAT(kartspeed) - GETKARTSTAT(kartweight) -#undef GETKARTSTAT - - // 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) - continue; - if (S_sfx[i].skinsound != -1 - && !stricmp(S_sfx[i].name, - stoken + 2)) - { - skin->soundsid[S_sfx[i].skinsound] = - S_AddSoundFx(value+2, S_sfx[i].singularity, S_sfx[i].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); - } -next_token: - 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); - } - else - { - // search in the normal sprite tables - size_t name; - boolean found = false; - const char *sprname = skin->sprite; - for (name = 0;sprnames[name][0] != '\0';name++) - if (strncmp(sprnames[name], sprname, 4) == 0) - { - found = true; - skin->spritedef = sprites[name]; - } - - // not found so make a new one - // go through the entire current wad looking for our sprite - // don't just mass add anything beginning with our four letters. - // "HOODFACE" is not a sprite name. - if (!found) - { - UINT16 localllump = 0, lstart = UINT16_MAX, lend = UINT16_MAX; - const char *lname; - - 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 (lstart == UINT16_MAX) - lstart = localllump; - // If already set do nothing - } - else - { - if (lstart != UINT16_MAX) - { - lend = localllump; - break; - } - // If not already set do nothing - } - ++localllump; - } - - R_AddSingleSpriteDef(sprname, &skin->spritedef, wadnum, lstart, lend); - } - - // I don't particularly care about skipping to the end of the used frames. - // We could be using frames from ANYWHERE in the current WAD file, including - // right before us, which is a terrible idea. - // So just let the function in the while loop take care of it for us. - } - - R_FlushTranslationColormapCache(); - - CONS_Printf(M_GetText("Added skin '%s'\n"), skin->name); -#ifdef SKINVALUES - (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 - Forceskin_cons_t[numskins+1].value = numskins; - Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name; - skin->localskin = false; - skin->localnum = numskins; - ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numskins); - } - else - { - skin->localskin = true; - skin->localnum = numlocalskins; - ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numlocalskins); - } - -#ifdef HWRENDER - if (rendermode == render_opengl) - HWR_AddPlayerMD2(lnumskins, local); -#endif - if (!local) - { - skinstats[skin->kartspeed-1][skin->kartweight-1][skinstatscount[skin->kartspeed-1][skin->kartweight-1]] = numskins; - CONS_Debug(DBG_SETUP, M_GetText("Added %d to %d, %d\n"), numskins, skin->kartweight, skin->kartweight); - skinstatscount[skin->kartspeed-1][skin->kartweight-1]++; - CONS_Debug(DBG_SETUP, M_GetText("Incremented %d, %d to %d\n"), skin->kartspeed, skin->kartweight, skinstatscount[skin->kartspeed - 1][skin->kartweight - 1]); - skinsorted[numskins] = numskins; - } - - allskins[numallskins] = K_GetSkinArray(local)[lnumskins]; - - local ? numlocalskins++ : numskins++; - numallskins++; - } - -#undef lnumskins - //sortSkinGrid(); - - return; -} diff --git a/src/r_things.h b/src/r_things.h index 91b3d4608..251cb182d 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -1,4 +1,4 @@ -// SONIC ROBO BLAST 2 +// SONIC ROBO BLAST 2 KART //----------------------------------------------------------------------------- // Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1998-2000 by DooM Legacy Team. @@ -18,13 +18,7 @@ extern "C" { #endif -#include "sounds.h" #include "r_plane.h" -#include "r_patch.h" - -// "Left" and "Right" character symbols for additional rotation functionality -#define ROT_L ('L' - '0') -#define ROT_R ('R' - '0') // number of sprite lumps for spritewidth,offset,topoffset lookup tables // Fab: this is a hack : should allocate the lookup tables per sprite @@ -67,11 +61,8 @@ fixed_t R_GetSpriteDirectionalLighting(angle_t angle); fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope); -//faB: find sprites in wadfile, replace existing, add new ones -// (only sprites from namelist are added or replaced) -void R_AddSpriteDefs(UINT16 wadnum); - //SoM: 6/5/2000: Light sprites correctly! +boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 wadnum, UINT16 startlump, UINT16 endlump); void R_AddSprites(sector_t *sec, INT32 lightlevel); void R_AddPrecipitationSprites(void); void R_InitSprites(void); @@ -91,62 +82,12 @@ typedef struct void R_DrawMasked(maskcount_t* masks, UINT8 nummasks); -boolean R_ThingVisible (mobj_t *thing); -boolean R_ThingWithinDist (mobj_t *thing, INT32 limit_dist); +boolean R_ThingVisible(mobj_t *thing); +boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist); -boolean R_ThingIsFullBright (mobj_t *thing); -boolean R_ThingIsSemiBright (mobj_t *thing); -boolean R_ThingIsFullDark (mobj_t *thing); - -// ----------- -// SKINS STUFF -// ----------- -#define SKINNAMESIZE 16 -// should be all lowercase!! S_SKIN processing does a strlwr -#define DEFAULTSKIN "sonic" -#define DEFAULTSKIN2 "tails" // secondary player -#define DEFAULTSKIN3 "knuckles" // third player -#define DEFAULTSKIN4 "eggman" // fourth player - -typedef struct -{ - char name[SKINNAMESIZE+1]; // INT16 descriptive name of the skin - spritedef_t spritedef; - spriteinfo_t sprinfo; - UINT16 wadnum; - char sprite[4]; // Sprite name, if seperated from S_SKIN. - skinflags_t flags; - - char realname[SKINNAMESIZE+1]; // Display name for level completion. - char hudname[SKINNAMESIZE+1]; // HUD name to display (officially exactly 5 characters long) - char facerank[9], facewant[9], facemmap[9]; // Arbitrarily named patch lumps - - // SRB2kart - UINT8 kartspeed; - UINT8 kartweight; - // - - // Definable color translation table - UINT8 starttranscolor; - UINT8 prefcolor; - fixed_t highresscale; // scale of highres, default is 0.5 - - // specific sounds per skin - sfxenum_t soundsid[NUMSKINSOUNDS]; // sound # in S_sfx table - - boolean localskin; - INT32 localnum; -} skin_t; - -extern CV_PossibleValue_t Forceskin_cons_t[]; - -// had to move those here Zzz... -INT32 K_GetSkinNum(player_t *player); -INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local); -skin_t *K_GetPlayerSkin(player_t *player); -skin_t *K_GetMobjSkin(const mobj_t *mobj); -patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); -skin_t *K_GetSkinArray(boolean local); +boolean R_ThingIsFullBright(mobj_t *thing); +boolean R_ThingIsSemiBright(mobj_t *thing); +boolean R_ThingIsFullDark(mobj_t *thing); // ----------- // NOT SKINS STUFF ! @@ -232,6 +173,8 @@ void R_AllocVisSpriteMemory(void); UINT8 *R_GetSpriteTranslation(vissprite_t *vis); +void R_InitDrawNodes(void); + // ---------- // DRAW NODES // ---------- @@ -250,71 +193,6 @@ typedef struct drawnode_s struct drawnode_s *prev; } drawnode_t; -extern INT32 numskins; -extern INT32 numlocalskins; -extern INT32 numallskins; -extern skin_t skins[MAXSKINS]; -extern UINT8 skinstats[9][9][MAXSKINS]; -extern UINT8 skinstatscount[9][9]; -extern UINT8 skinsorted[MAXSKINS]; - -void sortSkinGrid(void); -extern skin_t localskins[MAXLOCALSKINS]; -extern skin_t allskins[MAXSKINS+MAXLOCALSKINS]; - -boolean SetPlayerSkin(INT32 playernum,const char *skinname); -void SetPlayerSkinByNum(INT32 playernum,INT32 skinnum); // Tails 03-16-2002 -void SetLocalPlayerSkin(INT32 playernum,const char *skinname, consvar_t *cvar); -INT32 R_SkinAvailable(const char *name); -INT32 R_AnySkinAvailable(const char *name); -INT32 R_LocalSkinAvailable(const char *name, boolean local); -void R_AddSkins(UINT16 wadnum, boolean local); - -void R_InitDrawNodes(void); - -char *GetPlayerFacePic(INT32 skinnum); - -// Functions to go from sprite character ID to frame number -// for 2.1 compatibility this still uses the old 'A' + frame code -// The use of symbols tends to be painful for wad editors though -// So the future version of this tries to avoid using symbols -// as much as possible while also defining all 64 slots in a sane manner -// 2.1: [[ ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ]] -// Future: [[ ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@ ]] -FUNCMATH FUNCINLINE static ATTRINLINE char R_Frame2Char(UINT8 frame) -{ -#if 1 // 2.1 compat - return 'A' + frame; -#else - if (frame < 26) return 'A' + frame; - if (frame < 36) return '0' + (frame - 26); - if (frame < 62) return 'a' + (frame - 36); - if (frame == 62) return '!'; - if (frame == 63) return '@'; - return '\xFF'; -#endif -} - -FUNCMATH FUNCINLINE static ATTRINLINE UINT8 R_Char2Frame(char cn) -{ -#if 1 // 2.1 compat - if (cn == '+') return '\\' - 'A'; // PK3 can't use backslash, so use + instead - return cn - 'A'; -#else - if (cn >= 'A' && cn <= 'Z') return cn - 'A'; - if (cn >= '0' && cn <= '9') return (cn - '0') + 26; - if (cn >= 'a' && cn <= 'z') return (cn - 'a') + 36; - if (cn == '!') return 62; - if (cn == '@') return 63; - return 255; -#endif -} - -FUNCMATH FUNCINLINE static ATTRINLINE boolean R_ValidSpriteAngle(UINT8 rotation) -{ - return ((rotation <= 8) || (rotation == ROT_L) || (rotation == ROT_R)); -} - #ifdef __cplusplus } // extern "C" #endif