From 570572fcf2f6561c920279c98df53b79a79d86b7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 2 Nov 2016 11:44:48 +0100 Subject: [PATCH] - scriptified a_hereticimp.cpp. - fixed the comparison against 0 simplification which did not negate the result for '=='. --- src/CMakeLists.txt | 1 - src/g_heretic/a_hereticimp.cpp | 96 ----------------- src/scripting/codegeneration/codegen.cpp | 103 ++++++++++--------- wadsrc/static/zscript/heretic/hereticimp.txt | 79 ++++++++++++-- 4 files changed, 128 insertions(+), 151 deletions(-) delete mode 100644 src/g_heretic/a_hereticimp.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12df2e61c..adc90444d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -845,7 +845,6 @@ set( NOT_COMPILED_SOURCE_FILES g_heretic/a_chicken.cpp g_heretic/a_dsparil.cpp g_heretic/a_hereticartifacts.cpp - g_heretic/a_hereticimp.cpp g_heretic/a_hereticweaps.cpp g_heretic/a_ironlich.cpp g_heretic/a_knight.cpp diff --git a/src/g_heretic/a_hereticimp.cpp b/src/g_heretic/a_hereticimp.cpp deleted file mode 100644 index 39dfb049e..000000000 --- a/src/g_heretic/a_hereticimp.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* -#include "templates.h" -#include "actor.h" -#include "info.h" -#include "m_random.h" -#include "s_sound.h" -#include "p_local.h" -#include "gstrings.h" -#include "vm.h" -*/ - -static FRandom pr_impmsatk ("ImpMsAttack"); -static FRandom pr_imp ("ImpExplode"); - - -//---------------------------------------------------------------------------- -// -// PROC A_ImpMsAttack -// -//---------------------------------------------------------------------------- - -DEFINE_ACTION_FUNCTION(AActor, A_ImpMsAttack) -{ - PARAM_SELF_PROLOGUE(AActor); - - if (!self->target || pr_impmsatk() > 64) - { - self->SetState (self->SeeState); - return 0; - } - A_SkullAttack(self, 12.); - return 0; -} - -//---------------------------------------------------------------------------- -// -// PROC A_ImpExplode -// -//---------------------------------------------------------------------------- - -DEFINE_ACTION_FUNCTION(AActor, A_ImpExplode) -{ - PARAM_SELF_PROLOGUE(AActor); - - AActor *chunk; - - self->flags &= ~MF_NOGRAVITY; - - chunk = Spawn("HereticImpChunk1", self->Pos(), ALLOW_REPLACE); - chunk->Vel.X = pr_imp.Random2() / 64.; - chunk->Vel.Y = pr_imp.Random2() / 64.; - chunk->Vel.Z = 9; - - chunk = Spawn("HereticImpChunk2", self->Pos(), ALLOW_REPLACE); - chunk->Vel.X = pr_imp.Random2() / 64.; - chunk->Vel.Y = pr_imp.Random2() / 64.; - chunk->Vel.Z = 9; - if (self->special1 == 666) - { // Extreme death crash - self->SetState (self->FindState("XCrash")); - } - return 0; -} - -//---------------------------------------------------------------------------- -// -// PROC A_ImpDeath -// -//---------------------------------------------------------------------------- - -DEFINE_ACTION_FUNCTION(AActor, A_ImpDeath) -{ - PARAM_SELF_PROLOGUE(AActor); - - self->flags &= ~MF_SOLID; - self->flags2 |= MF2_FLOORCLIP; - return 0; -} - -//---------------------------------------------------------------------------- -// -// PROC A_ImpXDeath1 -// -//---------------------------------------------------------------------------- - -DEFINE_ACTION_FUNCTION(AActor, A_ImpXDeath1) -{ - PARAM_SELF_PROLOGUE(AActor); - - self->flags &= ~MF_SOLID; - self->flags |= MF_NOGRAVITY; - self->flags2 |= MF2_FLOORCLIP; - self->special1 = 666; // Flag the crash routine - return 0; -} - diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index f1dfab523..d3923b231 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -3091,64 +3091,71 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx) } else { - // also simplify comparisons against zero. For these a bool cast on the other value will do just as well and create better code. - if (left->isConstant()) + // also simplify comparisons against zero. For these a bool cast/unary not on the other value will do just as well and create better code. + if (Operator != TK_ApproxEq) { - bool leftisnull; - switch (left->ValueType->GetRegType()) + if (left->isConstant()) { - case REGT_INT: - leftisnull = static_cast(left)->GetValue().GetInt() == 0; - break; + bool leftisnull; + switch (left->ValueType->GetRegType()) + { + case REGT_INT: + leftisnull = static_cast(left)->GetValue().GetInt() == 0; + break; - case REGT_FLOAT: - assert(left->ValueType->GetRegCount() == 1); // vectors should not be able to get here. - leftisnull = static_cast(left)->GetValue().GetFloat() == 0; - break; + case REGT_FLOAT: + assert(left->ValueType->GetRegCount() == 1); // vectors should not be able to get here. + leftisnull = static_cast(left)->GetValue().GetFloat() == 0; + break; - case REGT_POINTER: - leftisnull = static_cast(left)->GetValue().GetPointer() == nullptr; - break; + case REGT_POINTER: + leftisnull = static_cast(left)->GetValue().GetPointer() == nullptr; + break; + + default: + leftisnull = false; + } + if (leftisnull) + { + FxExpression *x; + if (Operator == TK_Eq) x = new FxUnaryNotBoolean(right); + else x = new FxBoolCast(right); + right = nullptr; + delete this; + return x->Resolve(ctx); + } - default: - leftisnull = false; } - if (leftisnull) + if (right->isConstant()) { - FxExpression *x = new FxBoolCast(right); - right = nullptr; - delete this; - return x->Resolve(ctx); - } - - } - if (right->isConstant()) - { - bool rightisnull; - switch (right->ValueType->GetRegType()) - { - case REGT_INT: - rightisnull = static_cast(right)->GetValue().GetInt() == 0; - break; + bool rightisnull; + switch (right->ValueType->GetRegType()) + { + case REGT_INT: + rightisnull = static_cast(right)->GetValue().GetInt() == 0; + break; - case REGT_FLOAT: - assert(right->ValueType->GetRegCount() == 1); // vectors should not be able to get here. - rightisnull = static_cast(right)->GetValue().GetFloat() == 0; - break; + case REGT_FLOAT: + assert(right->ValueType->GetRegCount() == 1); // vectors should not be able to get here. + rightisnull = static_cast(right)->GetValue().GetFloat() == 0; + break; - case REGT_POINTER: - rightisnull = static_cast(right)->GetValue().GetPointer() == nullptr; - break; + case REGT_POINTER: + rightisnull = static_cast(right)->GetValue().GetPointer() == nullptr; + break; - default: - rightisnull = false; - } - if (rightisnull) - { - FxExpression *x = new FxBoolCast(left); - left = nullptr; - delete this; - return x->Resolve(ctx); + default: + rightisnull = false; + } + if (rightisnull) + { + FxExpression *x; + if (Operator == TK_Eq) x = new FxUnaryNotBoolean(left); + else x = new FxBoolCast(left); + left = nullptr; + delete this; + return x->Resolve(ctx); + } } } } diff --git a/wadsrc/static/zscript/heretic/hereticimp.txt b/wadsrc/static/zscript/heretic/hereticimp.txt index 5764094de..34738ed56 100644 --- a/wadsrc/static/zscript/heretic/hereticimp.txt +++ b/wadsrc/static/zscript/heretic/hereticimp.txt @@ -3,6 +3,8 @@ class HereticImp : Actor { + bool extremecrash; + Default { Health 40; @@ -26,12 +28,6 @@ class HereticImp : Actor HitObituary "$OB_HERETICIMPHIT"; } - native void A_ImpMsAttack(); - native void A_ImpDeath(); - native void A_ImpXDeath1(); - native void A_ImpExplode(); - - States { Spawn: @@ -75,6 +71,77 @@ class HereticImp : Actor IMPX Z -1; Stop; } + + + //---------------------------------------------------------------------------- + // + // PROC A_ImpMsAttack + // + //---------------------------------------------------------------------------- + + void A_ImpMsAttack() + { + if (!target || random[ImpMSAtk]() > 64) + { + SetState (SeeState); + return; + } + A_SkullAttack(12); +} + + //---------------------------------------------------------------------------- + // + // PROC A_ImpExplode + // + //---------------------------------------------------------------------------- + + void A_ImpExplode() + { + Actor chunk; + + bNoGravity = false; + + chunk = Spawn("HereticImpChunk1", pos, ALLOW_REPLACE); + chunk.vel.x = random2[ImpExplode]() / 64.; + chunk.vel.y = random2[ImpExplode]() / 64.; + chunk.vel.z = 9; + + chunk = Spawn("HereticImpChunk2", pos, ALLOW_REPLACE); + chunk.vel.x = random2[ImpExplode]() / 64.; + chunk.vel.y = random2[ImpExplode]() / 64.; + chunk.vel.z = 9; + + if (extremecrash) + { + SetState ("XCrash"); + } + } + + //---------------------------------------------------------------------------- + // + // PROC A_ImpDeath + // + //---------------------------------------------------------------------------- + + void A_ImpDeath() + { + bSolid = false; + bFloorClip = true; + } + + //---------------------------------------------------------------------------- + // + // PROC A_ImpXDeath1 + // + //---------------------------------------------------------------------------- + + void A_ImpXDeath1() + { + bSolid = false; + bFloorClip = true; + bNoGravity = true; + extremecrash = true; + } } // Heretic imp leader -------------------------------------------------------