- Turned DropItem into a plain struct again like it was before the scripting branch got merged.

Making this an object had little to no advantage, except being able to remove the deleter code. Now, with some of the class data already being allocated in a memory arena so that freeing it is easier, this can also be used for the drop item lists which makes it unnecessary to subject them to the GC. This also merges the memory arenas for VM functions and flat pointers because both get deleted at the same time so they can share the same one.
This commit is contained in:
Christoph Oelckers 2017-02-08 20:37:22 +01:00
parent 9499c22dfe
commit 8277299135
13 changed files with 30 additions and 48 deletions

View file

@ -572,12 +572,9 @@ struct FLinkContext
msecnode_t *render_list = nullptr;
};
class DDropItem : public DObject
struct FDropItem
{
DECLARE_CLASS(DDropItem, DObject)
HAS_OBJECT_POINTERS
public:
DDropItem *Next;
FDropItem *Next;
FName Name;
int Probability;
int Amount;
@ -610,7 +607,7 @@ public:
return (AActor *)(this->GetClass()->Defaults);
}
DDropItem *GetDropItems() const;
FDropItem *GetDropItems() const;
// Return true if the monster should use a missile attack, false for melee
bool SuggestMissileAttack (double dist);

View file

@ -1983,7 +1983,7 @@ static int PatchMisc (int dummy)
player->health = deh.StartHealth;
// Hm... I'm not sure that this is the right way to change this info...
DDropItem *di = PClass::FindActor(NAME_DoomPlayer)->DropItems;
FDropItem *di = PClass::FindActor(NAME_DoomPlayer)->DropItems;
while (di != NULL)
{
if (di->Name == NAME_Clip)

View file

@ -64,8 +64,7 @@
EXTERN_CVAR(Bool, strictdecorate);
// PUBLIC DATA DEFINITIONS -------------------------------------------------
FMemArena FlatpointerArena; // stores the flat pointers because freeing them individually is rather messy.
FMemArena ClassDataAllocator(32768); // use this for all static class data that can be released in bulk when the type system is shut down.
FTypeTable TypeTable;
TArray<PClass *> PClass::AllClasses;
@ -2858,7 +2857,7 @@ void PClass::StaticShutdown ()
// Unless something went wrong, anything left here should be class and type objects only, which do not own any scripts.
TypeTable.Clear();
Namespaces.ReleaseSymbols();
FlatpointerArena.FreeAllBlocks();
ClassDataAllocator.FreeAllBlocks();
bShutdown = true;
for (unsigned i = 0; i < PClass::AllClasses.Size(); ++i)
@ -3448,7 +3447,7 @@ void PClass::BuildFlatPointers ()
{ }
// Concatenate them into a new array
size_t *flat = (size_t*)FlatpointerArena.Alloc(sizeof(size_t) * (numPointers + numSuperPointers + ScriptPointers.Size() + 1));
size_t *flat = (size_t*)ClassDataAllocator.Alloc(sizeof(size_t) * (numPointers + numSuperPointers + ScriptPointers.Size() + 1));
if (numSuperPointers > 0)
{
memcpy (flat, ParentClass->FlatPointers, sizeof(size_t)*numSuperPointers);
@ -3514,7 +3513,7 @@ void PClass::BuildArrayPointers()
}
// Concatenate them into a new array
size_t *flat = (size_t*)FlatpointerArena.Alloc(sizeof(size_t) * (numSuperPointers + ScriptPointers.Size() + 1));
size_t *flat = (size_t*)ClassDataAllocator.Alloc(sizeof(size_t) * (numSuperPointers + ScriptPointers.Size() + 1));
if (numSuperPointers > 0)
{
memcpy(flat, ParentClass->ArrayPointers, sizeof(size_t)*numSuperPointers);

View file

@ -42,7 +42,7 @@ void A_Unblock(AActor *self, bool drop)
// If the actor has attached metadata for items to drop, drop those.
if (drop && !self->IsKindOf (RUNTIME_CLASS (APlayerPawn))) // [GRB]
{
DDropItem *di = self->GetDropItems();
auto di = self->GetDropItems();
if (di != NULL)
{

View file

@ -176,11 +176,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetSpriteIndex)
ACTION_RETURN_INT(GetSpriteIndex(sprt.GetChars(), false));
}
IMPLEMENT_CLASS(PClassActor, false, true)
IMPLEMENT_POINTERS_START(PClassActor)
IMPLEMENT_POINTER(DropItems)
IMPLEMENT_POINTERS_END
IMPLEMENT_CLASS(PClassActor, false, false)
//==========================================================================
//
@ -394,10 +390,9 @@ bool PClassActor::SetReplacement(FName replaceName)
//
//==========================================================================
void PClassActor::SetDropItems(DDropItem *drops)
void PClassActor::SetDropItems(FDropItem *drops)
{
DropItems = drops;
GC::WriteBarrier(this, DropItems);
}

View file

@ -234,12 +234,11 @@ private:
static DamageTypeDefinition *Get(FName type);
};
class DDropItem;
struct FDropItem;
class PClassActor : public PClass
{
DECLARE_CLASS(PClassActor, PClass);
HAS_OBJECT_POINTERS;
protected:
public:
static void StaticInit ();
@ -256,7 +255,7 @@ public:
void SetDamageFactor(FName type, double factor);
void SetPainChance(FName type, int chance);
bool SetReplacement(FName replaceName);
void SetDropItems(DDropItem *drops);
void SetDropItems(FDropItem *drops);
FState *FindState(int numnames, FName *names, bool exact=false) const;
FState *FindStateByString(const char *name, bool exact=false);
@ -303,7 +302,7 @@ public:
FName BloodType2; // Bloopsplatter replacement type
FName BloodType3; // AxeBlood replacement type
DDropItem *DropItems;
FDropItem *DropItems;
FString SourceLumpName;
FIntCVar *distancecheck;

View file

@ -7492,7 +7492,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetCameraHeight)
}
DDropItem *AActor::GetDropItems() const
FDropItem *AActor::GetDropItems() const
{
return GetClass()->DropItems;
}
@ -8100,16 +8100,10 @@ DEFINE_ACTION_FUNCTION(AActor, ApplyDamageFactors)
//
//----------------------------------------------------------------------------
IMPLEMENT_CLASS(DDropItem, false, true)
IMPLEMENT_POINTERS_START(DDropItem)
IMPLEMENT_POINTER(Next)
IMPLEMENT_POINTERS_END
DEFINE_FIELD(DDropItem, Next)
DEFINE_FIELD(DDropItem, Name)
DEFINE_FIELD(DDropItem, Probability)
DEFINE_FIELD(DDropItem, Amount)
DEFINE_FIELD(FDropItem, Next)
DEFINE_FIELD(FDropItem, Name)
DEFINE_FIELD(FDropItem, Probability)
DEFINE_FIELD(FDropItem, Amount)
void PrintMiscActorInfo(AActor *query)
{

View file

@ -1384,7 +1384,7 @@ void APlayerPawn::GiveDefaultInventory ()
AddInventory (barmor);
// Now add the items from the DECORATE definition
DDropItem *di = GetDropItems();
auto di = GetDropItems();
while (di)
{
@ -1514,7 +1514,7 @@ void APlayerPawn::Die (AActor *source, AActor *inflictor, int dmgflags)
AInventory *item;
// kgDROP - start - modified copy from a_action.cpp
DDropItem *di = weap->GetDropItems();
auto di = weap->GetDropItems();
if (di != NULL)
{

View file

@ -110,7 +110,7 @@ FScriptPosition & GetStateSource(FState *state);
// Extra info maintained while defining an actor.
//
//==========================================================================
class DDropItem;
class FDropItem;
struct Baggage
{
@ -126,7 +126,7 @@ struct Baggage
int Lumpnum;
FStateDefinitions statedef;
DDropItem *DropItemList;
FDropItem *DropItemList;
FScriptPosition ScriptPosition;
};

View file

@ -921,7 +921,7 @@ DEFINE_PROPERTY(dropitem, S_i_i, Actor)
bag.DropItemList = NULL;
}
DDropItem *di = new DDropItem;
FDropItem *di = (FDropItem*)ClassDataAllocator.Alloc(sizeof(FDropItem));
di->Name = type;
di->Probability = 255;
@ -939,7 +939,6 @@ DEFINE_PROPERTY(dropitem, S_i_i, Actor)
}
di->Next = bag.DropItemList;
bag.DropItemList = di;
GC::WriteBarrier(di);
}
//==========================================================================
@ -2685,7 +2684,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, startitem, S_i, PlayerPawn)
bag.DropItemList = NULL;
}
DDropItem *di = new DDropItem;
FDropItem *di = (FDropItem*)ClassDataAllocator.Alloc(sizeof(FDropItem));
di->Name = str;
di->Probability = 255;
@ -2697,7 +2696,6 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, startitem, S_i, PlayerPawn)
}
di->Next = bag.DropItemList;
bag.DropItemList = di;
GC::WriteBarrier(di);
}
//==========================================================================

