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...