- scriptified a_hereticimp.cpp.

- fixed the comparison against 0 simplification which did not negate the result for '=='.
This commit is contained in:
Christoph Oelckers 2016-11-02 11:44:48 +01:00
parent 8b21719068
commit 570572fcf2
4 changed files with 128 additions and 151 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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<FxConstant *>(left)->GetValue().GetInt() == 0;
break;
bool leftisnull;
switch (left->ValueType->GetRegType())
{
case REGT_INT:
leftisnull = static_cast<FxConstant *>(left)->GetValue().GetInt() == 0;
break;
case REGT_FLOAT:
assert(left->ValueType->GetRegCount() == 1); // vectors should not be able to get here.
leftisnull = static_cast<FxConstant *>(left)->GetValue().GetFloat() == 0;
break;
case REGT_FLOAT:
assert(left->ValueType->GetRegCount() == 1); // vectors should not be able to get here.
leftisnull = static_cast<FxConstant *>(left)->GetValue().GetFloat() == 0;
break;
case REGT_POINTER:
leftisnull = static_cast<FxConstant *>(left)->GetValue().GetPointer() == nullptr;
break;
case REGT_POINTER:
leftisnull = static_cast<FxConstant *>(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<FxConstant *>(right)->GetValue().GetInt() == 0;
break;
bool rightisnull;
switch (right->ValueType->GetRegType())
{
case REGT_INT:
rightisnull = static_cast<FxConstant *>(right)->GetValue().GetInt() == 0;
break;
case REGT_FLOAT:
assert(right->ValueType->GetRegCount() == 1); // vectors should not be able to get here.
rightisnull = static_cast<FxConstant *>(right)->GetValue().GetFloat() == 0;
break;
case REGT_FLOAT:
assert(right->ValueType->GetRegCount() == 1); // vectors should not be able to get here.
rightisnull = static_cast<FxConstant *>(right)->GetValue().GetFloat() == 0;
break;
case REGT_POINTER:
rightisnull = static_cast<FxConstant *>(right)->GetValue().GetPointer() == nullptr;
break;
case REGT_POINTER:
rightisnull = static_cast<FxConstant *>(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);
}
}
}
}

View file

@ -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 -------------------------------------------------------