Fix StyleCop warnings in OpenRA.Game
This commit is contained in:
@@ -24,12 +24,13 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
||||||
{
|
{
|
||||||
[Sync] public Player Owner;
|
|
||||||
|
|
||||||
public readonly ActorInfo Info;
|
public readonly ActorInfo Info;
|
||||||
public readonly World World;
|
public readonly World World;
|
||||||
public readonly uint ActorID;
|
public readonly uint ActorID;
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
public Player Owner;
|
||||||
|
|
||||||
public bool IsInWorld { get; internal set; }
|
public bool IsInWorld { get; internal set; }
|
||||||
public bool Destroyed { get; private set; }
|
public bool Destroyed { get; private set; }
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static CVec operator -(CPos a, CPos b) { return new CVec(a.X - b.X, a.Y - b.Y); }
|
public static CVec operator -(CPos a, CPos b) { return new CVec(a.X - b.X, a.Y - b.Y); }
|
||||||
|
|
||||||
public static bool operator ==(CPos me, CPos other) { return (me.X == other.X && me.Y == other.Y); }
|
public static bool operator ==(CPos me, CPos other) { return me.X == other.X && me.Y == other.Y; }
|
||||||
public static bool operator !=(CPos me, CPos other) { return !(me == other); }
|
public static bool operator !=(CPos me, CPos other) { return !(me == other); }
|
||||||
|
|
||||||
public static CPos Max(CPos a, CPos b) { return new CPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
public static CPos Max(CPos a, CPos b) { return new CPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static CVec operator -(CVec a) { return new CVec(-a.X, -a.Y); }
|
public static CVec operator -(CVec a) { return new CVec(-a.X, -a.Y); }
|
||||||
|
|
||||||
public static bool operator ==(CVec me, CVec other) { return (me.X == other.X && me.Y == other.Y); }
|
public static bool operator ==(CVec me, CVec other) { return me.X == other.X && me.Y == other.Y; }
|
||||||
public static bool operator !=(CVec me, CVec other) { return !(me == other); }
|
public static bool operator !=(CVec me, CVec other) { return !(me == other); }
|
||||||
|
|
||||||
public static CVec Max(CVec a, CVec b) { return new CVec(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
public static CVec Max(CVec a, CVec b) { return new CVec(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
||||||
@@ -48,8 +48,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
return new CVec(
|
return new CVec(
|
||||||
Math.Min(r.Right, Math.Max(X, r.Left)),
|
Math.Min(r.Right, Math.Max(X, r.Left)),
|
||||||
Math.Min(r.Bottom, Math.Max(Y, r.Top))
|
Math.Min(r.Bottom, Math.Max(Y, r.Top)));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
||||||
|
|||||||
@@ -91,8 +91,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
return (k & mod) == mod;
|
return (k & mod) == mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k)
|
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k)
|
||||||
where V : new()
|
where V : new()
|
||||||
{
|
{
|
||||||
@@ -184,6 +183,7 @@ namespace OpenRA
|
|||||||
u = nextU;
|
u = nextU;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,6 @@ namespace OpenRA
|
|||||||
// Adjust for other rounding modes
|
// Adjust for other rounding modes
|
||||||
if (round == ISqrtRoundMode.Nearest && remainder > root)
|
if (round == ISqrtRoundMode.Nearest && remainder > root)
|
||||||
root += 1;
|
root += 1;
|
||||||
|
|
||||||
else if (round == ISqrtRoundMode.Ceiling && root * root < number)
|
else if (round == ISqrtRoundMode.Ceiling && root * root < number)
|
||||||
root += 1;
|
root += 1;
|
||||||
|
|
||||||
@@ -284,7 +283,6 @@ namespace OpenRA
|
|||||||
// Adjust for other rounding modes
|
// Adjust for other rounding modes
|
||||||
if (round == ISqrtRoundMode.Nearest && remainder > root)
|
if (round == ISqrtRoundMode.Nearest && remainder > root)
|
||||||
root += 1;
|
root += 1;
|
||||||
|
|
||||||
else if (round == ISqrtRoundMode.Ceiling && root * root < number)
|
else if (round == ISqrtRoundMode.Ceiling && root * root < number)
|
||||||
root += 1;
|
root += 1;
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ namespace OpenRA
|
|||||||
return res;
|
return res;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(ushort))
|
else if (fieldType == typeof(ushort))
|
||||||
{
|
{
|
||||||
ushort res;
|
ushort res;
|
||||||
@@ -147,7 +146,6 @@ namespace OpenRA
|
|||||||
return res;
|
return res;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(float))
|
else if (fieldType == typeof(float))
|
||||||
{
|
{
|
||||||
float res;
|
float res;
|
||||||
@@ -155,7 +153,6 @@ namespace OpenRA
|
|||||||
return res * (value.Contains('%') ? 0.01f : 1f);
|
return res * (value.Contains('%') ? 0.01f : 1f);
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(decimal))
|
else if (fieldType == typeof(decimal))
|
||||||
{
|
{
|
||||||
decimal res;
|
decimal res;
|
||||||
@@ -163,14 +160,12 @@ namespace OpenRA
|
|||||||
return res * (value.Contains('%') ? 0.01m : 1m);
|
return res * (value.Contains('%') ? 0.01m : 1m);
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(string))
|
else if (fieldType == typeof(string))
|
||||||
{
|
{
|
||||||
if (field != null && field.HasAttribute<TranslateAttribute>())
|
if (field != null && field.HasAttribute<TranslateAttribute>())
|
||||||
return Regex.Replace(value, "@[^@]+@", m => Translate(m.Value.Substring(1, m.Value.Length - 2)), RegexOptions.Compiled);
|
return Regex.Replace(value, "@[^@]+@", m => Translate(m.Value.Substring(1, m.Value.Length - 2)), RegexOptions.Compiled);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(Color))
|
else if (fieldType == typeof(Color))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -187,7 +182,6 @@ namespace OpenRA
|
|||||||
Exts.ParseIntegerInvariant(parts[3]).Clamp(0, 255));
|
Exts.ParseIntegerInvariant(parts[3]).Clamp(0, 255));
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(Color[]))
|
else if (fieldType == typeof(Color[]))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -208,7 +202,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(HSLColor))
|
else if (fieldType == typeof(HSLColor))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -222,7 +215,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(Hotkey))
|
else if (fieldType == typeof(Hotkey))
|
||||||
{
|
{
|
||||||
Hotkey res;
|
Hotkey res;
|
||||||
@@ -231,7 +223,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(WRange))
|
else if (fieldType == typeof(WRange))
|
||||||
{
|
{
|
||||||
WRange res;
|
WRange res;
|
||||||
@@ -240,7 +231,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(WVec))
|
else if (fieldType == typeof(WVec))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -253,7 +243,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(WVec[]))
|
else if (fieldType == typeof(WVec[]))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -274,7 +263,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return vecs;
|
return vecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(WPos))
|
else if (fieldType == typeof(WPos))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -287,7 +275,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(WAngle))
|
else if (fieldType == typeof(WAngle))
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
@@ -295,7 +282,6 @@ namespace OpenRA
|
|||||||
return new WAngle(res);
|
return new WAngle(res);
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(WRot))
|
else if (fieldType == typeof(WRot))
|
||||||
{
|
{
|
||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
@@ -310,7 +296,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(CPos))
|
else if (fieldType == typeof(CPos))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -318,7 +303,6 @@ namespace OpenRA
|
|||||||
Exts.ParseIntegerInvariant(parts[0]),
|
Exts.ParseIntegerInvariant(parts[0]),
|
||||||
Exts.ParseIntegerInvariant(parts[1]));
|
Exts.ParseIntegerInvariant(parts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(CVec))
|
else if (fieldType == typeof(CVec))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -326,7 +310,6 @@ namespace OpenRA
|
|||||||
Exts.ParseIntegerInvariant(parts[0]),
|
Exts.ParseIntegerInvariant(parts[0]),
|
||||||
Exts.ParseIntegerInvariant(parts[1]));
|
Exts.ParseIntegerInvariant(parts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType.IsEnum)
|
else if (fieldType.IsEnum)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -338,10 +321,8 @@ namespace OpenRA
|
|||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(bool))
|
else if (fieldType == typeof(bool))
|
||||||
return ParseYesNo(value, fieldType, fieldName);
|
return ParseYesNo(value, fieldType, fieldName);
|
||||||
|
|
||||||
else if (fieldType.IsArray)
|
else if (fieldType.IsArray)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
@@ -354,7 +335,6 @@ namespace OpenRA
|
|||||||
ret.SetValue(GetValue(fieldName, fieldType.GetElementType(), parts[i].Trim(), field), i);
|
ret.SetValue(GetValue(fieldName, fieldType.GetElementType(), parts[i].Trim(), field), i);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(Size))
|
else if (fieldType == typeof(Size))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -362,7 +342,6 @@ namespace OpenRA
|
|||||||
Exts.ParseIntegerInvariant(parts[0]),
|
Exts.ParseIntegerInvariant(parts[0]),
|
||||||
Exts.ParseIntegerInvariant(parts[1]));
|
Exts.ParseIntegerInvariant(parts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(int2))
|
else if (fieldType == typeof(int2))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -370,7 +349,6 @@ namespace OpenRA
|
|||||||
Exts.ParseIntegerInvariant(parts[0]),
|
Exts.ParseIntegerInvariant(parts[0]),
|
||||||
Exts.ParseIntegerInvariant(parts[1]));
|
Exts.ParseIntegerInvariant(parts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(float2))
|
else if (fieldType == typeof(float2))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -383,7 +361,6 @@ namespace OpenRA
|
|||||||
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
|
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
|
||||||
return new float2(xx, yy);
|
return new float2(xx, yy);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(Rectangle))
|
else if (fieldType == typeof(Rectangle))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -393,7 +370,6 @@ namespace OpenRA
|
|||||||
Exts.ParseIntegerInvariant(parts[2]),
|
Exts.ParseIntegerInvariant(parts[2]),
|
||||||
Exts.ParseIntegerInvariant(parts[3]));
|
Exts.ParseIntegerInvariant(parts[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>))
|
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>))
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -401,14 +377,12 @@ namespace OpenRA
|
|||||||
var argValues = new object[] { parts };
|
var argValues = new object[] { parts };
|
||||||
return fieldType.GetConstructor(argTypes).Invoke(argValues);
|
return fieldType.GetConstructor(argTypes).Invoke(argValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||||
{
|
{
|
||||||
var innerType = fieldType.GetGenericArguments().First();
|
var innerType = fieldType.GetGenericArguments().First();
|
||||||
var innerValue = GetValue("Nullable<T>", innerType, value, field);
|
var innerValue = GetValue("Nullable<T>", innerType, value, field);
|
||||||
return fieldType.GetConstructor(new[] { innerType }).Invoke(new[] { innerValue });
|
return fieldType.GetConstructor(new[] { innerType }).Invoke(new[] { innerValue });
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(DateTime))
|
else if (fieldType == typeof(DateTime))
|
||||||
{
|
{
|
||||||
DateTime dt;
|
DateTime dt;
|
||||||
@@ -416,7 +390,6 @@ namespace OpenRA
|
|||||||
return dt;
|
return dt;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var conv = TypeDescriptor.GetConverter(fieldType);
|
var conv = TypeDescriptor.GetConverter(fieldType);
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
return new MiniYaml(
|
return new MiniYaml(
|
||||||
null,
|
null,
|
||||||
fields.Select(info => new MiniYamlNode(info.YamlName, FormatValue(o, info.Field))).ToList()
|
fields.Select(info => new MiniYamlNode(info.YamlName, FormatValue(o, info.Field))).ToList());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MiniYamlNode SaveField(object o, string field)
|
public static MiniYamlNode SaveField(object o, string field)
|
||||||
|
|||||||
@@ -142,9 +142,9 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
} while (len != 0);
|
} while (len != 0);
|
||||||
}
|
}
|
||||||
// literal value
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// literal value
|
||||||
var symbol = EncodedLiterals ? Decode(litcode, br) : br.ReadBits(8);
|
var symbol = EncodedLiterals ? Decode(litcode, br) : br.ReadBits(8);
|
||||||
outBuffer[next++] = (byte)symbol;
|
outBuffer[next++] = (byte)symbol;
|
||||||
if (next == MAXWIN)
|
if (next == MAXWIN)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
uint l = 0, r = 0;
|
uint l = 0, r = 0;
|
||||||
|
|
||||||
for (var i = 0; i < 18; )
|
for (var i = 0; i < 18;)
|
||||||
{
|
{
|
||||||
Encrypt(ref l, ref r);
|
Encrypt(ref l, ref r);
|
||||||
m_p[i++] = l;
|
m_p[i++] = l;
|
||||||
@@ -34,7 +34,7 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < 4; ++i)
|
for (var i = 0; i < 4; ++i)
|
||||||
for (var j = 0; j < 256; )
|
for (var j = 0; j < 256;)
|
||||||
{
|
{
|
||||||
Encrypt(ref l, ref r);
|
Encrypt(ref l, ref r);
|
||||||
m_s[i, j++] = l;
|
m_s[i, j++] = l;
|
||||||
@@ -45,7 +45,7 @@ namespace OpenRA.FileFormats
|
|||||||
public uint[] Encrypt(uint[] data) { return RunCipher(data, Encrypt); }
|
public uint[] Encrypt(uint[] data) { return RunCipher(data, Encrypt); }
|
||||||
public uint[] Decrypt(uint[] data) { return RunCipher(data, Decrypt); }
|
public uint[] Decrypt(uint[] data) { return RunCipher(data, Decrypt); }
|
||||||
|
|
||||||
delegate void CipherFunc( ref uint a, ref uint b );
|
delegate void CipherFunc(ref uint a, ref uint b);
|
||||||
|
|
||||||
static uint[] RunCipher(uint[] data, CipherFunc f)
|
static uint[] RunCipher(uint[] data, CipherFunc f)
|
||||||
{
|
{
|
||||||
@@ -56,7 +56,7 @@ namespace OpenRA.FileFormats
|
|||||||
while (size-- > 0)
|
while (size-- > 0)
|
||||||
{
|
{
|
||||||
var a = SwapBytes(data[i]);
|
var a = SwapBytes(data[i]);
|
||||||
var b = SwapBytes(data[i+1]);
|
var b = SwapBytes(data[i + 1]);
|
||||||
|
|
||||||
f(ref a, ref b);
|
f(ref a, ref b);
|
||||||
|
|
||||||
@@ -73,13 +73,14 @@ namespace OpenRA.FileFormats
|
|||||||
_a ^= m_p[0];
|
_a ^= m_p[0];
|
||||||
|
|
||||||
var x = false;
|
var x = false;
|
||||||
for( var i = 1; i <= 16; i++, x ^= true)
|
for (var i = 1; i <= 16; i++, x ^= true)
|
||||||
{
|
{
|
||||||
if (x)
|
if (x)
|
||||||
Round(ref _a, _b, i);
|
Round(ref _a, _b, i);
|
||||||
else
|
else
|
||||||
Round(ref _b, _a, i);
|
Round(ref _b, _a, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
_b ^= m_p[17];
|
_b ^= m_p[17];
|
||||||
|
|
||||||
a = _b;
|
a = _b;
|
||||||
@@ -99,6 +100,7 @@ namespace OpenRA.FileFormats
|
|||||||
else
|
else
|
||||||
Round(ref _b, _a, i);
|
Round(ref _b, _a, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
_b ^= m_p[0];
|
_b ^= m_p[0];
|
||||||
|
|
||||||
a = _b;
|
a = _b;
|
||||||
@@ -400,7 +402,6 @@ namespace OpenRA.FileFormats
|
|||||||
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
|
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
|
||||||
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace OpenRA.FileFormats
|
|||||||
public uint[] key2 = new uint[64];
|
public uint[] key2 = new uint[64];
|
||||||
public uint len;
|
public uint len;
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicKey pubkey = new PublicKey();
|
PublicKey pubkey = new PublicKey();
|
||||||
|
|
||||||
uint[] glob1 = new uint[64];
|
uint[] glob1 = new uint[64];
|
||||||
@@ -81,6 +82,7 @@ namespace OpenRA.FileFormats
|
|||||||
keylen = key[j];
|
keylen = key[j];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keylen <= len * 4)
|
if (keylen <= len * 4)
|
||||||
move_key_to_big(n, key.Skip(j).ToArray(), keylen, len);
|
move_key_to_big(n, key.Skip(j).ToArray(), keylen, len);
|
||||||
}
|
}
|
||||||
@@ -105,6 +107,7 @@ namespace OpenRA.FileFormats
|
|||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
bitlen--;
|
bitlen--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitlen;
|
return bitlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,13 +127,13 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
static int cmp_bignum(uint[] n1, uint[] n2, uint len)
|
static int cmp_bignum(uint[] n1, uint[] n2, uint len)
|
||||||
{
|
{
|
||||||
|
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
--len;
|
--len;
|
||||||
if (n1[len] < n2[len]) return -1;
|
if (n1[len] < n2[len]) return -1;
|
||||||
if (n1[len] > n2[len]) return 1;
|
if (n1[len] > n2[len]) return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +152,7 @@ namespace OpenRA.FileFormats
|
|||||||
for (; i < len; i++) n[i] = 0;
|
for (; i < len; i++) n[i] = 0;
|
||||||
bits = bits % 32;
|
bits = bits % 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bits == 0) return;
|
if (bits == 0) return;
|
||||||
for (i = 0; i < len - 1; i++) n[i] = (n[i] >> bits) | (n[i + 1] << (32 -
|
for (i = 0; i < len - 1; i++) n[i] = (n[i] >> bits) | (n[i + 1] << (32 -
|
||||||
bits));
|
bits));
|
||||||
@@ -166,6 +170,7 @@ namespace OpenRA.FileFormats
|
|||||||
for (; i > 0; i--) n[i] = 0;
|
for (; i > 0; i--) n[i] = 0;
|
||||||
bits = bits % 32;
|
bits = bits % 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bits == 0) return;
|
if (bits == 0) return;
|
||||||
for (i = len - 1; i > 0; i--) n[i] = (n[i] << bits) | (n[i - 1] >> (32 -
|
for (i = len - 1; i > 0; i--) n[i] = (n[i] << bits) | (n[i - 1] >> (32 -
|
||||||
bits));
|
bits));
|
||||||
@@ -196,6 +201,7 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return carry;
|
return carry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,8 +221,8 @@ namespace OpenRA.FileFormats
|
|||||||
i2 = *ps2++;
|
i2 = *ps2++;
|
||||||
*pd++ = (ushort)(i1 - i2 - carry);
|
*pd++ = (ushort)(i1 - i2 - carry);
|
||||||
if (((i1 - i2 - carry) & 0x10000) != 0) carry = 1; else carry = 0;
|
if (((i1 - i2 - carry) & 0x10000) != 0) carry = 1; else carry = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return carry;
|
return carry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +251,7 @@ namespace OpenRA.FileFormats
|
|||||||
sub_bignum(n_tmp, n_tmp, n2, 0, (int)len);
|
sub_bignum(n_tmp, n_tmp, n2, 0, (int)len);
|
||||||
n1[j] |= bit;
|
n1[j] |= bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bit >>= 1;
|
bit >>= 1;
|
||||||
if (bit == 0)
|
if (bit == 0)
|
||||||
{
|
{
|
||||||
@@ -252,6 +259,7 @@ namespace OpenRA.FileFormats
|
|||||||
bit = 0x80000000;
|
bit = 0x80000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_bignum(n_tmp, 0, len);
|
init_bignum(n_tmp, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,6 +286,7 @@ namespace OpenRA.FileFormats
|
|||||||
shr_bignum(glob1_hi_inv, 1, 2);
|
shr_bignum(glob1_hi_inv, 1, 2);
|
||||||
glob1_hi_bitlen--;
|
glob1_hi_bitlen--;
|
||||||
}
|
}
|
||||||
|
|
||||||
glob1_hi_inv_lo = (ushort)glob1_hi_inv[0];
|
glob1_hi_inv_lo = (ushort)glob1_hi_inv[0];
|
||||||
glob1_hi_inv_hi = (ushort)(glob1_hi_inv[0] >> 16);
|
glob1_hi_inv_hi = (ushort)(glob1_hi_inv[0] >> 16);
|
||||||
}
|
}
|
||||||
@@ -311,8 +320,8 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
fixed( uint * _psrc2 = &src2[0] )
|
fixed (uint* _psrc2 = &src2[0])
|
||||||
fixed(uint* _pdest = &dest[0])
|
fixed (uint* _pdest = &dest[0])
|
||||||
{
|
{
|
||||||
var psrc2 = (ushort*)_psrc2;
|
var psrc2 = (ushort*)_psrc2;
|
||||||
var pdest = (ushort*)_pdest;
|
var pdest = (ushort*)_pdest;
|
||||||
@@ -360,7 +369,7 @@ namespace OpenRA.FileFormats
|
|||||||
uint g2_len_x2, len_diff;
|
uint g2_len_x2, len_diff;
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
fixed( uint* g1 = &glob1[0])
|
fixed (uint* g1 = &glob1[0])
|
||||||
fixed (uint* g2 = &glob2[0])
|
fixed (uint* g2 = &glob2[0])
|
||||||
{
|
{
|
||||||
mul_bignum(glob2, n2, n3, len);
|
mul_bignum(glob2, n2, n3, len);
|
||||||
@@ -383,13 +392,15 @@ namespace OpenRA.FileFormats
|
|||||||
mul_bignum_word(esi, glob1, tmp, 2 * len);
|
mul_bignum_word(esi, glob1, tmp, 2 * len);
|
||||||
if ((*edi & 0x8000) == 0)
|
if ((*edi & 0x8000) == 0)
|
||||||
{
|
{
|
||||||
if (0 != sub_bignum((uint*)esi, (uint*)esi, g1, 0, (int)len)) (*edi)--;
|
if (0 != sub_bignum((uint*)esi, (uint*)esi, g1, 0, (int)len))(*edi)--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
neg_bignum(glob2, len);
|
neg_bignum(glob2, len);
|
||||||
dec_bignum(glob2, len);
|
dec_bignum(glob2, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
mov_bignum(n1, glob2, len);
|
mov_bignum(n1, glob2, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,6 +448,7 @@ namespace OpenRA.FileFormats
|
|||||||
bit_mask = 0x80000000;
|
bit_mask = 0x80000000;
|
||||||
pn3--;
|
pn3--;
|
||||||
}
|
}
|
||||||
|
|
||||||
calc_a_bignum(n_tmp, n1, n1, n4_len);
|
calc_a_bignum(n_tmp, n1, n1, n4_len);
|
||||||
if ((*pn3 & bit_mask) != 0)
|
if ((*pn3 & bit_mask) != 0)
|
||||||
calc_a_bignum(n1, n_tmp, n2, n4_len);
|
calc_a_bignum(n1, n_tmp, n2, n4_len);
|
||||||
@@ -444,6 +456,7 @@ namespace OpenRA.FileFormats
|
|||||||
mov_bignum(n1, n_tmp, n4_len);
|
mov_bignum(n1, n_tmp, n4_len);
|
||||||
bit_mask >>= 1;
|
bit_mask >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_bignum(n_tmp, 0, n4_len);
|
init_bignum(n_tmp, 0, n4_len);
|
||||||
clear_tmp_vars(len);
|
clear_tmp_vars(len);
|
||||||
}
|
}
|
||||||
@@ -455,7 +468,7 @@ namespace OpenRA.FileFormats
|
|||||||
while (len-- != 0) *dest++ = *src++;
|
while (len-- != 0) *dest++ = *src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe void process_predata(byte* pre, uint pre_len, byte *buf)
|
unsafe void process_predata(byte* pre, uint pre_len, byte* buf)
|
||||||
{
|
{
|
||||||
var n2 = new uint[64];
|
var n2 = new uint[64];
|
||||||
var n3 = new uint[64];
|
var n3 = new uint[64];
|
||||||
@@ -464,12 +477,12 @@ namespace OpenRA.FileFormats
|
|||||||
while (a + 1 <= pre_len)
|
while (a + 1 <= pre_len)
|
||||||
{
|
{
|
||||||
init_bignum(n2, 0, 64);
|
init_bignum(n2, 0, 64);
|
||||||
fixed( uint * pn2 = &n2[0] )
|
fixed (uint* pn2 = &n2[0])
|
||||||
memcpy((byte *)pn2, pre, (int)a + 1);
|
memcpy((byte*)pn2, pre, (int)a + 1);
|
||||||
calc_a_key(n3, n2, pubkey.key2, pubkey.key1, 64);
|
calc_a_key(n3, n2, pubkey.key2, pubkey.key1, 64);
|
||||||
|
|
||||||
fixed( uint * pn3 = &n3[0] )
|
fixed (uint* pn3 = &n3[0])
|
||||||
memcpy(buf, (byte *)pn3, (int)a);
|
memcpy(buf, (byte*)pn3, (int)a);
|
||||||
|
|
||||||
pre_len -= a + 1;
|
pre_len -= a + 1;
|
||||||
pre += a + 1;
|
pre += a + 1;
|
||||||
@@ -488,6 +501,7 @@ namespace OpenRA.FileFormats
|
|||||||
fixed (byte* psrc = &src[0])
|
fixed (byte* psrc = &src[0])
|
||||||
process_predata(psrc, len_predata(), pdest);
|
process_predata(psrc, len_predata(), pdest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest.Take(56).ToArray();
|
return dest.Take(56).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static class that uses a lookup table to calculates CRC32
|
/// Static class that uses a lookup table to calculates CRC32
|
||||||
/// checksums of input strings.
|
/// checksums of input strings.
|
||||||
@@ -104,6 +103,7 @@ namespace OpenRA.FileFormats
|
|||||||
crc ^= polynomial;
|
crc ^= polynomial;
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint Calculate(byte[] data)
|
public static uint Calculate(byte[] data)
|
||||||
{
|
{
|
||||||
return Calculate(data, 0xFFFFFFFF);
|
return Calculate(data, 0xFFFFFFFF);
|
||||||
@@ -125,6 +125,7 @@ namespace OpenRA.FileFormats
|
|||||||
crc ^= polynomial;
|
crc ^= polynomial;
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe uint Calculate(byte* data, uint len)
|
public static unsafe uint Calculate(byte* data, uint len)
|
||||||
{
|
{
|
||||||
return Calculate(data, len, 0xFFFFFFFF);
|
return Calculate(data, len, 0xFFFFFFFF);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.FileFormats
|
|||||||
if ((count & 0x8000) == 0)
|
if ((count & 0x8000) == 0)
|
||||||
{
|
{
|
||||||
// case 2
|
// case 2
|
||||||
destIndex += (count & 0x7FFF);
|
destIndex += count & 0x7FFF;
|
||||||
}
|
}
|
||||||
else if ((count & 0x4000) == 0)
|
else if ((count & 0x4000) == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,20 +22,20 @@ namespace OpenRA.FileFormats
|
|||||||
public HvaReader(Stream s)
|
public HvaReader(Stream s)
|
||||||
{
|
{
|
||||||
// Index swaps for transposing a matrix
|
// Index swaps for transposing a matrix
|
||||||
var ids = new byte[]{0,4,8,12,1,5,9,13,2,6,10,14};
|
var ids = new byte[] { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14 };
|
||||||
|
|
||||||
s.Seek(16, SeekOrigin.Begin);
|
s.Seek(16, SeekOrigin.Begin);
|
||||||
FrameCount = s.ReadUInt32();
|
FrameCount = s.ReadUInt32();
|
||||||
LimbCount = s.ReadUInt32();
|
LimbCount = s.ReadUInt32();
|
||||||
|
|
||||||
// Skip limb names
|
// Skip limb names
|
||||||
s.Seek(16*LimbCount, SeekOrigin.Current);
|
s.Seek(16 * LimbCount, SeekOrigin.Current);
|
||||||
Transforms = new float[16*FrameCount*LimbCount];
|
Transforms = new float[16 * FrameCount * LimbCount];
|
||||||
for (var j = 0; j < FrameCount; j++)
|
for (var j = 0; j < FrameCount; j++)
|
||||||
for (var i = 0; i < LimbCount; i++)
|
for (var i = 0; i < LimbCount; i++)
|
||||||
{
|
{
|
||||||
// Convert to column-major matrices and add the final matrix row
|
// Convert to column-major matrices and add the final matrix row
|
||||||
var c = 16*(LimbCount*j + i);
|
var c = 16 * (LimbCount * j + i);
|
||||||
Transforms[c + 3] = 0;
|
Transforms[c + 3] = 0;
|
||||||
Transforms[c + 7] = 0;
|
Transforms[c + 7] = 0;
|
||||||
Transforms[c + 11] = 0;
|
Transforms[c + 11] = 0;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.FileFormats
|
|||||||
Color[] palette = null;
|
Color[] palette = null;
|
||||||
var data = new List<byte>();
|
var data = new List<byte>();
|
||||||
|
|
||||||
for (; ; )
|
for (;;)
|
||||||
{
|
{
|
||||||
var length = IPAddress.NetworkToHostOrder(br.ReadInt32());
|
var length = IPAddress.NetworkToHostOrder(br.ReadInt32());
|
||||||
var type = Encoding.UTF8.GetString(br.ReadBytes(4));
|
var type = Encoding.UTF8.GetString(br.ReadBytes(4));
|
||||||
@@ -54,7 +54,6 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
case "IHDR":
|
case "IHDR":
|
||||||
{
|
{
|
||||||
|
|
||||||
var width = IPAddress.NetworkToHostOrder(cr.ReadInt32());
|
var width = IPAddress.NetworkToHostOrder(cr.ReadInt32());
|
||||||
var height = IPAddress.NetworkToHostOrder(cr.ReadInt32());
|
var height = IPAddress.NetworkToHostOrder(cr.ReadInt32());
|
||||||
var bitDepth = cr.ReadByte();
|
var bitDepth = cr.ReadByte();
|
||||||
@@ -67,8 +66,8 @@ namespace OpenRA.FileFormats
|
|||||||
if (interlace != 0) throw new InvalidDataException("Interlacing not supported");
|
if (interlace != 0) throw new InvalidDataException("Interlacing not supported");
|
||||||
|
|
||||||
bitmap = new Bitmap(width, height, MakePixelFormat(bitDepth, colorType));
|
bitmap = new Bitmap(width, height, MakePixelFormat(bitDepth, colorType));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "PLTE":
|
case "PLTE":
|
||||||
@@ -80,6 +79,7 @@ namespace OpenRA.FileFormats
|
|||||||
palette[i] = Color.FromArgb(r, g, b);
|
palette[i] = Color.FromArgb(r, g, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "tRNS":
|
case "tRNS":
|
||||||
@@ -87,12 +87,14 @@ namespace OpenRA.FileFormats
|
|||||||
for (var i = 0; i < length; i++)
|
for (var i = 0; i < length; i++)
|
||||||
palette[i] = Color.FromArgb(cr.ReadByte(), palette[i]);
|
palette[i] = Color.FromArgb(cr.ReadByte(), palette[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "IDAT":
|
case "IDAT":
|
||||||
{
|
{
|
||||||
data.AddRange(content);
|
data.AddRange(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "IEND":
|
case "IEND":
|
||||||
@@ -168,8 +170,8 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
enum PngColorType { Indexed = 1, Color = 2, Alpha = 4 };
|
enum PngColorType { Indexed = 1, Color = 2, Alpha = 4 }
|
||||||
enum PngFilter { None, Sub, Up, Average, Paeth };
|
enum PngFilter { None, Sub, Up, Average, Paeth }
|
||||||
|
|
||||||
static PixelFormat MakePixelFormat(byte bitDepth, PngColorType colorType)
|
static PixelFormat MakePixelFormat(byte bitDepth, PngColorType colorType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
static void ReadVoxelData(Stream s, VxlLimb l)
|
static void ReadVoxelData(Stream s, VxlLimb l)
|
||||||
{
|
{
|
||||||
var baseSize = l.Size[0]*l.Size[1];
|
var baseSize = l.Size[0] * l.Size[1];
|
||||||
var colStart = new int[baseSize];
|
var colStart = new int[baseSize];
|
||||||
for (var i = 0; i < baseSize; i++)
|
for (var i = 0; i < baseSize; i++)
|
||||||
colStart[i] = s.ReadInt32();
|
colStart[i] = s.ReadInt32();
|
||||||
s.Seek(4*baseSize, SeekOrigin.Current);
|
s.Seek(4 * baseSize, SeekOrigin.Current);
|
||||||
var dataStart = s.Position;
|
var dataStart = s.Position;
|
||||||
|
|
||||||
// Count the voxels in this limb
|
// Count the voxels in this limb
|
||||||
@@ -65,12 +65,12 @@ namespace OpenRA.FileFormats
|
|||||||
var count = s.ReadUInt8();
|
var count = s.ReadUInt8();
|
||||||
z += count;
|
z += count;
|
||||||
l.VoxelCount += count;
|
l.VoxelCount += count;
|
||||||
s.Seek(2*count + 1, SeekOrigin.Current);
|
s.Seek(2 * count + 1, SeekOrigin.Current);
|
||||||
} while (z < l.Size[2]);
|
} while (z < l.Size[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the data
|
// Read the data
|
||||||
l.VoxelMap = new Dictionary<byte, VxlElement>[l.Size[0],l.Size[1]];
|
l.VoxelMap = new Dictionary<byte, VxlElement>[l.Size[0], l.Size[1]];
|
||||||
for (var i = 0; i < baseSize; i++)
|
for (var i = 0; i < baseSize; i++)
|
||||||
{
|
{
|
||||||
// Empty column
|
// Empty column
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRA.FileFormats
|
|||||||
var x = (byte)(i % l.Size[0]);
|
var x = (byte)(i % l.Size[0]);
|
||||||
var y = (byte)(i / l.Size[0]);
|
var y = (byte)(i / l.Size[0]);
|
||||||
byte z = 0;
|
byte z = 0;
|
||||||
l.VoxelMap[x,y] = new Dictionary<byte, VxlElement>();
|
l.VoxelMap[x, y] = new Dictionary<byte, VxlElement>();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
z += s.ReadUInt8();
|
z += s.ReadUInt8();
|
||||||
@@ -93,9 +93,10 @@ namespace OpenRA.FileFormats
|
|||||||
v.Color = s.ReadUInt8();
|
v.Color = s.ReadUInt8();
|
||||||
v.Normal = s.ReadUInt8();
|
v.Normal = s.ReadUInt8();
|
||||||
|
|
||||||
l.VoxelMap[x,y].Add(z, v);
|
l.VoxelMap[x, y].Add(z, v);
|
||||||
z++;
|
z++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip duplicate count
|
// Skip duplicate count
|
||||||
s.ReadUInt8();
|
s.ReadUInt8();
|
||||||
} while (z < l.Size[2]);
|
} while (z < l.Size[2]);
|
||||||
@@ -104,7 +105,6 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
public VxlReader(Stream s)
|
public VxlReader(Stream s)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!s.ReadASCII(16).StartsWith("Voxel Animation"))
|
if (!s.ReadASCII(16).StartsWith("Voxel Animation"))
|
||||||
throw new InvalidDataException("Invalid vxl header");
|
throw new InvalidDataException("Invalid vxl header");
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip to the Limb footers
|
// Skip to the Limb footers
|
||||||
s.Seek(802 + 28*LimbCount + BodySize, SeekOrigin.Begin);
|
s.Seek(802 + 28 * LimbCount + BodySize, SeekOrigin.Begin);
|
||||||
|
|
||||||
var LimbDataOffset = new uint[LimbCount];
|
var LimbDataOffset = new uint[LimbCount];
|
||||||
for (var i = 0; i < LimbCount; i++)
|
for (var i = 0; i < LimbCount; i++)
|
||||||
@@ -143,7 +143,7 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
for (var i = 0; i < LimbCount; i++)
|
for (var i = 0; i < LimbCount; i++)
|
||||||
{
|
{
|
||||||
s.Seek(802 + 28*LimbCount + LimbDataOffset[i], SeekOrigin.Begin);
|
s.Seek(802 + 28 * LimbCount + LimbDataOffset[i], SeekOrigin.Begin);
|
||||||
ReadVoxelData(s, Limbs[i]);
|
ReadVoxelData(s, Limbs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace OpenRA.FileFormats
|
|||||||
public readonly int DataSize;
|
public readonly int DataSize;
|
||||||
public readonly byte[] RawOutput;
|
public readonly byte[] RawOutput;
|
||||||
|
|
||||||
public enum WaveType { Pcm = 0x1, ImaAdpcm = 0x11 };
|
public enum WaveType { Pcm = 0x1, ImaAdpcm = 0x11 }
|
||||||
public static WaveType Type { get; private set; }
|
public static WaveType Type { get; private set; }
|
||||||
|
|
||||||
public WavLoader(Stream s)
|
public WavLoader(Stream s)
|
||||||
@@ -69,6 +69,7 @@ namespace OpenRA.FileFormats
|
|||||||
UncompressedSize = s.ReadInt32();
|
UncompressedSize = s.ReadInt32();
|
||||||
s.ReadBytes(chunkSize - 4);
|
s.ReadBytes(chunkSize - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "data":
|
case "data":
|
||||||
DataSize = s.ReadInt32();
|
DataSize = s.ReadInt32();
|
||||||
@@ -80,6 +81,7 @@ namespace OpenRA.FileFormats
|
|||||||
var chunkSize = s.ReadInt32();
|
var chunkSize = s.ReadInt32();
|
||||||
s.ReadBytes(chunkSize);
|
s.ReadBytes(chunkSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.FileFormats
|
|||||||
entries.Add(new string(chars.ToArray()));
|
entries.Add(new string(chars.ToArray()));
|
||||||
|
|
||||||
// Skip comment
|
// Skip comment
|
||||||
while ((c = reader.ReadChar()) != 0);
|
while ((c = reader.ReadChar()) != 0) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ namespace OpenRA.FileFormats
|
|||||||
using (var writer = new BinaryWriter(data))
|
using (var writer = new BinaryWriter(data))
|
||||||
{
|
{
|
||||||
writer.Write(Encoding.ASCII.GetBytes("XCC by Olaf van der Spek"));
|
writer.Write(Encoding.ASCII.GetBytes("XCC by Olaf van der Spek"));
|
||||||
writer.Write(new byte[] {0x1A,0x04,0x17,0x27,0x10,0x19,0x80,0x00});
|
writer.Write(new byte[] { 0x1A, 0x04, 0x17, 0x27, 0x10, 0x19, 0x80, 0x00 });
|
||||||
|
|
||||||
writer.Write((int)(Entries.Aggregate(Entries.Length, (a,b) => a + b.Length) + 52)); // Size
|
writer.Write((int)(Entries.Aggregate(Entries.Length, (a, b) => a + b.Length) + 52)); // Size
|
||||||
writer.Write((int)0); // Type
|
writer.Write((int)0); // Type
|
||||||
writer.Write((int)0); // Version
|
writer.Write((int)0); // Version
|
||||||
writer.Write((int)0); // Game/Format (0 == TD)
|
writer.Write((int)0); // Game/Format (0 == TD)
|
||||||
@@ -64,4 +64,4 @@ namespace OpenRA.FileFormats
|
|||||||
return data.ToArray();
|
return data.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public string Name { get { return filename; } }
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
public int Priority { get { return 1000 + priority; }}
|
public int Priority { get { return 1000 + priority; } }
|
||||||
|
|
||||||
public IEnumerable<uint> ClassicHashes()
|
public IEnumerable<uint> ClassicHashes()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public Stream GetContent(string filename)
|
public Stream GetContent(string filename)
|
||||||
{
|
{
|
||||||
try { return File.OpenRead( Path.Combine( path, filename ) ); }
|
try { return File.OpenRead(Path.Combine(path, filename)); }
|
||||||
catch { return null; }
|
catch { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
return new MixFile(filename, type, order);
|
return new MixFile(filename, type, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(filename, order);
|
return new ZipFile(filename, order);
|
||||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ namespace OpenRA.FileSystem
|
|||||||
var TOCreader = new BinaryReader(s);
|
var TOCreader = new BinaryReader(s);
|
||||||
|
|
||||||
var fileCountInDirs = new List<uint>();
|
var fileCountInDirs = new List<uint>();
|
||||||
|
|
||||||
// Parse directories
|
// Parse directories
|
||||||
for (var i = 0; i < DirCount; i++)
|
for (var i = 0; i < DirCount; i++)
|
||||||
fileCountInDirs.Add(ParseDirectory(TOCreader));
|
fileCountInDirs.Add(ParseDirectory(TOCreader));
|
||||||
@@ -59,7 +60,6 @@ namespace OpenRA.FileSystem
|
|||||||
foreach (var fileCount in fileCountInDirs)
|
foreach (var fileCount in fileCountInDirs)
|
||||||
for (var i = 0; i < fileCount; i++)
|
for (var i = 0; i < fileCount; i++)
|
||||||
ParseFile(reader);
|
ParseFile(reader);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint ParseDirectory(BinaryReader reader)
|
static uint ParseDirectory(BinaryReader reader)
|
||||||
@@ -68,7 +68,7 @@ namespace OpenRA.FileSystem
|
|||||||
var FileCount = reader.ReadUInt16();
|
var FileCount = reader.ReadUInt16();
|
||||||
var ChunkSize = reader.ReadUInt16();
|
var ChunkSize = reader.ReadUInt16();
|
||||||
var NameLength = reader.ReadUInt16();
|
var NameLength = reader.ReadUInt16();
|
||||||
reader.ReadChars(NameLength); //var DirName = new String(reader.ReadChars(NameLength));
|
reader.ReadChars(NameLength); // var DirName = new String(reader.ReadChars(NameLength));
|
||||||
|
|
||||||
// Skip to the end of the chunk
|
// Skip to the end of the chunk
|
||||||
reader.ReadBytes(ChunkSize - NameLength - 6);
|
reader.ReadBytes(ChunkSize - NameLength - 6);
|
||||||
@@ -84,11 +84,11 @@ namespace OpenRA.FileSystem
|
|||||||
var ChunkSize = reader.ReadUInt16();
|
var ChunkSize = reader.ReadUInt16();
|
||||||
reader.ReadBytes(4);
|
reader.ReadBytes(4);
|
||||||
var NameLength = reader.ReadByte();
|
var NameLength = reader.ReadByte();
|
||||||
var FileName = new String(reader.ReadChars(NameLength));
|
var FileName = new string(reader.ReadChars(NameLength));
|
||||||
|
|
||||||
var hash = PackageEntry.HashFilename(FileName, PackageHashType.Classic);
|
var hash = PackageEntry.HashFilename(FileName, PackageHashType.Classic);
|
||||||
if (!index.ContainsKey(hash))
|
if (!index.ContainsKey(hash))
|
||||||
index.Add(hash, new PackageEntry(hash,AccumulatedData, CompressedSize));
|
index.Add(hash, new PackageEntry(hash, AccumulatedData, CompressedSize));
|
||||||
filenames.Add(FileName);
|
filenames.Add(FileName);
|
||||||
AccumulatedData += CompressedSize;
|
AccumulatedData += CompressedSize;
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ namespace OpenRA.FileSystem
|
|||||||
return index.ContainsKey(PackageEntry.HashFilename(filename, PackageHashType.Classic));
|
return index.ContainsKey(PackageEntry.HashFilename(filename, PackageHashType.Classic));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Priority { get { return 2000 + priority; }}
|
public int Priority { get { return 2000 + priority; } }
|
||||||
public string Name { get { return filename; } }
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
public void Write(Dictionary<string, byte[]> contents)
|
public void Write(Dictionary<string, byte[]> contents)
|
||||||
|
|||||||
@@ -68,9 +68,8 @@ namespace OpenRA.FileSystem
|
|||||||
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
|
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
|
||||||
|
|
||||||
index = entries.ToDictionaryWithConflictLog(x => x.Hash,
|
index = entries.ToDictionaryWithConflictLog(x => x.Hash,
|
||||||
"{0} ({1} format, Encrypted: {2}, DataStart: {3})".F(filename, (isCncMix ? "C&C" : "RA/TS/RA2"), isEncrypted, dataStart),
|
"{0} ({1} format, Encrypted: {2}, DataStart: {3})".F(filename, isCncMix ? "C&C" : "RA/TS/RA2", isEncrypted, dataStart),
|
||||||
null, x => "(offs={0}, len={1})".F(x.Offset, x.Length)
|
null, x => "(offs={0}, len={1})".F(x.Offset, x.Length));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<PackageEntry> ParseHeader(Stream s, long offset, out long headerEnd)
|
static List<PackageEntry> ParseHeader(Stream s, long offset, out long headerEnd)
|
||||||
@@ -83,7 +82,7 @@ namespace OpenRA.FileSystem
|
|||||||
for (var i = 0; i < numFiles; i++)
|
for (var i = 0; i < numFiles; i++)
|
||||||
items.Add(new PackageEntry(s));
|
items.Add(new PackageEntry(s));
|
||||||
|
|
||||||
headerEnd = offset + 6 + numFiles*PackageEntry.Size;
|
headerEnd = offset + 6 + numFiles * PackageEntry.Size;
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +100,8 @@ namespace OpenRA.FileSystem
|
|||||||
var numFiles = ms.ReadUInt16();
|
var numFiles = ms.ReadUInt16();
|
||||||
|
|
||||||
// Decrypt the full header - round bytes up to a full block
|
// Decrypt the full header - round bytes up to a full block
|
||||||
var blockCount = (13 + numFiles*PackageEntry.Size)/8;
|
var blockCount = (13 + numFiles * PackageEntry.Size) / 8;
|
||||||
headerEnd = offset + 80 + blockCount*8;
|
headerEnd = offset + 80 + blockCount * 8;
|
||||||
|
|
||||||
return Decrypt(ReadBlocks(s, offset + 80, blockCount), fish);
|
return Decrypt(ReadBlocks(s, offset + 80, blockCount), fish);
|
||||||
}
|
}
|
||||||
@@ -113,7 +112,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
var writer = new BinaryWriter(ms);
|
var writer = new BinaryWriter(ms);
|
||||||
foreach(var t in decrypted)
|
foreach (var t in decrypted)
|
||||||
writer.Write(t);
|
writer.Write(t);
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
|
|
||||||
@@ -126,7 +125,7 @@ namespace OpenRA.FileSystem
|
|||||||
s.Seek(offset, SeekOrigin.Begin);
|
s.Seek(offset, SeekOrigin.Begin);
|
||||||
|
|
||||||
// A block is a single encryption unit (represented as two 32-bit integers)
|
// A block is a single encryption unit (represented as two 32-bit integers)
|
||||||
var ret = new uint[2*count];
|
var ret = new uint[2 * count];
|
||||||
for (var i = 0; i < ret.Length; i++)
|
for (var i = 0; i < ret.Length; i++)
|
||||||
ret[i] = s.ReadUInt32();
|
ret[i] = s.ReadUInt32();
|
||||||
|
|
||||||
@@ -167,7 +166,7 @@ namespace OpenRA.FileSystem
|
|||||||
return hash.HasValue ? GetContent(hash.Value) : null;
|
return hash.HasValue ? GetContent(hash.Value) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly uint[] Nothing = {};
|
static readonly uint[] Nothing = { };
|
||||||
public IEnumerable<uint> ClassicHashes()
|
public IEnumerable<uint> ClassicHashes()
|
||||||
{
|
{
|
||||||
if (type == PackageHashType.Classic)
|
if (type == PackageHashType.Classic)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public class PackageEntry
|
public class PackageEntry
|
||||||
{
|
{
|
||||||
|
public const int Size = 12;
|
||||||
public readonly uint Hash;
|
public readonly uint Hash;
|
||||||
public readonly uint Offset;
|
public readonly uint Offset;
|
||||||
public readonly uint Length;
|
public readonly uint Length;
|
||||||
@@ -56,7 +57,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public static uint HashFilename(string name, PackageHashType type)
|
public static uint HashFilename(string name, PackageHashType type)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case PackageHashType.Classic:
|
case PackageHashType.Classic:
|
||||||
{
|
{
|
||||||
@@ -88,6 +89,7 @@ namespace OpenRA.FileSystem
|
|||||||
while (i-- != 0)
|
while (i-- != 0)
|
||||||
name += name[a << 2];
|
name += name[a << 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
return CRC32.Calculate(Encoding.ASCII.GetBytes(name));
|
return CRC32.Calculate(Encoding.ASCII.GetBytes(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ namespace OpenRA.FileSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary<uint, string> Names = new Dictionary<uint,string>();
|
static Dictionary<uint, string> Names = new Dictionary<uint, string>();
|
||||||
|
|
||||||
public static void AddStandardName(string s)
|
public static void AddStandardName(string s)
|
||||||
{
|
{
|
||||||
@@ -104,7 +106,5 @@ namespace OpenRA.FileSystem
|
|||||||
var crcHash = HashFilename(s, PackageHashType.CRC32); // TS
|
var crcHash = HashFilename(s, PackageHashType.CRC32); // TS
|
||||||
Names.Add(crcHash, s);
|
Names.Add(crcHash, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public const int Size = 12;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public static class Game
|
public static class Game
|
||||||
{
|
{
|
||||||
|
public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick
|
||||||
|
public const int Timestep = 40;
|
||||||
|
public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms
|
||||||
|
|
||||||
public static ModData modData;
|
public static ModData modData;
|
||||||
public static Settings Settings;
|
public static Settings Settings;
|
||||||
public static ICursor Cursor;
|
public static ICursor Cursor;
|
||||||
@@ -83,9 +87,6 @@ namespace OpenRA
|
|||||||
public static int RenderFrame = 0;
|
public static int RenderFrame = 0;
|
||||||
public static int NetFrameNumber { get { return orderManager.NetFrameNumber; } }
|
public static int NetFrameNumber { get { return orderManager.NetFrameNumber; } }
|
||||||
public static int LocalTick { get { return orderManager.LocalFrameNumber; } }
|
public static int LocalTick { get { return orderManager.LocalFrameNumber; } }
|
||||||
public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick
|
|
||||||
public const int Timestep = 40;
|
|
||||||
public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms
|
|
||||||
|
|
||||||
public static event Action<string, int> OnRemoteDirectConnect = (a, b) => { };
|
public static event Action<string, int> OnRemoteDirectConnect = (a, b) => { };
|
||||||
public static event Action<OrderManager> ConnectionStateChanged = _ => { };
|
public static event Action<OrderManager> ConnectionStateChanged = _ => { };
|
||||||
@@ -148,6 +149,7 @@ namespace OpenRA
|
|||||||
orderManager.World = new World(map, orderManager, isShellmap);
|
orderManager.World = new World(map, orderManager, isShellmap);
|
||||||
orderManager.World.Timestep = Timestep;
|
orderManager.World.Timestep = Timestep;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worldRenderer != null)
|
if (worldRenderer != null)
|
||||||
worldRenderer.Dispose();
|
worldRenderer.Dispose();
|
||||||
worldRenderer = new WorldRenderer(orderManager.World);
|
worldRenderer = new WorldRenderer(orderManager.World);
|
||||||
@@ -417,7 +419,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
|
|
||||||
var worldTimestep = world == null ? Timestep : world.Timestep;
|
var worldTimestep = world == null ? Timestep : world.Timestep;
|
||||||
var worldTickDelta = (tick - orderManager.LastTickTime);
|
var worldTickDelta = tick - orderManager.LastTickTime;
|
||||||
if (worldTimestep != 0 && worldTickDelta >= worldTimestep)
|
if (worldTimestep != 0 && worldTickDelta >= worldTimestep)
|
||||||
{
|
{
|
||||||
using (new PerfSample("tick_time"))
|
using (new PerfSample("tick_time"))
|
||||||
@@ -426,7 +428,6 @@ namespace OpenRA
|
|||||||
// If dt < TickJankThreshold then we should try and catch up by repeatedly ticking
|
// If dt < TickJankThreshold then we should try and catch up by repeatedly ticking
|
||||||
// If dt >= TickJankThreshold then we should accept the jank and progress at the normal rate
|
// If dt >= TickJankThreshold then we should accept the jank and progress at the normal rate
|
||||||
// dt is rounded down to an integer tick count in order to preserve fractional tick components.
|
// dt is rounded down to an integer tick count in order to preserve fractional tick components.
|
||||||
|
|
||||||
var integralTickTimestep = (worldTickDelta / worldTimestep) * worldTimestep;
|
var integralTickTimestep = (worldTickDelta / worldTimestep) * worldTimestep;
|
||||||
orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;
|
orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace OpenRA
|
|||||||
public string MapUid;
|
public string MapUid;
|
||||||
public string MapTitle;
|
public string MapTitle;
|
||||||
public DateTime StartTimeUtc;
|
public DateTime StartTimeUtc;
|
||||||
|
|
||||||
// Game end timestamp (when the recoding stopped).
|
// Game end timestamp (when the recoding stopped).
|
||||||
public DateTime EndTimeUtc;
|
public DateTime EndTimeUtc;
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
nodes.Add(new MiniYamlNode("Root", FieldSaver.Save(this)));
|
nodes.Add(new MiniYamlNode("Root", FieldSaver.Save(this)));
|
||||||
|
|
||||||
for (var i=0; i<Players.Count; i++)
|
for (var i = 0; i < Players.Count; i++)
|
||||||
nodes.Add(new MiniYamlNode("Player@{0}".F(i), FieldSaver.Save(Players[i])));
|
nodes.Add(new MiniYamlNode("Player@{0}".F(i), FieldSaver.Save(Players[i])));
|
||||||
|
|
||||||
return nodes.WriteToString();
|
return nodes.WriteToString();
|
||||||
@@ -133,34 +134,36 @@ namespace OpenRA
|
|||||||
|
|
||||||
public class Player
|
public class Player
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Start-up information
|
// Start-up information
|
||||||
//
|
|
||||||
|
|
||||||
public int ClientIndex;
|
public int ClientIndex;
|
||||||
|
|
||||||
// The player name, not guaranteed to be unique.
|
// The player name, not guaranteed to be unique.
|
||||||
public string Name;
|
public string Name;
|
||||||
public bool IsHuman;
|
public bool IsHuman;
|
||||||
public bool IsBot;
|
public bool IsBot;
|
||||||
|
|
||||||
// The faction name (aka Country)
|
// The faction name (aka Country)
|
||||||
public string FactionName;
|
public string FactionName;
|
||||||
|
|
||||||
// The faction id (aka Country, aka Race)
|
// The faction id (aka Country, aka Race)
|
||||||
public string FactionId;
|
public string FactionId;
|
||||||
public HSLColor Color;
|
public HSLColor Color;
|
||||||
|
|
||||||
// The team id on start-up, or 0 if the player is not part of the team.
|
// The team id on start-up, or 0 if the player is not part of the team.
|
||||||
public int Team;
|
public int Team;
|
||||||
public int SpawnPoint;
|
public int SpawnPoint;
|
||||||
|
|
||||||
// True if the faction was chosen at random; otherwise, false
|
// True if the faction was chosen at random; otherwise, false
|
||||||
public bool IsRandomFaction;
|
public bool IsRandomFaction;
|
||||||
|
|
||||||
// True if the spawn point was chosen at random; otherwise, false.</summary>
|
// True if the spawn point was chosen at random; otherwise, false.</summary>
|
||||||
public bool IsRandomSpawnPoint;
|
public bool IsRandomSpawnPoint;
|
||||||
|
|
||||||
//
|
|
||||||
// Information gathered at a later stage
|
// Information gathered at a later stage
|
||||||
//
|
|
||||||
|
|
||||||
// The game outcome for this player
|
// The game outcome for this player
|
||||||
public WinState Outcome;
|
public WinState Outcome;
|
||||||
|
|
||||||
// The time when this player won or lost the game
|
// The time when this player won or lost the game
|
||||||
public DateTime OutcomeTimestampUtc;
|
public DateTime OutcomeTimestampUtc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
//TODO: This is not exported into the documentation yet.
|
// TODO: This is not exported into the documentation yet.
|
||||||
[Desc("A unit/building inside the game. Every rules starts with one and adds trait to it.",
|
[Desc("A unit/building inside the game. Every rules starts with one and adds trait to it.",
|
||||||
"Special actors like world or player are usually defined in system.yaml and affect everything.")]
|
"Special actors like world or player are usually defined in system.yaml and affect everything.")]
|
||||||
public class ActorInfo
|
public class ActorInfo
|
||||||
@@ -29,7 +29,7 @@ namespace OpenRA
|
|||||||
public readonly TypeDictionary Traits = new TypeDictionary();
|
public readonly TypeDictionary Traits = new TypeDictionary();
|
||||||
List<ITraitInfo> constructOrderCache = null;
|
List<ITraitInfo> constructOrderCache = null;
|
||||||
|
|
||||||
public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
|
public ActorInfo(string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -46,15 +46,15 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
|
static MiniYaml GetParent(MiniYaml node, Dictionary<string, MiniYaml> allUnits)
|
||||||
{
|
{
|
||||||
MiniYaml inherits;
|
MiniYaml inherits;
|
||||||
node.ToDictionary().TryGetValue( "Inherits", out inherits );
|
node.ToDictionary().TryGetValue("Inherits", out inherits);
|
||||||
if( inherits == null || string.IsNullOrEmpty( inherits.Value ) )
|
if (inherits == null || string.IsNullOrEmpty(inherits.Value))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
MiniYaml parent;
|
MiniYaml parent;
|
||||||
allUnits.TryGetValue( inherits.Value, out parent );
|
allUnits.TryGetValue(inherits.Value, out parent);
|
||||||
if (parent == null)
|
if (parent == null)
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"Bogus inheritance -- actor type {0} does not exist".F(inherits.Value));
|
"Bogus inheritance -- actor type {0} does not exist".F(inherits.Value));
|
||||||
@@ -62,9 +62,9 @@ namespace OpenRA
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MiniYaml MergeWithParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
|
static MiniYaml MergeWithParent(MiniYaml node, Dictionary<string, MiniYaml> allUnits)
|
||||||
{
|
{
|
||||||
var parent = GetParent( node, allUnits );
|
var parent = GetParent(node, allUnits);
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
{
|
{
|
||||||
var result = MiniYaml.MergeStrict(node, MergeWithParent(parent, allUnits));
|
var result = MiniYaml.MergeStrict(node, MergeWithParent(parent, allUnits));
|
||||||
@@ -73,6 +73,7 @@ namespace OpenRA
|
|||||||
result.Nodes.RemoveAll(a => a.Key.StartsWith("-"));
|
result.Nodes.RemoveAll(a => a.Key.StartsWith("-"));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ namespace OpenRA
|
|||||||
var unresolved = source.Except(resolved);
|
var unresolved = source.Except(resolved);
|
||||||
|
|
||||||
var testResolve = new Func<Type, Type, bool>((a, b) => a == b || a.IsAssignableFrom(b));
|
var testResolve = new Func<Type, Type, bool>((a, b) => a == b || a.IsAssignableFrom(b));
|
||||||
var more = unresolved.Where(u => u.Dependencies.All( d => resolved.Exists(r => testResolve(d, r.Type)) ));
|
var more = unresolved.Where(u => u.Dependencies.All(d => resolved.Exists(r => testResolve(d, r.Type))));
|
||||||
|
|
||||||
// Re-evaluate the vars above until sorted
|
// Re-evaluate the vars above until sorted
|
||||||
while (more.Any())
|
while (more.Any())
|
||||||
@@ -146,11 +147,11 @@ namespace OpenRA
|
|||||||
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(UsesInit<>))
|
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(UsesInit<>))
|
||||||
.Select(i => i.GetGenericArguments()[0])).ToList();
|
.Select(i => i.GetGenericArguments()[0])).ToList();
|
||||||
|
|
||||||
inits.Add( typeof(OwnerInit) ); /* not exposed by a trait; this is used by the Actor itself */
|
inits.Add(typeof(OwnerInit)); /* not exposed by a trait; this is used by the Actor itself */
|
||||||
|
|
||||||
return inits.Select(
|
return inits.Select(
|
||||||
i => Pair.New(
|
i => Pair.New(
|
||||||
i.Name.Replace( "Init", "" ), i ));
|
i.Name.Replace("Init", ""), i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ namespace OpenRA.GameRules
|
|||||||
public int Length { get; private set; } // seconds
|
public int Length { get; private set; } // seconds
|
||||||
public bool Exists { get; private set; }
|
public bool Exists { get; private set; }
|
||||||
|
|
||||||
public MusicInfo( string key, MiniYaml value )
|
public MusicInfo(string key, MiniYaml value)
|
||||||
{
|
{
|
||||||
Title = value.Value;
|
Title = value.Value;
|
||||||
|
|
||||||
var nd = value.ToDictionary();
|
var nd = value.ToDictionary();
|
||||||
var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
|
var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
|
||||||
Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key)+"."+ext;
|
Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext;
|
||||||
if (!GlobalFileSystem.Exists(Filename))
|
if (!GlobalFileSystem.Exists(Filename))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
public class SoundInfo
|
public class SoundInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Ignore] public readonly Dictionary<string,string[]> Variants;
|
[FieldLoader.Ignore] public readonly Dictionary<string, string[]> Variants;
|
||||||
[FieldLoader.Ignore] public readonly Dictionary<string,string[]> Prefixes;
|
[FieldLoader.Ignore] public readonly Dictionary<string, string[]> Prefixes;
|
||||||
[FieldLoader.Ignore] public readonly Dictionary<string,string[]> Voices;
|
[FieldLoader.Ignore] public readonly Dictionary<string, string[]> Voices;
|
||||||
[FieldLoader.Ignore] public readonly Dictionary<string,string[]> Notifications;
|
[FieldLoader.Ignore] public readonly Dictionary<string, string[]> Notifications;
|
||||||
public readonly string DefaultVariant = ".aud" ;
|
public readonly string DefaultVariant = ".aud";
|
||||||
public readonly string DefaultPrefix = "" ;
|
public readonly string DefaultPrefix = "";
|
||||||
public readonly string[] DisableVariants = { };
|
public readonly string[] DisableVariants = { };
|
||||||
public readonly string[] DisablePrefixes = { };
|
public readonly string[] DisablePrefixes = { };
|
||||||
|
|
||||||
@@ -36,16 +36,16 @@ namespace OpenRA.GameRules
|
|||||||
public readonly Lazy<Dictionary<string, SoundPool>> VoicePools;
|
public readonly Lazy<Dictionary<string, SoundPool>> VoicePools;
|
||||||
public readonly Lazy<Dictionary<string, SoundPool>> NotificationsPools;
|
public readonly Lazy<Dictionary<string, SoundPool>> NotificationsPools;
|
||||||
|
|
||||||
public SoundInfo( MiniYaml y )
|
public SoundInfo(MiniYaml y)
|
||||||
{
|
{
|
||||||
FieldLoader.Load( this, y );
|
FieldLoader.Load(this, y);
|
||||||
Variants = Load(y, "Variants");
|
Variants = Load(y, "Variants");
|
||||||
Prefixes = Load(y, "Prefixes");
|
Prefixes = Load(y, "Prefixes");
|
||||||
Voices = Load(y, "Voices");
|
Voices = Load(y, "Voices");
|
||||||
Notifications = Load(y, "Notifications");
|
Notifications = Load(y, "Notifications");
|
||||||
|
|
||||||
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
|
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
|
||||||
NotificationsPools = Exts.Lazy(() => Notifications.ToDictionary( a => a.Key, a => new SoundPool(a.Value) ));
|
NotificationsPools = Exts.Lazy(() => Notifications.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ namespace OpenRA.GameRules
|
|||||||
[Desc("Can this warhead affect the actor that fired it.")]
|
[Desc("Can this warhead affect the actor that fired it.")]
|
||||||
public readonly bool AffectsParent = false;
|
public readonly bool AffectsParent = false;
|
||||||
|
|
||||||
[Desc("Delay in ticks before applying the warhead effect.","0 = instant (old model).")]
|
[Desc("Delay in ticks before applying the warhead effect.", "0 = instant (old model).")]
|
||||||
public readonly int Delay = 0;
|
public readonly int Delay = 0;
|
||||||
|
|
||||||
///<summary>Applies the warhead's effect against the target.</summary>
|
/// <summary>Applies the warhead's effect against the target.</summary>
|
||||||
public abstract void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers);
|
public abstract void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers);
|
||||||
|
|
||||||
///<summary>Checks if the warhead is valid against (can do something to) the target.</summary>
|
/// <summary>Checks if the warhead is valid against (can do something to) the target.</summary>
|
||||||
public bool IsValidAgainst(Target target, World world, Actor firedBy)
|
public bool IsValidAgainst(Target target, World world, Actor firedBy)
|
||||||
{
|
{
|
||||||
if (target.Type == TargetType.Actor)
|
if (target.Type == TargetType.Actor)
|
||||||
@@ -66,7 +66,7 @@ namespace OpenRA.GameRules
|
|||||||
// assumption has been removed from the yaml definitions
|
// assumption has been removed from the yaml definitions
|
||||||
public virtual bool CanTargetActor(ActorInfo victim, Actor firedBy) { return false; }
|
public virtual bool CanTargetActor(ActorInfo victim, Actor firedBy) { return false; }
|
||||||
|
|
||||||
///<summary>Checks if the warhead is valid against (can do something to) the actor.</summary>
|
/// <summary>Checks if the warhead is valid against (can do something to) the actor.</summary>
|
||||||
public bool IsValidAgainst(Actor victim, Actor firedBy)
|
public bool IsValidAgainst(Actor victim, Actor firedBy)
|
||||||
{
|
{
|
||||||
if (!CanTargetActor(victim.Info, firedBy))
|
if (!CanTargetActor(victim.Info, firedBy))
|
||||||
@@ -88,7 +88,7 @@ namespace OpenRA.GameRules
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>Checks if the warhead is valid against (can do something to) the frozen actor.</summary>
|
/// <summary>Checks if the warhead is valid against (can do something to) the frozen actor.</summary>
|
||||||
public bool IsValidAgainst(FrozenActor victim, Actor firedBy)
|
public bool IsValidAgainst(FrozenActor victim, Actor firedBy)
|
||||||
{
|
{
|
||||||
if (!CanTargetActor(victim.Info, firedBy))
|
if (!CanTargetActor(victim.Info, firedBy))
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
public class Animation
|
public class Animation
|
||||||
{
|
{
|
||||||
|
readonly int defaultTick = 40; // 25 fps == 40 ms
|
||||||
public Sequence CurrentSequence { get; private set; }
|
public Sequence CurrentSequence { get; private set; }
|
||||||
public bool IsDecoration = false;
|
public bool IsDecoration = false;
|
||||||
public Func<bool> Paused;
|
public Func<bool> Paused;
|
||||||
@@ -26,7 +27,6 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
readonly int defaultTick = 40; // 25 fps == 40 ms
|
|
||||||
bool tickAlways;
|
bool tickAlways;
|
||||||
|
|
||||||
public string Name { get { return name; } }
|
public string Name { get { return name; } }
|
||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
this.sequenceProvider = sequenceProvider;
|
this.sequenceProvider = sequenceProvider;
|
||||||
this.name = name.ToLowerInvariant();
|
this.name = name.ToLowerInvariant();
|
||||||
this.tickFunc = () => {};
|
this.tickFunc = () => { };
|
||||||
this.facingFunc = facingFunc;
|
this.facingFunc = facingFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,5 +50,4 @@ namespace OpenRA.Graphics
|
|||||||
return new AnimationWithOffset(a, null, null, null, null);
|
return new AnimationWithOffset(a, null, null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
return lineWidth;
|
return lineWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (LineWidth != value)
|
if (LineWidth != value)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Graphics
|
|||||||
if (defaultSrc != src)
|
if (defaultSrc != src)
|
||||||
root.Add(new MiniYamlNode("src", src));
|
root.Add(new MiniYamlNode("src", src));
|
||||||
|
|
||||||
return new MiniYaml(FieldSaver.FormatValue( this, this.GetType().GetField("rect") ), root);
|
return new MiniYaml(FieldSaver.FormatValue(this, this.GetType().GetField("rect")), root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace OpenRA.Graphics
|
|||||||
uint this[int index] { get; }
|
uint this[int index] { get; }
|
||||||
void CopyToArray(Array destination, int destinationOffset);
|
void CopyToArray(Array destination, int destinationOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IPaletteRemap { Color GetRemappedColor(Color original, int index); }
|
public interface IPaletteRemap { Color GetRemappedColor(Color original, int index); }
|
||||||
|
|
||||||
public static class Palette
|
public static class Palette
|
||||||
|
|||||||
@@ -87,13 +87,13 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
float2 ScreenPosition(WorldRenderer wr)
|
float2 ScreenPosition(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
return wr.ScreenPxPosition(pos) + wr.ScreenPxOffset(offset) - (0.5f*scale*sprite.size).ToInt2();
|
return wr.ScreenPxPosition(pos) + wr.ScreenPxOffset(offset) - (0.5f * scale * sprite.size).ToInt2();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BeforeRender(WorldRenderer wr) {}
|
public void BeforeRender(WorldRenderer wr) { }
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite, ScreenPosition(wr), palette, sprite.size*scale);
|
Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite, ScreenPosition(wr), palette, sprite.size * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderDebugGeometry(WorldRenderer wr)
|
public void RenderDebugGeometry(WorldRenderer wr)
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
return currentBatchRenderer;
|
return currentBatchRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (currentBatchRenderer == value)
|
if (currentBatchRenderer == value)
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BeforeRender(WorldRenderer wr) {}
|
public void BeforeRender(WorldRenderer wr) { }
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (!actor.IsInWorld || actor.IsDead)
|
if (!actor.IsInWorld || actor.IsDead)
|
||||||
@@ -154,6 +154,6 @@ namespace OpenRA.Graphics
|
|||||||
DrawExtraBars(wr, xy, Xy);
|
DrawExtraBars(wr, xy, Xy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderDebugGeometry(WorldRenderer wr) {}
|
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Graphics
|
|||||||
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxRenderable(pos + vec, bounds, scale, color); }
|
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxRenderable(pos + vec, bounds, scale, color); }
|
||||||
public IRenderable AsDecoration() { return this; }
|
public IRenderable AsDecoration() { return this; }
|
||||||
|
|
||||||
public void BeforeRender(WorldRenderer wr) {}
|
public void BeforeRender(WorldRenderer wr) { }
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
var screenPos = wr.ScreenPxPosition(pos);
|
var screenPos = wr.ScreenPxPosition(pos);
|
||||||
@@ -68,6 +68,6 @@ namespace OpenRA.Graphics
|
|||||||
wlr.DrawLine(br, br - v, color, color);
|
wlr.DrawLine(br, br - v, color, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderDebugGeometry(WorldRenderer wr) {}
|
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace OpenRA.Graphics
|
|||||||
CreateBuffer();
|
CreateBuffer();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Buffered { get { return data != null || texture == null; } }
|
public bool Buffered { get { return data != null || texture == null; } }
|
||||||
|
|
||||||
public Sheet(Size size)
|
public Sheet(Size size)
|
||||||
@@ -83,7 +84,6 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
texture.SetData(data, Size.Width, Size.Height);
|
texture.SetData(data, Size.Width, Size.Height);
|
||||||
|
|||||||
@@ -99,4 +99,3 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ namespace OpenRA.Graphics
|
|||||||
public readonly float top, left, bottom, right;
|
public readonly float top, left, bottom, right;
|
||||||
|
|
||||||
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
|
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
|
||||||
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) {}
|
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) { }
|
||||||
|
|
||||||
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel, BlendMode blendMode)
|
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel, BlendMode blendMode)
|
||||||
: this(sheet, bounds, float2.Zero, channel, blendMode) {}
|
: this(sheet, bounds, float2.Zero, channel, blendMode) { }
|
||||||
|
|
||||||
public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode)
|
public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode)
|
||||||
{
|
{
|
||||||
@@ -40,10 +40,10 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
this.fractionalOffset = offset / this.size;
|
this.fractionalOffset = offset / this.size;
|
||||||
|
|
||||||
left = (float)(bounds.Left) / sheet.Size.Width;
|
left = (float)bounds.Left / sheet.Size.Width;
|
||||||
top = (float)(bounds.Top) / sheet.Size.Height;
|
top = (float)bounds.Top / sheet.Size.Height;
|
||||||
right = (float)(bounds.Right) / sheet.Size.Width;
|
right = (float)bounds.Right / sheet.Size.Width;
|
||||||
bottom = (float)(bounds.Bottom) / sheet.Size.Height;
|
bottom = (float)bounds.Bottom / sheet.Size.Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
s.sheet.CommitData();
|
s.sheet.CommitData();
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace OpenRA.Graphics
|
|||||||
public SpriteCache(ISpriteLoader[] loaders, string[] exts, SheetBuilder sheetBuilder)
|
public SpriteCache(ISpriteLoader[] loaders, string[] exts, SheetBuilder sheetBuilder)
|
||||||
{
|
{
|
||||||
SheetBuilder = sheetBuilder;
|
SheetBuilder = sheetBuilder;
|
||||||
|
|
||||||
// Include extension-less version
|
// Include extension-less version
|
||||||
exts = exts.Append("").ToArray();
|
exts = exts.Append("").ToArray();
|
||||||
sprites = new Cache<string, Sprite[]>(filename => SpriteLoader.GetSprites(filename, exts, loaders, sheetBuilder));
|
sprites = new Cache<string, Sprite[]>(filename => SpriteLoader.GetSprites(filename, exts, loaders, sheetBuilder));
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Graphics
|
|||||||
public IRenderable OffsetBy(WVec vec) { return new TargetLineRenderable(waypoints.Select(w => w + vec), color); }
|
public IRenderable OffsetBy(WVec vec) { return new TargetLineRenderable(waypoints.Select(w => w + vec), color); }
|
||||||
public IRenderable AsDecoration() { return this; }
|
public IRenderable AsDecoration() { return this; }
|
||||||
|
|
||||||
public void BeforeRender(WorldRenderer wr) {}
|
public void BeforeRender(WorldRenderer wr) { }
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (!waypoints.Any())
|
if (!waypoints.Any())
|
||||||
@@ -57,6 +57,6 @@ namespace OpenRA.Graphics
|
|||||||
wr.DrawTargetMarker(color, first);
|
wr.DrawTargetMarker(color, first);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderDebugGeometry(WorldRenderer wr) {}
|
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRA.Graphics
|
|||||||
public IRenderable OffsetBy(WVec vec) { return this; }
|
public IRenderable OffsetBy(WVec vec) { return this; }
|
||||||
public IRenderable AsDecoration() { return this; }
|
public IRenderable AsDecoration() { return this; }
|
||||||
|
|
||||||
public void BeforeRender(WorldRenderer wr) {}
|
public void BeforeRender(WorldRenderer wr) { }
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
Game.Renderer.SpriteRenderer.DrawSprite(sprite, screenPos, palette, sprite.size * scale);
|
Game.Renderer.SpriteRenderer.DrawSprite(sprite, screenPos, palette, sprite.size * scale);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
public static class Util
|
public static class Util
|
||||||
{
|
{
|
||||||
|
// yes, our channel order is nuts.
|
||||||
|
static readonly int[] channelMasks = { 2, 1, 0, 3 };
|
||||||
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||||
|
|
||||||
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, int palette, int nv, float2 size)
|
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, int palette, int nv, float2 size)
|
||||||
@@ -38,8 +40,6 @@ namespace OpenRA.Graphics
|
|||||||
vertices[nv + 3] = new Vertex(d, r.left, r.bottom, attribP, attribC);
|
vertices[nv + 3] = new Vertex(d, r.left, r.bottom, attribP, attribC);
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
|
||||||
|
|
||||||
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
||||||
public static void FastCopyIntoChannel(Sprite dest, int channelOffset, byte[] src)
|
public static void FastCopyIntoChannel(Sprite dest, int channelOffset, byte[] src)
|
||||||
{
|
{
|
||||||
@@ -58,6 +58,7 @@ namespace OpenRA.Graphics
|
|||||||
data[destOffset] = src[srcOffset];
|
data[destOffset] = src[srcOffset];
|
||||||
destOffset += 4;
|
destOffset += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
destOffset += destSkip;
|
destOffset += destSkip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,9 +108,9 @@ namespace OpenRA.Graphics
|
|||||||
for (var i = 0; i < 4; i++)
|
for (var i = 0; i < 4; i++)
|
||||||
for (var j = 0; j < 4; j++)
|
for (var j = 0; j < 4; j++)
|
||||||
{
|
{
|
||||||
mtx[4*i + j] = 0;
|
mtx[4 * i + j] = 0;
|
||||||
for (var k = 0; k < 4; k++)
|
for (var k = 0; k < 4; k++)
|
||||||
mtx[4*i + j] += lhs[4*k + j]*rhs[4*i + k];
|
mtx[4 * i + j] += lhs[4 * k + j] * rhs[4 * i + k];
|
||||||
}
|
}
|
||||||
|
|
||||||
return mtx;
|
return mtx;
|
||||||
@@ -122,7 +123,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
ret[j] = 0;
|
ret[j] = 0;
|
||||||
for (var k = 0; k < 4; k++)
|
for (var k = 0; k < 4; k++)
|
||||||
ret[j] += mtx[4*k + j]*vec[k];
|
ret[j] += mtx[4 * k + j] * vec[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -132,124 +133,124 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
var mtx = new float[16];
|
var mtx = new float[16];
|
||||||
|
|
||||||
mtx[0] = m[5]*m[10]*m[15] -
|
mtx[0] = m[5] * m[10] * m[15] -
|
||||||
m[5]*m[11]*m[14] -
|
m[5] * m[11] * m[14] -
|
||||||
m[9]*m[6]*m[15] +
|
m[9] * m[6] * m[15] +
|
||||||
m[9]*m[7]*m[14] +
|
m[9] * m[7] * m[14] +
|
||||||
m[13]*m[6]*m[11] -
|
m[13] * m[6] * m[11] -
|
||||||
m[13]*m[7]*m[10];
|
m[13] * m[7] * m[10];
|
||||||
|
|
||||||
mtx[4] = -m[4]*m[10]*m[15] +
|
mtx[4] = -m[4] * m[10] * m[15] +
|
||||||
m[4]*m[11]*m[14] +
|
m[4] * m[11] * m[14] +
|
||||||
m[8]*m[6]*m[15] -
|
m[8] * m[6] * m[15] -
|
||||||
m[8]*m[7]*m[14] -
|
m[8] * m[7] * m[14] -
|
||||||
m[12]*m[6]*m[11] +
|
m[12] * m[6] * m[11] +
|
||||||
m[12]*m[7]*m[10];
|
m[12] * m[7] * m[10];
|
||||||
|
|
||||||
mtx[8] = m[4]*m[9]*m[15] -
|
mtx[8] = m[4] * m[9] * m[15] -
|
||||||
m[4]*m[11]*m[13] -
|
m[4] * m[11] * m[13] -
|
||||||
m[8]*m[5]*m[15] +
|
m[8] * m[5] * m[15] +
|
||||||
m[8]*m[7]*m[13] +
|
m[8] * m[7] * m[13] +
|
||||||
m[12]*m[5]*m[11] -
|
m[12] * m[5] * m[11] -
|
||||||
m[12]*m[7]*m[9];
|
m[12] * m[7] * m[9];
|
||||||
|
|
||||||
mtx[12] = -m[4]*m[9]*m[14] +
|
mtx[12] = -m[4] * m[9] * m[14] +
|
||||||
m[4]*m[10]*m[13] +
|
m[4] * m[10] * m[13] +
|
||||||
m[8]*m[5]*m[14] -
|
m[8] * m[5] * m[14] -
|
||||||
m[8]*m[6]*m[13] -
|
m[8] * m[6] * m[13] -
|
||||||
m[12]*m[5]*m[10] +
|
m[12] * m[5] * m[10] +
|
||||||
m[12]*m[6]*m[9];
|
m[12] * m[6] * m[9];
|
||||||
|
|
||||||
mtx[1] = -m[1]*m[10]*m[15] +
|
mtx[1] = -m[1] * m[10] * m[15] +
|
||||||
m[1]*m[11]*m[14] +
|
m[1] * m[11] * m[14] +
|
||||||
m[9]*m[2]*m[15] -
|
m[9] * m[2] * m[15] -
|
||||||
m[9]*m[3]*m[14] -
|
m[9] * m[3] * m[14] -
|
||||||
m[13]*m[2]*m[11] +
|
m[13] * m[2] * m[11] +
|
||||||
m[13]*m[3]*m[10];
|
m[13] * m[3] * m[10];
|
||||||
|
|
||||||
mtx[5] = m[0]*m[10]*m[15] -
|
mtx[5] = m[0] * m[10] * m[15] -
|
||||||
m[0]*m[11]*m[14] -
|
m[0] * m[11] * m[14] -
|
||||||
m[8]*m[2]*m[15] +
|
m[8] * m[2] * m[15] +
|
||||||
m[8]*m[3]*m[14] +
|
m[8] * m[3] * m[14] +
|
||||||
m[12]*m[2]*m[11] -
|
m[12] * m[2] * m[11] -
|
||||||
m[12]*m[3]*m[10];
|
m[12] * m[3] * m[10];
|
||||||
|
|
||||||
mtx[9] = -m[0]*m[9]*m[15] +
|
mtx[9] = -m[0] * m[9] * m[15] +
|
||||||
m[0]*m[11]*m[13] +
|
m[0] * m[11] * m[13] +
|
||||||
m[8]*m[1]*m[15] -
|
m[8] * m[1] * m[15] -
|
||||||
m[8]*m[3]*m[13] -
|
m[8] * m[3] * m[13] -
|
||||||
m[12]*m[1]*m[11] +
|
m[12] * m[1] * m[11] +
|
||||||
m[12]*m[3]*m[9];
|
m[12] * m[3] * m[9];
|
||||||
|
|
||||||
mtx[13] = m[0]*m[9]*m[14] -
|
mtx[13] = m[0] * m[9] * m[14] -
|
||||||
m[0]*m[10]*m[13] -
|
m[0] * m[10] * m[13] -
|
||||||
m[8]*m[1]*m[14] +
|
m[8] * m[1] * m[14] +
|
||||||
m[8]*m[2]*m[13] +
|
m[8] * m[2] * m[13] +
|
||||||
m[12]*m[1]*m[10] -
|
m[12] * m[1] * m[10] -
|
||||||
m[12]*m[2]*m[9];
|
m[12] * m[2] * m[9];
|
||||||
|
|
||||||
mtx[2] = m[1]*m[6]*m[15] -
|
mtx[2] = m[1] * m[6] * m[15] -
|
||||||
m[1]*m[7]*m[14] -
|
m[1] * m[7] * m[14] -
|
||||||
m[5]*m[2]*m[15] +
|
m[5] * m[2] * m[15] +
|
||||||
m[5]*m[3]*m[14] +
|
m[5] * m[3] * m[14] +
|
||||||
m[13]*m[2]*m[7] -
|
m[13] * m[2] * m[7] -
|
||||||
m[13]*m[3]*m[6];
|
m[13] * m[3] * m[6];
|
||||||
|
|
||||||
mtx[6] = -m[0]*m[6]*m[15] +
|
mtx[6] = -m[0] * m[6] * m[15] +
|
||||||
m[0]*m[7]*m[14] +
|
m[0] * m[7] * m[14] +
|
||||||
m[4]*m[2]*m[15] -
|
m[4] * m[2] * m[15] -
|
||||||
m[4]*m[3]*m[14] -
|
m[4] * m[3] * m[14] -
|
||||||
m[12]*m[2]*m[7] +
|
m[12] * m[2] * m[7] +
|
||||||
m[12]*m[3]*m[6];
|
m[12] * m[3] * m[6];
|
||||||
|
|
||||||
mtx[10] = m[0]*m[5]*m[15] -
|
mtx[10] = m[0] * m[5] * m[15] -
|
||||||
m[0]*m[7]*m[13] -
|
m[0] * m[7] * m[13] -
|
||||||
m[4]*m[1]*m[15] +
|
m[4] * m[1] * m[15] +
|
||||||
m[4]*m[3]*m[13] +
|
m[4] * m[3] * m[13] +
|
||||||
m[12]*m[1]*m[7] -
|
m[12] * m[1] * m[7] -
|
||||||
m[12]*m[3]*m[5];
|
m[12] * m[3] * m[5];
|
||||||
|
|
||||||
mtx[14] = -m[0]*m[5]*m[14] +
|
mtx[14] = -m[0] * m[5] * m[14] +
|
||||||
m[0]*m[6]*m[13] +
|
m[0] * m[6] * m[13] +
|
||||||
m[4]*m[1]*m[14] -
|
m[4] * m[1] * m[14] -
|
||||||
m[4]*m[2]*m[13] -
|
m[4] * m[2] * m[13] -
|
||||||
m[12]*m[1]*m[6] +
|
m[12] * m[1] * m[6] +
|
||||||
m[12]*m[2]*m[5];
|
m[12] * m[2] * m[5];
|
||||||
|
|
||||||
mtx[3] = -m[1]*m[6]*m[11] +
|
mtx[3] = -m[1] * m[6] * m[11] +
|
||||||
m[1]*m[7]*m[10] +
|
m[1] * m[7] * m[10] +
|
||||||
m[5]*m[2]*m[11] -
|
m[5] * m[2] * m[11] -
|
||||||
m[5]*m[3]*m[10] -
|
m[5] * m[3] * m[10] -
|
||||||
m[9]*m[2]*m[7] +
|
m[9] * m[2] * m[7] +
|
||||||
m[9]*m[3]*m[6];
|
m[9] * m[3] * m[6];
|
||||||
|
|
||||||
mtx[7] = m[0]*m[6]*m[11] -
|
mtx[7] = m[0] * m[6] * m[11] -
|
||||||
m[0]*m[7]*m[10] -
|
m[0] * m[7] * m[10] -
|
||||||
m[4]*m[2]*m[11] +
|
m[4] * m[2] * m[11] +
|
||||||
m[4]*m[3]*m[10] +
|
m[4] * m[3] * m[10] +
|
||||||
m[8]*m[2]*m[7] -
|
m[8] * m[2] * m[7] -
|
||||||
m[8]*m[3]*m[6];
|
m[8] * m[3] * m[6];
|
||||||
|
|
||||||
mtx[11] = -m[0]*m[5]*m[11] +
|
mtx[11] = -m[0] * m[5] * m[11] +
|
||||||
m[0]*m[7]*m[9] +
|
m[0] * m[7] * m[9] +
|
||||||
m[4]*m[1]*m[11] -
|
m[4] * m[1] * m[11] -
|
||||||
m[4]*m[3]*m[9] -
|
m[4] * m[3] * m[9] -
|
||||||
m[8]*m[1]*m[7] +
|
m[8] * m[1] * m[7] +
|
||||||
m[8]*m[3]*m[5];
|
m[8] * m[3] * m[5];
|
||||||
|
|
||||||
mtx[15] = m[0]*m[5]*m[10] -
|
mtx[15] = m[0] * m[5] * m[10] -
|
||||||
m[0]*m[6]*m[9] -
|
m[0] * m[6] * m[9] -
|
||||||
m[4]*m[1]*m[10] +
|
m[4] * m[1] * m[10] +
|
||||||
m[4]*m[2]*m[9] +
|
m[4] * m[2] * m[9] +
|
||||||
m[8]*m[1]*m[6] -
|
m[8] * m[1] * m[6] -
|
||||||
m[8]*m[2]*m[5];
|
m[8] * m[2] * m[5];
|
||||||
|
|
||||||
var det = m[0]*mtx[0] + m[1]*mtx[4] + m[2]*mtx[8] + m[3]*mtx[12];
|
var det = m[0] * mtx[0] + m[1] * mtx[4] + m[2] * mtx[8] + m[3] * mtx[12];
|
||||||
if (det == 0)
|
if (det == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (var i = 0; i < 16; i++)
|
for (var i = 0; i < 16; i++)
|
||||||
mtx[i] *= 1/det;
|
mtx[i] *= 1 / det;
|
||||||
|
|
||||||
return mtx;
|
return mtx;
|
||||||
}
|
}
|
||||||
@@ -258,33 +259,33 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
var fmtx = new float[16];
|
var fmtx = new float[16];
|
||||||
for (var i = 0; i < 16; i++)
|
for (var i = 0; i < 16; i++)
|
||||||
fmtx[i] = imtx[i]*1f / imtx[15];
|
fmtx[i] = imtx[i] * 1f / imtx[15];
|
||||||
return fmtx;
|
return fmtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float[] MatrixAABBMultiply(float[] mtx, float[] bounds)
|
public static float[] MatrixAABBMultiply(float[] mtx, float[] bounds)
|
||||||
{
|
{
|
||||||
// Corner offsets
|
// Corner offsets
|
||||||
var ix = new uint[] {0,0,0,0,3,3,3,3};
|
var ix = new uint[] { 0, 0, 0, 0, 3, 3, 3, 3 };
|
||||||
var iy = new uint[] {1,1,4,4,1,1,4,4};
|
var iy = new uint[] { 1, 1, 4, 4, 1, 1, 4, 4 };
|
||||||
var iz = new uint[] {2,5,2,5,2,5,2,5};
|
var iz = new uint[] { 2, 5, 2, 5, 2, 5, 2, 5 };
|
||||||
|
|
||||||
// Vectors to opposing corner
|
// Vectors to opposing corner
|
||||||
var ret = new float[] {float.MaxValue, float.MaxValue, float.MaxValue,
|
var ret = new float[] { float.MaxValue, float.MaxValue, float.MaxValue,
|
||||||
float.MinValue, float.MinValue, float.MinValue};
|
float.MinValue, float.MinValue, float.MinValue };
|
||||||
|
|
||||||
// Transform vectors and find new bounding box
|
// Transform vectors and find new bounding box
|
||||||
for (var i = 0; i < 8; i++)
|
for (var i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
var vec = new float[] {bounds[ix[i]], bounds[iy[i]], bounds[iz[i]], 1};
|
var vec = new float[] { bounds[ix[i]], bounds[iy[i]], bounds[iz[i]], 1 };
|
||||||
var tvec = MatrixVectorMultiply(mtx, vec);
|
var tvec = MatrixVectorMultiply(mtx, vec);
|
||||||
|
|
||||||
ret[0] = Math.Min(ret[0], tvec[0]/tvec[3]);
|
ret[0] = Math.Min(ret[0], tvec[0] / tvec[3]);
|
||||||
ret[1] = Math.Min(ret[1], tvec[1]/tvec[3]);
|
ret[1] = Math.Min(ret[1], tvec[1] / tvec[3]);
|
||||||
ret[2] = Math.Min(ret[2], tvec[2]/tvec[3]);
|
ret[2] = Math.Min(ret[2], tvec[2] / tvec[3]);
|
||||||
ret[3] = Math.Max(ret[3], tvec[0]/tvec[3]);
|
ret[3] = Math.Max(ret[3], tvec[0] / tvec[3]);
|
||||||
ret[4] = Math.Max(ret[4], tvec[1]/tvec[3]);
|
ret[4] = Math.Max(ret[4], tvec[1] / tvec[3]);
|
||||||
ret[5] = Math.Max(ret[5], tvec[2]/tvec[3]);
|
ret[5] = Math.Max(ret[5], tvec[2] / tvec[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -61,12 +61,12 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
var l = limbData[limb];
|
var l = limbData[limb];
|
||||||
var t = new float[16];
|
var t = new float[16];
|
||||||
Array.Copy(transforms, 16*(Limbs*frame + limb), t, 0, 16);
|
Array.Copy(transforms, 16 * (Limbs * frame + limb), t, 0, 16);
|
||||||
|
|
||||||
// Fix limb position
|
// Fix limb position
|
||||||
t[12] *= l.Scale*(l.Bounds[3] - l.Bounds[0]) / l.Size[0];
|
t[12] *= l.Scale * (l.Bounds[3] - l.Bounds[0]) / l.Size[0];
|
||||||
t[13] *= l.Scale*(l.Bounds[4] - l.Bounds[1]) / l.Size[1];
|
t[13] *= l.Scale * (l.Bounds[4] - l.Bounds[1]) / l.Size[1];
|
||||||
t[14] *= l.Scale*(l.Bounds[5] - l.Bounds[2]) / l.Size[2];
|
t[14] *= l.Scale * (l.Bounds[5] - l.Bounds[2]) / l.Size[2];
|
||||||
|
|
||||||
// Center, flip and scale
|
// Center, flip and scale
|
||||||
t = Util.MatrixMultiply(t, Util.TranslationMatrix(l.Bounds[0], l.Bounds[1], l.Bounds[2]));
|
t = Util.MatrixMultiply(t, Util.TranslationMatrix(l.Bounds[0], l.Bounds[1], l.Bounds[2]));
|
||||||
@@ -84,8 +84,8 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return limbData.Select(a => a.Size.Select(b => a.Scale*b).ToArray())
|
return limbData.Select(a => a.Size.Select(b => a.Scale * b).ToArray())
|
||||||
.Aggregate((a,b) => new float[]
|
.Aggregate((a, b) => new float[]
|
||||||
{
|
{
|
||||||
Math.Max(a[0], b[0]),
|
Math.Max(a[0], b[0]),
|
||||||
Math.Max(a[1], b[1]),
|
Math.Max(a[1], b[1]),
|
||||||
@@ -96,8 +96,8 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public float[] Bounds(uint frame)
|
public float[] Bounds(uint frame)
|
||||||
{
|
{
|
||||||
var ret = new float[] {float.MaxValue,float.MaxValue,float.MaxValue,
|
var ret = new float[] { float.MaxValue, float.MaxValue, float.MaxValue,
|
||||||
float.MinValue,float.MinValue,float.MinValue};
|
float.MinValue, float.MinValue, float.MinValue };
|
||||||
|
|
||||||
for (uint j = 0; j < Limbs; j++)
|
for (uint j = 0; j < Limbs; j++)
|
||||||
{
|
{
|
||||||
@@ -115,7 +115,7 @@ namespace OpenRA.Graphics
|
|||||||
for (var i = 0; i < 3; i++)
|
for (var i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
ret[i] = Math.Min(ret[i], bb[i]);
|
ret[i] = Math.Min(ret[i], bb[i]);
|
||||||
ret[i+3] = Math.Max(ret[i+3], bb[i+3]);
|
ret[i + 3] = Math.Max(ret[i + 3], bb[i + 3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,5 +30,4 @@ namespace OpenRA.Graphics
|
|||||||
FrameFunc = frame;
|
FrameFunc = frame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ namespace OpenRA.Graphics
|
|||||||
return new Vertex[4]
|
return new Vertex[4]
|
||||||
{
|
{
|
||||||
new Vertex(coord(0, 0), s.left, s.top, channelP, channelC),
|
new Vertex(coord(0, 0), s.left, s.top, channelP, channelC),
|
||||||
new Vertex(coord(su, 0),s.right, s.top, channelP, channelC),
|
new Vertex(coord(su, 0), s.right, s.top, channelP, channelC),
|
||||||
new Vertex(coord(su, sv), s.right, s.bottom, channelP, channelC),
|
new Vertex(coord(su, sv), s.right, s.bottom, channelP, channelC),
|
||||||
new Vertex(coord(0, sv), s.left, s.bottom, channelP, channelC)
|
new Vertex(coord(0, sv), s.left, s.bottom, channelP, channelC)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Graphics
|
|||||||
var hva = unit;
|
var hva = unit;
|
||||||
if (info.Value != null)
|
if (info.Value != null)
|
||||||
{
|
{
|
||||||
var fields = info.Value.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
var fields = info.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (fields.Length >= 1)
|
if (fields.Length >= 1)
|
||||||
vxl = hva = fields[0].Trim();
|
vxl = hva = fields[0].Trim();
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ namespace OpenRA.Graphics
|
|||||||
var seq = sequences.ToDictionary(my => LoadVoxel(unit, my));
|
var seq = sequences.ToDictionary(my => LoadVoxel(unit, my));
|
||||||
units.Add(unit, seq);
|
units.Add(unit, seq);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException) {} // Do nothing; we can crash later if we actually wanted art
|
catch (FileNotFoundException) { } // Do nothing; we can crash later if we actually wanted art
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Voxel GetVoxel(string unitName, string voxelName)
|
public static Voxel GetVoxel(string unitName, string voxelName)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Graphics
|
|||||||
if (world.OrderGenerator != null)
|
if (world.OrderGenerator != null)
|
||||||
effectRenderables = effectRenderables.Concat(world.OrderGenerator.RenderAfterWorld(this, world));
|
effectRenderables = effectRenderables.Concat(world.OrderGenerator.RenderAfterWorld(this, world));
|
||||||
|
|
||||||
// Iterating via foreach() copies the structs, so enumerate by index
|
// Iterating via foreach copies the structs, so enumerate by index
|
||||||
var renderables = worldRenderables.Concat(effectRenderables).ToList();
|
var renderables = worldRenderables.Concat(effectRenderables).ToList();
|
||||||
|
|
||||||
Game.Renderer.WorldVoxelRenderer.BeginFrame();
|
Game.Renderer.WorldVoxelRenderer.BeginFrame();
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ namespace OpenRA
|
|||||||
public readonly string MenuWidget = null;
|
public readonly string MenuWidget = null;
|
||||||
public readonly string MusicMenuWidget = null;
|
public readonly string MusicMenuWidget = null;
|
||||||
public readonly string BackgroundWidget = null;
|
public readonly string BackgroundWidget = null;
|
||||||
public readonly string[] TestFiles = {};
|
public readonly string[] TestFiles = { };
|
||||||
public readonly string[] DiskTestFiles = {};
|
public readonly string[] DiskTestFiles = { };
|
||||||
public readonly string PackageToExtractFromCD = null;
|
public readonly string PackageToExtractFromCD = null;
|
||||||
public readonly string[] ExtractFilesFromCD = {};
|
public readonly string[] ExtractFilesFromCD = { };
|
||||||
public readonly string[] CopyFilesFromCD = {};
|
public readonly string[] CopyFilesFromCD = { };
|
||||||
|
|
||||||
public readonly string PackageMirrorList = null;
|
public readonly string PackageMirrorList = null;
|
||||||
|
|
||||||
@@ -153,4 +153,4 @@ namespace OpenRA
|
|||||||
z.Close();
|
z.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
get { return initDict.Value; }
|
get { return initDict.Value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
Lazy<TypeDictionary> initDict;
|
Lazy<TypeDictionary> initDict;
|
||||||
|
|
||||||
public ActorReference( string type ) : this(type, new Dictionary<string, MiniYaml>()) { }
|
public ActorReference(string type) : this(type, new Dictionary<string, MiniYaml>()) { }
|
||||||
|
|
||||||
public ActorReference(string type, Dictionary<string, MiniYaml> inits)
|
public ActorReference(string type, Dictionary<string, MiniYaml> inits)
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,7 @@ namespace OpenRA
|
|||||||
var initName = init.GetType().Name;
|
var initName = init.GetType().Name;
|
||||||
ret.Nodes.Add(new MiniYamlNode(initName.Substring(0, initName.Length - 4), FieldSaver.Save(init)));
|
ret.Nodes.Add(new MiniYamlNode(initName.Substring(0, initName.Length - 4), FieldSaver.Save(init)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,12 @@ namespace OpenRA
|
|||||||
|
|
||||||
public class Map
|
public class Map
|
||||||
{
|
{
|
||||||
|
public const int MaxTilesInCircleRange = 50;
|
||||||
|
public readonly TileShape TileShape;
|
||||||
|
[FieldLoader.Ignore]
|
||||||
|
public readonly WVec[] SubCellOffsets;
|
||||||
|
public readonly SubCell DefaultSubCell;
|
||||||
|
public readonly SubCell LastSubCell;
|
||||||
[FieldLoader.Ignore] public IFolder Container;
|
[FieldLoader.Ignore] public IFolder Container;
|
||||||
public string Path { get; private set; }
|
public string Path { get; private set; }
|
||||||
|
|
||||||
@@ -131,12 +137,6 @@ namespace OpenRA
|
|||||||
public Bitmap CustomPreview;
|
public Bitmap CustomPreview;
|
||||||
public bool InvalidCustomRules { get; private set; }
|
public bool InvalidCustomRules { get; private set; }
|
||||||
|
|
||||||
public readonly TileShape TileShape;
|
|
||||||
[FieldLoader.Ignore]
|
|
||||||
public readonly WVec[] SubCellOffsets;
|
|
||||||
public readonly SubCell DefaultSubCell;
|
|
||||||
public readonly SubCell LastSubCell;
|
|
||||||
|
|
||||||
public WVec OffsetOfSubCell(SubCell subCell) { return SubCellOffsets[(int)subCell]; }
|
public WVec OffsetOfSubCell(SubCell subCell) { return SubCellOffsets[(int)subCell]; }
|
||||||
|
|
||||||
[FieldLoader.LoadUsing("LoadOptions")]
|
[FieldLoader.LoadUsing("LoadOptions")]
|
||||||
@@ -207,14 +207,14 @@ namespace OpenRA
|
|||||||
var tileShape = Game.modData.Manifest.TileShape;
|
var tileShape = Game.modData.Manifest.TileShape;
|
||||||
var tileRef = new TerrainTile(tileset.Templates.First().Key, (byte)0);
|
var tileRef = new TerrainTile(tileset.Templates.First().Key, (byte)0);
|
||||||
|
|
||||||
var makeMapTiles = Exts.Lazy(() =>
|
var makeMapTiles = Exts.Lazy(() =>
|
||||||
{
|
{
|
||||||
var ret = new CellLayer<TerrainTile>(tileShape, size);
|
var ret = new CellLayer<TerrainTile>(tileShape, size);
|
||||||
ret.Clear(tileRef);
|
ret.Clear(tileRef);
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
var makeMapHeight = Exts.Lazy(() =>
|
var makeMapHeight = Exts.Lazy(() =>
|
||||||
{
|
{
|
||||||
var ret = new CellLayer<byte>(tileShape, size);
|
var ret = new CellLayer<byte>(tileShape, size);
|
||||||
ret.Clear(0);
|
ret.Clear(0);
|
||||||
@@ -421,12 +421,10 @@ namespace OpenRA
|
|||||||
root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));
|
root.Add(new MiniYamlNode("Options", FieldSaver.SaveDifferences(Options, new MapOptions())));
|
||||||
|
|
||||||
root.Add(new MiniYamlNode("Players", null,
|
root.Add(new MiniYamlNode("Players", null,
|
||||||
Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList())
|
Players.Select(p => new MiniYamlNode("PlayerReference@{0}".F(p.Key), FieldSaver.SaveDifferences(p.Value, new PlayerReference()))).ToList()));
|
||||||
);
|
|
||||||
|
|
||||||
root.Add(new MiniYamlNode("Actors", null,
|
root.Add(new MiniYamlNode("Actors", null,
|
||||||
Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList())
|
Actors.Value.Select(x => new MiniYamlNode(x.Key, x.Value.Save())).ToList()));
|
||||||
);
|
|
||||||
|
|
||||||
root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges.Value)));
|
root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges.Value)));
|
||||||
root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
|
root.Add(new MiniYamlNode("Rules", null, RuleDefinitions));
|
||||||
@@ -623,7 +621,6 @@ namespace OpenRA
|
|||||||
// (b) Therefore:
|
// (b) Therefore:
|
||||||
// - ax + by adds (a - b) * 512 + 512 to u
|
// - ax + by adds (a - b) * 512 + 512 to u
|
||||||
// - ax + by adds (a + b) * 512 + 512 to v
|
// - ax + by adds (a + b) * 512 + 512 to v
|
||||||
|
|
||||||
var z = Contains(cell) ? 512 * MapHeight.Value[cell] : 0;
|
var z = Contains(cell) ? 512 * MapHeight.Value[cell] : 0;
|
||||||
return new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), z);
|
return new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), z);
|
||||||
}
|
}
|
||||||
@@ -721,7 +718,6 @@ namespace OpenRA
|
|||||||
string ComputeHash()
|
string ComputeHash()
|
||||||
{
|
{
|
||||||
// UID is calculated by taking an SHA1 of the yaml and binary data
|
// UID is calculated by taking an SHA1 of the yaml and binary data
|
||||||
|
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
// Read the relevant data into the buffer
|
// Read the relevant data into the buffer
|
||||||
@@ -837,7 +833,7 @@ namespace OpenRA
|
|||||||
var edge = rand.Next(2) == 0;
|
var edge = rand.Next(2) == 0;
|
||||||
|
|
||||||
var x = isX ? rand.Next(Bounds.Left, Bounds.Right) : (edge ? Bounds.Left : Bounds.Right);
|
var x = isX ? rand.Next(Bounds.Left, Bounds.Right) : (edge ? Bounds.Left : Bounds.Right);
|
||||||
var y = !isX ? rand.Next(Bounds.Top, Bounds.Bottom) : (edge ? Bounds.Top : Bounds.Bottom);
|
var y = !isX ? rand.Next(Bounds.Top, Bounds.Bottom) : (edge ? Bounds.Top : Bounds.Bottom);
|
||||||
|
|
||||||
return MapToCell(TileShape, new CPos(x, y));
|
return MapToCell(TileShape, new CPos(x, y));
|
||||||
}
|
}
|
||||||
@@ -851,14 +847,13 @@ namespace OpenRA
|
|||||||
return new WRange(Math.Min(x, y) * dir.Length);
|
return new WRange(Math.Min(x, y) * dir.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public const int MaxTilesInCircleRange = 50;
|
|
||||||
static CVec[][] TilesByDistance = InitTilesByDistance(MaxTilesInCircleRange);
|
static CVec[][] TilesByDistance = InitTilesByDistance(MaxTilesInCircleRange);
|
||||||
|
|
||||||
static CVec[][] InitTilesByDistance(int max)
|
static CVec[][] InitTilesByDistance(int max)
|
||||||
{
|
{
|
||||||
var ts = new List<CVec>[max + 1];
|
var ts = new List<CVec>[max + 1];
|
||||||
for (var i = 0; i < max + 1; i++)
|
for (var i = 0; i < max + 1; i++)
|
||||||
ts [i] = new List<CVec>();
|
ts[i] = new List<CVec>();
|
||||||
|
|
||||||
for (var j = -max; j <= max; j++)
|
for (var j = -max; j <= max; j++)
|
||||||
for (var i = -max; i <= max; i++)
|
for (var i = -max; i <= max; i++)
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
// Milliseconds to wait on one loop when nothing to do
|
// Milliseconds to wait on one loop when nothing to do
|
||||||
var emptyDelay = 50;
|
var emptyDelay = 50;
|
||||||
|
|
||||||
// Keep the thread alive for at least 5 seconds after the last minimap generation
|
// Keep the thread alive for at least 5 seconds after the last minimap generation
|
||||||
var maxKeepAlive = 5000 / emptyDelay;
|
var maxKeepAlive = 5000 / emptyDelay;
|
||||||
var keepAlive = maxKeepAlive;
|
var keepAlive = maxKeepAlive;
|
||||||
@@ -151,6 +152,7 @@ namespace OpenRA
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (todo.Count == 0)
|
if (todo.Count == 0)
|
||||||
{
|
{
|
||||||
Thread.Sleep(emptyDelay);
|
Thread.Sleep(emptyDelay);
|
||||||
@@ -170,6 +172,7 @@ namespace OpenRA
|
|||||||
createdPreview = true;
|
createdPreview = true;
|
||||||
bitmap = Minimap.RenderMapPreview(modData.DefaultRules.TileSets[p.Map.Tileset], p.Map, modData.DefaultRules, true);
|
bitmap = Minimap.RenderMapPreview(modData.DefaultRules.TileSets[p.Map.Tileset], p.Map, modData.DefaultRules, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this is not generally thread-safe, but it works here because:
|
// Note: this is not generally thread-safe, but it works here because:
|
||||||
// (a) This worker is the only thread writing to this sheet
|
// (a) This worker is the only thread writing to this sheet
|
||||||
// (b) The main thread is the only thread reading this sheet
|
// (b) The main thread is the only thread reading this sheet
|
||||||
@@ -192,7 +195,9 @@ namespace OpenRA
|
|||||||
Thread.Sleep(Environment.ProcessorCount == 1 ? 25 : 5);
|
Thread.Sleep(Environment.ProcessorCount == 1 ? 25 : 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sheetBuilder.Current.ReleaseBuffer();
|
sheetBuilder.Current.ReleaseBuffer();
|
||||||
|
|
||||||
// The buffer is not fully reclaimed until changes are written out to the texture.
|
// The buffer is not fully reclaimed until changes are written out to the texture.
|
||||||
// We will access the texture in order to force changes to be written out, allowing the buffer to be freed.
|
// We will access the texture in order to force changes to be written out, allowing the buffer to be freed.
|
||||||
Game.RunAfterTick(() => sheetBuilder.Current.GetTexture());
|
Game.RunAfterTick(() => sheetBuilder.Current.GetTexture());
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA
|
|||||||
public readonly string map_type;
|
public readonly string map_type;
|
||||||
public readonly int players;
|
public readonly int players;
|
||||||
public readonly Rectangle bounds;
|
public readonly Rectangle bounds;
|
||||||
public readonly int[] spawnpoints = {};
|
public readonly int[] spawnpoints = { };
|
||||||
public readonly string minimap;
|
public readonly string minimap;
|
||||||
public readonly bool downloading;
|
public readonly bool downloading;
|
||||||
}
|
}
|
||||||
@@ -142,12 +142,12 @@ namespace OpenRA
|
|||||||
|
|
||||||
var spawns = new List<CPos>();
|
var spawns = new List<CPos>();
|
||||||
for (var j = 0; j < r.spawnpoints.Length; j += 2)
|
for (var j = 0; j < r.spawnpoints.Length; j += 2)
|
||||||
spawns.Add(new CPos(r.spawnpoints[j], r.spawnpoints[j+1]));
|
spawns.Add(new CPos(r.spawnpoints[j], r.spawnpoints[j + 1]));
|
||||||
SpawnPoints = spawns;
|
SpawnPoints = spawns;
|
||||||
|
|
||||||
CustomPreview = new Bitmap(new MemoryStream(Convert.FromBase64String(r.minimap)));
|
CustomPreview = new Bitmap(new MemoryStream(Convert.FromBase64String(r.minimap)));
|
||||||
}
|
}
|
||||||
catch (Exception) {}
|
catch (Exception) { }
|
||||||
|
|
||||||
if (CustomPreview != null)
|
if (CustomPreview != null)
|
||||||
cache.CacheMinimap(this);
|
cache.CacheMinimap(this);
|
||||||
@@ -177,7 +177,6 @@ namespace OpenRA
|
|||||||
var mapUrl = Game.Settings.Game.MapRepository + Uid;
|
var mapUrl = Game.Settings.Game.MapRepository + Uid;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var request = WebRequest.Create(mapUrl);
|
var request = WebRequest.Create(mapUrl);
|
||||||
request.Method = "HEAD";
|
request.Method = "HEAD";
|
||||||
var res = request.GetResponse();
|
var res = request.GetResponse();
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ namespace OpenRA
|
|||||||
throw new InvalidDataException("Duplicate key '{0}' in {1}".F(y.Key, y.Location), ex);
|
throw new InvalidDataException("Duplicate key '{0}' in {1}".F(y.Key, y.Location), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace OpenRA
|
|||||||
LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value));
|
LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value));
|
||||||
LoadScreen.Display();
|
LoadScreen.Display();
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetLoader = new WidgetLoader(this);
|
WidgetLoader = new WidgetLoader(this);
|
||||||
RulesetCache = new RulesetCache(this);
|
RulesetCache = new RulesetCache(this);
|
||||||
RulesetCache.LoadingProgress += HandleLoadingProgress;
|
RulesetCache.LoadingProgress += HandleLoadingProgress;
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ namespace OpenRA.Network
|
|||||||
var boxedCopy = Expression.Convert(getMember, typeof(object));
|
var boxedCopy = Expression.Convert(getMember, typeof(object));
|
||||||
return Expression.Lambda<Func<ISync, object>>(boxedCopy, name, new[] { syncParam }).Compile();
|
return Expression.Lambda<Func<ISync, object>>(boxedCopy, name, new[] { syncParam }).Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
return MemberToString(getMember, memberType, name);
|
return MemberToString(getMember, memberType, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,5 @@ namespace OpenRA
|
|||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,12 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
public enum PowerState { Normal, Low, Critical };
|
public enum PowerState { Normal, Low, Critical }
|
||||||
public enum WinState { Undefined, Won, Lost };
|
public enum WinState { Undefined, Won, Lost }
|
||||||
|
|
||||||
public class Player : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding
|
public class Player : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding
|
||||||
{
|
{
|
||||||
public Actor PlayerActor;
|
public readonly Actor PlayerActor;
|
||||||
public WinState WinState = WinState.Undefined;
|
|
||||||
|
|
||||||
public readonly HSLColor Color;
|
public readonly HSLColor Color;
|
||||||
|
|
||||||
public readonly string PlayerName;
|
public readonly string PlayerName;
|
||||||
@@ -39,6 +37,8 @@ namespace OpenRA
|
|||||||
public readonly bool Playable = true;
|
public readonly bool Playable = true;
|
||||||
public readonly int ClientIndex;
|
public readonly int ClientIndex;
|
||||||
public readonly PlayerReference PlayerReference;
|
public readonly PlayerReference PlayerReference;
|
||||||
|
|
||||||
|
public WinState WinState = WinState.Undefined;
|
||||||
public bool IsBot;
|
public bool IsBot;
|
||||||
public int SpawnPoint;
|
public int SpawnPoint;
|
||||||
public bool HasObjectives = false;
|
public bool HasObjectives = false;
|
||||||
@@ -84,6 +84,7 @@ namespace OpenRA
|
|||||||
botType = pr.Bot;
|
botType = pr.Bot;
|
||||||
Country = ChooseCountry(world, pr.Race);
|
Country = ChooseCountry(world, pr.Race);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
|
||||||
Shroud = PlayerActor.Trait<Shroud>();
|
Shroud = PlayerActor.Trait<Shroud>();
|
||||||
|
|
||||||
@@ -138,7 +139,7 @@ namespace OpenRA
|
|||||||
set { luaInterface.Value[runtime, keyValue] = value; }
|
set { luaInterface.Value[runtime, keyValue] = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public LuaValue Equals (LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
Player a, b;
|
Player a, b;
|
||||||
if (!left.TryGetClrValue<Player>(out a) || !right.TryGetClrValue<Player>(out b))
|
if (!left.TryGetClrValue<Player>(out a) || !right.TryGetClrValue<Player>(out b))
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public void PerformActions()
|
public void PerformActions()
|
||||||
{
|
{
|
||||||
Action a = () => {};
|
Action a = () => { };
|
||||||
lock (syncRoot)
|
lock (syncRoot)
|
||||||
{
|
{
|
||||||
var t = Game.RunTime;
|
var t = Game.RunTime;
|
||||||
@@ -39,6 +39,7 @@ namespace OpenRA.Primitives
|
|||||||
a = da.Action + a;
|
a = da.Action + a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a();
|
a();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,16 +32,16 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public static int GetValue(string[] val)
|
public static int GetValue(string[] val)
|
||||||
{
|
{
|
||||||
return val.Select( a => bits[a] ).Aggregate( 0, (a,b) => a | b );
|
return val.Select(a => bits[a]).Aggregate(0, (a, b) => a | b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<string> GetStrings(int val)
|
public static IEnumerable<string> GetStrings(int val)
|
||||||
{
|
{
|
||||||
for( var i = 0; i < 32; i++ )
|
for (var i = 0; i < 32; i++)
|
||||||
{
|
{
|
||||||
var x = 1 << i;
|
var x = 1 << i;
|
||||||
if ((val & x) != 0)
|
if ((val & x) != 0)
|
||||||
yield return bits.Single( a => a.Value == x ).Key;
|
yield return bits.Single(a => a.Value == x).Key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ namespace OpenRA.Primitives
|
|||||||
return BitAllocator<T>.GetStrings(Value).JoinWith(",");
|
return BitAllocator<T>.GetStrings(Value).JoinWith(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(Bits<T> me, Bits<T> other) { return (me.Value == other.Value); }
|
public static bool operator ==(Bits<T> me, Bits<T> other) { return me.Value == other.Value; }
|
||||||
public static bool operator !=(Bits<T> me, Bits<T> other) { return !(me == other); }
|
public static bool operator !=(Bits<T> me, Bits<T> other) { return !(me == other); }
|
||||||
|
|
||||||
public bool Equals(Bits<T> other) { return other == this; }
|
public bool Equals(Bits<T> other) { return other == this; }
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace OpenRA.Primitives
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ContainsKey(T key) { return cache.ContainsKey(key); }
|
public bool ContainsKey(T key) { return cache.ContainsKey(key); }
|
||||||
public bool TryGetValue(T key, out U value) { return cache.TryGetValue(key, out value); }
|
public bool TryGetValue(T key, out U value) { return cache.TryGetValue(key, out value); }
|
||||||
public int Count { get { return cache.Count; } }
|
public int Count { get { return cache.Count; } }
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace OpenRA.Primitives
|
|||||||
public class ObservableCollection<T> : Collection<T>, IObservableCollection
|
public class ObservableCollection<T> : Collection<T>, IObservableCollection
|
||||||
{
|
{
|
||||||
public event Action<object> OnAdd = k => { };
|
public event Action<object> OnAdd = k => { };
|
||||||
|
|
||||||
// TODO Workaround for https://github.com/OpenRA/OpenRA/issues/6101
|
// TODO Workaround for https://github.com/OpenRA/OpenRA/issues/6101
|
||||||
#pragma warning disable 67
|
#pragma warning disable 67
|
||||||
public event Action<object> OnRemove = k => { };
|
public event Action<object> OnRemove = k => { };
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public event Action<object> OnAdd = k => { };
|
public event Action<object> OnAdd = k => { };
|
||||||
public event Action<object> OnRemove = k => { };
|
public event Action<object> OnRemove = k => { };
|
||||||
|
|
||||||
// TODO Workaround for https://github.com/OpenRA/OpenRA/issues/6101
|
// TODO Workaround for https://github.com/OpenRA/OpenRA/issues/6101
|
||||||
#pragma warning disable 67
|
#pragma warning disable 67
|
||||||
public event Action<int> OnRemoveAt = i => { };
|
public event Action<int> OnRemoveAt = i => { };
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
static Pair()
|
static Pair()
|
||||||
{
|
{
|
||||||
Pair<char,Color>.uc = new ColorEqualityComparer();
|
Pair<char, Color>.uc = new ColorEqualityComparer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid the default crappy one
|
// avoid the default crappy one
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRA.Primitives
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Empty { get { return (level == 0); } }
|
public bool Empty { get { return level == 0; } }
|
||||||
|
|
||||||
T At(int level, int index) { return items[level][index]; }
|
T At(int level, int index) { return items[level][index]; }
|
||||||
T Above(int level, int index) { return items[level - 1][index >> 1]; }
|
T Above(int level, int index) { return items[level - 1][index >> 1]; }
|
||||||
@@ -62,7 +62,7 @@ namespace OpenRA.Primitives
|
|||||||
return At(lastLevel, lastIndex);
|
return At(lastLevel, lastIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Peek() { return At(0,0); }
|
public T Peek() { return At(0, 0); }
|
||||||
public T Pop()
|
public T Pop()
|
||||||
{
|
{
|
||||||
if (level == 0 && index == 0)
|
if (level == 0 && index == 0)
|
||||||
|
|||||||
@@ -20,30 +20,30 @@ namespace OpenRA.Primitives
|
|||||||
Dictionary<Type, object> dataSingular = new Dictionary<Type, object>();
|
Dictionary<Type, object> dataSingular = new Dictionary<Type, object>();
|
||||||
Dictionary<Type, List<object>> dataMultiple = new Dictionary<Type, List<object>>();
|
Dictionary<Type, List<object>> dataMultiple = new Dictionary<Type, List<object>>();
|
||||||
|
|
||||||
public void Add( object val )
|
public void Add(object val)
|
||||||
{
|
{
|
||||||
var t = val.GetType();
|
var t = val.GetType();
|
||||||
|
|
||||||
foreach( var i in t.GetInterfaces() )
|
foreach (var i in t.GetInterfaces())
|
||||||
InnerAdd( i, val );
|
InnerAdd(i, val);
|
||||||
foreach( var tt in t.BaseTypes() )
|
foreach (var tt in t.BaseTypes())
|
||||||
InnerAdd( tt, val );
|
InnerAdd(tt, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerAdd( Type t, object val )
|
void InnerAdd(Type t, object val)
|
||||||
{
|
{
|
||||||
List<object> objs;
|
List<object> objs;
|
||||||
object obj;
|
object obj;
|
||||||
|
|
||||||
if( dataMultiple.TryGetValue( t, out objs ) )
|
if (dataMultiple.TryGetValue(t, out objs))
|
||||||
objs.Add( val );
|
objs.Add(val);
|
||||||
else if( dataSingular.TryGetValue( t, out obj ) )
|
else if (dataSingular.TryGetValue(t, out obj))
|
||||||
{
|
{
|
||||||
dataSingular.Remove( t );
|
dataSingular.Remove(t);
|
||||||
dataMultiple.Add( t, new List<object> { obj, val } );
|
dataMultiple.Add(t, new List<object> { obj, val });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dataSingular.Add( t, val );
|
dataSingular.Add(t, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains<T>()
|
public bool Contains<T>()
|
||||||
@@ -83,12 +83,12 @@ namespace OpenRA.Primitives
|
|||||||
List<object> objs;
|
List<object> objs;
|
||||||
object obj;
|
object obj;
|
||||||
|
|
||||||
if( dataMultiple.TryGetValue( typeof( T ), out objs ) )
|
if (dataMultiple.TryGetValue(typeof(T), out objs))
|
||||||
return objs.Cast<T>();
|
return objs.Cast<T>();
|
||||||
else if( dataSingular.TryGetValue( typeof( T ), out obj ) )
|
else if (dataSingular.TryGetValue(typeof(T), out obj))
|
||||||
return new T[] { (T)obj };
|
return new T[] { (T)obj };
|
||||||
else
|
else
|
||||||
return new T[ 0 ];
|
return new T[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator GetEnumerator()
|
public IEnumerator GetEnumerator()
|
||||||
@@ -99,9 +99,9 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public static class TypeExts
|
public static class TypeExts
|
||||||
{
|
{
|
||||||
public static IEnumerable<Type> BaseTypes( this Type t )
|
public static IEnumerable<Type> BaseTypes(this Type t)
|
||||||
{
|
{
|
||||||
while( t != null )
|
while (t != null)
|
||||||
{
|
{
|
||||||
yield return t;
|
yield return t;
|
||||||
t = t.BaseType;
|
t = t.BaseType;
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static float2 operator *(float a, float2 b) { return new float2(a * b.X, a * b.Y); }
|
public static float2 operator *(float a, float2 b) { return new float2(a * b.X, a * b.Y); }
|
||||||
public static float2 operator *(float2 b, float a) { return new float2(a * b.X, a * b.Y); }
|
public static float2 operator *(float2 b, float a) { return new float2(a * b.X, a * b.Y); }
|
||||||
public static float2 operator *( float2 a, float2 b ) { return new float2( a.X * b.X, a.Y * b.Y ); }
|
public static float2 operator *(float2 a, float2 b) { return new float2(a.X * b.X, a.Y * b.Y); }
|
||||||
public static float2 operator /( float2 a, float2 b ) { return new float2( a.X / b.X, a.Y / b.Y ); }
|
public static float2 operator /(float2 a, float2 b) { return new float2(a.X / b.X, a.Y / b.Y); }
|
||||||
public static float2 operator /(float2 a, float b) { return new float2(a.X / b, a.Y / b); }
|
public static float2 operator /(float2 a, float b) { return new float2(a.X / b, a.Y / b); }
|
||||||
|
|
||||||
public static bool operator ==(float2 me, float2 other) { return (me.X == other.X && me.Y == other.Y); }
|
public static bool operator ==(float2 me, float2 other) { return me.X == other.X && me.Y == other.Y; }
|
||||||
public static bool operator !=(float2 me, float2 other) { return !(me == other); }
|
public static bool operator !=(float2 me, float2 other) { return !(me == other); }
|
||||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Scripting
|
|||||||
throw new LuaException("Unable to convert parameter {0} to {1}".F(i, pi[i].ParameterType.Name));
|
throw new LuaException("Unable to convert parameter {0} to {1}".F(i, pi[i].ParameterType.Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret = (mi.Invoke(Target, clrArgs));
|
var ret = mi.Invoke(Target, clrArgs);
|
||||||
return ret.ToLuaValue(context);
|
return ret.ToLuaValue(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace OpenRA.Scripting
|
|||||||
// TODO: Lua 5.3 will introduce an integer type, so this will be able to go away
|
// TODO: Lua 5.3 will introduce an integer type, so this will be able to go away
|
||||||
if (value is LuaNumber && t.IsAssignableFrom(typeof(int)))
|
if (value is LuaNumber && t.IsAssignableFrom(typeof(int)))
|
||||||
{
|
{
|
||||||
clrObject = (int)(value.ToNumber().Value);
|
clrObject = (int)value.ToNumber().Value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,10 @@ namespace OpenRA
|
|||||||
actors.RemoveAll(a => !a.IsInWorld || (!a.Owner.IsAlliedWith(world.RenderPlayer) && world.FogObscures(a)));
|
actors.RemoveAll(a => !a.IsInWorld || (!a.Owner.IsAlliedWith(world.RenderPlayer) && world.FogObscures(a)));
|
||||||
|
|
||||||
foreach (var cg in controlGroups.Values)
|
foreach (var cg in controlGroups.Values)
|
||||||
|
{
|
||||||
// note: NOT `!a.IsInWorld`, since that would remove things that are in transports.
|
// note: NOT `!a.IsInWorld`, since that would remove things that are in transports.
|
||||||
cg.RemoveAll(a => a.Destroyed || a.Owner != world.LocalPlayer);
|
cg.RemoveAll(a => a.Destroyed || a.Owner != world.LocalPlayer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
public class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
|
public const int MaxOrderLength = 131072;
|
||||||
public Socket socket;
|
public Socket socket;
|
||||||
public List<byte> data = new List<byte>();
|
public List<byte> data = new List<byte>();
|
||||||
public ReceiveState State = ReceiveState.Header;
|
public ReceiveState State = ReceiveState.Header;
|
||||||
public int ExpectLength = 8;
|
public int ExpectLength = 8;
|
||||||
public int Frame = 0;
|
public int Frame = 0;
|
||||||
public int MostRecentFrame = 0;
|
public int MostRecentFrame = 0;
|
||||||
public const int MaxOrderLength = 131072;
|
|
||||||
|
|
||||||
public int TimeSinceLastResponse { get { return Game.RunTime - lastReceivedTime; } }
|
public int TimeSinceLastResponse { get { return Game.RunTime - lastReceivedTime; } }
|
||||||
public bool TimeoutMessageShown = false;
|
public bool TimeoutMessageShown = false;
|
||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Server
|
|||||||
var rx = new byte[1024];
|
var rx = new byte[1024];
|
||||||
var len = 0;
|
var len = 0;
|
||||||
|
|
||||||
for (; ; )
|
for (;;)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -107,12 +107,11 @@ namespace OpenRA.Server
|
|||||||
MostRecentFrame = Frame;
|
MostRecentFrame = Frame;
|
||||||
ExpectLength = 8;
|
ExpectLength = 8;
|
||||||
State = ReceiveState.Header;
|
State = ReceiveState.Header;
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ReceiveState { Header, Data };
|
public enum ReceiveState { Header, Data }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA
|
|||||||
var path = Platform.SupportDir + "Logs";
|
var path = Platform.SupportDir + "Logs";
|
||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
for(var i = 0;; i++ )
|
for (var i = 0;; i++)
|
||||||
yield return Path.Combine(path, i > 0 ? "{0}.{1}".F(baseFilename, i) : baseFilename);
|
yield return Path.Combine(path, i > 0 ? "{0}.{1}".F(baseFilename, i) : baseFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ namespace OpenRA.Support
|
|||||||
if (index == 0) Generate();
|
if (index == 0) Generate();
|
||||||
|
|
||||||
var y = mt[index];
|
var y = mt[index];
|
||||||
y ^= (y >> 11);
|
y ^= y >> 11;
|
||||||
y ^= ((y << 7) & 2636928640);
|
y ^= (y << 7) & 2636928640;
|
||||||
y ^= ((y << 15) & 4022730752);
|
y ^= (y << 15) & 4022730752;
|
||||||
y ^= y >> 18;
|
y ^= y >> 18;
|
||||||
|
|
||||||
index = (index + 1) % 624;
|
index = (index + 1) % 624;
|
||||||
@@ -77,7 +77,7 @@ namespace OpenRA.Support
|
|||||||
var y = (mt[i] & 0x80000000) | (mt[(i + 1) % 624] & 0x7fffffff);
|
var y = (mt[i] & 0x80000000) | (mt[(i + 1) % 624] & 0x7fffffff);
|
||||||
mt[i] = mt[(i + 397u) % 624u] ^ (y >> 1);
|
mt[i] = mt[(i + 397u) % 624u] ^ (y >> 1);
|
||||||
if ((y & 1) == 1)
|
if ((y & 1) == 1)
|
||||||
mt[i] = (mt[i] ^ 2567483615);
|
mt[i] = mt[i] ^ 2567483615;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Support
|
|||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
|
|
||||||
public static void Increment( string item, double x )
|
public static void Increment(string item, double x)
|
||||||
{
|
{
|
||||||
items[item].val += x;
|
items[item].val += x;
|
||||||
}
|
}
|
||||||
@@ -91,6 +91,7 @@ namespace OpenRA.Support
|
|||||||
sum += samples[n];
|
sum += samples[n];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum / i;
|
return sum / i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ namespace OpenRA.Support
|
|||||||
{
|
{
|
||||||
public sealed class PerfTimer : IDisposable
|
public sealed class PerfTimer : IDisposable
|
||||||
{
|
{
|
||||||
|
// Tree settings
|
||||||
|
const int Digits = 6;
|
||||||
|
const string IndentationString = "| ";
|
||||||
|
const string FormatSeperation = " ms ";
|
||||||
|
static readonly string FormatString = "{0," + Digits + ":0}" + FormatSeperation + "{1}";
|
||||||
readonly string name;
|
readonly string name;
|
||||||
readonly float thresholdMs;
|
readonly float thresholdMs;
|
||||||
readonly byte depth;
|
readonly byte depth;
|
||||||
@@ -27,12 +32,6 @@ namespace OpenRA.Support
|
|||||||
|
|
||||||
static ThreadLocal<PerfTimer> Parent = new ThreadLocal<PerfTimer>();
|
static ThreadLocal<PerfTimer> Parent = new ThreadLocal<PerfTimer>();
|
||||||
|
|
||||||
// Tree settings
|
|
||||||
const int Digits = 6;
|
|
||||||
const string IndentationString = "| ";
|
|
||||||
const string FormatSeperation = " ms ";
|
|
||||||
static readonly string FormatString = "{0," + Digits + ":0}" + FormatSeperation + "{1}";
|
|
||||||
|
|
||||||
public PerfTimer(string name, float thresholdMs = 0)
|
public PerfTimer(string name, float thresholdMs = 0)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|||||||
@@ -86,8 +86,9 @@ namespace OpenRA
|
|||||||
Indent(sb, d);
|
Indent(sb, d);
|
||||||
sb.AppendFormat("TypeName=`{0}`", tle.TypeName);
|
sb.AppendFormat("TypeName=`{0}`", tle.TypeName);
|
||||||
}
|
}
|
||||||
else // TODO: more exception types
|
else
|
||||||
{
|
{
|
||||||
|
// TODO: more exception types
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.InnerException != null)
|
if (e.InnerException != null)
|
||||||
|
|||||||
@@ -33,18 +33,18 @@ namespace OpenRA
|
|||||||
|
|
||||||
static Dictionary<Type, MethodInfo> hashFunctions = new Dictionary<Type, MethodInfo>()
|
static Dictionary<Type, MethodInfo> hashFunctions = new Dictionary<Type, MethodInfo>()
|
||||||
{
|
{
|
||||||
{typeof(int2), ((Func<int2, int>)hash_int2).Method},
|
{ typeof(int2), ((Func<int2, int>)hash_int2).Method },
|
||||||
{typeof(CPos), ((Func<CPos, int>)hash_CPos).Method},
|
{ typeof(CPos), ((Func<CPos, int>)hash_CPos).Method },
|
||||||
{typeof(CVec), ((Func<CVec, int>)hash_CVec).Method},
|
{ typeof(CVec), ((Func<CVec, int>)hash_CVec).Method },
|
||||||
{typeof(WRange), ((Func<WRange, int>)hash<WRange>).Method},
|
{ typeof(WRange), ((Func<WRange, int>)hash<WRange>).Method },
|
||||||
{typeof(WPos), ((Func<WPos, int>)hash<WPos>).Method},
|
{ typeof(WPos), ((Func<WPos, int>)hash<WPos>).Method },
|
||||||
{typeof(WVec), ((Func<WVec, int>)hash<WVec>).Method},
|
{ typeof(WVec), ((Func<WVec, int>)hash<WVec>).Method },
|
||||||
{typeof(WAngle), ((Func<WAngle, int>)hash<WAngle>).Method},
|
{ typeof(WAngle), ((Func<WAngle, int>)hash<WAngle>).Method },
|
||||||
{typeof(WRot), ((Func<WRot, int>)hash<WRot>).Method},
|
{ typeof(WRot), ((Func<WRot, int>)hash<WRot>).Method },
|
||||||
{typeof(TypeDictionary), ((Func<TypeDictionary, int>)hash_tdict).Method},
|
{ typeof(TypeDictionary), ((Func<TypeDictionary, int>)hash_tdict).Method },
|
||||||
{typeof(Actor), ((Func<Actor, int>)hash_actor).Method},
|
{ typeof(Actor), ((Func<Actor, int>)hash_actor).Method },
|
||||||
{typeof(Player), ((Func<Player, int>)hash_player).Method},
|
{ typeof(Player), ((Func<Player, int>)hash_player).Method },
|
||||||
{typeof(Target), ((Func<Target, int>)hash_target).Method},
|
{ typeof(Target), ((Func<Target, int>)hash_target).Method },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void EmitSyncOpcodes(Type type, ILGenerator il)
|
static void EmitSyncOpcodes(Type type, ILGenerator il)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace OpenRA
|
|||||||
else
|
else
|
||||||
end = mid;
|
end = mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,6 +188,7 @@ namespace OpenRA
|
|||||||
this.actor = actor;
|
this.actor = actor;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() { index = actors.BinarySearchMany(actor) - 1; }
|
public void Reset() { index = actors.BinarySearchMany(actor) - 1; }
|
||||||
public bool MoveNext() { return ++index < actors.Count && actors[index].ActorID == actor; }
|
public bool MoveNext() { return ++index < actors.Count && actors[index].ActorID == actor; }
|
||||||
public T Current { get { return traits[index]; } }
|
public T Current { get { return traits[index]; } }
|
||||||
@@ -219,6 +221,7 @@ namespace OpenRA
|
|||||||
traits = container.traits;
|
traits = container.traits;
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() { index = -1; }
|
public void Reset() { index = -1; }
|
||||||
public bool MoveNext() { return ++index < actors.Count; }
|
public bool MoveNext() { return ++index < actors.Count; }
|
||||||
public TraitPair<T> Current { get { return new TraitPair<T> { Actor = actors[index], Trait = traits[index] }; } }
|
public TraitPair<T> Current { get { return new TraitPair<T> { Actor = actors[index], Trait = traits[index] }; } }
|
||||||
|
|||||||
@@ -16,6 +16,5 @@ namespace OpenRA.Traits
|
|||||||
public readonly string Type = null;
|
public readonly string Type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Armor {}
|
public class Armor { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ namespace OpenRA.Traits
|
|||||||
if (target.Type == TargetType.Invalid)
|
if (target.Type == TargetType.Invalid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
yield return new TargetLineRenderable(new [] { self.CenterPosition, target.CenterPosition }, c);
|
yield return new TargetLineRenderable(new[] { self.CenterPosition, target.CenterPosition }, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,5 +131,4 @@ namespace OpenRA.Traits
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Traits
|
|||||||
public virtual object Create(ActorInitializer init) { return new Health(init, this); }
|
public virtual object Create(ActorInitializer init) { return new Health(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum DamageState { Undamaged, Light, Medium, Heavy, Critical, Dead };
|
public enum DamageState { Undamaged, Light, Medium, Heavy, Critical, Dead }
|
||||||
|
|
||||||
public class Health : ISync, ITick
|
public class Health : ISync, ITick
|
||||||
{
|
{
|
||||||
@@ -173,8 +173,8 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
[FieldFromYamlKey] public readonly float value = 1f;
|
[FieldFromYamlKey] public readonly float value = 1f;
|
||||||
public HealthInit() { }
|
public HealthInit() { }
|
||||||
public HealthInit( float init ) { value = init; }
|
public HealthInit(float init) { value = init; }
|
||||||
public float Value( World world ) { return value; }
|
public float Value(World world) { return value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HealthExts
|
public static class HealthExts
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace OpenRA.Traits
|
|||||||
if (!self.World.AllowDevCommands)
|
if (!self.World.AllowDevCommands)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch(order.OrderString)
|
switch (order.OrderString)
|
||||||
{
|
{
|
||||||
case "DevEnableTech":
|
case "DevEnableTech":
|
||||||
{
|
{
|
||||||
@@ -97,6 +97,7 @@ namespace OpenRA.Traits
|
|||||||
for (var i = 0; i < Info.ResourceGrowth; i++)
|
for (var i = 0; i < Info.ResourceGrowth; i++)
|
||||||
a.Trait.Seed(a.Actor);
|
a.Trait.Seed(a.Actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public class PlayerResources : ITick, ISync
|
public class PlayerResources : ITick, ISync
|
||||||
{
|
{
|
||||||
|
const float displayCashFracPerFrame = .07f;
|
||||||
|
const int displayCashDeltaPerFrame = 37;
|
||||||
readonly Player Owner;
|
readonly Player Owner;
|
||||||
int AdviceInterval;
|
int AdviceInterval;
|
||||||
|
|
||||||
@@ -97,8 +99,6 @@ namespace OpenRA.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float displayCashFracPerFrame = .07f;
|
|
||||||
const int displayCashDeltaPerFrame = 37;
|
|
||||||
int nextSiloAdviceTime = 0;
|
int nextSiloAdviceTime = 0;
|
||||||
int nextCashTickTime = 0;
|
int nextCashTickTime = 0;
|
||||||
|
|
||||||
@@ -130,8 +130,7 @@ namespace OpenRA.Traits
|
|||||||
var diff = Math.Abs(Cash - DisplayCash);
|
var diff = Math.Abs(Cash - DisplayCash);
|
||||||
var move = Math.Min(Math.Max((int)(diff * displayCashFracPerFrame),
|
var move = Math.Min(Math.Max((int)(diff * displayCashFracPerFrame),
|
||||||
displayCashDeltaPerFrame), diff);
|
displayCashDeltaPerFrame), diff);
|
||||||
|
|
||||||
|
|
||||||
if (DisplayCash < Cash)
|
if (DisplayCash < Cash)
|
||||||
{
|
{
|
||||||
DisplayCash += move;
|
DisplayCash += move;
|
||||||
@@ -159,7 +158,6 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void playCashTickUp(Actor self)
|
public void playCashTickUp(Actor self)
|
||||||
{
|
{
|
||||||
if (Game.Settings.Sound.CashTicks)
|
if (Game.Settings.Sound.CashTicks)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Traits
|
|||||||
pipImages.PlayRepeating(pipStrings[0]);
|
pipImages.PlayRepeating(pipStrings[0]);
|
||||||
|
|
||||||
var pipSize = pipImages.Image.size.ToInt2();
|
var pipSize = pipImages.Image.size.ToInt2();
|
||||||
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, - (3 + pipSize.Y / 2));
|
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, -(3 + pipSize.Y / 2));
|
||||||
var pipxyOffset = new int2(0, 0);
|
var pipxyOffset = new int2(0, 0);
|
||||||
var pal = wr.Palette(Info.Palette);
|
var pal = wr.Palette(Info.Palette);
|
||||||
var width = self.Bounds.Width;
|
var width = self.Bounds.Width;
|
||||||
@@ -135,7 +135,5 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Traits
|
|||||||
public enum TargetType { Invalid, Actor, Terrain, FrozenActor }
|
public enum TargetType { Invalid, Actor, Terrain, FrozenActor }
|
||||||
public struct Target
|
public struct Target
|
||||||
{
|
{
|
||||||
public static readonly Target[] None = {};
|
public static readonly Target[] None = { };
|
||||||
public static readonly Target Invalid = new Target { type = TargetType.Invalid };
|
public static readonly Target Invalid = new Target { type = TargetType.Invalid };
|
||||||
|
|
||||||
TargetType type;
|
TargetType type;
|
||||||
@@ -54,7 +54,7 @@ namespace OpenRA.Traits
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Target FromFrozenActor(FrozenActor a) { return new Target { frozen = a, type = TargetType.FrozenActor }; }
|
public static Target FromFrozenActor(FrozenActor a) { return new Target { frozen = a, type = TargetType.FrozenActor }; }
|
||||||
|
|
||||||
public Actor Actor { get { return actor; } }
|
public Actor Actor { get { return actor; } }
|
||||||
public FrozenActor FrozenActor { get { return frozen; } }
|
public FrozenActor FrozenActor { get { return frozen; } }
|
||||||
@@ -115,7 +115,7 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Positions available to target for range checks
|
// Positions available to target for range checks
|
||||||
static readonly WPos[] NoPositions = {};
|
static readonly WPos[] NoPositions = { };
|
||||||
public IEnumerable<WPos> Positions
|
public IEnumerable<WPos> Positions
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -125,14 +125,14 @@ namespace OpenRA.Traits
|
|||||||
case TargetType.Actor:
|
case TargetType.Actor:
|
||||||
var targetable = actor.TraitOrDefault<ITargetable>();
|
var targetable = actor.TraitOrDefault<ITargetable>();
|
||||||
if (targetable == null)
|
if (targetable == null)
|
||||||
return new [] { actor.CenterPosition };
|
return new[] { actor.CenterPosition };
|
||||||
|
|
||||||
var positions = targetable.TargetablePositions(actor);
|
var positions = targetable.TargetablePositions(actor);
|
||||||
return positions.Any() ? positions : new [] { actor.CenterPosition };
|
return positions.Any() ? positions : new[] { actor.CenterPosition };
|
||||||
case TargetType.FrozenActor:
|
case TargetType.FrozenActor:
|
||||||
return new [] { frozen.CenterPosition };
|
return new[] { frozen.CenterPosition };
|
||||||
case TargetType.Terrain:
|
case TargetType.Terrain:
|
||||||
return new [] { pos };
|
return new[] { pos };
|
||||||
default:
|
default:
|
||||||
case TargetType.Invalid:
|
case TargetType.Invalid:
|
||||||
return NoPositions;
|
return NoPositions;
|
||||||
@@ -146,7 +146,7 @@ namespace OpenRA.Traits
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Target ranges are calculated in 2D, so ignore height differences
|
// Target ranges are calculated in 2D, so ignore height differences
|
||||||
var rangeSquared = range.Range*range.Range;
|
var rangeSquared = range.Range * range.Range;
|
||||||
return Positions.Any(t => (t - origin).HorizontalLengthSquared <= rangeSquared);
|
return Positions.Any(t => (t - origin).HorizontalLengthSquared <= rangeSquared);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +168,5 @@ namespace OpenRA.Traits
|
|||||||
return "Invalid";
|
return "Invalid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ using OpenRA.Primitives;
|
|||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
// depends on the order of pips in WorldRenderer.cs!
|
// depends on the order of pips in WorldRenderer.cs!
|
||||||
public enum PipType { Transparent, Green, Yellow, Red, Gray, Blue, Ammo, AmmoEmpty };
|
public enum PipType { Transparent, Green, Yellow, Red, Gray, Blue, Ammo, AmmoEmpty }
|
||||||
public enum TagType { None, Fake, Primary };
|
public enum TagType { None, Fake, Primary }
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum Stance
|
public enum Stance
|
||||||
@@ -65,7 +65,7 @@ namespace OpenRA.Traits
|
|||||||
Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued);
|
Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags] public enum TargetModifiers { None = 0, ForceAttack = 1, ForceQueue = 2, ForceMove = 4 };
|
[Flags] public enum TargetModifiers { None = 0, ForceAttack = 1, ForceQueue = 2, ForceMove = 4 }
|
||||||
|
|
||||||
public static class TargetModifiersExts
|
public static class TargetModifiersExts
|
||||||
{
|
{
|
||||||
@@ -173,6 +173,7 @@ namespace OpenRA.Traits
|
|||||||
nearestDistance = dist;
|
nearestDistance = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nearest;
|
return nearest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,9 +91,11 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
start = current;
|
start = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev == act)
|
if (prev == act)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -476,7 +476,6 @@ namespace OpenRA.Traits
|
|||||||
yield return bins[j * cols + i];
|
yield return bins[j * cols + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<Actor> ActorsInBox(WPos a, WPos b)
|
public IEnumerable<Actor> ActorsInBox(WPos a, WPos b)
|
||||||
{
|
{
|
||||||
var left = Math.Min(a.X, b.X);
|
var left = Math.Min(a.X, b.X);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
for (var j = top; j <= bottom; j++)
|
for (var j = top; j <= bottom; j++)
|
||||||
for (var i = left; i <= right; i++)
|
for (var i = left; i <= right; i++)
|
||||||
frozen[viewer][j*cols + i].Add(fa, bounds);
|
frozen[viewer][j * cols + i].Add(fa, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(Player viewer, FrozenActor fa)
|
public void Remove(Player viewer, FrozenActor fa)
|
||||||
@@ -117,7 +117,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
var i = (worldPx.X / info.BinSize).Clamp(0, cols - 1);
|
var i = (worldPx.X / info.BinSize).Clamp(0, cols - 1);
|
||||||
var j = (worldPx.Y / info.BinSize).Clamp(0, rows - 1);
|
var j = (worldPx.Y / info.BinSize).Clamp(0, rows - 1);
|
||||||
return frozen[viewer][j*cols + i]
|
return frozen[viewer][j * cols + i]
|
||||||
.Where(kv => kv.Key.IsValid && kv.Value.Contains(worldPx))
|
.Where(kv => kv.Key.IsValid && kv.Value.Contains(worldPx))
|
||||||
.Select(kv => kv.Key);
|
.Select(kv => kv.Key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,15 @@ namespace OpenRA
|
|||||||
if (Angle < 0)
|
if (Angle < 0)
|
||||||
Angle += 1024;
|
Angle += 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly WAngle Zero = new WAngle(0);
|
public static readonly WAngle Zero = new WAngle(0);
|
||||||
public static WAngle FromFacing(int facing) { return new WAngle(facing*4); }
|
public static WAngle FromFacing(int facing) { return new WAngle(facing * 4); }
|
||||||
public static WAngle FromDegrees(int degrees) { return new WAngle(degrees*1024/360); }
|
public static WAngle FromDegrees(int degrees) { return new WAngle(degrees * 1024 / 360); }
|
||||||
public static WAngle operator +(WAngle a, WAngle b) { return new WAngle(a.Angle + b.Angle); }
|
public static WAngle operator +(WAngle a, WAngle b) { return new WAngle(a.Angle + b.Angle); }
|
||||||
public static WAngle operator -(WAngle a, WAngle b) { return new WAngle(a.Angle - b.Angle); }
|
public static WAngle operator -(WAngle a, WAngle b) { return new WAngle(a.Angle - b.Angle); }
|
||||||
public static WAngle operator -(WAngle a) { return new WAngle(-a.Angle); }
|
public static WAngle operator -(WAngle a) { return new WAngle(-a.Angle); }
|
||||||
|
|
||||||
public static bool operator ==(WAngle me, WAngle other) { return (me.Angle == other.Angle); }
|
public static bool operator ==(WAngle me, WAngle other) { return me.Angle == other.Angle; }
|
||||||
public static bool operator !=(WAngle me, WAngle other) { return !(me == other); }
|
public static bool operator !=(WAngle me, WAngle other) { return !(me == other); }
|
||||||
|
|
||||||
public override int GetHashCode() { return Angle.GetHashCode(); }
|
public override int GetHashCode() { return Angle.GetHashCode(); }
|
||||||
@@ -67,7 +68,7 @@ namespace OpenRA
|
|||||||
return new WAngle(x >= 0 ? 0 : 512);
|
return new WAngle(x >= 0 ? 0 : 512);
|
||||||
|
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
return new WAngle(Math.Sign(y)*256);
|
return new WAngle(Math.Sign(y) * 256);
|
||||||
|
|
||||||
var ay = Math.Abs(y);
|
var ay = Math.Abs(y);
|
||||||
var ax = Math.Abs(x);
|
var ax = Math.Abs(x);
|
||||||
@@ -75,9 +76,9 @@ namespace OpenRA
|
|||||||
// Find the closest angle that satisfies y = x*tan(theta)
|
// Find the closest angle that satisfies y = x*tan(theta)
|
||||||
var bestVal = int.MaxValue;
|
var bestVal = int.MaxValue;
|
||||||
var bestAngle = 0;
|
var bestAngle = 0;
|
||||||
for (var i = 0; i < 256; i+= stride)
|
for (var i = 0; i < 256; i += stride)
|
||||||
{
|
{
|
||||||
var val = Math.Abs(1024*ay - ax*TanTable[i]);
|
var val = Math.Abs(1024 * ay - ax * TanTable[i]);
|
||||||
if (val < bestVal)
|
if (val < bestVal)
|
||||||
{
|
{
|
||||||
bestVal = val;
|
bestVal = val;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace OpenRA
|
|||||||
public static WPos operator -(WPos a, WVec b) { return new WPos(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
|
public static WPos operator -(WPos a, WVec b) { return new WPos(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
|
||||||
public static WVec operator -(WPos a, WPos b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
|
public static WVec operator -(WPos a, WPos b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
|
||||||
|
|
||||||
public static bool operator ==(WPos me, WPos other) { return (me.X == other.X && me.Y == other.Y && me.Z == other.Z); }
|
public static bool operator ==(WPos me, WPos other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
|
||||||
public static bool operator !=(WPos me, WPos other) { return !(me == other); }
|
public static bool operator !=(WPos me, WPos other) { return !(me == other); }
|
||||||
|
|
||||||
public static WPos Lerp(WPos a, WPos b, int mul, int div) { return a + (b - a) * mul / div; }
|
public static WPos Lerp(WPos a, WPos b, int mul, int div) { return a + (b - a) * mul / div; }
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public WRange(int r) { Range = r; }
|
public WRange(int r) { Range = r; }
|
||||||
public static readonly WRange Zero = new WRange(0);
|
public static readonly WRange Zero = new WRange(0);
|
||||||
public static WRange FromCells(int cells) { return new WRange(1024*cells); }
|
public static WRange FromCells(int cells) { return new WRange(1024 * cells); }
|
||||||
|
|
||||||
public static WRange operator +(WRange a, WRange b) { return new WRange(a.Range + b.Range); }
|
public static WRange operator +(WRange a, WRange b) { return new WRange(a.Range + b.Range); }
|
||||||
public static WRange operator -(WRange a, WRange b) { return new WRange(a.Range - b.Range); }
|
public static WRange operator -(WRange a, WRange b) { return new WRange(a.Range - b.Range); }
|
||||||
@@ -39,7 +39,7 @@ namespace OpenRA
|
|||||||
public static bool operator <=(WRange a, WRange b) { return a.Range <= b.Range; }
|
public static bool operator <=(WRange a, WRange b) { return a.Range <= b.Range; }
|
||||||
public static bool operator >=(WRange a, WRange b) { return a.Range >= b.Range; }
|
public static bool operator >=(WRange a, WRange b) { return a.Range >= b.Range; }
|
||||||
|
|
||||||
public static bool operator ==(WRange me, WRange other) { return (me.Range == other.Range); }
|
public static bool operator ==(WRange me, WRange other) { return me.Range == other.Range; }
|
||||||
public static bool operator !=(WRange me, WRange other) { return !(me == other); }
|
public static bool operator !=(WRange me, WRange other) { return !(me == other); }
|
||||||
|
|
||||||
// Sampled a N-sample probability density function in the range [-1024..1024]
|
// Sampled a N-sample probability density function in the range [-1024..1024]
|
||||||
@@ -79,7 +79,7 @@ namespace OpenRA
|
|||||||
if (cell < 0)
|
if (cell < 0)
|
||||||
subcell = -subcell;
|
subcell = -subcell;
|
||||||
|
|
||||||
result = new WRange(1024*cell + subcell);
|
result = new WRange(1024 * cell + subcell);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +94,7 @@ namespace OpenRA
|
|||||||
return 1;
|
return 1;
|
||||||
return Range.CompareTo(((WRange)obj).Range);
|
return Range.CompareTo(((WRange)obj).Range);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CompareTo(WRange other) { return Range.CompareTo(other.Range); }
|
public int CompareTo(WRange other) { return Range.CompareTo(other.Range); }
|
||||||
|
|
||||||
public override string ToString() { return Range.ToString(); }
|
public override string ToString() { return Range.ToString(); }
|
||||||
@@ -139,6 +140,7 @@ namespace OpenRA
|
|||||||
default: throw new LuaException("WPos does not define a member '{0}'".F(key));
|
default: throw new LuaException("WPos does not define a member '{0}'".F(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
throw new LuaException("WRange is read-only. Use WRange.New to create a new value");
|
throw new LuaException("WRange is read-only. Use WRange.New to create a new value");
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ namespace OpenRA
|
|||||||
public static WRot operator -(WRot a, WRot b) { return new WRot(a.Roll - b.Roll, a.Pitch - b.Pitch, a.Yaw - b.Yaw); }
|
public static WRot operator -(WRot a, WRot b) { return new WRot(a.Roll - b.Roll, a.Pitch - b.Pitch, a.Yaw - b.Yaw); }
|
||||||
public static WRot operator -(WRot a) { return new WRot(-a.Roll, -a.Pitch, -a.Yaw); }
|
public static WRot operator -(WRot a) { return new WRot(-a.Roll, -a.Pitch, -a.Yaw); }
|
||||||
|
|
||||||
public static bool operator ==(WRot me, WRot other) { return (me.Roll == other.Roll &&
|
public static bool operator ==(WRot me, WRot other) { return me.Roll == other.Roll &&
|
||||||
me.Pitch == other.Pitch && me.Yaw == other.Yaw); }
|
me.Pitch == other.Pitch && me.Yaw == other.Yaw; }
|
||||||
|
|
||||||
public static bool operator !=(WRot me, WRot other) { return !(me == other); }
|
public static bool operator !=(WRot me, WRot other) { return !(me == other); }
|
||||||
|
|
||||||
public WRot WithYaw(WAngle yaw)
|
public WRot WithYaw(WAngle yaw)
|
||||||
@@ -53,10 +54,10 @@ namespace OpenRA
|
|||||||
// Normalized to 1024 == 1.0
|
// Normalized to 1024 == 1.0
|
||||||
return new int[4]
|
return new int[4]
|
||||||
{
|
{
|
||||||
(int)((sr*cp*cy - cr*sp*sy) / 1048576), // x
|
(int)((sr * cp * cy - cr * sp * sy) / 1048576), // x
|
||||||
(int)((cr*sp*cy + sr*cp*sy) / 1048576), // y
|
(int)((cr * sp * cy + sr * cp * sy) / 1048576), // y
|
||||||
(int)((cr*cp*sy - sr*sp*cy) / 1048576), // z
|
(int)((cr * cp * sy - sr * sp * cy) / 1048576), // z
|
||||||
(int)((cr*cp*cy + sr*sp*sy) / 1048576) // w
|
(int)((cr * cp * cy + sr * sp * sy) / 1048576) // w
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,24 +65,24 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
var q = AsQuarternion();
|
var q = AsQuarternion();
|
||||||
|
|
||||||
// Theoretically 1024**2, but may differ slightly due to rounding
|
// Theoretically 1024 * * 2, but may differ slightly due to rounding
|
||||||
var lsq = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
|
var lsq = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3];
|
||||||
|
|
||||||
// Quarternion components use 10 bits, so there's no risk of overflow
|
// Quarternion components use 10 bits, so there's no risk of overflow
|
||||||
var mtx = new int[16];
|
var mtx = new int[16];
|
||||||
mtx[0] = lsq - 2*(q[1]*q[1] + q[2]*q[2]);
|
mtx[0] = lsq - 2 * (q[1] * q[1] + q[2] * q[2]);
|
||||||
mtx[1] = 2*(q[0]*q[1] + q[2]*q[3]);
|
mtx[1] = 2 * (q[0] * q[1] + q[2] * q[3]);
|
||||||
mtx[2] = 2*(q[0]*q[2] - q[1]*q[3]);
|
mtx[2] = 2 * (q[0] * q[2] - q[1] * q[3]);
|
||||||
mtx[3] = 0;
|
mtx[3] = 0;
|
||||||
|
|
||||||
mtx[4] = 2*(q[0]*q[1] - q[2]*q[3]);
|
mtx[4] = 2 * (q[0] * q[1] - q[2] * q[3]);
|
||||||
mtx[5] = lsq - 2*(q[0]*q[0] + q[2]*q[2]);
|
mtx[5] = lsq - 2 * (q[0] * q[0] + q[2] * q[2]);
|
||||||
mtx[6] = 2*(q[1]*q[2] + q[0]*q[3]);
|
mtx[6] = 2 * (q[1] * q[2] + q[0] * q[3]);
|
||||||
mtx[7] = 0;
|
mtx[7] = 0;
|
||||||
|
|
||||||
mtx[8] = 2*(q[0]*q[2] + q[1]*q[3]);
|
mtx[8] = 2 * (q[0] * q[2] + q[1] * q[3]);
|
||||||
mtx[9] = 2*(q[1]*q[2] - q[0]*q[3]);
|
mtx[9] = 2 * (q[1] * q[2] - q[0] * q[3]);
|
||||||
mtx[10] = lsq - 2*(q[0]*q[0] + q[1]*q[1]);
|
mtx[10] = lsq - 2 * (q[0] * q[0] + q[1] * q[1]);
|
||||||
mtx[11] = 0;
|
mtx[11] = 0;
|
||||||
|
|
||||||
mtx[12] = 0;
|
mtx[12] = 0;
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ namespace OpenRA
|
|||||||
public static WVec operator -(WVec a) { return new WVec(-a.X, -a.Y, -a.Z); }
|
public static WVec operator -(WVec a) { return new WVec(-a.X, -a.Y, -a.Z); }
|
||||||
public static WVec operator /(WVec a, int b) { return new WVec(a.X / b, a.Y / b, a.Z / b); }
|
public static WVec operator /(WVec a, int b) { return new WVec(a.X / b, a.Y / b, a.Z / b); }
|
||||||
public static WVec operator *(int a, WVec b) { return new WVec(a * b.X, a * b.Y, a * b.Z); }
|
public static WVec operator *(int a, WVec b) { return new WVec(a * b.X, a * b.Y, a * b.Z); }
|
||||||
public static WVec operator *(WVec a, int b) { return b*a; }
|
public static WVec operator *(WVec a, int b) { return b * a; }
|
||||||
|
|
||||||
public static bool operator ==(WVec me, WVec other) { return (me.X == other.X && me.Y == other.Y && me.Z == other.Z); }
|
public static bool operator ==(WVec me, WVec other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
|
||||||
public static bool operator !=(WVec me, WVec other) { return !(me == other); }
|
public static bool operator !=(WVec me, WVec other) { return !(me == other); }
|
||||||
|
|
||||||
public static int Dot(WVec a, WVec b) { return a.X * b.X + a.Y * b.Y + a.Z * b.Z; }
|
public static int Dot(WVec a, WVec b) { return a.X * b.X + a.Y * b.Y + a.Z * b.Z; }
|
||||||
@@ -48,9 +48,9 @@ namespace OpenRA
|
|||||||
var ly = (long)Y;
|
var ly = (long)Y;
|
||||||
var lz = (long)Z;
|
var lz = (long)Z;
|
||||||
return new WVec(
|
return new WVec(
|
||||||
(int)((lx * mtx[0] + ly*mtx[4] + lz*mtx[8]) / mtx[15]),
|
(int)((lx * mtx[0] + ly * mtx[4] + lz * mtx[8]) / mtx[15]),
|
||||||
(int)((lx * mtx[1] + ly*mtx[5] + lz*mtx[9]) / mtx[15]),
|
(int)((lx * mtx[1] + ly * mtx[5] + lz * mtx[9]) / mtx[15]),
|
||||||
(int)((lx * mtx[2] + ly*mtx[6] + lz*mtx[10]) / mtx[15]));
|
(int)((lx * mtx[2] + ly * mtx[6] + lz * mtx[10]) / mtx[15]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WVec Lerp(WVec a, WVec b, int mul, int div) { return a + (b - a) * mul / div; }
|
public static WVec Lerp(WVec a, WVec b, int mul, int div) { return a + (b - a) * mul / div; }
|
||||||
@@ -65,7 +65,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
// Add an additional quadratic variation to height
|
// Add an additional quadratic variation to height
|
||||||
// Uses fp to avoid integer overflow
|
// Uses fp to avoid integer overflow
|
||||||
var offset = (int)((float)((float)(b - a).Length*pitch.Tan()*mul*(div - mul)) / (float)(1024*div*div));
|
var offset = (int)((float)((float)(b - a).Length * pitch.Tan() * mul * (div - mul)) / (float)(1024 * div * div));
|
||||||
return new WVec(ret.X, ret.Y, ret.Z + offset);
|
return new WVec(ret.X, ret.Y, ret.Z + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Widgets
|
|||||||
if (ClickThrough || !RenderBounds.Contains(mi.Location))
|
if (ClickThrough || !RenderBounds.Contains(mi.Location))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Draggable || moving && (!TakeMouseFocus(mi) || mi.Button != MouseButton.Left))
|
if (!Draggable || (moving && (!TakeMouseFocus(mi) || mi.Button != MouseButton.Left)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (prevMouseLocation == null)
|
if (prevMouseLocation == null)
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
public class ButtonWidget : Widget
|
public class ButtonWidget : Widget
|
||||||
{
|
{
|
||||||
|
public readonly string TooltipContainer;
|
||||||
|
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
|
||||||
public Func<ButtonWidget, Hotkey> GetKey = _ => Hotkey.Invalid;
|
public Func<ButtonWidget, Hotkey> GetKey = _ => Hotkey.Invalid;
|
||||||
|
|
||||||
public Hotkey Key
|
public Hotkey Key
|
||||||
{
|
{
|
||||||
get { return GetKey(this); }
|
get { return GetKey(this); }
|
||||||
@@ -40,19 +43,17 @@ namespace OpenRA.Widgets
|
|||||||
public Func<Color> GetContrastColor;
|
public Func<Color> GetContrastColor;
|
||||||
public Func<bool> IsDisabled;
|
public Func<bool> IsDisabled;
|
||||||
public Func<bool> IsHighlighted;
|
public Func<bool> IsHighlighted;
|
||||||
public Action<MouseInput> OnMouseDown = _ => {};
|
public Action<MouseInput> OnMouseDown = _ => { };
|
||||||
public Action<MouseInput> OnMouseUp = _ => {};
|
public Action<MouseInput> OnMouseUp = _ => { };
|
||||||
|
|
||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
public readonly string TooltipContainer;
|
|
||||||
public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
|
|
||||||
[Translate] public string TooltipText;
|
[Translate] public string TooltipText;
|
||||||
public Func<string> GetTooltipText;
|
public Func<string> GetTooltipText;
|
||||||
|
|
||||||
// Equivalent to OnMouseUp, but without an input arg
|
// Equivalent to OnMouseUp, but without an input arg
|
||||||
public Action OnClick = () => {};
|
public Action OnClick = () => { };
|
||||||
public Action OnDoubleClick = () => {};
|
public Action OnDoubleClick = () => { };
|
||||||
public Action<KeyInput> OnKeyPress = _ => {};
|
public Action<KeyInput> OnKeyPress = _ => { };
|
||||||
|
|
||||||
protected readonly Ruleset ModRules;
|
protected readonly Ruleset ModRules;
|
||||||
|
|
||||||
@@ -149,14 +150,15 @@ namespace OpenRA.Widgets
|
|||||||
return YieldMouseFocus(mi);
|
return YieldMouseFocus(mi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only fire the onMouseUp event if we successfully lost focus, and were pressed
|
|
||||||
else if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
|
else if (HasMouseFocus && mi.Event == MouseInputEvent.Up)
|
||||||
{
|
{
|
||||||
|
// Only fire the onMouseUp event if we successfully lost focus, and were pressed
|
||||||
if (Depressed && !disabled)
|
if (Depressed && !disabled)
|
||||||
OnMouseUp(mi);
|
OnMouseUp(mi);
|
||||||
|
|
||||||
return YieldMouseFocus(mi);
|
return YieldMouseFocus(mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Down)
|
if (mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
// OnMouseDown returns false if the button shouldn't be pressed
|
// OnMouseDown returns false if the button shouldn't be pressed
|
||||||
@@ -210,7 +212,7 @@ namespace OpenRA.Widgets
|
|||||||
var colordisabled = GetColorDisabled();
|
var colordisabled = GetColorDisabled();
|
||||||
var contrast = GetContrastColor();
|
var contrast = GetContrastColor();
|
||||||
var s = font.Measure(text);
|
var s = font.Measure(text);
|
||||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
var stateOffset = Depressed ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||||
var position = new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y - BaseLine + (Bounds.Height - s.Y) / 2);
|
var position = new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y - BaseLine + (Bounds.Height - s.Y) / 2);
|
||||||
|
|
||||||
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);
|
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user