Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

ParticleSystems.ParticleGenerator


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
//=============================================================================
// $Author: Mfox $
// $Date: 2/27/03 7:06p $
// $Revision: 25 $
//=============================================================================

//------------------------------------------------------------------------------
// Name:	ParticleGenerator.uc
// Author:	Aaron R Leiby
// Date:	4 March 2000
//------------------------------------------------------------------------------
// Description:	Base class of all particle generators.
//------------------------------------------------------------------------------
// How to use this class:
//------------------------------------------------------------------------------

class ParticleGenerator extends Actor
	abstract
	native;

//////////////
// Versions //
//////////////

const PARTICLEVERSION_Current			= 3;
const PARTICLEVERSION_AutoLit			= 3;
const PARTICLEVERSION_AffectingForces	= 2;
const PARTICLEVERSION_NumParticlesFix	= 1;

///////////////
// Variables //
///////////////

var() public  editinline OrderedArray<ParticleTemplate> ParticleTemplates;	

var() public  editinline OrderedArray<Force> Forces;// All forces currently affecting the particles of this system.
													// (Wind and stuff may add its own forces to the list.)
													// (Many ParticleGenerators may all reference the same force.)

////////////////////////
// Advanced variables //
////////////////////////

var(ParticleAdvanced)
      public  Array< Class<Force> > DefaultForces;	// Forces automatically installed when spawned.

var(ParticleAdvanced)
      public  Array<Name>         IgnoredForces;	// Forces may be assigned a label.  This particle generator
													// will ignore forces with matching labels (unless explicitly
													// added to the Forces array by an LD).  Only enforced via the
													// AddForce function.

var(ParticleAdvanced)
      public  float               PrimeTime;		// If you want a ParticleGenerator to appear like it has been
													// running for a while already when it is first spawned, then 
													// set its PrimeTime accordingly (in seconds).  Note: Forces
													// will be evaluated in their current state at start-up.

var(ParticleAdvanced)
      public  float               MaxTickSize;		// Tick updates are quantized into chunks of this size (if 
													// they are larger).  This way we can interpolate the generator's
													// movement, rotation or whatever and make it look like it was
													// updated at 120fps (or whatever) rather than the actual 30fps.

var(ParticleAdvanced)
      public  float               IdleTime;			// How many seconds pass of not being drawn, before the tick code 
													// gets shut off.
var(ParticleAdvanced)
      public  float               ParticleLifeSpan;	// Since LifeSpan doesn't get updated if our zone hasn't been drawn
													// recently, we need to manually track it ourself.  Set this variable
													// when you want the generator to be destroyed in X seconds.

var(ParticleAdvanced)
      public  int                 ParticleVersion;	// Used to maintain backward compatibility across builds.  Allows
													// old systems to be identified and fixed in newer builds.

var(ParticleAdvanced)
      public  bool                bInterpolate;		// Break ticks up into MaxTickSize chuncks and interpolate the
													// location accordingly.  (Makes for smoother distribution of 
													// particles.)

var(ParticleAdvanced)
      public  bool                bCollisionBound;	// Use collision cylinder for bounding box visibility instead of
													// true bounding box visiblilty calculated by LocationForces.

var(ParticleAdvanced)
      public  bool                bShowBoundingBox;	// Displays the combined bounding boxes of all ParticleTemplates
													// as used by the visibility code.

var(ParticleAdvanced)
      public  bool                bLockParticles;	// Disable forces, cleaning, and render relative to the system.

var   private bool                bAttachment;		// Set if we are a golem attachment.

var   private           matrix    LockedLocalToWorld;	// Used interally for rendering locked systems relatively.

var   private transient float     LastTimeDrawn;
var   private transient vector    LastLocation;
var   private transient float     LastPitch, LastYaw, LastRoll;
var   private transient float     LastBoundSizeSquared;


/////////////////////////
// Selection variables //
/////////////////////////

var(ParticleSelection)
      public  enum Select
{
	SELECT_Linear,									// Cyclically iterate through the ParticleTemplates array.
	SELECT_Random									// Randomly pick a particle from the ParticleTemplates array.

} SelectionMethod;

var(ParticleSelection) 
      public bool bLinearFrequenciesChanged;		// If you are using Linear Distribution, you need to set this 
													// variable to true if you change any of the templates' weights.  
													// This tells the underlaying code to update itself accordingly.
													// Once the weights have been recalculated (i.e. the next time 
													// the frame is drawn), this variable will automatically be reset 
													// to false.

// Used internally.
var private float LargestWeight;					// The currently largest linear weight.
var private int   TemplateIndex;					// Current index into the particle template list.
var private int   TemplateIteration;				// Keeps track of how many times we have iterated through the 
													// template list in linear distribution.


/////////////////////
// Trigger support //
/////////////////////

var(              ) public  bool  bOn;
var(TriggerSupport) public  bool  bInitiallyOn;
var(TriggerSupport) public  float TimerDuration;
var                 private float InternalTimer;

