Since we're already into optimization:
Higor wrote:Code: Select all
local string LevelName;
LevelName = string(self);
LevelName = Left( LevelName, InStr(LevelName,".") );
Few people seem to realize that actors are always directly contained in the map package itself. As a result you can extract the package name without any explicit string manipulation operations:
Code: Select all
local string LevelName;
LevelName = string(Outer); // assuming code is in an actor subclass, otherwise access Outer through an actor reference
Or just use Outer.Name directly to skip the string conversion altogether. This should work really well in combination with a Switch statement. Here's a piece of code we used in
JB2004c's "map fixes" to apply map-specific fixes so we didn't need to re-release fixed versions of those maps:
Code: Select all
// in PreBeginPlay() of a Mutator-like class (UT200x differentiates between Mutator and GameRules)
// SetInitialState will later pick up the InitialState value set here
// we opted for Locs() (opposite of Caps()) to prevent polluting the name table and ensure the actual string representation matches
switch (Locs(Level.Outer.Name)) {
case "jb-arlon-gold": InitialState = 'Arlon'; break;
case "jb-aswan-v2": InitialState = 'Aswan'; break;
case "jb-atlantis-gold": InitialState = 'Atlantis'; break;
case "jb-babylontemple-gold": InitialState = 'BabylonTemple'; break;
case "jb-collateral": InitialState = 'Collateral'; break;
case "jb-cosmos": InitialState = 'Cosmos'; break;
case "jb-frostbite": InitialState = 'Frostbite'; break;
case "jb-heights-gold-v2": InitialState = 'Heights'; break;
case "jb-indusrage2-gold": InitialState = 'IndusRage'; break;
case "jb-poseidon-gold": InitialState = 'Poseidon'; break;
case "jb-thedecks": InitialState = 'TheDecks'; break;
}
(Most of the fixes spawned or modified actors in the various states' BeginState(). Some of the fixes involved more complex logic, so states were needed.)
Later, for my UT2004 Christmas Decorations server actor, I used code like this piece:
Code: Select all
switch (Locs(A.StaticMesh.Name))
{
case "idomatakkenmid":
case "idomatakkenend":
SpawnEmitter(A, class'ChristmasTreeLightsEmitterF');
break;
case "miscstatue01ba": // for some reason myLevel'd in ONS-Crossfire
SpawnDecoHat(A, vect(-4,0,111), rot(0,16384,-2048), 0.47, vect(1,1,2));
SpawnDecoBag(A, vect(24,16,60), rot(0,-16384,3072), 2.0, vect(1,1,1));
break;
case "colWallFirePot2AR": // face deco on Bridge of Fate
SpawnDecoHat(A, vect(0,3,-4), rot(0,0,0), 0.25, vect(1.5,0.5,1.05));
break;
case "bannersconce": // myLevel'd in BR-Serenity, but also in sc_volcano_m package
SpawnDecoHat(A, vect(0,2,144), rot(0,32768,3072), 0.225, vect(1,1,1));
break;
case "hourekandelaarkemtelelcitilicht": // myLevel'd
case "kandelaarkemtelelcitilicht": // from HourmeshstuffX3, but possibly also myLevel'd
SpawnDecoHat(A, vect(456.4,48.95,94), rot(0,0,0), 0.2, vect(1,1,1));
break;
case "phonepole": // don't want spiffingrad left out
SpawnDecoHat(A, vect(-89,11,-12), rot(0,32768,0), 0.46, vect(1,1,1.5));
break;
case "StatueCon1":
SpawnDecoHat(A, vect(-56,-64,536), rot(0,16384,-1024), 0.8, vect(0.85,1,1));
SpawnDecoBag(A, vect(-16,-64,480), rot(0,-16384,0), 2.0, vect(0.9,1,1.5));
break;
}
There's nothing wrong with the question style bool function returning the value through an out parameter, it's actually a relatively common pattern in e.g. C# as well. (A common pattern there is something like "Foo value; if (dict.TryGetValue(key, out value)) DoSomethingWith(value);")
I also don't think (without explicitly profiling it) the assingment + null check approach will provide any significant performance changes over the bool return + out parameter approach.