From d1b2ef53686d18c6e1a9427df49e194e60dbc806 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 10 Feb 2016 14:38:08 +0100 Subject: [PATCH] - some refactoring of olddecorations.cpp to move some repeated code into a subfunction. --- src/d_dehacked.cpp | 2 +- src/info.cpp | 5 +++++ src/info.h | 2 ++ src/thingdef/olddecorations.cpp | 18 +++++++++--------- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 82d26d7ab..cceb7c20e 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1715,7 +1715,7 @@ static void SetPointer(FState *state, PFunction *sym, int frame = 0) { if (sym == NULL) { - state->SetAction(NULL); + state->ClearAction(); return; } else diff --git a/src/info.cpp b/src/info.cpp index 3a800e2cf..d827cd7a0 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -61,6 +61,11 @@ FRandom FState::pr_statetics("StateTics"); cycle_t ActionCycles; +void FState::SetAction(const char *name) +{ + ActionFunc = FindGlobalActionFunction(name)->Variants[0].Implementation; +} + bool FState::CallAction(AActor *self, AActor *stateowner) { if (ActionFunc != NULL) diff --git a/src/info.h b/src/info.h index 460adb0fb..5d9d36879 100644 --- a/src/info.h +++ b/src/info.h @@ -126,6 +126,8 @@ struct FState Frame = frame - 'A'; } void SetAction(VMFunction *func) { ActionFunc = func; } + void ClearAction() { ActionFunc = NULL; } + void SetAction(const char *name); bool CallAction(AActor *self, AActor *stateowner); static PClassActor *StaticFindStateOwner (const FState *state); static PClassActor *StaticFindStateOwner (const FState *state, PClassActor *info); diff --git a/src/thingdef/olddecorations.cpp b/src/thingdef/olddecorations.cpp index fa543e372..b04c589ee 100644 --- a/src/thingdef/olddecorations.cpp +++ b/src/thingdef/olddecorations.cpp @@ -234,24 +234,24 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) { if (extra.bExplosive) { - type->OwnedStates[extra.DeathStart].SetAction(FindGlobalActionFunction("A_Explode")->Variants[0].Implementation); + type->OwnedStates[extra.DeathStart].SetAction("A_Explode"); } } else { // The first frame plays the death sound and // the second frame makes it nonsolid. - type->OwnedStates[extra.DeathStart].SetAction(FindGlobalActionFunction("A_Scream")->Variants[0].Implementation); + type->OwnedStates[extra.DeathStart].SetAction("A_Scream"); if (extra.bSolidOnDeath) { } else if (extra.DeathStart + 1 < extra.DeathEnd) { - type->OwnedStates[extra.DeathStart+1].SetAction(FindGlobalActionFunction("A_NoBlocking")->Variants[0].Implementation); + type->OwnedStates[extra.DeathStart+1].SetAction("A_NoBlocking"); } else { - type->OwnedStates[extra.DeathStart].SetAction(FindGlobalActionFunction("A_ScreamAndUnblock")->Variants[0].Implementation); + type->OwnedStates[extra.DeathStart].SetAction("A_ScreamAndUnblock"); } if (extra.DeathHeight == 0) @@ -283,17 +283,17 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) // The first frame plays the burn sound and // the second frame makes it nonsolid. - type->OwnedStates[extra.FireDeathStart].SetAction(FindGlobalActionFunction("A_ActiveSound")->Variants[0].Implementation); + type->OwnedStates[extra.FireDeathStart].SetAction("A_ActiveSound"); if (extra.bSolidOnBurn) { } else if (extra.FireDeathStart + 1 < extra.FireDeathEnd) { - type->OwnedStates[extra.FireDeathStart+1].SetAction(FindGlobalActionFunction("A_NoBlocking")->Variants[0].Implementation); + type->OwnedStates[extra.FireDeathStart+1].SetAction("A_NoBlocking"); } else { - type->OwnedStates[extra.FireDeathStart].SetAction(FindGlobalActionFunction("A_ActiveAndUnblock")->Variants[0].Implementation); + type->OwnedStates[extra.FireDeathStart].SetAction("A_ActiveAndUnblock"); } if (extra.BurnHeight == 0) extra.BurnHeight = ((AActor*)(type->Defaults))->height; @@ -314,14 +314,14 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) type->OwnedStates[i].Tics = 5; type->OwnedStates[i].TicRange = 0; type->OwnedStates[i].Misc1 = 0; - type->OwnedStates[i].SetAction(FindGlobalActionFunction("A_FreezeDeath")->Variants[0].Implementation); + type->OwnedStates[i].SetAction("A_FreezeDeath"); i = type->NumOwnedStates - 1; type->OwnedStates[i].NextState = &type->OwnedStates[i]; type->OwnedStates[i].Tics = 1; type->OwnedStates[i].TicRange = 0; type->OwnedStates[i].Misc1 = 0; - type->OwnedStates[i].SetAction(FindGlobalActionFunction("A_FreezeDeathChunks")->Variants[0].Implementation); + type->OwnedStates[i].SetAction("A_FreezeDeathChunks"); bag.statedef.SetStateLabel("Ice", &type->OwnedStates[extra.IceDeathStart]); } else if (extra.bGenericIceDeath)