Skip to content

Commit

Permalink
Merge branch 'bleed' into rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dnqbob committed Oct 31, 2023
2 parents 484ea5c + c0da41a commit fe664ed
Show file tree
Hide file tree
Showing 108 changed files with 919 additions and 431 deletions.
173 changes: 158 additions & 15 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -946,37 +946,180 @@ dotnet_diagnostic.CA2251.severity = warning
# Ensure ThreadStatic is only used with static fields.
dotnet_diagnostic.CA2259.severity = suggestion # TODO: Change to warning once using .NET 7 or later.

### Roslynator
### https://github.com/JosefPihrt/Roslynator/tree/main/docs/analyzers
### Roslynator.Analyzers
### https://josefpihrt.github.io/docs/roslynator/analyzers

# We disable the rule category by setting severity to none.
# Below we enable specific rules by setting severity to warning.
dotnet_analyzer_diagnostic.category-roslynator.severity = none

# Remove redundant 'sealed' modifier.
dotnet_diagnostic.RCS1034.severity = warning

# Remove argument list from attribute.
dotnet_diagnostic.RCS1039.severity = warning

# Remove empty initializer.
dotnet_diagnostic.RCS1041.severity = warning

# Remove enum default underlying type.
dotnet_diagnostic.RCS1042.severity = warning

# Remove 'partial' modifier from type with a single part.
dotnet_diagnostic.RCS1043.severity = warning

# Use lambda expression instead of anonymous method.
dotnet_diagnostic.RCS1048.severity = warning

# Simplify boolean comparison.
dotnet_diagnostic.RCS1049.severity = warning

# Use compound assignment.
dotnet_diagnostic.RCS1058.severity = warning

# Avoid locking on publicly accessible instance.
dotnet_diagnostic.RCS1059.severity = warning

# Remove empty 'finally' clause.
dotnet_diagnostic.RCS1066.severity = warning

# Simplify logical negation.
dotnet_diagnostic.RCS1068.severity = warning

# Remove redundant base constructor call.
dotnet_diagnostic.RCS1071.severity = warning

# Remove empty namespace declaration.
dotnet_diagnostic.RCS1072.severity = warning

# Remove redundant constructor.
dotnet_diagnostic.RCS1074.severity = warning

# Use 'Count' property instead of 'Any' method.
dotnet_diagnostic.RCS1080.severity = warning

# Use read-only auto-implemented property.
dotnet_diagnostic.RCS1170.severity = warning
# Use coalesce expression instead of conditional expression.
dotnet_diagnostic.RCS1084.severity = warning

# Unnecessary interpolated string.
dotnet_diagnostic.RCS1214.severity = warning
# Remove empty region.
dotnet_diagnostic.RCS1091.severity = warning

# Default label should be the last label in a switch section.
dotnet_diagnostic.RCS1099.severity = warning

# Unnecessary interpolation.
dotnet_diagnostic.RCS1105.severity = warning

# Remove redundant 'ToCharArray' call.
dotnet_diagnostic.RCS1107.severity = warning

# Add 'static' modifier to all partial class declarations.
dotnet_diagnostic.RCS1108.severity = warning

# Combine 'Enumerable.Where' method chain.
dotnet_diagnostic.RCS1112.severity = warning

# Use 'string.IsNullOrEmpty' method.
dotnet_diagnostic.RCS1113.severity = warning

# Bitwise operation on enum without Flags attribute.
dotnet_diagnostic.RCS1130.severity = warning

# Remove redundant overriding member.
dotnet_diagnostic.RCS1132.severity = warning

# Remove redundant Dispose/Close call.
dotnet_diagnostic.RCS1133.severity = warning

# Remove redundant statement.
dotnet_diagnostic.RCS1134.severity = warning

# Merge switch sections with equivalent content.
dotnet_diagnostic.RCS1136.severity = warning

# Simplify coalesce expression.
dotnet_diagnostic.RCS1143.severity = warning

# Remove redundant cast.
dotnet_diagnostic.RCS1151.severity = warning

# Use StringComparison when comparing strings.
dotnet_diagnostic.RCS1155.severity = warning

# Use EventHandler<T>.
dotnet_diagnostic.RCS1159.severity = warning

# Unused type parameter.
dotnet_diagnostic.RCS1164.severity = warning

# Use 'is' operator instead of 'as' operator.
dotnet_diagnostic.RCS1172.severity = warning

# Unused 'this' parameter.
dotnet_diagnostic.RCS1175.severity = warning

# Unnecessary assignment.
dotnet_diagnostic.RCS1179.severity = warning

# Use constant instead of field.
dotnet_diagnostic.RCS1187.severity = warning

# Join string expressions.
dotnet_diagnostic.RCS1190.severity = warning

# Declare enum value as combination of names.
dotnet_diagnostic.RCS1191.severity = warning

# Unnecessary usage of verbatim string literal.
dotnet_diagnostic.RCS1192.severity = warning

# Use pattern matching instead of combination of 'as' operator and null check.
dotnet_diagnostic.RCS1221.severity = warning
# Overriding member should not change 'params' modifier.
dotnet_diagnostic.RCS1193.severity = warning

# Use ^ operator.
dotnet_diagnostic.RCS1195.severity = warning

# Unnecessary null check.
dotnet_diagnostic.RCS1199.severity = warning

# Use EventArgs.Empty.
dotnet_diagnostic.RCS1204.severity = warning

# Order type parameter constraints.
dotnet_diagnostic.RCS1209.severity = warning

# Unnecessary interpolated string.
dotnet_diagnostic.RCS1214.severity = warning

# Expression is always equal to 'true'.
dotnet_diagnostic.RCS1215.severity = warning

# Use StringComparison when comparing strings.
dotnet_diagnostic.RCS1155.severity = warning
# Unnecessary unsafe context.
dotnet_diagnostic.RCS1216.severity = warning

# Simplify code branching.
dotnet_diagnostic.RCS1218.severity = warning

# Use pattern matching instead of combination of 'is' operator and cast operator.
dotnet_diagnostic.RCS1220.severity = warning

# Make class sealed.
dotnet_diagnostic.RCS1225.severity = warning

# Add paragraph to documentation comment.
dotnet_diagnostic.RCS1226.severity = warning

# Validate arguments correctly.
dotnet_diagnostic.RCS1227.severity = warning

# Unnecessary explicit use of enumerator.
dotnet_diagnostic.RCS1230.severity = warning

# Abstract type should not have public constructors.
dotnet_diagnostic.RCS1160.severity = warning
# Use short-circuiting operator.
dotnet_diagnostic.RCS1233.severity = warning

# Optimize 'Dictionary<TKey, TValue>.ContainsKey' call.
# Optimize method call.
dotnet_diagnostic.RCS1235.severity = warning

# Call extension method as instance method.
dotnet_diagnostic.RCS1196.severity = warning
# Use 'for' statement instead of 'while' statement.
dotnet_diagnostic.RCS1239.severity = warning
6 changes: 4 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<Optimize>false</Optimize>
<!-- Enable only for Debug builds to improve compile-time performance for Release builds -->
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<!-- Enabling GenerateDocumentationFile is required for IDE0005 (Remove unnecessary import)
<!-- Enabling GenerateDocumentationFile is required for IDE0005 (Remove unnecessary import)
rule to run in command line builds. https://github.com/dotnet/roslyn/issues/41640
Enable only for Debug builds to improve compile-time performance for Release builds -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -51,8 +51,10 @@
</ItemGroup>
</Target>

<!-- StyleCop -->
<!-- StyleCop/Roslynator -->
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
<!-- Roslynator analyzers fail to run under Mono (AD0001) -->
<PackageReference Include="Roslynator.Analyzers" Version="4.2.0" PrivateAssets="All" Condition="'$(MSBuildRuntimeType)'!='Mono'" />
</ItemGroup>
</Project>
13 changes: 9 additions & 4 deletions OpenRA.Game/Activities/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,22 @@ protected bool TickChild(Actor self)
}

/// <summary>
/// <para>
/// Called every tick to run activity logic. Returns false if the activity should
/// remain active, or true if it is complete. Cancelled activities must ensure they
/// return the actor to a consistent state before returning true.
///
/// </para>
/// <para>
/// Child activities can be queued using QueueChild, and these will be ticked
/// instead of the parent while they are active. Activities that need to run logic
/// in parallel with child activities should set ChildHasPriority to false and
/// manually call TickChildren.
///
/// </para>
/// <para>
/// Queuing one or more child activities and returning true is valid, and causes
/// the activity to be completed immediately (without ticking again) once the
/// children have completed.
/// </para>
/// </summary>
public virtual bool Tick(Actor self)
{
Expand Down Expand Up @@ -225,10 +229,11 @@ public void QueueChild(Activity activity)
}

