Merge pull request #5411 from RoosterDragon/general-clean

General Cleanup
This commit is contained in:
Chris Forbes
2014-05-25 11:03:03 +12:00
92 changed files with 177 additions and 179 deletions

View File

@@ -402,10 +402,10 @@ namespace OpenRA
}
[AttributeUsage(AttributeTargets.Field)]
public class IgnoreAttribute : Attribute { }
public sealed class IgnoreAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public class LoadUsingAttribute : Attribute
public sealed class LoadUsingAttribute : Attribute
{
Func<MiniYaml, object> loaderFuncCache;
public readonly string Loader;
@@ -440,12 +440,12 @@ namespace OpenRA
}
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class TranslateAttribute : Attribute { }
public sealed class TranslateAttribute : Attribute { }
public class FieldFromYamlKeyAttribute : Attribute { }
public sealed class FieldFromYamlKeyAttribute : Attribute { }
// mirrors DescriptionAttribute from System.ComponentModel but we dont want to have to use that everywhere.
public class DescAttribute : Attribute
public sealed class DescAttribute : Attribute
{
public readonly string[] Lines;
public DescAttribute(params string[] lines) { Lines = lines; }

View File

@@ -47,7 +47,7 @@ namespace OpenRA.FileFormats
delegate void CipherFunc( ref uint a, ref uint b );
uint[] RunCipher(uint[] data, CipherFunc f)
static uint[] RunCipher(uint[] data, CipherFunc f)
{
uint[] result = new uint[data.Length];
@@ -120,7 +120,7 @@ namespace OpenRA.FileFormats
a ^= bf_f(b) ^ m_p[n];
}
uint SwapBytes(uint i)
static uint SwapBytes(uint i)
{
i = (i << 16) | (i >> 16);
i = ((i << 8) & 0xff00ff00) | ((i >> 8) & 0x00ff00ff);

View File

@@ -35,13 +35,13 @@ namespace OpenRA.FileFormats
uint glob1_hi_bitlen;
uint glob1_hi_inv_lo, glob1_hi_inv_hi;
void init_bignum(uint[] n, uint val, uint len)
static void init_bignum(uint[] n, uint val, uint len)
{
for (int i = 0; i < len; i++) n[i] = 0;
n[0] = val;
}
void move_key_to_big(uint[] n, byte[] key, uint klen, uint blen)
static void move_key_to_big(uint[] n, byte[] key, uint klen, uint blen)
{
byte sign;
@@ -60,7 +60,7 @@ namespace OpenRA.FileFormats
}
}
void key_to_bignum(uint[] n, byte[] key, uint len)
static void key_to_bignum(uint[] n, byte[] key, uint len)
{
uint keylen;
int i;
@@ -85,7 +85,7 @@ namespace OpenRA.FileFormats
move_key_to_big(n, key.Skip(j).ToArray(), keylen, len);
}
uint len_bignum(uint[] n, uint len)
static uint len_bignum(uint[] n, uint len)
{
uint i;
i = len - 1;
@@ -93,7 +93,7 @@ namespace OpenRA.FileFormats
return i + 1;
}
uint bitlen_bignum(uint[] n, uint len)
static uint bitlen_bignum(uint[] n, uint len)
{
uint ddlen, bitlen, mask;
ddlen = len_bignum(n, len);
@@ -122,7 +122,7 @@ namespace OpenRA.FileFormats
return (55 / a + 1) * (a + 1);
}
int cmp_bignum(uint[] n1, uint[] n2, uint len)
static int cmp_bignum(uint[] n1, uint[] n2, uint len)
{
while (len > 0)
@@ -134,12 +134,12 @@ namespace OpenRA.FileFormats
return 0;
}
void mov_bignum(uint[] dest, uint[] src, uint len)
static void mov_bignum(uint[] dest, uint[] src, uint len)
{
Array.Copy(src, dest, len);
}
void shr_bignum(uint[] n, int bits, int len)
static void shr_bignum(uint[] n, int bits, int len)
{
int i; int i2 = bits / 32;
@@ -155,7 +155,7 @@ namespace OpenRA.FileFormats
n[i] = n[i] >> bits;
}
void shl_bignum(uint[] n, int bits, int len)
static void shl_bignum(uint[] n, int bits, int len)
{
int i, i2;
@@ -172,7 +172,7 @@ namespace OpenRA.FileFormats
n[0] <<= bits;
}
uint sub_bignum(uint[] dest, uint[] src1, uint[] src2, uint carry, int len)
static uint sub_bignum(uint[] dest, uint[] src1, uint[] src2, uint carry, int len)
{
uint i1, i2;
@@ -199,7 +199,7 @@ namespace OpenRA.FileFormats
return carry;
}
unsafe uint sub_bignum(uint* dest, uint* src1, uint* src2, uint carry, int len)
static unsafe uint sub_bignum(uint* dest, uint* src1, uint* src2, uint carry, int len)
{
uint i1, i2;
@@ -220,7 +220,7 @@ namespace OpenRA.FileFormats
return carry;
}
void inv_bignum(uint[] n1, uint[] n2, uint len)
static void inv_bignum(uint[] n1, uint[] n2, uint len)
{
uint[] n_tmp = new uint[64];
uint n2_bytelen, bit;
@@ -255,7 +255,7 @@ namespace OpenRA.FileFormats
init_bignum(n_tmp, 0, len);
}
void inc_bignum(uint[] n, uint len)
static void inc_bignum(uint[] n, uint len)
{
int i = 0;
while ((++n[i] == 0) && (--len > 0)) i++;
@@ -282,7 +282,7 @@ namespace OpenRA.FileFormats
glob1_hi_inv_hi = (ushort)(glob1_hi_inv[0] >> 16);
}
unsafe void mul_bignum_word(ushort *pn1, uint[] n2, uint mul, uint len)
static unsafe void mul_bignum_word(ushort* pn1, uint[] n2, uint mul, uint len)
{
uint i, tmp;
unsafe
@@ -305,7 +305,7 @@ namespace OpenRA.FileFormats
}
}
void mul_bignum(uint[] dest, uint[] src1, uint[] src2, uint len)
static void mul_bignum(uint[] dest, uint[] src1, uint[] src2, uint len)
{
uint i;
@@ -324,13 +324,13 @@ namespace OpenRA.FileFormats
}
}
void not_bignum(uint[] n, uint len)
static void not_bignum(uint[] n, uint len)
{
uint i;
for (i = 0; i < len; i++) n[i] = ~n[i];
}
void neg_bignum(uint[] n, uint len)
static void neg_bignum(uint[] n, uint len)
{
not_bignum(n, len);
inc_bignum(n, len);
@@ -348,7 +348,7 @@ namespace OpenRA.FileFormats
return i & 0xffff;
}
void dec_bignum(uint[] n, uint len)
static void dec_bignum(uint[] n, uint len)
{
int i = 0;
while ((--n[i] == 0xffffffff) && (--len > 0))
@@ -450,7 +450,7 @@ namespace OpenRA.FileFormats
}
}
unsafe void memcpy(byte* dest, byte* src, int len)
static unsafe void memcpy(byte* dest, byte* src, int len)
{
while (len-- != 0) *dest++ = *src++;
}

