From 4a87a598fb0926ff36d4740879af859f78a91b56 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Feb 2017 00:59:09 +0100 Subject: [PATCH] - do floatification of the UDMF Health property as it should have been. --- specs/udmf_zdoom.txt | 2 +- src/dobjtype.cpp | 14 ++------------ src/dobjtype.h | 5 +---- src/doomdata.h | 2 +- src/p_mobj.cpp | 10 +++++----- src/p_setup.cpp | 4 ++-- src/p_udmf.cpp | 4 ++-- 7 files changed, 14 insertions(+), 27 deletions(-) diff --git a/specs/udmf_zdoom.txt b/specs/udmf_zdoom.txt index f4af55f2df..eeb3c2a560 100644 --- a/specs/udmf_zdoom.txt +++ b/specs/udmf_zdoom.txt @@ -263,7 +263,7 @@ Note: All fields default to false unless mentioned otherwise. gravity = ; // Set per-actor gravity. Positive values are multiplied with the class's property, // negative values are used as their absolute. Default = 1.0. - health = ; // Set per-actor health. Positive values are multiplied with the class's property, + health = ; // Set per-actor health. Positive values are multiplied with the class's property, // negative values are used as their absolute. Default = 1. renderstyle = ; // Set per-actor render style, overriding the class default. Possible values can be "normal", diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 97d154a3b8..75193b868b 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -3160,6 +3160,7 @@ void PClass::InitializeDefaults() optr->ObjNext = nullptr; optr->SetClass(this); + // Copy the defaults from the parent but leave the DObject part alone because it contains important data. if (ParentClass->Defaults != nullptr) { @@ -3173,13 +3174,6 @@ void PClass::InitializeDefaults() { memset(Defaults + sizeof(DObject), 0, Size - sizeof(DObject)); } - - if (MetaSize != 0) - { - Meta = (BYTE*)ClassDataAllocator.Alloc(MetaSize); - memset(Meta, 0, MetaSize); - if (ParentClass->MetaSize > 0) memcpy(Meta, ParentClass->Meta, ParentClass->MetaSize); - } } if (bRuntimeClass) @@ -3189,14 +3183,10 @@ void PClass::InitializeDefaults() if (Defaults != nullptr) ParentClass->InitializeSpecials(Defaults, ParentClass->Defaults); for (const PField *field : Fields) { - if (!(field->Flags & VARF_Native) && !(field->Flags & VARF_Meta)) + if (!(field->Flags & VARF_Native)) { field->Type->SetDefaultValue(Defaults, unsigned(field->Offset), &SpecialInits); } - if (!(field->Flags & VARF_Native) && (field->Flags & VARF_Meta)) - { - field->Type->SetDefaultValue(Meta, unsigned(field->Offset), &MetaInits); - } } } } diff --git a/src/dobjtype.h b/src/dobjtype.h index 24951c9d89..0151e6c119 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -560,9 +560,8 @@ class PClass : public PNativeStruct protected: // We unravel _WITH_META here just as we did for PType. TArray SpecialInits; - TArray MetaInits; void Derive(PClass *newclass, FName name); - void InitializeSpecials(void *addr, void *defaults, TArray* PClass::*Inits); + void InitializeSpecials(void *addr, void *defaults) const; void SetSuper(); public: void WriteValue(FSerializer &ar, const char *key,const void *addr) const override; @@ -583,8 +582,6 @@ public: const size_t *FlatPointers; // object pointers defined by this class and all its superclasses; not initialized by default const size_t *ArrayPointers; // dynamic arrays containing object pointers. BYTE *Defaults; - BYTE *Meta; // Per-class static script data - unsigned MetaSize; bool bRuntimeClass; // class was defined at run-time, not compile-time bool bExported; // This type has been declared in a script bool bDecorateClass; // may be subject to some idiosyncracies due to DECORATE backwards compatibility diff --git a/src/doomdata.h b/src/doomdata.h index eca7dcd4aa..39f0d184a5 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -359,7 +359,7 @@ struct FMapThing double Alpha; DWORD fillcolor; DVector2 Scale; - int health; + double Health; int score; short pitch; short roll; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 88bb1d40a9..f38ac12bb3 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5930,13 +5930,13 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position) mobj->LevelSpawned (); } - if (mthing->health > 0) - mobj->health *= mthing->health; + if (mthing->Health > 0) + mobj->health = int(mobj->health * mthing->Health); else - mobj->health = -mthing->health; - if (mthing->health == 0) + mobj->health = -int(mthing->Health); + if (mthing->Health == 0) mobj->CallDie(NULL, NULL); - else if (mthing->health != 1) + else if (mthing->Health != 1) mobj->StartHealth = mobj->health; return mobj; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 308054a8b3..76e8b6b340 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1741,7 +1741,7 @@ void P_LoadThings (MapData * map) mti[i].ClassFilter = 0xffff; // Doom map format doesn't have class flags so spawn for all player classes mti[i].RenderStyle = STYLE_Count; mti[i].Alpha = -1; - mti[i].health = 1; + mti[i].Health = 1; mti[i].FloatbobPhase = -1; mti[i].pos.X = LittleShort(mt->x); @@ -1837,7 +1837,7 @@ void P_LoadThings2 (MapData * map) mti[i].Gravity = 1; mti[i].RenderStyle = STYLE_Count; mti[i].Alpha = -1; - mti[i].health = 1; + mti[i].Health = 1; mti[i].FloatbobPhase = -1; } delete[] mtp; diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 27293b9188..4d5e00e48a 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -518,7 +518,7 @@ public: th->Gravity = 1; th->RenderStyle = STYLE_Count; th->Alpha = -1; - th->health = 1; + th->Health = 1; th->FloatbobPhase = -1; sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -746,7 +746,7 @@ public: break; case NAME_Health: - th->health = CheckInt(key); + th->Health = CheckFloat(key); break; case NAME_Score: