From a573c63f60225445efc69fd886ed731aa57f5e3e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 4 Dec 2018 00:22:26 +0100 Subject: [PATCH] - removed all direct access to AInventory's members. We are getting closer to make class Inventory fully scripted. --- src/b_think.cpp | 6 ++-- src/c_functions.cpp | 2 +- src/d_dehacked.cpp | 12 ++++---- src/dobject.h | 6 ++++ src/g_statusbar/sbarinfo_commands.cpp | 40 +++++++++++++-------------- src/g_statusbar/shared_sbar.cpp | 6 ++-- src/info.cpp | 2 +- src/namedef.h | 5 +++- src/p_acs.cpp | 12 ++++---- src/scripting/thingdef.h | 6 ++-- src/scripting/thingdef_properties.cpp | 23 ++++++++------- 11 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/b_think.cpp b/src/b_think.cpp index 19acdb6f01..8c231f80e4 100644 --- a/src/b_think.cpp +++ b/src/b_think.cpp @@ -371,8 +371,8 @@ void DBot::WhatToGet (AActor *item) return; auto ammo1 = heldWeapon->PointerVar(NAME_Ammo1); auto ammo2 = heldWeapon->PointerVar(NAME_Ammo2); - if ((ammo1 == NULL || ammo1->IntVar(NAME_Amount) >= ammo1->MaxAmount) && - (ammo2 == NULL || ammo2->IntVar(NAME_Amount) >= ammo2->MaxAmount)) + if ((ammo1 == NULL || ammo1->IntVar(NAME_Amount) >= ammo1->IntVar(NAME_MaxAmount)) && + (ammo2 == NULL || ammo2->IntVar(NAME_Amount) >= ammo2->IntVar(NAME_MaxAmount))) { return; } @@ -384,7 +384,7 @@ void DBot::WhatToGet (AActor *item) auto parent = item->GetClass(); while (parent->ParentClass != ac) parent = static_cast(parent->ParentClass); AInventory *holdingammo = player->mo->FindInventory(parent); - if (holdingammo != NULL && holdingammo->IntVar(NAME_Amount) >= holdingammo->MaxAmount) + if (holdingammo != NULL && holdingammo->IntVar(NAME_Amount) >= holdingammo->IntVar(NAME_MaxAmount)) { return; } diff --git a/src/c_functions.cpp b/src/c_functions.cpp index d3d61b6f8f..f675b51744 100644 --- a/src/c_functions.cpp +++ b/src/c_functions.cpp @@ -76,7 +76,7 @@ void C_PrintInv(AActor *target) { Printf (" %s #%u (%d/%d)\n", item->GetClass()->TypeName.GetChars(), item->InventoryID, - item->IntVar(NAME_Amount), item->MaxAmount); + item->IntVar(NAME_Amount), item->IntVar(NAME_MaxAmount)); count++; } Printf (" List count: %d\n", count); diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 06d2ccc155..8f69fc3e75 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1548,7 +1548,7 @@ static int PatchAmmo (int ammoNum) defaultAmmo = (AInventory*)GetDefaultByType (ammoType); if (defaultAmmo != NULL) { - max = &defaultAmmo->MaxAmount; + max = &defaultAmmo->IntVar(NAME_MaxAmount); per = &defaultAmmo->IntVar(NAME_Amount); } } @@ -1571,7 +1571,7 @@ static int PatchAmmo (int ammoNum) // Calculate the new backpack-given amounts for this ammo. if (ammoType != NULL) { - defaultAmmo->IntVar("BackpackMaxAmount") = defaultAmmo->MaxAmount * 2; + defaultAmmo->IntVar("BackpackMaxAmount") = defaultAmmo->IntVar(NAME_MaxAmount) * 2; defaultAmmo->IntVar("BackpackAmount") = defaultAmmo->IntVar(NAME_Amount); } @@ -1588,7 +1588,7 @@ static int PatchAmmo (int ammoNum) if (type->IsDescendantOf (ammoType)) { defaultAmmo = (AInventory *)GetDefaultByType (type); - defaultAmmo->MaxAmount = *max; + defaultAmmo->IntVar(NAME_MaxAmount) = *max; defaultAmmo->IntVar(NAME_Amount) = Scale (defaultAmmo->IntVar(NAME_Amount), *per, oldclip); } else if (type->IsDescendantOf (NAME_Weapon)) @@ -1981,20 +1981,20 @@ static int PatchMisc (int dummy) health = static_cast (GetDefaultByName ("HealthBonus")); if (health!=NULL) { - health->MaxAmount = 2 * deh.MaxHealth; + health->IntVar(NAME_MaxAmount) = 2 * deh.MaxHealth; } health = static_cast (GetDefaultByName ("Soulsphere")); if (health!=NULL) { health->IntVar(NAME_Amount) = deh.SoulsphereHealth; - health->MaxAmount = deh.MaxSoulsphere; + health->IntVar(NAME_MaxAmount) = deh.MaxSoulsphere; } health = static_cast (GetDefaultByName ("MegasphereHealth")); if (health!=NULL) { - health->IntVar(NAME_Amount) = health->MaxAmount = deh.MegasphereHealth; + health->IntVar(NAME_Amount) = health->IntVar(NAME_MaxAmount) = deh.MegasphereHealth; } APlayerPawn *player = static_cast (GetDefaultByName ("DoomPlayer")); diff --git a/src/dobject.h b/src/dobject.h index ff885d4cab..81e44d80a0 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -244,6 +244,7 @@ public: // Add other types as needed. inline bool &BoolVar(FName field); inline int &IntVar(FName field); + inline FTextureID &TextureIDVar(FName field); inline FSoundID &SoundVar(FName field); inline PalEntry &ColorVar(FName field); inline FName &NameVar(FName field); @@ -443,6 +444,11 @@ inline int &DObject::IntVar(FName field) return *(int*)ScriptVar(field, nullptr); } +inline FTextureID &DObject::TextureIDVar(FName field) +{ + return *(FTextureID*)ScriptVar(field, nullptr); +} + inline FSoundID &DObject::SoundVar(FName field) { return *(FSoundID*)ScriptVar(field, nullptr); diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index e07c04f2e2..1cae8dcb8c 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -154,7 +154,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl } else { - sprite = ((AInventory *)GetDefaultByType(item))->Icon; + sprite = ((AInventory *)GetDefaultByType(item))->TextureIDVar(NAME_Icon); } image = -1; } @@ -270,7 +270,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl { auto item = statusBar->CPlayer->mo->FindInventory(NAME_Sigil); if (item != NULL) - texture = TexMan(item->Icon); + texture = TexMan(item->TextureIDVar(NAME_Icon)); } else if(type == HEXENARMOR_ARMOR || type == HEXENARMOR_SHIELD || type == HEXENARMOR_HELM || type == HEXENARMOR_AMULET) { @@ -294,7 +294,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl else if(type == INVENTORYICON) texture = TexMan(sprite); else if(type == SELECTEDINVENTORYICON && statusBar->CPlayer->mo->InvSel != NULL) - texture = TexMan(statusBar->CPlayer->mo->InvSel->Icon); + texture = TexMan(statusBar->CPlayer->mo->InvSel->TextureIDVar(NAME_Icon)); else if(image >= 0) texture = statusBar->Images[image]; @@ -1365,7 +1365,7 @@ class CommandDrawNumber : public CommandDrawString return; } else - num = statusBar->ammo1->MaxAmount; + num = statusBar->ammo1->IntVar(NAME_MaxAmount); break; case AMMO2CAPACITY: if(statusBar->ammo2 == NULL) //no ammo, do not draw @@ -1374,15 +1374,15 @@ class CommandDrawNumber : public CommandDrawString return; } else - num = statusBar->ammo2->MaxAmount; + num = statusBar->ammo2->IntVar(NAME_MaxAmount); break; case AMMOCAPACITY: { AInventory* item = statusBar->CPlayer->mo->FindInventory(inventoryItem); if(item != NULL) - num = item->MaxAmount; + num = item->IntVar(NAME_MaxAmount); else - num = ((AInventory *)GetDefaultByType(inventoryItem))->MaxAmount; + num = ((AInventory *)GetDefaultByType(inventoryItem))->IntVar(NAME_MaxAmount); break; } case FRAGS: @@ -2131,7 +2131,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgARTIBOX], rx, ry, block->XOffset(), block->YOffset(), bgalpha, block->FullScreenOffsets()); if(style != STYLE_Strife) //Strife draws the cursor before the icons - statusBar->DrawGraphic(TexMan(item->Icon), rx - (style == STYLE_HexenStrict ? 2 : 0), ry - (style == STYLE_HexenStrict ? 1 : 0), block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); + statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), rx - (style == STYLE_HexenStrict ? 2 : 0), ry - (style == STYLE_HexenStrict ? 1 : 0), block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); if(item == statusBar->CPlayer->mo->InvSel) { if(style == STYLE_Heretic) @@ -2146,7 +2146,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgSELECTBOX], rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); } if(style == STYLE_Strife) - statusBar->DrawGraphic(TexMan(item->Icon), rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); + statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); if(counters != NULL && (alwaysShowCounter || item->IntVar(NAME_Amount) != 1)) { counters[i]->valueArgument = item->IntVar(NAME_Amount); @@ -2359,7 +2359,7 @@ class CommandDrawKeyBar : public SBarInfoCommand int rowWidth = 0; for(unsigned int i = 0;i < number+keyOffset;i++) { - while(!item->Icon.isValid() || !item->IsKindOf(NAME_Key)) + while(!item->TextureIDVar(NAME_Icon).isValid() || !item->IsKindOf(NAME_Key)) { item = item->Inventory; if(item == NULL) @@ -2369,22 +2369,22 @@ class CommandDrawKeyBar : public SBarInfoCommand { if(!vertical) { - statusBar->DrawGraphic(TexMan(item->Icon), x+slotOffset, y+rowOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); - rowWidth = rowIconSize == -1 ? TexMan(item->Icon)->GetScaledHeight()+2 : rowIconSize; + statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), x+slotOffset, y+rowOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); + rowWidth = rowIconSize == -1 ? TexMan(item->TextureIDVar(NAME_Icon))->GetScaledHeight()+2 : rowIconSize; } else { - statusBar->DrawGraphic(TexMan(item->Icon), x+rowOffset, y+slotOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); - rowWidth = rowIconSize == -1 ? TexMan(item->Icon)->GetScaledWidth()+2 : rowIconSize; + statusBar->DrawGraphic(TexMan(item->TextureIDVar(NAME_Icon)), x+rowOffset, y+slotOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); + rowWidth = rowIconSize == -1 ? TexMan(item->TextureIDVar(NAME_Icon))->GetScaledWidth()+2 : rowIconSize; } // If cmd.special is -1 then the slot size is auto detected if(iconSize == -1) { if(!vertical) - slotOffset += (reverse ? -1 : 1) * (TexMan(item->Icon)->GetScaledWidth() + 2); + slotOffset += (reverse ? -1 : 1) * (TexMan(item->TextureIDVar(NAME_Icon))->GetScaledWidth() + 2); else - slotOffset += (reverse ? -1 : 1) * (TexMan(item->Icon)->GetScaledHeight() + 2); + slotOffset += (reverse ? -1 : 1) * (TexMan(item->TextureIDVar(NAME_Icon))->GetScaledHeight() + 2); } else slotOffset += (reverse ? -iconSize : iconSize); @@ -2697,7 +2697,7 @@ class CommandDrawBar : public SBarInfoCommand max = 1; } else - max = statusBar->ammo1->MaxAmount; + max = statusBar->ammo1->IntVar(NAME_MaxAmount); break; case AMMO2: value = statusBar->ammocount2; @@ -2707,7 +2707,7 @@ class CommandDrawBar : public SBarInfoCommand max = 1; } else - max = statusBar->ammo2->MaxAmount; + max = statusBar->ammo2->IntVar(NAME_MaxAmount); break; case AMMO: { @@ -2715,7 +2715,7 @@ class CommandDrawBar : public SBarInfoCommand if(item != NULL) { value = item->IntVar(NAME_Amount); - max = item->MaxAmount; + max = item->IntVar(NAME_MaxAmount); } else value = 0; @@ -2743,7 +2743,7 @@ class CommandDrawBar : public SBarInfoCommand if(item != NULL) { value = item->IntVar(NAME_Amount); - max = item->MaxAmount; + max = item->IntVar(NAME_MaxAmount); } else value = 0; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index b1bd87b430..6c3ccc8398 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1765,9 +1765,9 @@ int GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale) *applyscale = false; } - if (item == nullptr) return FNullTextureID().GetIndex(); + if (item == nullptr) return 0; - FTextureID picnum, Icon = item->Icon, AltIcon = item->AltHUDIcon; + FTextureID picnum, Icon = item->TextureIDVar(NAME_Icon), AltIcon = item->TextureIDVar(NAME_AltHUDIcon); FState * state = NULL, *ReadyState; picnum.SetNull(); @@ -1780,7 +1780,7 @@ int GetInventoryIcon(AInventory *item, uint32_t flags, int *applyscale) } else { - if (!(flags & DI_SKIPICON) && item->Icon.isValid()) + if (!(flags & DI_SKIPICON) && Icon.isValid()) picnum = Icon; else if (!(flags & DI_SKIPALTICON)) picnum = AltIcon; diff --git a/src/info.cpp b/src/info.cpp index c4be50d47f..edeaabbe60 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -361,7 +361,7 @@ static void LoadAltHudStuff() } else tex.SetInvalid(); - if (ti) ((AInventory*)GetDefaultByType(ti))->AltHUDIcon = tex; + if (ti) GetDefaultByType(ti)->TextureIDVar(NAME_AltHUDIcon) = tex; } } } diff --git a/src/namedef.h b/src/namedef.h index b69ff416b8..a965fba631 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -98,7 +98,10 @@ xx(ArmorType) xx(HexenArmor) xx(Slots) xx(SlotsIncrement) - +xx(InterHubAmount) +xx(Icon) +xx(AltHUDIcon) +xx(PickupFlash) xx(BulletPuff) xx(StrifePuff) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index f8164d2989..8f943fa37b 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1843,11 +1843,11 @@ int CheckInventory (AActor *activator, const char *type, bool max) { if (item) { - return item->MaxAmount; + return item->IntVar(NAME_MaxAmount); } else if (info != nullptr && info->IsDescendantOf(NAME_Inventory)) { - return ((AInventory *)GetDefaultByType(info))->MaxAmount; + return ((AInventory *)GetDefaultByType(info))->IntVar(NAME_MaxAmount); } } return item ? item->IntVar(NAME_Amount) : 0; @@ -9353,11 +9353,11 @@ scriptwait: item = activator->FindInventory (static_cast(type)); if (item != NULL) { - STACK(1) = item->MaxAmount; + STACK(1) = item->IntVar(NAME_MaxAmount); } else { - STACK(1) = ((AInventory *)GetDefaultByType (type))->MaxAmount; + STACK(1) = ((AInventory *)GetDefaultByType (type))->IntVar(NAME_MaxAmount); } } else @@ -9382,14 +9382,14 @@ scriptwait: item = activator->FindInventory (type); if (item != NULL) { - item->MaxAmount = STACK(1); + item->IntVar(NAME_MaxAmount) = STACK(1); } else { item = activator->GiveInventoryType (type); if (item != NULL) { - item->MaxAmount = STACK(1); + item->IntVar(NAME_MaxAmount) = STACK(1); item->IntVar(NAME_Amount) = 0; } } diff --git a/src/scripting/thingdef.h b/src/scripting/thingdef.h index 33d9e7450e..10bc366958 100644 --- a/src/scripting/thingdef.h +++ b/src/scripting/thingdef.h @@ -71,12 +71,12 @@ struct FFlagDef void FinalizeClass(PClass *cls, FStateDefinitions &statedef); FFlagDef *FindFlag (const PClass *type, const char *part1, const char *part2, bool strict = false); void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int index); -bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index); +bool CheckDeprecatedFlags(AActor *actor, PClassActor *info, int index); const char *GetFlagName(unsigned int flagnum, int flagoffset); void ModActorFlag(AActor *actor, FFlagDef *fd, bool set); bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printerror = true); -INTBOOL CheckActorFlag(const AActor *actor, FFlagDef *fd); -INTBOOL CheckActorFlag(const AActor *owner, const char *flagname, bool printerror = true); +INTBOOL CheckActorFlag(AActor *actor, FFlagDef *fd); +INTBOOL CheckActorFlag(AActor *owner, const char *flagname, bool printerror = true); #define FLAG_NAME(flagnum, flagvar) GetFlagName(flagnum, myoffsetof(AActor, flagvar)) diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index a279ed070d..f2b734c529 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -206,7 +206,7 @@ bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printer // //========================================================================== -INTBOOL CheckActorFlag(const AActor *owner, FFlagDef *fd) +INTBOOL CheckActorFlag(AActor *owner, FFlagDef *fd) { if (fd->structoffset == -1) { @@ -232,7 +232,7 @@ INTBOOL CheckActorFlag(const AActor *owner, FFlagDef *fd) #endif } -INTBOOL CheckActorFlag(const AActor *owner, const char *flagname, bool printerror) +INTBOOL CheckActorFlag(AActor *owner, const char *flagname, bool printerror) { const char *dot = strchr (flagname, '.'); FFlagDef *fd; @@ -310,15 +310,15 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in case DEPF_PICKUPFLASH: if (set) { - static_cast(defaults)->PickupFlash = FindClassTentative("PickupFlash", RUNTIME_CLASS(AActor)); + defaults->PointerVar(NAME_PickupFlash) = FindClassTentative("PickupFlash", RUNTIME_CLASS(AActor)); } else { - static_cast(defaults)->PickupFlash = NULL; + defaults->PointerVar(NAME_PickupFlash) = nullptr; } break; case DEPF_INTERHUBSTRIP: // Old system was 0 or 1, so if the flag is cleared, assume 1. - static_cast(defaults)->InterHubAmount = set ? 0 : 1; + defaults->IntVar(NAME_InterHubAmount) = set ? 0 : 1; break; case DEPF_NOTRAIL: { @@ -351,7 +351,7 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in // //=========================================================================== -bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index) +bool CheckDeprecatedFlags(AActor *actor, PClassActor *info, int index) { // A deprecated flag is false if // a) it hasn't been added here @@ -391,11 +391,10 @@ bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index) return (actor->BounceFlags & (BOUNCE_TypeMask|BOUNCE_UseSeeSound)) == BOUNCE_DoomCompat; case DEPF_PICKUPFLASH: - return static_cast(actor)->PickupFlash == PClass::FindClass("PickupFlash"); - // A pure name lookup may or may not be more efficient, but I know no static identifier for PickupFlash. + return actor->PointerVar(NAME_PickupFlash) == PClass::FindClass(NAME_PickupFlash); case DEPF_INTERHUBSTRIP: - return !(static_cast(actor)->InterHubAmount); + return !(actor->IntVar(NAME_InterHubAmount)); } return false; // Any entirely unknown flag is not set @@ -1151,7 +1150,7 @@ static void SetIcon(FTextureID &icon, Baggage &bag, const char *i) DEFINE_CLASS_PROPERTY(icon, S, Inventory) { PROP_STRING_PARM(i, 0); - SetIcon(defaults->Icon, bag, i); + SetIcon(defaults->TextureIDVar(NAME_Icon), bag, i); } //========================================================================== @@ -1160,7 +1159,7 @@ DEFINE_CLASS_PROPERTY(icon, S, Inventory) DEFINE_CLASS_PROPERTY(althudicon, S, Inventory) { PROP_STRING_PARM(i, 0); - SetIcon(defaults->AltHUDIcon, bag, i); + SetIcon(defaults->TextureIDVar(NAME_AltHUDIcon), bag, i); } //========================================================================== @@ -1168,7 +1167,7 @@ DEFINE_CLASS_PROPERTY(althudicon, S, Inventory) //========================================================================== DEFINE_CLASS_PROPERTY(defmaxamount, 0, Inventory) { - defaults->MaxAmount = gameinfo.definventorymaxamount; + defaults->IntVar(NAME_MaxAmount) = gameinfo.definventorymaxamount; } //==========================================================================