Hi,
I just finished testing a mutator and would like to know how the following code could be optimized.
It's the tick event and it runs for each player so the code inside needs to be as concise as possible.
Perhaps other Actors could be used to take advantage of UT's threading.
The rest of the code can be seen in the zip file attached below.
P.S: I'm guessing the "simulated" is probably not needed (I'm still having trouble understanding replication).
I just finished testing a mutator and would like to know how the following code could be optimized.
It's the tick event and it runs for each player so the code inside needs to be as concise as possible.
Perhaps other Actors could be used to take advantage of UT's threading.
The rest of the code can be seen in the zip file attached below.
P.S: I'm guessing the "simulated" is probably not needed (I'm still having trouble understanding replication).
Code:
simulated function Tick( float DeltaTime )
{
local int playerID, lastYaw, lastPitch, deltaYaw, deltaPitch, maxDeltaYaw, maxDeltaPitch;
local Pawn p;
// Check if game has started
if( getTimeSinceGameStart() == 0 )
return;
p = Level.PawnList; // get start of linked list of Pawns
while( p != none )
{
if( isValidPlayer( p ) )
{
playerID = p.PlayerReplicationInfo.PlayerID;
// Get data from arrays
lastYaw = lastYawArray[ playerID ];
lastPitch = lastPitchArray[ playerID ];
if( p.bJustTeleported ) // Pitch is reset when entering a teleporter
lastPitch = p.ViewRotation.Pitch;
// When a player dies, the Pawn is hidden and tweened while a carcass is spawned in it's place
if( p.GetStateName() == 'Dying' || p.bHidden )
{
lastYaw = p.ViewRotation.Yaw;
lastPitch = p.ViewRotation.Pitch;
}
// Refer to ModifyPlayer() for an explanation of why this test is carried out
if( pawnArray[ playerID ] == none || pawnArray[ playerID ] != p )
lastYaw = p.ViewRotation.Yaw;
// Use absolute function as Yaw values can be negative
deltaYaw = abs( abs( p.ViewRotation.Yaw ) - abs( lastYaw ) );
// Calculate Pitch difference ( max up 18000<-0/65536->49152 max down )
if( p.ViewRotation.Pitch > 0 && p.ViewRotation.Pitch <= 18000 )
{
if( lastPitch > 0 && lastPitch <= 18000 )
deltaPitch = abs( p.ViewRotation.Pitch - lastPitch );
else if( lastPitch >= 49152 && lastPitch <= 65536 )
deltaPitch = p.ViewRotation.Pitch + ( 65536 - lastPitch );
else if( p.ViewRotation.Pitch >= 49152 && p.ViewRotation.Pitch <= 65536 )
{
if( lastPitch > 0 && lastPitch <= 18000 )
deltaPitch = ( 65536 - p.ViewRotation.Pitch ) + lastPitch;
else if( lastPitch >= 49152 && lastPitch <= 65536 )
deltaPitch = abs( p.ViewRotation.Pitch - lastPitch );
}
if( deltaYaw > maxDeltaYaw )
maxDeltaYaw = deltaYaw;
if( deltaPitch > maxDeltaPitch )
maxDeltaPitch = deltaPitch;
if( maxDeltaYaw > maxYawLimit || maxDeltaPitch > maxPitchLimit )
{
maxDeltaYawArray[ playerID ] = maxDeltaYaw;
maxDeltaPitchArray[ playerID ] = maxDeltaPitch;
SaveConfig();
handlePlayer( p );
}
}
lastYaw = p.ViewRotation.Yaw;
lastPitch = p.ViewRotation.Pitch;
// Save data to arrays
lastYawArray[ playerID ] = lastYaw;
lastPitchArray[ playerID ] = lastPitch;
deltaYawArray[ playerID ] = deltaYaw;
deltaPitchArray[ playerID ] = deltaPitch;
}
p = p.nextPawn;
}
}
Attachments
Last edited: