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

IGVisualEffectsSubsystem.VisualEffectsSubsystem


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
class VisualEffectsSubsystem extends IGEffectsSystem.EffectsSubsystem
    native
    config(VisualEffects);

enum MatchResult
{
    MatchResult_None,           //no match & no default
    MatchResult_Matched,        //found a match with a non-default material
    MatchResult_UseDefault      //no explicit material matched, but use default
};

var private array<class<Actor> > MatchingEffectClasses;
var private array<class<Actor> > DefaultEffectClasses;
var private array<class<Actor> > SelectedEffectClasses;

var private int CurrentDecal;

// Either a source or an overrideWorldLocation must be specified to identify the location of the new effect
simulated event Actor PlayEffectSpecification(
    EffectSpecification EffectSpec,
    Actor Source,
    optional Actor Target,
    optional Material TargetMaterial,
    optional vector overrideWorldLocation,
    optional rotator overrideWorldRotation,
    optional IEffectObserver Observer)
{
    local VisualEffectSpecification visualEffectSpec;
    local Actor effect;
    local int i;
    local MatchResult result;
    local Vector AdditionalLocationOffset;
	local class<Actor> EffectSpecClass;
	local Vector CullLocation;

	if (EffectSpec == None)
		return None;

    visualEffectSpec = VisualEffectSpecification(EffectSpec);
    assert(visualEffectSpec != None);

    // Clear the effect classes arrays
    MatchingEffectClasses.Remove(0, MatchingEffectClasses.length);
    DefaultEffectClasses.Remove(0, DefaultEffectClasses.length);
    
    // Find the index of the specified material
    for (i=0; i<visualEffectSpec.materialType.length; i++)
    {
		EffectSpecClass = visualEffectSpec.EffectClass[i];
        if (TargetMaterial != None && visualEffectSpec.materialType[i] == TargetMaterial.MaterialVisualType)
        {
            // make sure that the effect class specified actually exists
            // (i.e., could be spawned).
            if (EffectSpecClass == None)
				assertWithDescription(false, "EffectsManager::PlayEffect(): Nonexistent EffectClass specified for effect named "$EffectSpec.name$" materialType "$TargetMaterial.MaterialVisualType);            

            MatchingEffectClasses[MatchingEffectClasses.length] = EffectSpecClass;
            result = MatchResult_Matched;
        }
        
        if (visualEffectSpec.MaterialType[i] == MVT_Default)
        {
            // Make sure that the default effect class specified actually exists
            // (i.e., could be spawned).
            if(EffectSpecClass == None)
				assertWithDescription(false, "EffectsManager::PlayEffect(): Nonexistent *default* EffectClass specified for effect named "$EffectSpec.name);            

            DefaultEffectClasses[DefaultEffectClasses.length] = EffectSpecClass;

            // If we haven't found any match, then use this default
            if (result == MatchResult_None)
                result = MatchResult_UseDefault;
        }
    }

    // Either the default effect was requested, or no effect class was defined
    // for the specified material type and we're falling back to the
    // default. 

    SelectedEffectClasses.Remove(0, SelectedEffectClasses.length);
    switch (result)
    {
        case MatchResult_None:
            // Return because there is no default class to spawn
            return None;
        
        case MatchResult_Matched:
            //copy the matching classes into the selected array (since we can't have reference to an array)
            for (i=0; i<MatchingEffectClasses.length; ++i)
                SelectedEffectClasses[SelectedEffectClasses.length] = MatchingEffectClasses[i];
            break;

        case MatchResult_UseDefault:
            //copy the default classes into the selected array (since we can't have reference to an array)
            for (i=0; i<DefaultEffectClasses.length; ++i)
                SelectedEffectClasses[SelectedEffectClasses.length] = DefaultEffectClasses[i];
            break;
    }

    // Spawn the selected effects.
    // 
    // Note that we'll spawn them at (0,0,0).  This indicates to Actor::PostBeginPlay()
    //  that the Actor's location has not been initialized, so the 'Spawned'
    //  effect event should not be triggered... we'll do that ourselves below.

    for (i=0; i<SelectedEffectClasses.length; ++i)
    {
		// Don't spawn FX if the level's detail level is lower than the detail level
		// required for the effect
		if((SelectedEffectClasses[i].Default.bHighDetail && Level.DetailMode == DM_Low) || 
			(SelectedEffectClasses[i].Default.bSuperHighDetail && Level.DetailMode != DM_SuperHigh))
		{
			if (EffectsSystem.LogEffectEvents)
			{
				log("**** "$Name$" NOT spawning "$SelectedEffectClasses[i]$" because Level is DetailMode="$GetEnum(EDetailMode, Level.DetailMode)$
					" and effect is (bHighDetail="$SelectedEffectClasses[i].Default.bHighDetail$
					", bSuperHighDetail="$SelectedEffectClasses[i].Default.bSuperHighDetail$")");
			}

			// don't spawn this effect because client's detail setting is too low
			continue;
		}
		else if (EffectsSystem.LogEffectEvents)
		{
			log("**** "$Name$" SPAWNING "$SelectedEffectClasses[i]$"; Level is DetailMode="$GetEnum(EDetailMode, Level.DetailMode)$
				" and effect is (bHighDetail="$SelectedEffectClasses[i].Default.bHighDetail$
			    ", bSuperHighDetail="$SelectedEffectClasses[i].Default.bSuperHighDetail$")");
		}
				
#if IG_TRIBES3	// rowan: distance cull fx at spawn
		if (SelectedEffectClasses[i].Default.CullDistance > 0)
		{
			if (overrideWorldLocation != vect(0,0,0))
				CullLocation = overrideWorldLocation;
			else if (Source != None)
				CullLocation = Source.Location;

			if (!Level.GetLocalPlayerController().CheckCullDistance(CullLocation, SelectedEffectClasses[i].Default.CullDistance))
			{
//				log("Distance Culled FX!!!!!");
				continue;
			}
		}
#endif

        if (Source != None)
        {
            // Spawn with owner being the Source Actor, and its tag is the name of the
            // EffectSpecification (to identify it later for stopping).
            effect = ProxySpawn(SelectedEffectClasses[i], Source, EffectSpec.name, vect(0,0,0));
        }
        else
        {
            // Since we have no source, check that we have an overrideWorldLocation... enforce the rule above.
			if (overrideWorldLocation == vect(0,0,0))
			{
				assertWithDescription(false, "EffectsManager::PlayEffect() was called with no Source and no overrideWorldLocation... I don't know where to put the effect!?");
			}

            // Spawn with the outer of this EffectsManager as the owner
            effect = ProxySpawn(SelectedEffectClasses[i], GameInfo(Outer), EffectSpec.name, vect(0,0,0));
        }

        if (effect == None)
        {
			assertWithDescription(false, "VisualEffectsSubsystem.PlayEffectSpecification(): couldn't spawn effect "$EffectSpec.name$" with Source "$Source$" (chose SelectedEffectClasses[i]="$SelectedEffectClasses[i]$")");
		}
		else if (EffectsSystem.LogEffectEvents)
		{
			log("**** "$Name$" ---> Spawn returned: "$effect);
		}

        // If a location is passed explicitly, then use that.
        //otherwise, if the effect should be attached, then attach it.
        //otherwise, if a source was passed, then locate the effect at the source.
        //(we already asserted that we have either a source or an overrideWorldLocation.)
		
		// rowan: runtime handle NULL effect
		if (effect != None)
		{
			if (overrideWorldLocation != vect(0,0,0))
			{
				//use passed location & rotation
				effect.SetLocation(overrideWorldLocation);
				effect.SetRotation(overrideWorldRotation);
			}
			else if (effectSpec.AttachToSource)
			{
				if (Source == None)
					assertWithDescription(false, "EffectsManager: tried to attach effect "$EffectSpec.name$" to None Source");

				if (Source != None)
				{
					if (effectSpec.AttachmentBone == '' || effectSpec.AttachmentBone == 'PIVOT')
					{
						// attach relative to the source's location (its pivot)
						effect.SetBase(Source);
					}
					else if (effectSpec.AttachmentBone == 'CENTER')
					{
						effect.SetBase(Source);
						// attach relative to the source's bounding sphere center
						AdditionalLocationOffset = Source.GetRenderBoundingSphere() - Source.Location;
					}
					else
					{
						// attach to the specified bone
						Source.AttachToBone(effect, effectSpec.AttachmentBone);
					}
				}

				effect.SetRelativeLocation(effectSpec.LocationOffset + AdditionalLocationOffset);
				effect.SetRelativeRotation(effectSpec.RotationOffset);
			}
			else if (Source != None)
			{
				effect.SetLocation(Source.Location);
				effect.SetRotation(Source.Rotation);
			}

			if (effect.IsA('ProjectedDecal'))
			{
				// Invert rotation of the projector to face hit location
				ProjectedDecal(effect).Target = Target;
				ProjectedDecal(effect).SetRotation(rotator(vector(effect.Rotation) * vect(-1,-1,-1)));
				ProjectedDecal(effect).Init();
			}

			if (Observer != None)
				Observer.OnEffectStarted(effect);
		}
    }

    return effect;
}