var(TriggerSupport) public  int   MaxParticles;		// Maximum particles emitted per trigger.
var                 private int   ParticleCount;	// Used internally to enforce ParticleCount.

var(TriggerSupport) public  Button Trig, UnTrig;

// Ramp support.
var(TriggerSupport) public  float RampUpTime;
var(TriggerSupport) public  float RampDownTime;
var                 private float RampTimer;
var                 protected float VolumeScale;
var private enum Ramp
{
	RAMP_None,
	RAMP_Up,
	RAMP_Down

} RampDir;

// Sound support.
var(Sound) public sound SoundOn, SoundOff, SoundLoop;


///////////////
// Overrides //
///////////////

//------------------------------------------------------------------------------
simulated event PreBeginPlay()
{
	Super.PreBeginPlay();
	if( bDeleteMe )
		return;
	bOn = bInitiallyOn;
	if( bLockParticles )
		bHidden = !bOn;
}

//------------------------------------------------------------------------------
simulated event PostBeginPlay()
{
	Super.PostBeginPlay();
	if( bDeleteMe )
		return;
	RegisterExternallyAffectedTemplates();
}

//------------------------------------------------------------------------------
simulated event Destroyed()
{
	UnRegisterExternallyAffectedTemplates();
	Super.Destroyed();
}

//------------------------------------------------------------------------------
function AutoDestroy()
{
	ParticleTemplates.Length = 0;
	Forces.Length = 0;
}

/////////////////////
// Trigger support //
/////////////////////

//------------------------------------------------------------------------------
simulated event TurnOn()
{
	if(RampUpTime>0)
	{
		RampDir=RAMP_Up;
		RampTimer=RampUpTime;
	}
	else
	{
		RampDir=RAMP_None;
		RampTimer=0;
	}

	ParticleCount = MaxParticles;

	bOn = true;

	// Force Linear frequencies to be recalculated if used.
//	bLinearFrequenciesChanged = true;	// this causes the concussion grenade ring to disappear (and other effects).  -- this was originally added to fix the kai/tosc transformation crash.
	TemplateIndex = 0;		// just resetting these two vars instead seems to also fix the kai/tosc transformation, but doesn't have the bad side effect of the above change.
	TemplateIteration = 1;

	if( bLockParticles )
		bHidden = false;

	if( SoundOn? )
		PlaySound( SoundOn );
	if( SoundLoop? )
		AmbientSound = SoundLoop;
}

//------------------------------------------------------------------------------
simulated event TurnOff()
{
	switch(RampDir)
	{
	case RAMP_None:
	case RAMP_Up:

		if(RampDownTime>0)
		{
			RampDir=RAMP_Down;
			RampTimer=RampDownTime;
		}
		else
		{
			RampDir=RAMP_None;
			RampTimer=0;
		}

		break;

	case RAMP_Down:

		if(RampUpTime>0)
		{
			RampDir=RAMP_Up;
			RampTimer=RampUpTime;
		}
		else
		{
			RampDir=RAMP_None;
			RampTimer=0;
		}

		break;

	default:
		warn("Invalid RampDir!");
		break;
	}

	bOn = RampDir!=RAMP_None;

	if( bLockParticles )
		bHidden = true;

	if( SoundOff? )
		PlaySound( SoundOff );
	if( SoundLoop? )
		AmbientSound = None;
}

//------------------------------------------------------------------------------
simulated function SendTrigger(){ Trigger(Self,Instigator); }
simulated function SendUnTrigger(){ UnTrigger(Self,Instigator); }

//------------------------------------------------------------------------------
// Toggles us on and off when triggered.
//------------------------------------------------------------------------------
simulated state() TriggerToggle
{
	simulated function Trigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		if(!bOn) TurnOn();
		else     TurnOff();
	}
}

//------------------------------------------------------------------------------
// Toggled when Triggered.
// Toggled back to initial state when UnTriggered.
//------------------------------------------------------------------------------
simulated state() TriggerControl
{
	simulated function Trigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		if(!bInitiallyOn) TurnOn();
		else              TurnOff();
	}

	simulated function UnTrigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		if(bInitiallyOn) TurnOn();
		else             TurnOff();
	}
}

//------------------------------------------------------------------------------
// Toggled when triggered.
// Toggled back to initial state after TimerDuration seconds.
//------------------------------------------------------------------------------
simulated state() TriggerTimed
{
	simulated function Trigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		if(!bInitiallyOn) TurnOn();
		else              TurnOff();
		InternalTimer = TimerDuration;	// bOn will be toggled automatically internally.
	}
}

////////////////
// Interfaces //
////////////////

