Code: Select all
////////////////////////////
// Cyber: check for nearby environmental hazards
////////////////////////////
singular function checkForHazards(GC gc)
{
local DamageTrigger DT;
local ZoneInfo ZI;
local Cloud CL;
local string threatType;
local string threatDam;
local int typecastIt;
local Actor acti;
ForEach Player.RadiusActors(class'DamageTrigger', DT, 512)
{
threatType = (string(DT.damageType));
typecastIt = (int(DT.damageAmount));
threatDam = (string(typecastIt));
acti = DT;
}
if (acti == None)
{
ForEach Player.RadiusActors(class'ZoneInfo', ZI, 1024)
{
if (ZI.bPainZone)
{
threatType = (string(ZI.DamageType));
threatDam = (string(ZI.DamagePerSec));
acti = ZI;
}
}
}
if (acti == None)
{
ForEach Player.RadiusActors(class'Cloud', CL, 512)
{
if (CL.Damage > 1)
{
threatType = (string(CL.damageType));
typecastIt = (int(CL.Damage));
threatDam = (string(typecastIt));
acti = CL;
}
}
}
if (threatType != "" && threatType != "shot")
{
if (bHazardRefresh)
Player.PlaySound(sound'hazardwarn',SLOT_None);
if (threatType == "Exploded")
{
threatType = "Fatal";
threatDam = "Fatal";
}
bHazardRefresh=False;
DrawThreatDetectionAugmentation(gc, acti, threatType, threatDam);
}
else
bHazardRefresh=True;
}
1. would one ForEach RadiusActors loop looking for class'actor' be more suitable than three ForEach loops looking for the more specific actor classes as above?
2. Is there any way I can optimize this at all?
3. on the unreal wiki ForEach loop page it says the following under the "Pitfalls" section:
"Pay special attention when you modify the list in some way. Adding items to the list, for example spawning actors during an AllActors loop, can create an infinite loop where the engine continues to create actors until it runs out of memory or crashes for other reasons!"
DX code uses ForEach AllActors(class'actor somewhat commonly, and also spawns actors somewhat commonly, such as fragments. So how come we don't suffer frequent crashes if the above is true?