//************************************************************************** //** //** ## ## ## ## ## #### #### ### ### //** ## ## ## ## ## ## ## ## ## ## #### #### //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## //** ## ## ######## ## ## ## ## ## ## ## ### ## //** ### ## ## ### ## ## ## ## ## ## //** # ## ## # #### #### ## ## //** //** $Id: LightEffect.vc 1583 2006-06-27 19:05:42Z dj_jl $ //** //** Copyright (C) 1999-2006 Jānis Legzdiņš //** //** This program is free software; you can redistribute it and/or //** modify it under the terms of the GNU General Public License //** as published by the Free Software Foundation; either version 2 //** of the License, or (at your option) any later version. //** //** This program is distributed in the hope that it will be useful, //** but WITHOUT ANY WARRANTY; without even the implied warranty of //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //** GNU General Public License for more details. //** //************************************************************************** class LightEffect : Lighting; enum { LIGHTEV_Fade, LIGHTEV_Glow, LIGHTEV_Flicker, LIGHTEV_Strobe }; int Type; int Value1; int Value2; float Time1; float Time2; int Direction; float Time; float Delta; //============================================================================ // // Init // //============================================================================ void Init(sector_t* InSector, int Arg1, int Arg2, int Arg3, int Arg4, int Arg5, int InType) { Sector = InSector; Sector->LightingData = self; Type = InType; Time = 0.0; switch (Type) { case LIGHTEV_Fade: Value1 = Arg2; // destination lightlevel Delta = itof((Arg2 - Sector->params.lightlevel) / Arg3) * 32.0; // delta lightlevel if (Sector->params.lightlevel <= Arg2) { Direction = 1; // get brighter } else { Direction = -1; } break; case LIGHTEV_Glow: Value1 = Arg2; // upper lightlevel Value2 = Arg3; // lower lightlevel Delta = itof((Arg2 - Sector->params.lightlevel) / Arg4) * 32.0; // lightlevel delta if (Sector->params.lightlevel <= Arg2) { Direction = 1; // get brighter } else { Direction = -1; } break; case LIGHTEV_Flicker: Value1 = Arg2; // upper lightlevel Value2 = Arg3; // lower lightlevel Sector->params.lightlevel = Value1; Time = itof((P_Random() & 64) + 1) / 32.0; break; case LIGHTEV_Strobe: Value1 = Arg2; // upper lightlevel Value2 = Arg3; // lower lightlevel Time1 = itof(Arg4) / 35.0; // upper tics Time2 = itof(Arg5) / 35.0; // lower tics Time = itof(Arg4) / 35.0; Sector->params.lightlevel = Value1; break; } } //============================================================================ // // Tick // //============================================================================ void Tick(float DeltaTime) { int d; if (Time) { Time -= DeltaTime; if (Time <= 0.0) { Time = 0.0; } return; } switch (Type) { case LIGHTEV_Fade: d = ftoi(Delta * DeltaTime); if (!d) d = Direction; Sector->params.lightlevel += d; if (Direction == 1) { if (Sector->params.lightlevel >= Value1) { Sector->params.lightlevel = Value1; if (Sector->LightingData == self) Sector->LightingData = none; Destroy(); } } else if (Sector->params.lightlevel <= Value1) { Sector->params.lightlevel = Value1; if (Sector->LightingData == self) Sector->LightingData = none; Destroy(); } break; case LIGHTEV_Glow: Sector->params.lightlevel += ftoi(Delta * DeltaTime); if (Direction == 1) { if (Sector->params.lightlevel >= Value1) { Sector->params.lightlevel = Value1; Delta = -Delta; Direction = -1; // reverse direction } } else if (Sector->params.lightlevel <= Value2) { Sector->params.lightlevel = Value2; Delta = -Delta; Direction = 1; // reverse direction } break; case LIGHTEV_Flicker: if (Sector->params.lightlevel == Value1) { Sector->params.lightlevel = Value2; Time = itof((P_Random() & 7) + 1) / 32.0; } else { Sector->params.lightlevel = Value1; Time = itof((P_Random() & 31) + 1) / 32.0; } break; case LIGHTEV_Strobe: if (Sector->params.lightlevel == Value1) { Sector->params.lightlevel = Value2; Time = Time2; } else { Sector->params.lightlevel = Value1; Time = Time1; } break; } } defaultproperties { }