public native event AddForce				( Force AddedForce );
public native event RemoveForce				( Force RemovedForce );
public native event RemoveForceType			( name ClassName, optional bool bAndSubclasses );
public native event AddTemplate				( ParticleTemplate T );
public native event RemoveTemplate			( ParticleTemplate T );
public native event RemoveTemplateType		( name ClassName, optional bool bAndSubclasses );
public native event GetParticleTemplates	( out Object T );	// (TArray<UParticleTemplate*>*)
public native event Conform					( ParticleGenerator Image, optional bool bDeleteExisting /* =true */ );
public native event Duplicate				( out ParticleGenerator D, Level L );
public native event ExchangeTemplate		( ParticleTemplate Old, ParticleTemplate New );
public native event Clean();
public native event LockParticles();
public native event UnLockParticles();
public native event ValidateComponents();
public native event RegisterExternallyAffectedTemplates();
public native event UnRegisterExternallyAffectedTemplates();
public native function float GetMaxLifeSpan();
public native event ManualTick( float DeltaSeconds );

static native function vector ParticleGetLocation( ParticleHandle P );
static native function ParticleSetLocation( ParticleHandle P, vector Loc );
static native function vector ParticleGetVelocity( ParticleHandle P );
static native function ParticleSetVelocity( ParticleHandle P, vector Vel );

public function SetAttachment( bool B ){ bAttachment=B; }


/////////////
// Helpers //
/////////////

//------------------------------------------------------------------------------
// Use this instead of calling Destroy() to give existing particles to 
// run their course.
//------------------------------------------------------------------------------
public simulated function ParticleDestroy()
{
	bOn = false;
	ParticleLifeSpan = GetMaxLifeSpan();
}

//------------------------------------------------------------------------------
public static function ParticleGenerator CreateNew( actor Helper, ParticleGenerator Template, optional vector Location )
{
	local ParticleGenerator Image;
	local ParticleGenerator NewSystem;

	assert(Template!=None);

	if( Location == vect(0,0,0) )
		Location = Helper.Location;

	Image = Template;

	// Fix ARL: When we spawn a new ParticleGenerator, its PostBeginPlay will call RegisterExternallyAffectedTemplates on all the old templates before they are conformed!!
	// (This is especially bad when those templates are from another package like AssaultFX and cause cross level dependencies which result in garbage collection leaks.)
	// (For now I've hacked it by adding an outer check in ALevelInfo::RegisterAffectedTemplate.)
	// (Might be good to check if this can happen to forces as well.)

	NewSystem = Helper.Spawn( Image.Class,,, Location, Image.Rotation, Image );
	if( NewSystem.bDeleteMe ) NewSystem = None;
	if( NewSystem != None )
	{
		NewSystem.Conform( Image, false );
		NewSystem.RegisterExternallyAffectedTemplates();
	}

	return NewSystem;
}

//------------------------------------------------------------------------------
public static function ParticleGenerator DynamicCreateNew( actor Helper, class Type, string TemplateName, optional vector Location )
{
	local ParticleGenerator Image;
	local ParticleGenerator NewSystem;

	if( Location == vect(0,0,0) )
		Location = Helper.Location;

	Image = ParticleGenerator(DynamicLoadObject( TemplateName, Type ));

	if( Image != None )
	{
		NewSystem = Helper.Spawn( Image.Class,,, Location, Image.Rotation, Image );
		if( NewSystem.bDeleteMe ) NewSystem = None;
		if( NewSystem != None )
		{
			NewSystem.Conform( Image, false );
			NewSystem.RegisterExternallyAffectedTemplates();
		}
	}
	else
	{
		warn( TemplateName$" not found." );
	}

	return NewSystem;
}

defaultproperties
{
     DefaultForces(0)=Class'ParticleSystems.DecayForce'
     DefaultForces(1)=Class'ParticleSystems.LocatorForce'
	MaxTickSize=0.008333
	LockedLocalToWorld=(XPlane=(X=1.000000),YPlane=(Y=1.000000),ZPlane=(Z=1.000000),WPlane=(W=1.000000))
	SelectionMethod=SELECT_Random
	bLinearFrequenciesChanged=true
	bOn=true
	bInitiallyOn=true
	Trig="SendTrigger"
	UnTrig="SendUnTrigger"
	DrawType=DT_Custom
	bCanTeleport=true
	bAcceptsProjectors=true
	RemoteRole=ROLE_None
	VisibilityRadius=5000.000000
	VisibilityHeight=5000.000000
	Style=STY_Translucent
	bUnlit=true
	bBlockZeroExtentTraces=false
	bBlockNonZeroExtentTraces=false
	bEdCanOverlap=true
     UseReticleOnEvents(0)="UseReticleText"
     UseReticleOnEvents(1)="UseReticleCorners"
     UseReticleOnEvents(2)="UseReticleTopBars"
     ProximityReticleOnEvents(0)="ProximityReticleCorners"
     ProximityReticleOnEvents(1)="ProximityReticleTopBars"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: sk 3-1-2016 10:38:40.000 - Creation time: sk 3-1-2016 10:48:40.749 - Created with UnCodeX