View File

@@ -66,7 +66,7 @@ namespace OpenRA.FileFormats
return ret;
}
bool ProcessEntry(string line, IniSection currentSection)
static bool ProcessEntry(string line, IniSection currentSection)
{
var comment = line.IndexOf(';');
if (comment >= 0)

View File

@@ -257,7 +257,7 @@ namespace OpenRA.FileFormats
int cachedFrame = -1;
void DecodeFrameData( int frame )
void DecodeFrameData()
{
cachedFrame = currentFrame;
for (var y = 0; y < blocks.Y; y++)
@@ -280,7 +280,7 @@ namespace OpenRA.FileFormats
get
{
if (cachedFrame != currentFrame)
DecodeFrameData(currentFrame);
DecodeFrameData();
return frameData;
}

View File

@@ -40,7 +40,7 @@ namespace OpenRA.FileFormats
uint BodySize;
void ReadVoxelData(Stream s, VxlLimb l)
static void ReadVoxelData(Stream s, VxlLimb l)
{
var baseSize = l.Size[0]*l.Size[1];
var colStart = new int[baseSize];

View File

@@ -62,7 +62,7 @@ namespace OpenRA.FileSystem
}
uint ParseDirectory(BinaryReader reader)
static uint ParseDirectory(BinaryReader reader)
{
// Parse directory header
var FileCount = reader.ReadUInt16();

View File

@@ -73,7 +73,7 @@ namespace OpenRA.FileSystem
);
}
List<PackageEntry> ParseHeader(Stream s, long offset, out long headerEnd)
static List<PackageEntry> ParseHeader(Stream s, long offset, out long headerEnd)
{
s.Seek(offset, SeekOrigin.Begin);
var numFiles = s.ReadUInt16();
@@ -87,7 +87,7 @@ namespace OpenRA.FileSystem
return items;
}
MemoryStream DecryptHeader(Stream s, long offset, out long headerEnd)
static MemoryStream DecryptHeader(Stream s, long offset, out long headerEnd)
{
s.Seek(offset, SeekOrigin.Begin);
@@ -121,7 +121,7 @@ namespace OpenRA.FileSystem
return ms;
}
uint[] ReadBlocks(Stream s, long offset, int count)
static uint[] ReadBlocks(Stream s, long offset, int count)
{
s.Seek(offset, SeekOrigin.Begin);

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Graphics
return j < 0 ? j + trail.Length : j;
}
WPos Average(params WPos[] list)
static WPos Average(params WPos[] list)
{
return list.Average();
}

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Graphics
{
public class Minimap
public static class Minimap
{
public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false)
{

View File

@@ -14,6 +14,7 @@ using OpenRA.FileFormats;
namespace OpenRA.Graphics
{
[Serializable]
public class SheetOverflowException : Exception
{
public SheetOverflowException(string message)

View File

@@ -134,12 +134,7 @@ namespace OpenRA.Graphics
return g;
}
static SpriteFont()
{
library = new Library();
}
static Library library;
static Library library = new Library();
static SheetBuilder builder;
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Graphics
int totalVertexCount;
int cachedVertexCount;
SheetBuilder CreateSheetBuilder()
static SheetBuilder CreateSheetBuilder()
{
var allocated = false;
Func<Sheet> allocate = () =>

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Graphics
Theater = new Theater(world.TileSet);
terrainRenderer = new TerrainRenderer(world, this);
devTrait = new Lazy<DeveloperMode>(() => world.LocalPlayer != null ? world.LocalPlayer.PlayerActor.Trait<DeveloperMode>() : null);
devTrait = Exts.Lazy(() => world.LocalPlayer != null ? world.LocalPlayer.PlayerActor.Trait<DeveloperMode>() : null);
}
PaletteReference CreatePaletteReference(string name)

View File

@@ -15,7 +15,7 @@ using OpenRA.Graphics;
namespace OpenRA
{
[AttributeUsage(AttributeTargets.Assembly)]
public class RendererAttribute : Attribute
public sealed class RendererAttribute : Attribute
{
public readonly Type Type;

View File

@@ -293,6 +293,7 @@ namespace OpenRA
}
}
[Serializable]
public class YamlException : Exception
{
public YamlException(string s) : base(s) { }

View File

@@ -145,12 +145,12 @@ namespace OpenRA.Network
throw new InvalidOperationException("Out of sync in frame {0}.\n {1}\n Compare syncreport.log with other players.".F(frame, orders.ElementAt(index).Order.ToString()));
}
void OutOfSync(int frame)
static void OutOfSync(int frame)
{
throw new InvalidOperationException("Out of sync in frame {0}.\n Compare syncreport.log with other players.".F(frame));
}
void OutOfSync(int frame, string blame)
static void OutOfSync(int frame, string blame)
{
throw new InvalidOperationException("Out of sync in frame {0}: Blame {1}.\n Compare syncreport.log with other players.".F(frame, blame));
}

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Network
});
}
bool IsGameStart(byte[] data)
static bool IsGameStart(byte[] data)
{
if (data.Length == 5 && data[4] == 0xbf)
return false;

View File

@@ -14,7 +14,7 @@ using Mono.Nat;
namespace OpenRA.Network
{
public class UPnP
public static class UPnP
{
public static INatDevice NatDevice;

View File

@@ -102,6 +102,6 @@ namespace OpenRA
}
[AttributeUsage(AttributeTargets.Constructor)]
public class UseCtorAttribute : Attribute { }
public sealed class UseCtorAttribute : Attribute { }
}
}

View File

@@ -23,7 +23,7 @@ namespace OpenRA
{
public static PlatformType CurrentPlatform { get { return currentPlatform.Value; } }
static Lazy<PlatformType> currentPlatform = new Lazy<PlatformType>(GetCurrentPlatform);
static Lazy<PlatformType> currentPlatform = Exts.Lazy(GetCurrentPlatform);
static PlatformType GetCurrentPlatform()
{

View File

@@ -17,9 +17,7 @@ namespace OpenRA.Primitives
static class BitAllocator<T> where T : struct
{
static int nextVal = 1;
static Cache<string,int> bits;
static BitAllocator() { bits = new Cache<string, int>( _ => Allocate() ); }
static Cache<string, int> bits = new Cache<string, int>(_ => Allocate());
static int Allocate()
{

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Primitives
{
hax = new Dictionary<T, U>(c);
if (loader == null)
throw new ArgumentNullException();
throw new ArgumentNullException("loader");
this.loader = loader;
}

View File

@@ -34,13 +34,13 @@ namespace OpenRA.Scripting
}
// For traitinfos that provide actor / player commands
public class ScriptPropertyGroupAttribute : Attribute
public sealed class ScriptPropertyGroupAttribute : Attribute
{
public readonly string Category;
public ScriptPropertyGroupAttribute(string category) { Category = category; }
}
public class ScriptActorPropertyActivityAttribute : Attribute { }
public sealed class ScriptActorPropertyActivityAttribute : Attribute { }
public abstract class ScriptActorProperties
{
@@ -75,7 +75,7 @@ namespace OpenRA.Scripting
}
}
public class ScriptGlobalAttribute : Attribute
public sealed class ScriptGlobalAttribute : Attribute
{
public readonly string Name;
public ScriptGlobalAttribute(string name) { Name = name; }

View File

@@ -49,23 +49,23 @@ namespace OpenRA.Scripting
public static string LuaDocString(this MemberInfo mi)
{
if (mi is MethodInfo)
var methodInfo = mi as MethodInfo;
if (methodInfo != null)
{
var methodInfo = mi as MethodInfo;
var parameters = methodInfo.GetParameters().Select(pi => pi.LuaDocString());
return "{0} {1}({2})".F(methodInfo.ReturnType.LuaDocString(), mi.Name, parameters.JoinWith(", "));
}
if (mi is PropertyInfo)
var propertyInfo = mi as PropertyInfo;
if (propertyInfo != null)
{
var pi = mi as PropertyInfo;
var types = new List<string>();
if (pi.GetGetMethod() != null)
if (propertyInfo.GetGetMethod() != null)
types.Add("get;");
if (pi.GetSetMethod() != null)
if (propertyInfo.GetSetMethod() != null)
types.Add("set;");
return "{0} {1} {{ {2} }}".F(pi.PropertyType.LuaDocString(), mi.Name, types.JoinWith(" "));
return "{0} {1} {{ {2} }}".F(propertyInfo.PropertyType.LuaDocString(), mi.Name, types.JoinWith(" "));
}
return "Unknown field: {0}".F(mi.Name);

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Scripting
if (!IsMethod)
throw new LuaException("Trying to invoke a ScriptMemberWrapper that isn't a method!");
var mi = Member as MethodInfo;
var mi = (MethodInfo)Member;
var pi = mi.GetParameters();
object[] clrArgs = new object[pi.Length];
@@ -71,7 +71,7 @@ namespace OpenRA.Scripting
throw new LuaException("Unable to convert parameter {0} to {1}".F(i, pi[i].ParameterType.Name));
}
var ret = (Member as MethodInfo).Invoke(Target, clrArgs);
var ret = (mi.Invoke(Target, clrArgs));
return ret.ToLuaValue(context);
}

View File

@@ -687,7 +687,7 @@ namespace OpenRA.Server
}
}
void SendData(Socket s, byte[] data)
static void SendData(Socket s, byte[] data)
{
var start = 0;
var length = data.Length;

View File

@@ -260,7 +260,7 @@ namespace OpenRA
root.WriteToFile(settingsFile);
}
void LoadSectionYaml(MiniYaml yaml, object section)
static void LoadSectionYaml(MiniYaml yaml, object section)
{
var defaults = Activator.CreateInstance(section.GetType());
FieldLoader.InvalidValueAction = (s, t, f) =>

View File

@@ -607,7 +607,7 @@ namespace OpenRA
slot.FrameStarted = currFrame;
slot.Sound = sound;
slot.IsRelative = relative;
return new OpenAlSound(source, (sound as OpenAlSoundSource).Buffer, loop, relative, pos, volume * atten);
return new OpenAlSound(source, ((OpenAlSoundSource)sound).Buffer, loop, relative, pos, volume * atten);
}
public float Volume

View File

@@ -79,9 +79,9 @@ namespace OpenRA
sb.AppendFormat("Exception of type `{0}`: {1}", e.GetType().FullName, e.Message);
if (e is TypeLoadException)
var tle = e as TypeLoadException;
if (tle != null)
{
var tle = (TypeLoadException)e;
sb.AppendLine();
Indent(sb, d);
sb.AppendFormat("TypeName=`{0}`", tle.TypeName);

View File

@@ -19,7 +19,7 @@ using OpenRA.Primitives;
namespace OpenRA
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class SyncAttribute : Attribute { }
public sealed class SyncAttribute : Attribute { }
public interface ISync { } /* marker interface */
public static class Sync

View File

@@ -76,7 +76,7 @@ namespace OpenRA
InnerGet(t).Add(actor, val);
}
void CheckDestroyed(Actor actor)
static void CheckDestroyed(Actor actor)
{
if (actor.Destroyed)
throw new InvalidOperationException("Attempted to get trait from destroyed object ({0})".F(actor));

View File

@@ -15,11 +15,11 @@ namespace OpenRA.Traits
/* attributes used by RALint to understand the rules */
[AttributeUsage(AttributeTargets.Field)]
public class ActorReferenceAttribute : Attribute { }
public sealed class ActorReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public class WeaponReferenceAttribute : Attribute { }
public sealed class WeaponReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public class VoiceReferenceAttribute : Attribute { }
public sealed class VoiceReferenceAttribute : Attribute { }
}

View File

@@ -71,7 +71,7 @@ namespace OpenRA
return widget;
}
Widget NewWidget(string widgetType, WidgetArgs args)
static Widget NewWidget(string widgetType, WidgetArgs args)
{
widgetType = widgetType.Split('@')[0];
return Game.modData.ObjectCreator.CreateObject<Widget>(widgetType + "Widget", args);

View File

@@ -229,7 +229,7 @@ namespace OpenRA.Widgets
return false;
}
IEnumerable<Actor> SelectActorsInBox(World world, int2 a, int2 b, Func<Actor, bool> cond)
static IEnumerable<Actor> SelectActorsInBox(World world, int2 a, int2 b, Func<Actor, bool> cond)
{
return world.ScreenMap.ActorsInBox(a, b)
.Where(x => x.HasTrait<Selectable>() && x.Trait<Selectable>().Info.Selectable && !world.FogObscures(x) && cond(x))