User Tag List

Results 1 to 5 of 5
  1. #1
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,675
    Country:

    Code review: Supplier (50%) and WeaponFiding optimization.

    Playes and Bots have an inventory chain, players owns one piece of inventory, and this piece of inventory owns the next inventory and so we have a chained list.

    Weaponfinding routines loop through this chain, it's naturally faster if weapons are arranged in front of the list isn't it?

    This code modifies SiegeGI.AddDefaultInventory
    It performs a run on the player's inventory chain and puts weapons first.
    This makes weapon switching faster (1 millisecond is sometimes appreciated :chuncky
    And is half of the planned optimization on the Suppliers, these perform 10 weaponfinding checks every 0.2 seconds per player, so yeah...

    There's no edition actually, we're adding code at the end of the function, it looks like this:
    Code:
    function AddDefaultInventory(Pawn playerPawn)
    {
        local int i;
        local Weapon newWeapon;
    	local inventory inv, previnv;
    
        if ( PlayerPawn.IsA('Spectator') || (bRequireReady && (CountDown > 0)) )
             return;
    
        GivePlayerWeapon(playerPawn, WeaponClasses[12]);
    
        for ( i = 0; i < 12; i++ )
            if ( WeaponClasses[i] != None )
                GivePlayerWeapon(playerPawn, WeaponClasses[i]);
    
    //CACUS HACK, rearrange inventory chain so supplied weapons can be found faster
    	if ( playerPawn.Inventory == none  )
    		return; //BUGHERE, no inventory given?
    
    	inv = playerPawn.Inventory;
    
    	While ( inv.Inventory != none )
    	{
    		previnv = inv;
    		inv = inv.Inventory;
    
    //This is a valid suppliable weapon (90% chance), let's put it in front of the list
    		if ( (Weapon(Inv) != none) && (Weapon(Inv).AmmoType != none) )
    		{
    			previnv.Inventory = inv.Inventory; //Remove from middle of chain
    			inv.Inventory = playerPawn.Inventory; //Appear on front
    			playerPawn.Inventory = inv;
    		}
    	}
    }
    If you wonder what the hell WEAPON_SEARCH is, it's my iterator, it provides more control by jumping between code sections inside a function.

    You can even use jumps to enter or leave another For, While, etc iterator.

    I haven't tested it since I don't have Siege installed, but can check that the inventory chain isn't broken or anything when testing it if you can see the weapons and ammo amounts on your HUD...
    Last edited by Higor; 05-13-2012 at 12:39 AM. Reason: Changed loop type

  2. #2
    Moderator .seVered.]['s Avatar
    Join Date
    Jun 2011
    Location
    Near a River and Under a Bridge
    Posts
    2,122
    Country:
    Since your builds are also in your players inventory, can't we put an ICON up for Nuke's that you have built or are finished building.

  3. #3
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,675
    Country:
    Builds are in inventory when you pick them up.

    One way of adding onscreen icons is by creating an extra, hidden inventory item that checks serverside for the player's nukes, saves the remaining time and health %.
    The client receives both values on the 'n' nukes (can be up to 4) and then draws icons onscreen like relics do.

    Another way of doing that is adding a general checker for both teams and let the player's hud find it clientside, but that would provide a good hacker a way to read the opposing team's nuke status, sure that can be prevented but doesn't fit in a paragraph of explanations. I'll leave that for another time.

  4. #4
    Rampage Feralidragon's Avatar
    Join Date
    Jan 2011
    Posts
    374
    Country:
    Goto? Are you showing a "goto" for algorithmic understanding purposes or are you actually saying a goto should be used?
    I ask this because if it's the latter, you certainly don't want to use goto's, you use either "for" or "while" cicles ("while" would be the one to use here), never goto's outside state code.

    Don't get me wrong, but the process of optimization has to go hand-in-hand with good algorithmic structure to keep the code readable, understandable, stable and "debug-able".

  5. #5
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,675
    Country:
    Changed loop type.
    Removed unneeded comments.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Code review: Supplier ammo-giving optimization.
    By Higor in forum Code Reviews
    Replies: 19
    Last Post: 06-07-2012, 08:34 AM
  2. Code review: Supplier ammo-giving optimization.
    By Higor in forum #siegepug Discussion
    Replies: 19
    Last Post: 06-07-2012, 08:34 AM
  3. Code review: Jetpack
    By Higor in forum Code Reviews
    Replies: 7
    Last Post: 06-01-2012, 05:19 PM
  4. Code review: sgHUD
    By Higor in forum #siegepug Discussion
    Replies: 6
    Last Post: 06-01-2012, 03:45 PM
  5. Code review: Supplier (50%) and WeaponFiding optimization.
    By Higor in forum #siegepug Discussion
    Replies: 4
    Last Post: 05-13-2012, 12:41 AM

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
  •