View file

@ -8,6 +8,8 @@
#include "doomerrors.h"
#include "memarena.h"
extern FMemArena ClassDataAllocator;
#define MAX_RETURNS 8 // Maximum number of results a function called by script code can return
#define MAX_TRY_DEPTH 8 // Maximum number of nested TRYs in a single function
@ -716,7 +718,7 @@ public:
void *operator new(size_t size)
{
return Allocator.Alloc(size);
return ClassDataAllocator.Alloc(size);
}
void operator delete(void *block) {}
@ -729,7 +731,6 @@ public:
}
AllFunctions.Clear();
}
static FMemArena Allocator;
static TArray<VMFunction *> AllFunctions;
protected:
};

View file

@ -43,7 +43,6 @@ int VMCalls[10];
IMPLEMENT_CLASS(VMException, false, false)
FMemArena VMFunction::Allocator(32768);
TArray<VMFunction *> VMFunction::AllFunctions;
@ -95,7 +94,7 @@ void VMScriptFunction::Alloc(int numops, int numkonstd, int numkonstf, int numko
assert(numkonsts >= 0 && numkonsts <= 65535);
assert(numkonsta >= 0 && numkonsta <= 65535);
assert(numlinenumbers >= 0 && numlinenumbers <= 65535);
void *mem = Allocator.Alloc(numops * sizeof(VMOP) +
void *mem = ClassDataAllocator.Alloc(numops * sizeof(VMOP) +
numkonstd * sizeof(int) +
numkonstf * sizeof(double) +
numkonsts * sizeof(FString) +

View file

@ -256,7 +256,7 @@ class BlockThingsIterator : Object native
native bool Next();
}
class DropItem : Object native
struct DropItem native
{
native readonly DropItem Next;
native readonly name Name;