// ckline NOTE: keeping this function around even though it's no longer needed now that we don't 
// use a projector pool. However, it's potentially a good place to hook in functionality needed
// to finish implementing LogState()
simulated function Actor ProxySpawn(class<actor> SpawnClass, actor SpawnOwner, name SpawnTag, vector SpawnLocation)
{
    local Actor Result;

    Result = SpawnOwner.Spawn(SpawnClass, SpawnOwner, SpawnTag, SpawnLocation);
    //Log("VisualFX: "$SpawnOwner$".Spawn("$SpawnClass$","$SpawnOwner$","$SpawnTag$","$SpawnLocation$") returned "$Result);

    return Result;
}

simulated event StopEffectSpecification(
    EffectSpecification EffectSpec,
    Actor Source)
{
    local Actor effect;

    //stop effects with tag=effectTag
    //if Source is specified, then only stop those whose owner is Source
    foreach DynamicActors(class'Actor', effect, EffectSpec.name)
        if (source == None || effect.Owner == source)
            StopEffect(effect, true);  //TMC TODO confirm assumption: visual effects explicitly stopped want to be stopped over time (respawnDeadParticles=false, but let existing particles live-out their lifetimes)
}

simulated function StopEffect(Actor it, bool stopOverTime)
{
    if (stopOverTime && it.IsA('Emitter'))
        Emitter(it).Kill();
    else
        it.Destroy();
}

// Print the current effects to the log
simulated function LogState()
{
//    local int i;
//    local String StateString;

    Log("----------------------------------------------------------------");
    Log("|              VISUAL EFFECTS SUBSYSTEM STATE                   |");
    Log("----------------------------------------------------------------");

Log("| WARNING: LogState() not yet implemented for visual effects subsystem");
// TODO: implement this function for visual effects with output similar to sound effects
//
//    Log("| Existing effects:");
//    for (i = 0; i < CurrentSounds.Length; ++i)
//    {
//        StateString = "None";
//        if (CurrentSounds[i] != None) { StateString = CurrentSounds[i].toString(); }
//        Log("|   #"$i$": "$StateString);
//    }
    Log("----------------------------------------------------------------");
}

simulated event OnEffectSpawned(Actor SpawnedEffect)
{
	if (SpawnedEffect != None && SpawnedEffect.bNeedLifetimeEffectEvents)
	{
		SpawnedEffect.TriggerEffectEvent('Spawned');
		SpawnedEffect.TriggerEffectEvent('Alive');
	}
}

defaultproperties
{
    EffectSpecificationSubClass=class'VisualEffectSpecification'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 16:02:14.000 - Creation time: st 23.5.2018 00:10:50.495 - Created with UnCodeX