User Tag List

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,676
    Country:

    Code review: sgTeleporter

    Checking on teleporters now.

    First, we start by removing unneeded functions:

    Code:
    simulated function Actor SpecialHandling(Pawn Other)
    SpecialHandling is an event that only gets called on NavigationPoint subclasses, it does absolutely nothing here.

    Code:
    simulated function FindTriggerPawn()
    This is called by SpecialHandling only, unneeded as well.

    Code:
    simulated function Upgraded()
    {
    	Super.Upgraded();
    }
    There's absolutely no need to do this.

    ====
    Going to the optimization now.
    Finding the teleporter destination shouldn't be performed on every touch, storing it and handling it with user made events is better.
    We'll add 2 variables with different purposes:
    Code:
    var bool bHasOtherSide;
    var sgTeleporter OtherSide;
    OtherSide will be the shortcut to the destination, the destination will have one pointing here as well.
    bHasOtherSide is going to be a replicated variable so we must add it to the REPLICATION block, this will work to make clients know when a teleporter is active or not, still needs proper graphical implementation, have you guys decided what to use?


    FinishBuilding:
    Code:
    simulated function FinishBuilding()
    {
    	Super.FinishBuilding();
    	bEnabled=true;
    }
    Let's add more functionality and setup the initial link if we have one.
    We'll also set the TAG variable to make tele finding iterations faster (TeleNetwork).

    New code:
    Code:
    simulated function FinishBuilding()
    {
    	Super.FinishBuilding();
    	bEnabled=true;
    	
    	if ( Team == 0 )		Tag = 'sgTeleRed';
    	else if ( Team == 1 )		Tag = 'sgTeleGlue';
    	else if ( Team == 2 )		Tag = 'sgTeleGreen';
    	else		Tag = 'sgTeleGold';
    
    	if ( Level.NetMode == NM_Client )
    		return;
    
    	OtherTele = FindOther();
    	if ( OtherTele != none )
    	{
    		bHasOtherTele = true;
    		OtherTele.OtherTele = self;
    		OtherTele.bHasOtherTele = true;
    	}
    }
    As soon as the teleporter finishes building it will locate it's destination, it will also set a team specific TAG.
    What's with the TAG anyways? AllActors iterator can search by tag in native code, so if we make sure all teleporters in a team use the same tag, we don't even have to check for Team later.
    If the destination is found, the Destination's destination is set to this teleporter, so the other doesn't have to bother finding this tele.


    FindOther:
    Code:
    simulated function sgTeleporter FindOther(optional Pawn instigator)
    {
    	local Pawn p;
    	local sgTeleporter teleDest;
    	local sgTeleNetwork sgTN;
    	local bool bTeleNetwork;
    	local bool bNext;
    	local int iTel;
    	local bool bFirst;
    	local sgTeleporter firstteleDest;
    
    	if (instigator!=None)
    		bTeleNetwork = (sgTeleNetwork(instigator.FindInventoryType(class'sgTeleNetwork')) != None);
    
        	for ( p = Level.PawnList; p != None; p = p.nextPawn )
    		if (p.IsA('sgTeleporter'))
    		{
    
    			teleDest=sgTeleporter(p);
    			if (teleDest.Team == instigator.PlayerReplicationInfo.Team)
    			{
    				if (bTeleNetwork)
    				{
    					if (!bFirst) { firstteleDest = teleDest; bFirst = true; }
    					if (teleDest == Self) bNext = true;
    					else if (bNext == true) return teleDest;
    				}
    				else
    				if (teleDest.URL2==URL1 && teleDest != Self) return teleDest;
    			}
    		}
        	return firstteleDest;
    }
    Let's program one case for the other tele, and another case for the TeleNetwork, so we make it faster and legible.
    Also, no need to TypeCast the resulting sgTeleNetwork search, FindInventoryType always returns NONE or the desired class.
    A map can indeed have over 50 pawns, doing an AllActors() iteration will be faster and cleaner than doing a PawnList check.
    We'll be doing the usual local variables cleanup as well.

    Suggested code:
    Code:
    simulated function sgTeleporter FindOther(optional Pawn instigator)
    {
    	local sgTeleporter sgTele, firstTele;
    	local bool bNext;
    
    	if ( (instigator != none) && (instigator.FindInventoryType(class'sgTeleNetwork') != None) )
    	{
    		ForEach AllActors ( class'sgTeleporter', sgTele, Tag)
    		{
    			if ( sgTele == self )
    			{
    				bNext = true;
    				continue;
    			}
    			if ( bNext )
    				return sgTele;
    			if ( firstTele == none )
    				firstTele = sgTele;
    		}
    		return firstTele;
    	}
    
    	if ( OtherTele != none )
    		return OtherTele;
    
    	ForEach AllActors ( class'sgTeleporter, sgTele, Tag)
    	{
    		if ( (sgTele != self) && (sgTele.URL1 == URL1) )
    			return sgTele;
    	}
    	return none;
    }
    TeleNetwork destination finding is found in a different iterator, so we avoid extra checks, firstTele can be NONE there so we already cover this special case of having only two teleporters.
    It picks the OtherTele if we already saved it, otherwise we try finding one anyways (used by FinishedBuilding).


    We must also add a notification at Teleporter destruction so we remove actor references, I'd rather use engine's Destroyed() event rather than the Destruct() function, besides Destruct() calls Destroy() so Destroyed() gets called anyways. (lol words)
    Code:
    event Destroyed()
    {
    	if ( OtherTele != none )
    	{
    		OtherTele.OtherTele = none;
    		OtherTele.bHasOtherTele = false;
    	}
    	Super.Destroyed() //Just in case...
    }

    Side effects:
    If destination teleporter is relevant on client machine, player will experience lag-free teleportation!!
    EDIT: Only if we also replicate URL1 variable.

    What about SuperBoosters and sgTeleporter combos?
    Are these not intended to work or is it a bug?
    Last edited by Higor; 05-26-2012 at 04:44 PM. Reason: Modified FinishBuilding()

  2. #2
    Rampage Feralidragon's Avatar
    Join Date
    Jan 2011
    Posts
    374
    Country:
    Quote Originally Posted by Higor View Post
    Side effects:
    If destination teleporter is relevant on client machine, player will experience lag-free teleportation!!
    EDIT: Only if we also replicate URL1 variable.
    Well, that means if you add the builder as instigator of both teleporters, they're always relevant to him.
    Also, going down that road you can put them with bAlwaysRelevant=True as well. bAlwaysRelevant should be avoided at all costs, but this seems a rare case where its usage would be correct, given the actual teleporter functionality and since you never have many of them in a match and since they don't update often.

    Quote Originally Posted by Higor View Post
    What about SuperBoosters and sgTeleporter combos?
    Are these not intended to work or is it a bug?
    I think it's intended to work, personally I love doing that ingame, and it's only effective if the team gets interested in using it (great for attacking quickly), plus both are easy to kill anytime (and that happens a lot), so either ways it should stay that way imho.
    Last edited by Feralidragon; 05-25-2012 at 06:40 AM.

  3. #3
    Unstoppable audiosonic's Avatar
    Join Date
    Jan 2011
    Posts
    734
    Country:
    Quote Originally Posted by Feralidragon View Post
    I think it's intended to work, personally I love doing that ingame, and it's only effective if the team gets interested in using it (great for attacking quickly), plus both are easy to kill anytime (and that happens a lot), so either ways it should stay that way imho.
    He means the teleporters you build yourself, you can't use boosters through self-made teleporters, not sure whether this was intended this way, or just not able to get it right. However if you can get it to work it would make for some inchereschting gameplay regarding tele's.

  4. #4
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,676
    Country:
    Quote Originally Posted by Feralidragon View Post
    Well, that means if you add the builder as instigator of both teleporters, they're always relevant to him.
    Also, going down that road you can put them with bAlwaysRelevant=True as well. bAlwaysRelevant should be avoided at all costs, but this seems a rare case where its usage would be correct, given the actual teleporter functionality and since you never have many of them in a match and since they don't update often.


    I think it's intended to work, personally I love doing that ingame, and it's only effective if the team gets interested in using it (great for attacking quickly), plus both are easy to kill anytime (and that happens a lot), so either ways it should stay that way imho.
    It would indeed be nice to conduct tests by setting bAlwaysRelevant to true and reducing NetUpdateFrequency from 100 (WTF) to 5.

    Now that I think about it, isn't NetUpdateFrequency value a bit excessive on these stationary pawns?
    The buildings run LOTS of simulated code that actually simulate the Container's healing effect as well as the construction progress so it isn't that necessary to update these little changes all the time in my opinion.

  5. #5
    Moderator .seVered.]['s Avatar
    Join Date
    Jun 2011
    Location
    Near a River and Under a Bridge
    Posts
    2,125
    Country:
    Why not just base the rotating animation on the bHadOtherSide variable. Only have it spinning if it has a matching teleport. So unmatched teleports don't rotate.

  6. #6
    Rampage Feralidragon's Avatar
    Join Date
    Jan 2011
    Posts
    374
    Country:
    Quote Originally Posted by Higor View Post
    It would indeed be nice to conduct tests by setting bAlwaysRelevant to true and reducing NetUpdateFrequency from 100 (WTF) to 5.

    Now that I think about it, isn't NetUpdateFrequency value a bit excessive on these stationary pawns?
    The buildings run LOTS of simulated code that actually simulate the Container's healing effect as well as the construction progress so it isn't that necessary to update these little changes all the time in my opinion.
    NetUpdateFrequency is a tricky property, only because it's set to 100, it doesn't mean it will constantly update 100 times per second.
    First and foremost, this value is limited by the server tickrate, which by default is 20 (idk the current value on the siege server though).
    Second, NetUpdateFrequency only states the *max* frequency of replication updates, so if the actor doesn't have any updates (no variable that was changed server-side and needs to go to the client), then there's no problem, it won't update anyhow.
    So running simulated code has nothing to do with NetUpdateFrequency, because it all goes down to what you actually replicate from the server to the client, or vice-versa, which in the case of a teleporter you just replicate a few things on spawn, from there you don't have almost anything to replicate during the whole teleporter lifetime, so that's not an issue imo.

    If you still want to reduce it, reduce it to 10 and not just 5, I think 5 is too small (and if something needs to be replicated asap, players will notice the lag).

  7. #7
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,676
    Country:
    I know, thing is, that during construction, when the Energy amount is constantly changing, we don't have to update all these times when we're doing simulation.
    Now fire a neutron bomb, and you'll hog the bandwidth channels full of construction updates.

    Also, server tickrate is at 65!, a theoretical maximum of 65 updates per second on a stationary pawn seems excessive, and yes, 10 looks fine enough.

  8. #8
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,676
    Country:
    This post will explain how to make the teleporter stop spinning when there is no destination.
    It should only stop spinnig for players of that team so enemies won't notice if the team has a working tele or not.
    It requires the previous code from this thread to be applied to work.


    First, we add another variable:
    Code:
    var PlayerPawn LocalPlayer;

    Second, let's make a local player finding function
    Code:
    simulated function PlayerPawn FindLocalPlayer()
    {
    	local PlayerPawn P;
    	ForEach AllActors (class'PlayerPawn', P)
    	{
    		if ( (P.Player != none) && (ViewPort(P.Player) != none) )
    			return P;
    	}
    	return none;
    }
    :


    Third, we work on the teleporter graphics:
    Code:
    simulated function TeleporterGraphics( optional bool bReset)
    {
    	local sgMeshFx theFx;
    
    	if ( bReset )
    	{
    		if ( myFx.RotationRate == rot(0,0,0) )
    		{
    			For ( theFx=myFx ; theFx!=none ; theFx=theFx.NextFx )
    			{
    				theFx.RotationRate.Pitch = Rand(MFXrotX.Pitch);
    				theFx.RotationRate.Roll = Rand(MFXrotX.Roll);
    				theFx.RotationRate.Yaw = Rand(MFXrotX.Yaw);
    				if ( theFx.NextFx == theFx )
    					theFx.NextFx = none;
    			}
    		}
    		return;
    	}
    
    	if ( bHasOtherTele && (myFx.RotationRate != rot(0,0,0)) )
    		return;
    	if ( !bHasOtherTele && (myFx.RotationRate == rot(0,0,0)) )
    		return;
    
    	For ( theFx=myFx ; theFx!=none ; theFx=theFx.NextFx )
    	{
    		if ( bHasOtherTele )
    		{
    			theFx.RotationRate.Pitch = Rand(MFXrotX.Pitch);
    			theFx.RotationRate.Roll = Rand(MFXrotX.Roll);
    			theFx.RotationRate.Yaw = Rand(MFXrotX.Yaw);
    		}
    		else
    			theFx.RotationRate = rot(0,0,0);
    		if ( theFx.NextFx == theFx )
    			theFx.NextFx = none;
    	}
    }

    Fouth, we rewrite the Timer() function:
    Code:
    simulated event Timer()
    {
    	Super.Timer();
    
    	if ( Level.NetMode != NM_DedicatedServer )
    	{
    		if ( LocalPlayer == none )
    			LocalPlayer = FindLocalPlayer();
    		else if ( (LocalPlayer.PlayerReplicationInfo != none) && (LocalPlayer.PlayerReplicationInfo.Team == Team) )
    			TeleporterGraphics();
    		else
    			TeleporterGraphics( true);
    	}
    
    	if ( SCount > 0 || Role != ROLE_Authority )
            	return;
    }
    Now if you want a different effect, you can work that on TeleporterGraphics() alone without looking too much into the code.
    Remember that bHasOtherTele must be replicated.


    EDIT: REVIEWED
    Last edited by Higor; 05-27-2012 at 10:55 PM. Reason: REVIEWED, BUG FIXED

  9. #9
    Whicked Sick SilverWing's Avatar
    Join Date
    Jan 2011
    Posts
    1,140
    Country:
    ill put a poll up if people want the teleporters to be darker when inactive or to stop spinning when inactive


  10. #10
    Moderator .seVered.]['s Avatar
    Join Date
    Jun 2011
    Location
    Near a River and Under a Bridge
    Posts
    2,125
    Country:
    Quote Originally Posted by |uK|SilverWing View Post
    ill put a poll up if people want the teleporters to be darker when inactive or to stop spinning when inactive
    Cool, I think that would be the easier method of knowing.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code review: sgHUD
    By Higor in forum #siegepug Discussion
    Replies: 6
    Last Post: 06-01-2012, 02:45 PM
  2. Code review: sgTeleporter
    By Higor in forum #siegepug Discussion
    Replies: 12
    Last Post: 05-26-2012, 08:24 PM
  3. Code review: Mines 2
    By Higor in forum #siegepug Discussion
    Replies: 5
    Last Post: 05-26-2012, 02:49 PM
  4. Code review: sgProtector
    By Higor in forum #siegepug Discussion
    Replies: 9
    Last Post: 05-24-2012, 03:21 PM
  5. Code review: Mines
    By Higor in forum #siegepug Discussion
    Replies: 20
    Last Post: 05-21-2012, 09:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •