Fix IDE0032

This commit is contained in:
RoosterDragon
2023-02-19 11:19:28 +00:00
committed by Pavel Penev
parent e64c0a35c5
commit 98c4eaca83
52 changed files with 460 additions and 567 deletions

View File

@@ -18,24 +18,22 @@ namespace OpenRA.FileSystem
{
public sealed class Folder : IReadWritePackage
{
readonly string path;
public string Name { get; }
public Folder(string path)
{
this.path = path;
Name = path;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}
public string Name => path;
public IEnumerable<string> Contents
{
get
{
// Order may vary on different file systems and it matters for hashing.
return Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetDirectories(path))
return Directory.GetFiles(Name, "*", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetDirectories(Name))
.Select(Path.GetFileName)
.OrderBy(f => f);
}
@@ -43,14 +41,14 @@ namespace OpenRA.FileSystem
public Stream GetStream(string filename)
{
try { return File.OpenRead(Path.Combine(path, filename)); }
try { return File.OpenRead(Path.Combine(Name, filename)); }
catch { return null; }
}
public bool Contains(string filename)
{
var combined = Path.Combine(path, filename);
return combined.StartsWith(path, StringComparison.Ordinal) && File.Exists(combined);
var combined = Path.Combine(Name, filename);
return combined.StartsWith(Name, StringComparison.Ordinal) && File.Exists(combined);
}
public IReadOnlyPackage OpenPackage(string filename, FileSystem context)
@@ -82,7 +80,7 @@ namespace OpenRA.FileSystem
// in FileSystem.OpenPackage. Their internal name therefore contains the
// full parent path too. We need to be careful to not add a second path
// prefix to these hacked packages.
var filePath = filename.StartsWith(path) ? filename : Path.Combine(path, filename);
var filePath = filename.StartsWith(Name) ? filename : Path.Combine(Name, filename);
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
using (var s = File.Create(filePath))
@@ -96,7 +94,7 @@ namespace OpenRA.FileSystem
// in FileSystem.OpenPackage. Their internal name therefore contains the
// full parent path too. We need to be careful to not add a second path
// prefix to these hacked packages.
var filePath = filename.StartsWith(path) ? filename : Path.Combine(path, filename);
var filePath = filename.StartsWith(Name) ? filename : Path.Combine(Name, filename);
if (Directory.Exists(filePath))
Directory.Delete(filePath, true);
else if (File.Exists(filePath))

View File

@@ -142,23 +142,22 @@ namespace OpenRA.FileSystem
sealed class ZipFolder : IReadOnlyPackage
{
public string Name => path;
public string Name { get; }
public ReadOnlyZipFile Parent { get; }
readonly string path;
public ZipFolder(ReadOnlyZipFile parent, string path)
{
if (path.EndsWith("/", StringComparison.Ordinal))
path = path.Substring(0, path.Length - 1);
Name = path;
Parent = parent;
this.path = path;
}
public Stream GetStream(string filename)
{
// Zip files use '/' as a path separator
return Parent.GetStream(path + '/' + filename);
return Parent.GetStream(Name + '/' + filename);
}
public IEnumerable<string> Contents
@@ -167,9 +166,9 @@ namespace OpenRA.FileSystem
{
foreach (var entry in Parent.Contents)
{
if (entry.StartsWith(path, StringComparison.Ordinal) && entry != path)
if (entry.StartsWith(Name, StringComparison.Ordinal) && entry != Name)
{
var filename = entry.Substring(path.Length + 1);
var filename = entry.Substring(Name.Length + 1);
var dirLevels = filename.Split('/').Count(c => !string.IsNullOrEmpty(c));
if (dirLevels == 1)
yield return filename;
@@ -180,12 +179,12 @@ namespace OpenRA.FileSystem
public bool Contains(string filename)
{
return Parent.Contains(path + '/' + filename);
return Parent.Contains(Name + '/' + filename);
}
public IReadOnlyPackage OpenPackage(string filename, FileSystem context)
{
return Parent.OpenPackage(path + '/' + filename, context);
return Parent.OpenPackage(Name + '/' + filename, context);
}
public void Dispose() { /* nothing to do */ }

View File

@@ -37,12 +37,13 @@ namespace OpenRA.Graphics
readonly List<Sheet> sheets = new List<Sheet>();
readonly Func<Sheet> allocateSheet;
readonly int margin;
Sheet current;
TextureChannel channel;
int rowHeight = 0;
int2 p;
public Sheet Current { get; private set; }
public TextureChannel CurrentChannel { get; private set; }
public IEnumerable<Sheet> AllSheets => sheets;
public static Sheet AllocateSheet(SheetType type, int sheetSize)
{
return new Sheet(type, new Size(sheetSize, sheetSize));
@@ -73,10 +74,10 @@ namespace OpenRA.Graphics
public SheetBuilder(SheetType t, Func<Sheet> allocateSheet, int margin = 1)
{
channel = t == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
CurrentChannel = t == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
Type = t;
current = allocateSheet();
sheets.Add(current);
Current = allocateSheet();
sheets.Add(Current);
this.allocateSheet = allocateSheet;
this.margin = margin;
}
@@ -87,11 +88,11 @@ namespace OpenRA.Graphics
{
// Don't bother allocating empty sprites
if (size.Width == 0 || size.Height == 0)
return new Sprite(current, Rectangle.Empty, 0, spriteOffset, channel, BlendMode.Alpha);
return new Sprite(Current, Rectangle.Empty, 0, spriteOffset, CurrentChannel, BlendMode.Alpha);
var rect = Allocate(size, zRamp, spriteOffset);
Util.FastCopyIntoChannel(rect, src, type);
current.CommitBufferedData();
Current.CommitBufferedData();
return rect;
}
@@ -99,7 +100,7 @@ namespace OpenRA.Graphics
{
var rect = Allocate(new Size(src.Width, src.Height), scale);
Util.FastCopyIntoSprite(rect, src);
current.CommitBufferedData();
Current.CommitBufferedData();
return rect;
}
@@ -115,7 +116,7 @@ namespace OpenRA.Graphics
public Sprite Allocate(Size imageSize, float scale = 1f) { return Allocate(imageSize, 0, float3.Zero, scale); }
public Sprite Allocate(Size imageSize, float zRamp, in float3 spriteOffset, float scale = 1f)
{
if (imageSize.Width + p.X + margin > current.Size.Width)
if (imageSize.Width + p.X + margin > Current.Size.Width)
{
p = new int2(0, p.Y + rowHeight + margin);
rowHeight = imageSize.Height;
@@ -124,33 +125,29 @@ namespace OpenRA.Graphics
if (imageSize.Height > rowHeight)
rowHeight = imageSize.Height;
if (p.Y + imageSize.Height + margin > current.Size.Height)
if (p.Y + imageSize.Height + margin > Current.Size.Height)
{
var next = NextChannel(channel);
var next = NextChannel(CurrentChannel);
if (next == null)
{
current.ReleaseBuffer();
current = allocateSheet();
sheets.Add(current);
channel = Type == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
Current.ReleaseBuffer();
Current = allocateSheet();
sheets.Add(Current);
CurrentChannel = Type == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
}
else
channel = next.Value;
CurrentChannel = next.Value;
rowHeight = imageSize.Height;
p = int2.Zero;
}
var rect = new Sprite(current, new Rectangle(p.X + margin, p.Y + margin, imageSize.Width, imageSize.Height), zRamp, spriteOffset, channel, BlendMode.Alpha, scale);
var rect = new Sprite(Current, new Rectangle(p.X + margin, p.Y + margin, imageSize.Width, imageSize.Height), zRamp, spriteOffset, CurrentChannel, BlendMode.Alpha, scale);
p += new int2(imageSize.Width + margin, 0);
return rect;
}
public Sheet Current => current;
public TextureChannel CurrentChannel => channel;
public IEnumerable<Sheet> AllSheets => sheets;
public void Dispose()
{
foreach (var sheet in sheets)

View File

@@ -21,102 +21,95 @@ namespace OpenRA.Graphics
readonly Sprite sprite;
readonly WPos pos;
readonly WVec offset;
readonly int zOffset;
readonly PaletteReference palette;
readonly float scale;
readonly WAngle rotation = WAngle.Zero;
readonly float3 tint;
readonly TintModifiers tintModifiers;
readonly float alpha;
readonly bool isDecoration;
public SpriteRenderable(Sprite sprite, WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale, float alpha,
float3 tint, TintModifiers tintModifiers, bool isDecoration, WAngle rotation)
{
this.sprite = sprite;
this.pos = pos;
this.offset = offset;
this.zOffset = zOffset;
this.palette = palette;
Offset = offset;
ZOffset = zOffset;
Palette = palette;
this.scale = scale;
this.rotation = rotation;
this.tint = tint;
this.isDecoration = isDecoration;
this.tintModifiers = tintModifiers;
this.alpha = alpha;
Tint = tint;
IsDecoration = isDecoration;
TintModifiers = tintModifiers;
Alpha = alpha;
// PERF: Remove useless palette assignments for RGBA sprites
// HACK: This is working around the fact that palettes are defined on traits rather than sequences
// and can be removed once this has been fixed
if (sprite.Channel == TextureChannel.RGBA && !(palette?.HasColorShift ?? false))
this.palette = null;
Palette = null;
}
public SpriteRenderable(Sprite sprite, WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale, float alpha,
float3 tint, TintModifiers tintModifiers, bool isDecoration)
: this(sprite, pos, offset, zOffset, palette, scale, alpha, tint, tintModifiers, isDecoration, WAngle.Zero) { }
public WPos Pos => pos + offset;
public WVec Offset => offset;
public PaletteReference Palette => palette;
public int ZOffset => zOffset;
public bool IsDecoration => isDecoration;
public WPos Pos => pos + Offset;
public WVec Offset { get; }
public PaletteReference Palette { get; }
public int ZOffset { get; }
public bool IsDecoration { get; }
public float Alpha => alpha;
public float3 Tint => tint;
public TintModifiers TintModifiers => tintModifiers;
public float Alpha { get; }
public float3 Tint { get; }
public TintModifiers TintModifiers { get; }
public IPalettedRenderable WithPalette(PaletteReference newPalette)
{
return new SpriteRenderable(sprite, pos, offset, zOffset, newPalette, scale, alpha, tint, tintModifiers, isDecoration, rotation);
return new SpriteRenderable(sprite, pos, Offset, ZOffset, newPalette, scale, Alpha, Tint, TintModifiers, IsDecoration, rotation);
}
public IRenderable WithZOffset(int newOffset)
{
return new SpriteRenderable(sprite, pos, offset, newOffset, palette, scale, alpha, tint, tintModifiers, isDecoration, rotation);
return new SpriteRenderable(sprite, pos, Offset, newOffset, Palette, scale, Alpha, Tint, TintModifiers, IsDecoration, rotation);
}
public IRenderable OffsetBy(in WVec vec)
{
return new SpriteRenderable(sprite, pos + vec, offset, zOffset, palette, scale, alpha, tint, tintModifiers, isDecoration, rotation);
return new SpriteRenderable(sprite, pos + vec, Offset, ZOffset, Palette, scale, Alpha, Tint, TintModifiers, IsDecoration, rotation);
}
public IRenderable AsDecoration()
{
return new SpriteRenderable(sprite, pos, offset, zOffset, palette, scale, alpha, tint, tintModifiers, true, rotation);
return new SpriteRenderable(sprite, pos, Offset, ZOffset, Palette, scale, Alpha, Tint, TintModifiers, true, rotation);
}
public IModifyableRenderable WithAlpha(float newAlpha)
{
return new SpriteRenderable(sprite, pos, offset, zOffset, palette, scale, newAlpha, tint, tintModifiers, isDecoration, rotation);
return new SpriteRenderable(sprite, pos, Offset, ZOffset, Palette, scale, newAlpha, Tint, TintModifiers, IsDecoration, rotation);
}
public IModifyableRenderable WithTint(in float3 newTint, TintModifiers newTintModifiers)
{
return new SpriteRenderable(sprite, pos, offset, zOffset, palette, scale, alpha, newTint, newTintModifiers, isDecoration, rotation);
return new SpriteRenderable(sprite, pos, Offset, ZOffset, Palette, scale, Alpha, newTint, newTintModifiers, IsDecoration, rotation);
}
float3 ScreenPosition(WorldRenderer wr)
{
var s = 0.5f * scale * sprite.Size;
return wr.Screen3DPxPosition(pos) + wr.ScreenPxOffset(offset) - new float3((int)s.X, (int)s.Y, s.Z);
return wr.Screen3DPxPosition(pos) + wr.ScreenPxOffset(Offset) - new float3((int)s.X, (int)s.Y, s.Z);
}
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
var wsr = Game.Renderer.WorldSpriteRenderer;
var t = alpha * tint;
if (wr.TerrainLighting != null && (tintModifiers & TintModifiers.IgnoreWorldTint) == 0)
var t = Alpha * Tint;
if (wr.TerrainLighting != null && (TintModifiers & TintModifiers.IgnoreWorldTint) == 0)
t *= wr.TerrainLighting.TintAt(pos);
// Shader interprets negative alpha as a flag to use the tint colour directly instead of multiplying the sprite colour
var a = alpha;
if ((tintModifiers & TintModifiers.ReplaceColor) != 0)
var a = Alpha;
if ((TintModifiers & TintModifiers.ReplaceColor) != 0)
a *= -1;
wsr.DrawSprite(sprite, palette, ScreenPosition(wr), scale, t, a, rotation.RendererRadians());
wsr.DrawSprite(sprite, Palette, ScreenPosition(wr), scale, t, a, rotation.RendererRadians());
}
public void RenderDebugGeometry(WorldRenderer wr)

View File

@@ -16,10 +16,7 @@ namespace OpenRA.Graphics
public class UISpriteRenderable : IRenderable, IPalettedRenderable, IFinalizedRenderable
{
readonly Sprite sprite;
readonly WPos effectiveWorldPos;
readonly int2 screenPos;
readonly int zOffset;
readonly PaletteReference palette;
readonly float scale;
readonly float alpha;
readonly float rotation = 0f;
@@ -27,10 +24,10 @@ namespace OpenRA.Graphics
public UISpriteRenderable(Sprite sprite, WPos effectiveWorldPos, int2 screenPos, int zOffset, PaletteReference palette, float scale = 1f, float alpha = 1f, float rotation = 0f)
{
this.sprite = sprite;
this.effectiveWorldPos = effectiveWorldPos;
Pos = effectiveWorldPos;
this.screenPos = screenPos;
this.zOffset = zOffset;
this.palette = palette;
ZOffset = zOffset;
Palette = palette;
this.scale = scale;
this.alpha = alpha;
this.rotation = rotation;
@@ -39,18 +36,18 @@ namespace OpenRA.Graphics
// HACK: This is working around the fact that palettes are defined on traits rather than sequences
// and can be removed once this has been fixed
if (sprite.Channel == TextureChannel.RGBA && !(palette?.HasColorShift ?? false))
this.palette = null;
Palette = null;
}
// Does not exist in the world, so a world positions don't make sense
public WPos Pos => effectiveWorldPos;
public WPos Pos { get; }
public WVec Offset => WVec.Zero;
public bool IsDecoration => true;
public PaletteReference Palette => palette;
public int ZOffset => zOffset;
public PaletteReference Palette { get; }
public int ZOffset { get; }
public IPalettedRenderable WithPalette(PaletteReference newPalette) { return new UISpriteRenderable(sprite, effectiveWorldPos, screenPos, zOffset, newPalette, scale, alpha, rotation); }
public IPalettedRenderable WithPalette(PaletteReference newPalette) { return new UISpriteRenderable(sprite, Pos, screenPos, ZOffset, newPalette, scale, alpha, rotation); }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(in WVec vec) { return this; }
public IRenderable AsDecoration() { return this; }
@@ -58,7 +55,7 @@ namespace OpenRA.Graphics
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
Game.Renderer.SpriteRenderer.DrawSprite(sprite, palette, screenPos, scale, float3.Ones, alpha, rotation);
Game.Renderer.SpriteRenderer.DrawSprite(sprite, Palette, screenPos, scale, float3.Ones, alpha, rotation);
}
public void RenderDebugGeometry(WorldRenderer wr)

View File

@@ -66,9 +66,6 @@ namespace OpenRA.Graphics
WorldViewport lastViewportDistance;
float zoom = 1f;
float minZoom = 1f;
float maxZoom = 2f;
bool unlockMinZoom;
float unlockedMinZoomScale;
float unlockedMinZoom = 1f;
@@ -86,12 +83,13 @@ namespace OpenRA.Graphics
}
}
public float MinZoom => minZoom;
public float MinZoom { get; private set; } = 1f;
public float MaxZoom { get; private set; } = 2f;
public void AdjustZoom(float dz)
{
// Exponential ensures that equal positive and negative steps have the same effect
Zoom = (zoom * (float)Math.Exp(dz)).Clamp(unlockMinZoom ? unlockedMinZoom : minZoom, maxZoom);
Zoom = (zoom * (float)Math.Exp(dz)).Clamp(unlockMinZoom ? unlockedMinZoom : MinZoom, MaxZoom);
}
public void AdjustZoom(float dz, int2 center)
@@ -105,10 +103,10 @@ namespace OpenRA.Graphics
public void ToggleZoom()
{
// Unlocked zooms always reset to the default zoom
if (zoom < minZoom)
Zoom = minZoom;
if (zoom < MinZoom)
Zoom = MinZoom;
else
Zoom = zoom > minZoom ? minZoom : maxZoom;
Zoom = zoom > MinZoom ? MinZoom : MaxZoom;
}
public void UnlockMinimumZoom(float scale)
@@ -210,14 +208,14 @@ namespace OpenRA.Graphics
var vd = graphicSettings.ViewportDistance;
if (viewportSizes.AllowNativeZoom && vd == WorldViewport.Native)
minZoom = viewportSizes.DefaultScale;
MinZoom = viewportSizes.DefaultScale;
else
{
var range = viewportSizes.GetSizeRange(vd);
minZoom = CalculateMinimumZoom(range.X, range.Y) * viewportSizes.DefaultScale;
MinZoom = CalculateMinimumZoom(range.X, range.Y) * viewportSizes.DefaultScale;
}
maxZoom = Math.Min(minZoom * viewportSizes.MaxZoomScale, Game.Renderer.NativeResolution.Height * viewportSizes.DefaultScale / viewportSizes.MaxZoomWindowHeight);
MaxZoom = Math.Min(MinZoom * viewportSizes.MaxZoomScale, Game.Renderer.NativeResolution.Height * viewportSizes.DefaultScale / viewportSizes.MaxZoomWindowHeight);
if (unlockMinZoom)
{
@@ -225,19 +223,19 @@ namespace OpenRA.Graphics
// TODO: Allow zooming out until the full map is visible
// We need to improve our viewport scroll handling to center the map as we zoom out
// before this will work well enough to enable
unlockedMinZoom = minZoom * unlockedMinZoomScale;
unlockedMinZoom = MinZoom * unlockedMinZoomScale;
}
if (resetCurrentZoom)
Zoom = minZoom;
Zoom = MinZoom;
else
Zoom = Zoom.Clamp(minZoom, maxZoom);
Zoom = Zoom.Clamp(MinZoom, MaxZoom);
var maxSize = 1f / (unlockMinZoom ? unlockedMinZoom : minZoom) * new float2(Game.Renderer.NativeResolution);
var maxSize = 1f / (unlockMinZoom ? unlockedMinZoom : MinZoom) * new float2(Game.Renderer.NativeResolution);
Game.Renderer.SetMaximumViewportSize(new Size((int)maxSize.X, (int)maxSize.Y));
foreach (var t in worldRenderer.World.WorldActor.TraitsImplementing<INotifyViewportZoomExtentsChanged>())
t.ViewportZoomExtentsChanged(minZoom, maxZoom);
t.ViewportZoomExtentsChanged(MinZoom, MaxZoom);
}
public CPos ViewToWorld(int2 view)

View File

@@ -126,15 +126,12 @@ namespace OpenRA
// Current position, in map coordinates
int u, v;
// Current position, in cell coordinates
CPos current;
public CellRegionEnumerator(CellRegion region)
: this()
{
r = region;
Reset();
current = new MPos(u, v).ToCPos(r.gridType);
Current = new MPos(u, v).ToCPos(r.gridType);
}
public bool MoveNext()
@@ -152,7 +149,8 @@ namespace OpenRA
return false;
}
current = new MPos(u, v).ToCPos(r.gridType);
// Current position, in cell coordinates
Current = new MPos(u, v).ToCPos(r.gridType);
return true;
}
@@ -163,7 +161,7 @@ namespace OpenRA
v = r.mapTopLeft.V;
}
public CPos Current => current;
public CPos Current { get; private set; }
object IEnumerator.Current => Current;
public void Dispose() { }
}

View File

@@ -19,7 +19,6 @@ namespace OpenRA
public struct MapCoordsEnumerator : IEnumerator<MPos>
{
readonly MapCoordsRegion r;
MPos current;
public MapCoordsEnumerator(MapCoordsRegion region)
: this()
@@ -30,41 +29,38 @@ namespace OpenRA
public bool MoveNext()
{
var u = current.U + 1;
var v = current.V;
var u = Current.U + 1;
var v = Current.V;
// Check for column overflow
if (u > r.bottomRight.U)
if (u > r.BottomRight.U)
{
v += 1;
u = r.topLeft.U;
u = r.TopLeft.U;
// Check for row overflow
if (v > r.bottomRight.V)
if (v > r.BottomRight.V)
return false;
}
current = new MPos(u, v);
Current = new MPos(u, v);
return true;
}
public void Reset()
{
current = new MPos(r.topLeft.U - 1, r.topLeft.V);
Current = new MPos(r.TopLeft.U - 1, r.TopLeft.V);
}
public MPos Current => current;
public MPos Current { get; private set; }
object IEnumerator.Current => Current;
public void Dispose() { }
}
readonly MPos topLeft;
readonly MPos bottomRight;
public MapCoordsRegion(MPos mapTopLeft, MPos mapBottomRight)
{
topLeft = mapTopLeft;
bottomRight = mapBottomRight;
TopLeft = mapTopLeft;
BottomRight = mapBottomRight;
}
public override string ToString()
@@ -87,7 +83,7 @@ namespace OpenRA
return GetEnumerator();
}
public MPos TopLeft => topLeft;
public MPos BottomRight => bottomRight;
public MPos TopLeft { get; }
public MPos BottomRight { get; }
}
}

View File

@@ -83,14 +83,12 @@ namespace OpenRA
// Current position, in projected map coordinates
int u, v;
PPos current;
public ProjectedCellRegionEnumerator(ProjectedCellRegion region)
: this()
{
r = region;
Reset();
current = new PPos(u, v);
Current = new PPos(u, v);
}
public bool MoveNext()
@@ -108,7 +106,7 @@ namespace OpenRA
return false;
}
current = new PPos(u, v);
Current = new PPos(u, v);
return true;
}
@@ -119,7 +117,7 @@ namespace OpenRA
v = r.TopLeft.V;
}
public PPos Current => current;
public PPos Current { get; private set; }
object IEnumerator.Current => Current;
public void Dispose() { }
}

View File

@@ -107,12 +107,9 @@ namespace OpenRA.Network
readonly Queue<OrderPacket> sentImmediateOrders = new Queue<OrderPacket>();
readonly ConcurrentQueue<(int FromClient, byte[] Data)> receivedPackets = new ConcurrentQueue<(int, byte[])>();
TcpClient tcp;
IPEndPoint endpoint;
volatile ConnectionState connectionState = ConnectionState.Connecting;
volatile int clientId;
bool disposed;
string errorMessage;
public NetworkConnection(ConnectionTarget target)
{
@@ -124,6 +121,12 @@ namespace OpenRA.Network
}.Start();
}
public ConnectionState ConnectionState => connectionState;
public IPEndPoint EndPoint { get; private set; }
public string ErrorMessage { get; private set; }
void NetworkConnectionConnect()
{
var queue = new BlockingCollection<TcpClient>();
@@ -151,7 +154,7 @@ namespace OpenRA.Network
}
catch (Exception ex)
{
errorMessage = "Failed to connect";
ErrorMessage = "Failed to connect";
Log.Write("client", $"Failed to connect to {endpoint}: {ex.Message}");
}
})
@@ -163,7 +166,7 @@ namespace OpenRA.Network
if (!atLeastOneEndpoint)
{
errorMessage = "Failed to resolve address";
ErrorMessage = "Failed to resolve address";
connectionState = ConnectionState.NotConnected;
}
@@ -171,7 +174,7 @@ namespace OpenRA.Network
else if (queue.TryTake(out tcp, 5000))
{
// Copy endpoint here to have it even after getting disconnected.
endpoint = (IPEndPoint)tcp.Client.RemoteEndPoint;
EndPoint = (IPEndPoint)tcp.Client.RemoteEndPoint;
new Thread(NetworkConnectionReceive)
{
@@ -215,8 +218,8 @@ namespace OpenRA.Network
}
catch (Exception ex)
{
errorMessage = "Connection failed";
Log.Write("client", $"Connection to {endpoint} failed: {ex.Message}");
ErrorMessage = "Connection failed";
Log.Write("client", $"Connection to {EndPoint} failed: {ex.Message}");
}
finally
{
@@ -367,12 +370,6 @@ namespace OpenRA.Network
Recorder = new ReplayRecorder(chooseFilename);
}
public ConnectionState ConnectionState => connectionState;
public IPEndPoint EndPoint => endpoint;
public string ErrorMessage => errorMessage;
void IDisposable.Dispose()
{
if (disposed)

View File

@@ -329,6 +329,8 @@ namespace OpenRA
case OrderType.Fields:
{
var targetState = Target.SerializableState;
var fields = OrderFields.None;
if (Subject != null)
fields |= OrderFields.Subject;
@@ -339,7 +341,7 @@ namespace OpenRA
if (ExtraData != 0)
fields |= OrderFields.ExtraData;
if (Target.SerializableType != TargetType.Invalid)
if (targetState.Type != TargetType.Invalid)
fields |= OrderFields.Target;
if (Queued)
@@ -354,7 +356,7 @@ namespace OpenRA
if (ExtraLocation != CPos.Zero)
fields |= OrderFields.ExtraLocation;
if (Target.SerializableCell != null)
if (targetState.Cell != null)
fields |= OrderFields.TargetIsCell;
w.Write((short)fields);
@@ -364,12 +366,12 @@ namespace OpenRA
if (fields.HasField(OrderFields.Target))
{
w.Write((byte)Target.SerializableType);
switch (Target.SerializableType)
w.Write((byte)targetState.Type);
switch (targetState.Type)
{
case TargetType.Actor:
w.Write(UIntFromActor(Target.SerializableActor));
w.Write(Target.SerializableGeneration);
w.Write(UIntFromActor(targetState.Actor));
w.Write(targetState.Generation);
break;
case TargetType.FrozenActor:
w.Write(Target.FrozenActor.Viewer.PlayerActor.ActorID);
@@ -378,14 +380,14 @@ namespace OpenRA
case TargetType.Terrain:
if (fields.HasField(OrderFields.TargetIsCell))
{
w.Write(Target.SerializableCell.Value.Bits);
w.Write((byte)Target.SerializableSubCell);
w.Write(targetState.Cell.Value.Bits);
w.Write((byte)targetState.SubCell);
}
else
{
w.Write(Target.SerializablePos.X);
w.Write(Target.SerializablePos.Y);
w.Write(Target.SerializablePos.Z);
w.Write(targetState.Pos.X);
w.Write(targetState.Pos.Y);
w.Write(targetState.Pos.Z);
}
break;

View File

@@ -17,19 +17,13 @@ namespace OpenRA.Network
{
readonly Func<int> timestep;
long lastTickTime;
public TickTime(Func<int> timestep, long lastTickTime)
{
this.timestep = timestep;
this.lastTickTime = lastTickTime;
Value = lastTickTime;
}
public long Value
{
get => lastTickTime;
set => lastTickTime = value;
}
public long Value { get; set; }
public bool ShouldAdvance(long tick)
{
@@ -38,18 +32,18 @@ namespace OpenRA.Network
if (i == 0)
return false;
var tickDelta = tick - lastTickTime;
var tickDelta = tick - Value;
return tickDelta >= i;
}
public void AdvanceTickTime(long tick)
{
var tickDelta = tick - lastTickTime;
var tickDelta = tick - Value;
var currentTimestep = timestep();
var integralTickTimestep = tickDelta / currentTimestep * currentTimestep;
lastTickTime += integralTickTimestep >= Game.TimestepJankThreshold
Value += integralTickTimestep >= Game.TimestepJankThreshold
? integralTickTimestep
: currentTimestep;
}

View File

@@ -52,12 +52,11 @@ namespace OpenRA
IFrameBuffer worldBuffer;
Sheet worldSheet;
Sprite worldSprite;
int worldDownscaleFactor = 1;
Size lastMaximumViewportSize;
Size lastWorldViewportSize;
public Size WorldFrameBufferSize => worldSheet.Size;
public int WorldDownscaleFactor => worldDownscaleFactor;
public int WorldDownscaleFactor { get; private set; } = 1;
SheetBuilder fontSheetBuilder;
readonly IPlatform platform;
@@ -240,11 +239,11 @@ namespace OpenRA
var vh = worldViewport.Size.Height;
var bw = worldSheet.Size.Width;
var bh = worldSheet.Size.Height;
worldDownscaleFactor = 1;
while (vw / worldDownscaleFactor > bw || vh / worldDownscaleFactor > bh)
worldDownscaleFactor++;
WorldDownscaleFactor = 1;
while (vw / WorldDownscaleFactor > bw || vh / WorldDownscaleFactor > bh)
WorldDownscaleFactor++;
var s = new Size(vw / worldDownscaleFactor, vh / worldDownscaleFactor);
var s = new Size(vw / WorldDownscaleFactor, vh / WorldDownscaleFactor);
worldSprite = new Sprite(worldSheet, new Rectangle(int2.Zero, s), TextureChannel.RGBA);
lastWorldViewportSize = worldViewport.Size;
}
@@ -253,7 +252,7 @@ namespace OpenRA
if (lastWorldViewport != worldViewport)
{
WorldSpriteRenderer.SetViewportParams(worldSheet.Size, worldDownscaleFactor, depthMargin, worldViewport.Location);
WorldSpriteRenderer.SetViewportParams(worldSheet.Size, WorldDownscaleFactor, depthMargin, worldViewport.Location);
WorldModelRenderer.SetViewportParams();
lastWorldViewport = worldViewport;
@@ -391,10 +390,10 @@ namespace OpenRA
if (renderType == RenderType.World)
{
var r = Rectangle.FromLTRB(
rect.Left / worldDownscaleFactor,
rect.Top / worldDownscaleFactor,
(rect.Right + worldDownscaleFactor - 1) / worldDownscaleFactor,
(rect.Bottom + worldDownscaleFactor - 1) / worldDownscaleFactor);
rect.Left / WorldDownscaleFactor,
rect.Top / WorldDownscaleFactor,
(rect.Right + WorldDownscaleFactor - 1) / WorldDownscaleFactor,
(rect.Bottom + WorldDownscaleFactor - 1) / WorldDownscaleFactor);
worldBuffer.EnableScissor(r);
}
else
@@ -415,10 +414,10 @@ namespace OpenRA
{
var rect = scissorState.Peek();
var r = Rectangle.FromLTRB(
rect.Left / worldDownscaleFactor,
rect.Top / worldDownscaleFactor,
(rect.Right + worldDownscaleFactor - 1) / worldDownscaleFactor,
(rect.Bottom + worldDownscaleFactor - 1) / worldDownscaleFactor);
rect.Left / WorldDownscaleFactor,
rect.Top / WorldDownscaleFactor,
(rect.Right + WorldDownscaleFactor - 1) / WorldDownscaleFactor,
(rect.Bottom + WorldDownscaleFactor - 1) / WorldDownscaleFactor);
worldBuffer.EnableScissor(r);
}
else

View File

@@ -43,7 +43,6 @@ namespace OpenRA
ISoundSource videoSource;
ISound music;
ISound video;
MusicInfo currentMusic;
readonly Dictionary<uint, ISound> currentSounds = new Dictionary<uint, ISound>();
readonly Dictionary<string, ISound> currentNotifications = new Dictionary<string, ISound>();
public bool DummyEngine { get; }
@@ -226,7 +225,7 @@ namespace OpenRA
Action onMusicComplete;
public bool MusicPlaying { get; private set; }
public MusicInfo CurrentMusic => currentMusic;
public MusicInfo CurrentMusic { get; private set; }
public void PlayMusicThen(MusicInfo m, Action then)
{
@@ -235,7 +234,7 @@ namespace OpenRA
onMusicComplete = then;
if (m == currentMusic && music != null)
if (m == CurrentMusic && music != null)
{
soundEngine.PauseSound(music, false);
MusicPlaying = true;
@@ -263,7 +262,7 @@ namespace OpenRA
return;
}
currentMusic = m;
CurrentMusic = m;
MusicPlaying = true;
}
@@ -290,7 +289,7 @@ namespace OpenRA
music = null;
}
currentMusic = null;
CurrentMusic = null;
MusicPlaying = false;
}

View File

@@ -38,10 +38,10 @@ namespace OpenRA.Traits
public readonly WPos CenterPosition;
readonly Actor actor;
readonly ICreatesFrozenActors frozenTrait;
readonly Player viewer;
readonly Shroud shroud;
readonly List<WPos> targetablePositions = new List<WPos>();
public Player Viewer { get; }
public Player Owner { get; private set; }
public BitSet<TargetableType> TargetTypes { get; private set; }
public IEnumerable<WPos> TargetablePositions => targetablePositions;
@@ -86,7 +86,7 @@ namespace OpenRA.Traits
{
this.actor = actor;
this.frozenTrait = frozenTrait;
this.viewer = viewer;
Viewer = viewer;
shroud = viewer.Shroud;
NeedRenderables = startsRevealed;
@@ -119,7 +119,6 @@ namespace OpenRA.Traits
public bool IsValid => Owner != null;
public ActorInfo Info => actor.Info;
public Actor Actor => !actor.IsDead ? actor : null;
public Player Viewer => viewer;
public void RefreshState()
{
@@ -147,7 +146,7 @@ namespace OpenRA.Traits
Hidden = false;
foreach (var visibilityModifier in visibilityModifiers)
{
if (!visibilityModifier.IsVisible(actor, viewer))
if (!visibilityModifier.IsVisible(actor, Viewer))
{
Hidden = true;
break;

View File

@@ -20,10 +20,10 @@ namespace OpenRA.Traits
{
public static readonly Target[] None = Array.Empty<Target>();
public static readonly Target Invalid = default;
public Actor Actor { get; }
public FrozenActor FrozenActor { get; }
readonly TargetType type;
readonly Actor actor;
readonly FrozenActor frozen;
readonly WPos terrainCenterPosition;
readonly WPos[] terrainPositions;
readonly CPos? cell;
@@ -36,8 +36,8 @@ namespace OpenRA.Traits
this.terrainCenterPosition = terrainCenterPosition;
this.terrainPositions = terrainPositions ?? new[] { terrainCenterPosition };
actor = null;
frozen = null;
Actor = null;
FrozenActor = null;
cell = null;
subCell = null;
generation = 0;
@@ -51,20 +51,20 @@ namespace OpenRA.Traits
cell = c;
this.subCell = subCell;
actor = null;
frozen = null;
Actor = null;
FrozenActor = null;
generation = 0;
}
Target(Actor a, int generation)
{
type = TargetType.Actor;
actor = a;
Actor = a;
this.generation = generation;
terrainCenterPosition = WPos.Zero;
terrainPositions = null;
frozen = null;
FrozenActor = null;
cell = null;
subCell = null;
}
@@ -72,11 +72,11 @@ namespace OpenRA.Traits
Target(FrozenActor fa)
{
type = TargetType.FrozenActor;
frozen = fa;
FrozenActor = fa;
terrainCenterPosition = WPos.Zero;
terrainPositions = null;
actor = null;
Actor = null;
cell = null;
subCell = null;
generation = 0;
@@ -88,9 +88,6 @@ namespace OpenRA.Traits
public static Target FromActor(Actor a) { return a != null ? new Target(a, a.Generation) : Invalid; }
public static Target FromFrozenActor(FrozenActor fa) { return new Target(fa); }
public Actor Actor => actor;
public FrozenActor FrozenActor => frozen;
public TargetType Type
{
get
@@ -98,11 +95,11 @@ namespace OpenRA.Traits
if (type == TargetType.Actor)
{
// Actor is no longer in the world
if (!actor.IsInWorld || actor.IsDead)
if (!Actor.IsInWorld || Actor.IsDead)
return TargetType.Invalid;
// Actor generation has changed (teleported or captured)
if (actor.Generation != generation)
if (Actor.Generation != generation)
return TargetType.Invalid;
}
@@ -118,9 +115,9 @@ namespace OpenRA.Traits
switch (Type)
{
case TargetType.Actor:
return actor.IsTargetableBy(targeter);
return Actor.IsTargetableBy(targeter);
case TargetType.FrozenActor:
return frozen.IsValid && frozen.Visible && !frozen.Hidden;
return FrozenActor.IsValid && FrozenActor.Visible && !FrozenActor.Hidden;
case TargetType.Invalid:
return false;
default:
@@ -135,12 +132,12 @@ namespace OpenRA.Traits
{
get
{
if (actor == null)
if (Actor == null)
return false;
// PERF: Avoid LINQ.
var isTargetable = false;
foreach (var targetable in actor.Targetables)
foreach (var targetable in Actor.Targetables)
{
if (!targetable.IsTraitEnabled())
continue;
@@ -162,9 +159,9 @@ namespace OpenRA.Traits
switch (Type)
{
case TargetType.Actor:
return actor.CenterPosition;
return Actor.CenterPosition;
case TargetType.FrozenActor:
return frozen.CenterPosition;
return FrozenActor.CenterPosition;
case TargetType.Terrain:
return terrainCenterPosition;
default:
@@ -183,10 +180,10 @@ namespace OpenRA.Traits
switch (Type)
{
case TargetType.Actor:
return actor.GetTargetablePositions();
return Actor.GetTargetablePositions();
case TargetType.FrozenActor:
// TargetablePositions may be null if it is Invalid
return frozen.TargetablePositions ?? NoPositions;
return FrozenActor.TargetablePositions ?? NoPositions;
case TargetType.Terrain:
return terrainPositions;
default:
@@ -210,10 +207,10 @@ namespace OpenRA.Traits
switch (Type)
{
case TargetType.Actor:
return actor.ToString();
return Actor.ToString();
case TargetType.FrozenActor:
return frozen.ToString();
return FrozenActor.ToString();
case TargetType.Terrain:
return terrainCenterPosition.ToString();
@@ -291,11 +288,7 @@ namespace OpenRA.Traits
// Expose internal state for serialization by the orders code *only*
internal static Target FromSerializedActor(Actor a, int generation) { return a != null ? new Target(a, generation) : Invalid; }
internal TargetType SerializableType => type;
internal Actor SerializableActor => actor;
internal int SerializableGeneration => generation;
internal CPos? SerializableCell => cell;
internal SubCell? SerializableSubCell => subCell;
internal WPos SerializablePos => terrainCenterPosition;
internal (TargetType Type, Actor Actor, int Generation, CPos? Cell, SubCell? SubCell, WPos Pos) SerializableState =>
(type, Actor, generation, cell, subCell, terrainCenterPosition);
}
}