- scriptified the BeginPlay methods of the VavoomLight classes.

- moved m_Radius back to arg[3] and arg[4], so that scripts have access to light sizes again.
This commit is contained in:
Christoph Oelckers 2017-01-18 19:10:25 +01:00
parent 1ce7b80158
commit 87b9b6111d
4 changed files with 81 additions and 108 deletions

View file

@ -110,49 +110,6 @@ DEFINE_CLASS_PROPERTY(type, S, DynamicLight)
//
//==========================================================================
IMPLEMENT_CLASS(ADynamicLight, false, false)
IMPLEMENT_CLASS(AVavoomLight, false, false)
IMPLEMENT_CLASS(AVavoomLightWhite, false, false)
IMPLEMENT_CLASS(AVavoomLightColor, false, false)
void AVavoomLight::BeginPlay ()
{
// This must not call Super::BeginPlay!
ChangeStatNum(STAT_DLIGHT);
if (Sector) AddZ(-Sector->floorplane.ZatPoint(this), false);
lighttype = PointLight;
}
void AVavoomLightWhite::BeginPlay ()
{
m_Radius[0] = args[0] * 4;
args[LIGHT_RED] = 128;
args[LIGHT_GREEN] = 128;
args[LIGHT_BLUE] = 128;
if (gl.legacyMode && (flags4 & MF4_ATTENUATE))
{
m_Radius[0] = m_Radius[0] * 2 / 3;
}
Super::BeginPlay();
}
void AVavoomLightColor::BeginPlay ()
{
int l_args[5];
memcpy(l_args, args, sizeof(l_args));
memset(args, 0, sizeof(args));
m_Radius[0] = l_args[0] * 4;
args[LIGHT_RED] = l_args[1] >> 1;
args[LIGHT_GREEN] = l_args[2] >> 1;
args[LIGHT_BLUE] = l_args[3] >> 1;
if (gl.legacyMode && (flags4 & MF4_ATTENUATE))
{
m_Radius[0] = m_Radius[0] * 2 / 3;
}
Super::BeginPlay();
}
static FRandom randLight;
@ -174,8 +131,7 @@ void ADynamicLight::Serialize(FSerializer &arc)
arc("lightflags", lightflags, def->lightflags)
("lighttype", lighttype, def->lighttype)
("tickcount", m_tickCount, def->m_tickCount)
("currentradius", m_currentRadius, def->m_currentRadius)
.Array("lightradius", m_Radius, def->m_Radius, 2);
("currentradius", m_currentRadius, def->m_currentRadius);
if (lighttype == PulseLight)
arc("lastupdate", m_lastUpdate, def->m_lastUpdate)
@ -202,15 +158,13 @@ void ADynamicLight::BeginPlay()
//Super::BeginPlay();
ChangeStatNum(STAT_DLIGHT);
m_Radius[0] = args[LIGHT_INTENSITY];
m_Radius[1] = args[LIGHT_SECONDARY_INTENSITY];
specialf1 = DAngle(double(SpawnAngle)).Normalized360().Degrees;
visibletoplayer = true;
if (gl.legacyMode && (flags4 & MF4_ATTENUATE))
{
m_Radius[0] = m_Radius[0] * 2 / 3;
m_Radius[1] = m_Radius[1] * 2 / 3;
args[LIGHT_INTENSITY] = args[LIGHT_INTENSITY] * 2 / 3;
args[LIGHT_SECONDARY_INTENSITY] = args[LIGHT_SECONDARY_INTENSITY] * 2 / 3;
}
}
@ -242,7 +196,7 @@ void ADynamicLight::Activate(AActor *activator)
//Super::Activate(activator);
flags2&=~MF2_DORMANT;
m_currentRadius = float(m_Radius[0]);
m_currentRadius = float(args[LIGHT_INTENSITY]);
m_tickCount = 0;
if (lighttype == PulseLight)
@ -250,7 +204,7 @@ void ADynamicLight::Activate(AActor *activator)
float pulseTime = specialf1 / TICRATE;
m_lastUpdate = level.maptime;
m_cycler.SetParams(float(m_Radius[1]), float(m_Radius[0]), pulseTime);
m_cycler.SetParams(float(args[LIGHT_SECONDARY_INTENSITY]), float(args[LIGHT_INTENSITY]), pulseTime);
m_cycler.ShouldCycle(true);
m_cycler.SetCycleType(CYCLE_Sin);
m_currentRadius = m_cycler.GetVal();
@ -314,22 +268,22 @@ void ADynamicLight::Tick()
BYTE rnd = randLight();
float pct = specialf1 / 360.f;
m_currentRadius = float(m_Radius[rnd >= pct * 255]);
m_currentRadius = float(args[LIGHT_INTENSITY + (rnd >= pct * 255)]);
break;
}
case RandomFlickerLight:
{
int flickerRange = m_Radius[1] - m_Radius[0];
int flickerRange = args[LIGHT_SECONDARY_INTENSITY] - args[LIGHT_INTENSITY];
float amt = randLight() / 255.f;
if (m_tickCount > specialf1)
{
m_tickCount = 0;
}
if (m_tickCount++ == 0 || m_currentRadius > m_Radius[1])
if (m_tickCount++ == 0 || m_currentRadius > args[LIGHT_SECONDARY_INTENSITY])
{
m_currentRadius = float(m_Radius[0] + (amt * flickerRange));
m_currentRadius = float(args[LIGHT_INTENSITY] + (amt * flickerRange));
}
break;
}
@ -347,14 +301,14 @@ void ADynamicLight::Tick()
case RandomColorFlickerLight:
{
int flickerRange = m_Radius[1] - m_Radius[0];
int flickerRange = args[LIGHT_SECONDARY_INTENSITY] - args[LIGHT_INTENSITY];
float amt = randLight() / 255.f;
m_tickCount++;
if (m_tickCount > specialf1)
{
m_currentRadius = m_Radius[0] + (amt * flickerRange);
m_currentRadius = args[LIGHT_INTENSITY] + (amt * flickerRange);
m_tickCount = 0;
}
break;
@ -376,7 +330,7 @@ void ADynamicLight::Tick()
}
case PointLight:
m_currentRadius = float(m_Radius[0]);
m_currentRadius = float(args[LIGHT_INTENSITY]);
break;
}
UpdateLocation();
@ -428,7 +382,7 @@ void ADynamicLight::UpdateLocation()
if (lighttype == FlickerLight || lighttype == RandomFlickerLight || lighttype == PulseLight)
{
intensity = float(MAX(m_Radius[0], m_Radius[1]));
intensity = float(MAX(args[LIGHT_INTENSITY], args[LIGHT_SECONDARY_INTENSITY]));
}
else
{

View file

@ -178,8 +178,8 @@ void FLightDefaults::ApplyProperties(ADynamicLight * light) const
light->SetOffset(m_Pos);
light->halo = m_halo;
for (int a = 0; a < 3; a++) light->args[a] = clamp<int>((int)(m_Args[a]), 0, 255);
light->m_Radius[0] = int(m_Args[LIGHT_INTENSITY]);
light->m_Radius[1] = int(m_Args[LIGHT_SECONDARY_INTENSITY]);
light->args[LIGHT_INTENSITY] = int(m_Args[LIGHT_INTENSITY]);
light->args[LIGHT_SECONDARY_INTENSITY] = int(m_Args[LIGHT_SECONDARY_INTENSITY]);
light->flags4 &= ~(MF4_ADDITIVE | MF4_SUBTRACTIVE | MF4_DONTLIGHTSELF);
if (m_subtractive) light->flags4 |= MF4_SUBTRACTIVE;
if (m_additive) light->flags4 |= MF4_ADDITIVE;
@ -190,7 +190,7 @@ void FLightDefaults::ApplyProperties(ADynamicLight * light) const
float pulseTime = float(m_Param / TICRATE);
light->m_lastUpdate = level.maptime;
light->m_cycler.SetParams(float(light->m_Radius[1]), float(light->m_Radius[0]), pulseTime, oldtype == PulseLight);
light->m_cycler.SetParams(float(light->args[LIGHT_SECONDARY_INTENSITY]), float(light->args[LIGHT_INTENSITY]), pulseTime, oldtype == PulseLight);
light->m_cycler.ShouldCycle(true);
light->m_cycler.SetCycleType(CYCLE_Sin);
light->m_currentRadius = light->m_cycler.GetVal();

View file

@ -135,7 +135,6 @@ protected:
public:
int m_tickCount;
int m_Radius[2];
BYTE lightflags;
BYTE lighttype;
bool owned;
@ -147,28 +146,6 @@ public:
};
class AVavoomLight : public ADynamicLight
{
DECLARE_CLASS (AVavoomLight, ADynamicLight)
public:
virtual void BeginPlay();
};
class AVavoomLightWhite : public AVavoomLight
{
DECLARE_CLASS (AVavoomLightWhite, AVavoomLight)
public:
virtual void BeginPlay();
};
class AVavoomLightColor : public AVavoomLight
{
DECLARE_CLASS (AVavoomLightColor, AVavoomLight)
public:
void BeginPlay();
};
enum
{
STAT_DLIGHT=64

View file

@ -1,5 +1,28 @@
class DynamicLight : Actor native
{
enum EArgs
{
LIGHT_RED = 0,
LIGHT_GREEN = 1,
LIGHT_BLUE = 2,
LIGHT_INTENSITY = 3,
LIGHT_SECONDARY_INTENSITY = 4,
LIGHT_SCALE = 3,
};
enum ELightType
{
PointLight,
PulseLight,
FlickerLight,
RandomFlickerLight,
SectorLight,
SpotLight,
ColorPulseLight,
ColorFlickerLight,
RandomColorFlickerLight
};
Default
{
Height 0;
@ -136,29 +159,6 @@ class PointLightFlickerRandomSubtractive : PointLightFlickerRandom
}
}
class VavoomLight : DynamicLight native
{
Default
{
}
}
class VavoomLightWhite : VavoomLight native
{
Default
{
}
}
class VavoomLightColor : VavoomLight native
{
Default
{
}
}
class PointLightAttenuated : PointLight
{
Default
@ -199,3 +199,45 @@ class PointLightFlickerRandomAttenuated :PointLightFlickerRandom
}
}
class VavoomLight : DynamicLight
{
Default
{
DynamicLight.Type "Point";
}
override void BeginPlay ()
{
if (CurSector) AddZ(-CurSector.floorplane.ZatPoint(pos.XY), false); // z is absolute for Vavoom lights
Super.BeginPlay();
}
}
class VavoomLightWhite : VavoomLight
{
override void BeginPlay ()
{
args[LIGHT_INTENSITY] = args[0] * 4;
args[LIGHT_RED] = 128;
args[LIGHT_GREEN] = 128;
args[LIGHT_BLUE] = 128;
Super.BeginPlay();
}
}
class VavoomLightColor : VavoomLight
{
override void BeginPlay ()
{
int radius = args[0] * 4;
args[LIGHT_RED] = args[1] >> 1;
args[LIGHT_GREEN] = args[2] >> 1;
args[LIGHT_BLUE] = args[3] >> 1;
args[LIGHT_INTENSITY] = radius;
Super.BeginPlay();
}
}