diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index ac1f771280..1bb709284f 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -195,7 +195,7 @@ void D_GetPlayerColor (int player, float *h, float *s, float *v, FPlayerColorSet if (players[player].mo != NULL) { - colorset = P_GetPlayerColorSet(players[player].mo->GetClass()->TypeName, info->colorset); + colorset = players[player].mo->GetClass()->GetColorSet(info->colorset); } if (colorset != NULL) { diff --git a/src/d_player.h b/src/d_player.h index 3453819b02..b3dfe276d3 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -46,6 +46,20 @@ class player_t; +// Standard pre-defined skin colors +struct FPlayerColorSet +{ + FName Name; // Name of this color + + int Lump; // Lump to read the translation from, otherwise use next 2 fields + BYTE FirstColor, LastColor; // Describes the range of colors to use for the translation + + BYTE RepresentativeColor; // A palette entry representative of this translation, + // for map arrows and status bar backgrounds and such +}; +typedef TMap FPlayerColorSetMap; + + class PClassPlayerPawn : public PClassActor { DECLARE_CLASS(PClassPlayerPawn, PClassActor); @@ -53,6 +67,8 @@ protected: virtual void Derive(PClass *newclass); public: PClassPlayerPawn(); + void EnumColorSets(TArray *out); + FPlayerColorSet *GetColorSet(int setnum) { return ColorSets.CheckKey(setnum); } FString DisplayName; // Display name (used in menus, etc.) FString SoundClass; // Sound class @@ -63,11 +79,9 @@ public: fixed_t HexenArmor[5]; BYTE ColorRangeStart; // Skin color range BYTE ColorRangeEnd; + FPlayerColorSetMap ColorSets; }; -FPlayerColorSet *P_GetPlayerColorSet(FName classname, int setnum); -void P_EnumPlayerColorSets(FName classname, TArray *out); - class player_t; class APlayerPawn : public AActor diff --git a/src/info.cpp b/src/info.cpp index 2abe17bed0..5804a78576 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -494,25 +494,6 @@ void PClassActor::SetPainChance(FName type, int chance) // //========================================================================== -void PClassActor::SetColorSet(int index, const FPlayerColorSet *set) -{ - if (set != NULL) - { - if (ColorSets == NULL) ColorSets = new FPlayerColorSetMap; - ColorSets->Insert(index, *set); - } - else - { - if (ColorSets != NULL) - ColorSets->Remove(index); - } -} - -//========================================================================== -// -// -//========================================================================== - FDoomEdMap DoomEdMap; FDoomEdMap::FDoomEdEntry *FDoomEdMap::DoomEdHash[DOOMED_HASHSIZE]; diff --git a/src/info.h b/src/info.h index bdeefb53f6..a6f37771ce 100644 --- a/src/info.h +++ b/src/info.h @@ -123,21 +123,8 @@ FArchive &operator<< (FArchive &arc, FState *&state); #include "gametype.h" -// Standard pre-defined skin colors -struct FPlayerColorSet -{ - FName Name; // Name of this color - - int Lump; // Lump to read the translation from, otherwise use next 2 fields - BYTE FirstColor, LastColor; // Describes the range of colors to use for the translation - - BYTE RepresentativeColor; // A palette entry representative of this translation, - // for map arrows and status bar backgrounds and such -}; - typedef TMap DmgFactors; typedef TMap PainChanceList; -typedef TMap FPlayerColorSetMap; class DDropItem; class PClassActor : public PClass @@ -158,7 +145,6 @@ public: void RegisterIDs(); void SetDamageFactor(FName type, fixed_t factor); void SetPainChance(FName type, int chance); - void SetColorSet(int index, const FPlayerColorSet *set); size_t PropagateMark(); void InitializeNativeDefaults(); @@ -182,7 +168,6 @@ public: FStateLabels *StateList; DmgFactors *DamageFactors; PainChanceList *PainChances; - FPlayerColorSetMap *ColorSets; FString Obituary; // Player was killed by this actor FString HitObituary; // Player was killed by this actor in melee fixed_t DeathHeight; // Height on normal death diff --git a/src/m_menu.cpp b/src/m_menu.cpp index 94befe8fec..5d0bdaf2d5 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -2093,7 +2093,7 @@ void M_PlayerSetup (void) } PlayerSkin = players[consoleplayer].userinfo.skin; R_GetPlayerTranslation (players[consoleplayer].userinfo.color, - P_GetPlayerColorSet(PlayerClass->Type->TypeName, players[consoleplayer].userinfo.colorset), + PlayerClass->Type->GetColorSet(players[consoleplayer].userinfo.colorset), &skins[PlayerSkin], translationtables[TRANSLATION_Players][MAXPLAYERS]); PlayerState = GetDefaultByType (PlayerClass->Type)->SeeState; PlayerTics = PlayerState->GetTics(); @@ -2101,7 +2101,7 @@ void M_PlayerSetup (void) { FireTexture = new FBackdropTexture; } - P_EnumPlayerColorSets(PlayerClass->Type->TypeName, &PlayerColorSets); + PlayerClass->Type->EnumColorSets(&PlayerColorSets); } static void M_PlayerSetupTicker (void) @@ -2119,7 +2119,7 @@ static void M_PlayerSetupTicker (void) item = (MenuTime>>2) % (ClassMenuDef.numitems-1); PlayerClass = &PlayerClasses[D_PlayerClassToInt (ClassMenuItems[item].name)]; - P_EnumPlayerColorSets(PlayerClass->Type->TypeName, &PlayerColorSets); + PlayerClass->Type->EnumColorSets(&PlayerColorSets); } else { @@ -2133,7 +2133,7 @@ static void M_PlayerSetupTicker (void) PlayerSkin = R_FindSkin (skins[PlayerSkin].name, int(PlayerClass - &PlayerClasses[0])); R_GetPlayerTranslation (players[consoleplayer].userinfo.color, - P_GetPlayerColorSet(PlayerClass->Type->TypeName, players[consoleplayer].userinfo.colorset), + PlayerClass->Type->GetColorSet(players[consoleplayer].userinfo.colorset), &skins[PlayerSkin], translationtables[TRANSLATION_Players][MAXPLAYERS]); } @@ -2290,7 +2290,7 @@ static void M_PlayerSetupDrawer () } // Draw player color selection and sliders - FPlayerColorSet *colorset = P_GetPlayerColorSet(PlayerClass->Type->TypeName, players[consoleplayer].userinfo.colorset); + FPlayerColorSet *colorset = PlayerClass->Type->GetColorSet(players[consoleplayer].userinfo.colorset); x = SmallFont->StringWidth("Color") + 8 + PSetupDef.x; screen->DrawText(SmallFont, label, PSetupDef.x, PSetupDef.y + LINEHEIGHT*2+yo, "Color", DTA_Clean, true, TAG_DONE); screen->DrawText(SmallFont, value, x, PSetupDef.y + LINEHEIGHT*2+yo, @@ -2604,7 +2604,7 @@ static void M_ChangeSkin (int choice) } while (!PlayerClass->CheckSkin (PlayerSkin)); R_GetPlayerTranslation (players[consoleplayer].userinfo.color, - P_GetPlayerColorSet(PlayerClass->Type->TypeName, players[consoleplayer].userinfo.colorset), + PlayerClass->Type->GetColorSet(players[consoleplayer].userinfo.colorset), &skins[PlayerSkin], translationtables[TRANSLATION_Players][MAXPLAYERS]); cvar_set ("skin", skins[PlayerSkin].name); @@ -2762,7 +2762,7 @@ static void M_ChangeColorSet (int choice) mysnprintf(command, countof(command), "colorset %d", mycolorset); C_DoCommand(command); R_GetPlayerTranslation(players[consoleplayer].userinfo.color, - P_GetPlayerColorSet(PlayerClass->Type->TypeName, mycolorset), + PlayerClass->Type->GetColorSet(mycolorset), &skins[PlayerSkin], translationtables[TRANSLATION_Players][MAXPLAYERS]); } @@ -2773,7 +2773,7 @@ static void SendNewColor (int red, int green, int blue) mysnprintf (command, countof(command), "color \"%02x %02x %02x\"", red, green, blue); C_DoCommand (command); R_GetPlayerTranslation(MAKERGB (red, green, blue), - P_GetPlayerColorSet(PlayerClass->Type->TypeName, players[consoleplayer].userinfo.colorset), + PlayerClass->Type->GetColorSet(players[consoleplayer].userinfo.colorset), &skins[PlayerSkin], translationtables[TRANSLATION_Players][MAXPLAYERS]); } @@ -4116,5 +4116,5 @@ static void PickPlayerClass () } PlayerClass = &PlayerClasses[pclass]; - P_EnumPlayerColorSets(PlayerClass->Type->TypeName, &PlayerColorSets); + PlayerClass->Type->EnumColorSets(&PlayerColorSets); } diff --git a/src/p_user.cpp b/src/p_user.cpp index f2ee29234e..b3973a8fa7 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -421,6 +421,7 @@ void PClassPlayerPawn::Derive(PClass *newclass) newp->HealingRadiusType = HealingRadiusType; newp->ColorRangeStart = ColorRangeStart; newp->ColorRangeEnd = ColorRangeEnd; + newp->ColorSets = ColorSets; for (i = 0; i < countof(HexenArmor); ++i) { newp->HexenArmor[i] = HexenArmor[i]; @@ -431,6 +432,25 @@ void PClassPlayerPawn::Derive(PClass *newclass) } } +static int STACK_ARGS intcmp(const void *a, const void *b) +{ + return *(const int *)a - *(const int *)b; +} + +void PClassPlayerPawn::EnumColorSets(TArray *out) +{ + out->Clear(); + FPlayerColorSetMap::Iterator it(ColorSets); + FPlayerColorSetMap::Pair *pair; + + while (it.NextPair(pair)) + { + out->Push(pair->Key); + } + qsort(&(*out)[0], out->Size(), sizeof(int), intcmp); +} + + //=========================================================================== // // APlayerPawn @@ -2669,48 +2689,3 @@ void player_t::Serialize (FArchive &arc) original_oldbuttons = ~0; } } - - -static FPlayerColorSetMap *GetPlayerColors(FName classname) -{ - PClassPlayerPawn *cls = dyn_cast(PClass::FindClass(classname)); - - if (cls != NULL) - { - return cls->ColorSets; - } - return NULL; -} - -FPlayerColorSet *P_GetPlayerColorSet(FName classname, int setnum) -{ - FPlayerColorSetMap *map = GetPlayerColors(classname); - if (map == NULL) - { - return NULL; - } - return map->CheckKey(setnum); -} - -static int STACK_ARGS intcmp(const void *a, const void *b) -{ - return *(const int *)a - *(const int *)b; -} - -void P_EnumPlayerColorSets(FName classname, TArray *out) -{ - out->Clear(); - FPlayerColorSetMap *map = GetPlayerColors(classname); - if (map != NULL) - { - FPlayerColorSetMap::Iterator it(*map); - FPlayerColorSetMap::Pair *pair; - - while (it.NextPair(pair)) - { - out->Push(pair->Key); - } - qsort(&(*out)[0], out->Size(), sizeof(int), intcmp); - } -} - diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index d9667fb07f..4cc1b9bf73 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -153,12 +153,6 @@ PClassActor *CreateNewActor(const FScriptPosition &sc, FName typeName, FName par ti->PainChances = new PainChanceList; *ti->PainChances = *parent->PainChances; } - if (parent->ColorSets != NULL) - { - // copy color sets from parent - ti->ColorSets = new FPlayerColorSetMap; - *ti->ColorSets = *parent->ColorSets; - } ti->Replacee = ti->Replacement = NULL; ti->DoomEdNum = -1; return ti; diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index c6f4c285c4..ef147b1831 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1931,7 +1931,8 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, colorset, ISIII, PlayerPawn) } else { - info->SetColorSet(setnum, &color); + assert(info->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn))); + static_cast(info)->ColorSets.Insert(setnum, color); } } @@ -1955,7 +1956,8 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, colorsetfile, ISSI, PlayerPawn) } else if (color.Lump >= 0) { - info->SetColorSet(setnum, &color); + assert(info->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn))); + static_cast(info)->ColorSets.Insert(setnum, color); } } @@ -1972,7 +1974,8 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, clearcolorset, I, PlayerPawn) } else { - info->SetColorSet(setnum, NULL); + assert(info->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn))); + static_cast(info)->ColorSets.Remove(setnum); } }