/// <summary>
/// Prints the activity tree, starting from the top or optionally from a given origin.
///
/// <para>Prints the activity tree, starting from the top or optionally from a given origin.</para>
/// <para>
/// Call this method from any place that's called during a tick, such as the Tick() method itself or
/// the Before(First|Last)Run() methods. The origin activity will be marked in the output.
/// </para>
/// </summary>
/// <param name="self">The actor performing this activity.</param>
/// <param name="origin">Activity from which to start traversing, and which to mark. If null, mark the calling activity, and start traversal from the top.</param>
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/FieldLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ static object ParseNullable(string fieldName, Type fieldType, string value, Mini
if (string.IsNullOrEmpty(value))
return null;

var innerType = fieldType.GetGenericArguments().First();
var innerType = fieldType.GetGenericArguments()[0];
var innerValue = GetValue("Nullable<T>", innerType, value, field);
return fieldType.GetConstructor(new[] { innerType }).Invoke(new[] { innerValue });
}
Expand Down
7 changes: 4 additions & 3 deletions OpenRA.Game/FieldSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using OpenRA.Primitives;

namespace OpenRA
Expand Down Expand Up @@ -84,7 +85,7 @@ public static string FormatValue(object v)
// This is only for documentation generation
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
var result = "";
var result = new StringBuilder();
var dict = (System.Collections.IDictionary)v;
foreach (var kvp in dict)
{
Expand All @@ -94,10 +95,10 @@ public static string FormatValue(object v)
var formattedKey = FormatValue(key);
var formattedValue = FormatValue(value);

result += $"{formattedKey}: {formattedValue}{Environment.NewLine}";
result.Append($"{formattedKey}: {formattedValue}{Environment.NewLine}");
}

return result;
return result.ToString();
}

if (v is DateTime d)
Expand Down
27 changes: 27 additions & 0 deletions OpenRA.Game/Graphics/RenderPostProcessPassVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ public RenderPostProcessPassVertex(float x, float y)
}
}

[StructLayout(LayoutKind.Sequential)]
public readonly struct RenderPostProcessPassTexturedVertex
{
// 3d position
public readonly float X, Y;
public readonly float S, T;

public RenderPostProcessPassTexturedVertex(float x, float y, float s, float t)
{
X = x; Y = y;
S = s; T = t;
}
}

public sealed class RenderPostProcessPassShaderBindings : ShaderBindings
{
public RenderPostProcessPassShaderBindings(string name)
Expand All @@ -34,4 +48,17 @@ public RenderPostProcessPassShaderBindings(string name)
new ShaderVertexAttribute("aVertexPosition", ShaderVertexAttributeType.Float, 2, 0)
};
}

public sealed class RenderPostProcessPassTexturedShaderBindings : ShaderBindings
{
public RenderPostProcessPassTexturedShaderBindings(string name)
: base("postprocess_textured", "postprocess_textured_" + name)
{ }

public override ShaderVertexAttribute[] Attributes { get; } = new[]
{
new ShaderVertexAttribute("aVertexPosition", ShaderVertexAttributeType.Float, 2, 0),
new ShaderVertexAttribute("aVertexTexCoord", ShaderVertexAttributeType.Float, 2, 8),
};
}
}
8 changes: 4 additions & 4 deletions OpenRA.Game/Graphics/SheetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ public SheetBuilder(SheetType t, Func<Sheet> allocateSheet, int margin = 1)
this.margin = margin;
}

public Sprite Add(ISpriteFrame frame) { return Add(frame.Data, frame.Type, frame.Size, 0, frame.Offset); }
public Sprite Add(byte[] src, SpriteFrameType type, Size size) { return Add(src, type, size, 0, float3.Zero); }
public Sprite Add(byte[] src, SpriteFrameType type, Size size, float zRamp, in float3 spriteOffset)
public Sprite Add(ISpriteFrame frame, bool premultiplied = false) { return Add(frame.Data, frame.Type, frame.Size, 0, frame.Offset, premultiplied); }
public Sprite Add(byte[] src, SpriteFrameType type, Size size, bool premultiplied = false) { return Add(src, type, size, 0, float3.Zero, premultiplied); }
public Sprite Add(byte[] src, SpriteFrameType type, Size size, float zRamp, in float3 spriteOffset, bool premultiplied = false)
{
// Don't bother allocating empty sprites
if (size.Width == 0 || size.Height == 0)
return new Sprite(Current, Rectangle.Empty, 0, spriteOffset, CurrentChannel, BlendMode.Alpha);

var rect = Allocate(size, zRamp, spriteOffset);
Util.FastCopyIntoChannel(rect, src, type);
Util.FastCopyIntoChannel(rect, src, type, premultiplied);
Current.CommitBufferedData();
return rect;
}
Expand Down
Loading

0 comments on commit fe664ed

Please sign in to comment.