Move Util to Mods.Common.

This commit is contained in:
Paul Chote
2016-01-16 23:38:53 +00:00
parent 0039a2bdbf
commit b0bd252343
13 changed files with 27 additions and 26 deletions

View File

@@ -181,7 +181,6 @@
<Compile Include="Traits\Selectable.cs" /> <Compile Include="Traits\Selectable.cs" />
<Compile Include="Traits\Target.cs" /> <Compile Include="Traits\Target.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" /> <Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Util.cs" />
<Compile Include="Traits\ValidateOrder.cs" /> <Compile Include="Traits\ValidateOrder.cs" />
<Compile Include="Traits\World\Faction.cs" /> <Compile Include="Traits\World\Faction.cs" />
<Compile Include="Traits\World\ResourceType.cs" /> <Compile Include="Traits\World\ResourceType.cs" />

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Effects
target = args.PassiveTarget; target = args.PassiveTarget;
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
var maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length; var maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length;
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
} }

View File

@@ -116,8 +116,8 @@ namespace OpenRA.Mods.Common.Effects
target = args.PassiveTarget; target = args.PassiveTarget;
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
var range = OpenRA.Traits.Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers); var range = Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
var maxOffset = inaccuracy * (target - pos).Length / range; var maxOffset = inaccuracy * (target - pos).Length / range;
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024; target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
} }

View File

@@ -14,6 +14,7 @@ using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
@@ -200,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.Inaccuracy.Length > 0) if (info.Inaccuracy.Length > 0)
{ {
var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers); var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
offset = WVec.FromPDF(world.SharedRandom, 2) * inaccuracy / 1024; offset = WVec.FromPDF(world.SharedRandom, 2) * inaccuracy / 1024;
} }
@@ -723,8 +724,8 @@ namespace OpenRA.Mods.Common.Effects
desiredHFacing = hFacing; desiredHFacing = hFacing;
// Compute new direction the projectile will be facing // Compute new direction the projectile will be facing
hFacing = OpenRA.Traits.Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn); hFacing = Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn);
vFacing = OpenRA.Traits.Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn); vFacing = Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn);
// Compute the projectile's guided displacement // Compute the projectile's guided displacement
return new WVec(0, -1024 * speed, 0) return new WVec(0, -1024 * speed, 0)

View File

@@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Graphics
protected virtual Sprite GetSprite(int start, int frame, int facing) protected virtual Sprite GetSprite(int start, int frame, int facing)
{ {
var f = OpenRA.Traits.Util.QuantizeFacing(facing, Facings); var f = Util.QuantizeFacing(facing, Facings);
if (reverseFacings) if (reverseFacings)
f = (Facings - f) % Facings; f = (Facings - f) % Facings;

View File

@@ -144,19 +144,19 @@ namespace OpenRA.Mods.Common.Graphics
// Draw voxel bounding box // Draw voxel bounding box
var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc());
var scaleTransform = Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale);
var cameraTransform = Util.MakeFloatMatrix(voxel.camera.AsMatrix()); var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(voxel.camera.AsMatrix());
foreach (var v in draw) foreach (var v in draw)
{ {
var bounds = v.Voxel.Bounds(v.FrameFunc()); var bounds = v.Voxel.Bounds(v.FrameFunc());
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform, var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
(x, y) => Util.MatrixMultiply(x, Util.MakeFloatMatrix(y.AsMatrix()))); (x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
float sx, sy, sz; float sx, sy, sz;
wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz); wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz);
var pxPos = pxOrigin + new float2(sx, sy); var pxPos = pxOrigin + new float2(sx, sy);
var screenTransform = Util.MatrixMultiply(cameraTransform, worldTransform); var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
DrawBoundsBox(pxPos, screenTransform, bounds, iz, Color.Yellow); DrawBoundsBox(pxPos, screenTransform, bounds, iz, Color.Yellow);
} }
} }
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Graphics
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
{ {
var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 }; var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 };
var screen = Util.MatrixVectorMultiply(transform, vec); var screen = OpenRA.Graphics.Util.MatrixVectorMultiply(transform, vec);
corners[i] = pxPos + new float2(screen[0], screen[1]); corners[i] = pxPos + new float2(screen[0], screen[1]);
} }
@@ -192,8 +192,8 @@ namespace OpenRA.Mods.Common.Graphics
{ {
var pxOrigin = wr.ScreenPosition(voxel.pos); var pxOrigin = wr.ScreenPosition(voxel.pos);
var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc()); var draw = voxel.voxels.Where(v => v.DisableFunc == null || !v.DisableFunc());
var scaleTransform = Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale); var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(voxel.scale, voxel.scale, voxel.scale);
var cameraTransform = Util.MakeFloatMatrix(voxel.camera.AsMatrix()); var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(voxel.camera.AsMatrix());
var minX = float.MaxValue; var minX = float.MaxValue;
var minY = float.MaxValue; var minY = float.MaxValue;
@@ -203,17 +203,17 @@ namespace OpenRA.Mods.Common.Graphics
{ {
var bounds = v.Voxel.Bounds(v.FrameFunc()); var bounds = v.Voxel.Bounds(v.FrameFunc());
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform, var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
(x, y) => Util.MatrixMultiply(x, Util.MakeFloatMatrix(y.AsMatrix()))); (x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
float sx, sy, sz; float sx, sy, sz;
wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz); wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz);
var pxPos = pxOrigin + new float2(sx, sy); var pxPos = pxOrigin + new float2(sx, sy);
var screenTransform = Util.MatrixMultiply(cameraTransform, worldTransform); var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
{ {
var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 }; var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 };
var screen = Util.MatrixVectorMultiply(screenTransform, vec); var screen = OpenRA.Graphics.Util.MatrixVectorMultiply(screenTransform, vec);
minX = Math.Min(minX, pxPos.X + screen[0]); minX = Math.Min(minX, pxPos.X + screen[0]);
minY = Math.Min(minY, pxPos.Y + screen[1]); minY = Math.Min(minY, pxPos.Y + screen[1]);
maxX = Math.Max(maxX, pxPos.X + screen[0]); maxX = Math.Max(maxX, pxPos.X + screen[0]);

View File

@@ -730,6 +730,7 @@
<Compile Include="Orders\GuardOrderGenerator.cs" /> <Compile Include="Orders\GuardOrderGenerator.cs" />
<Compile Include="UtilityCommands\CheckExplicitInterfacesCommand.cs" /> <Compile Include="UtilityCommands\CheckExplicitInterfacesCommand.cs" />
<Compile Include="FileFormats\LZOCompression.cs" /> <Compile Include="FileFormats\LZOCompression.cs" />
<Compile Include="Util.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View File

@@ -15,7 +15,7 @@ using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives; using OpenRA.Primitives;
using Util = OpenRA.Traits.Util; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Orders namespace OpenRA.Mods.Common.Orders
{ {

View File

@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Traits
var sequence = a.Info.MuzzleSequence; var sequence = a.Info.MuzzleSequence;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)
sequence += OpenRA.Traits.Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString(); sequence += Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString();
var muzzleFlash = new AnimationWithOffset(muzzleAnim, var muzzleFlash = new AnimationWithOffset(muzzleAnim,
() => PortOffset(self, port), () => PortOffset(self, port),

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)
sequence += OpenRA.Traits.Util.QuantizeFacing(getFacing(), a.Info.MuzzleSplitFacings).ToString(); sequence += Util.QuantizeFacing(getFacing(), a.Info.MuzzleSplitFacings).ToString();
if (barrel == null) if (barrel == null)
return; return;

View File

@@ -190,14 +190,14 @@ namespace OpenRA.Mods.Common.Traits
void UpdateNeighbours(IReadOnlyDictionary<CPos, SubCell> footprint) void UpdateNeighbours(IReadOnlyDictionary<CPos, SubCell> footprint)
{ {
// Include actors inside the footprint too // Include actors inside the footprint too
var cells = OpenRA.Traits.Util.ExpandFootprint(footprint.Keys, true); var cells = Util.ExpandFootprint(footprint.Keys, true);
foreach (var p in cells.SelectMany(c => PreviewsAt(c))) foreach (var p in cells.SelectMany(c => PreviewsAt(c)))
p.ReplaceInit(new RuntimeNeighbourInit(NeighbouringPreviews(p.Footprint))); p.ReplaceInit(new RuntimeNeighbourInit(NeighbouringPreviews(p.Footprint)));
} }
Dictionary<CPos, string[]> NeighbouringPreviews(IReadOnlyDictionary<CPos, SubCell> footprint) Dictionary<CPos, string[]> NeighbouringPreviews(IReadOnlyDictionary<CPos, SubCell> footprint)
{ {
var cells = OpenRA.Traits.Util.ExpandFootprint(footprint.Keys, true).Except(footprint.Keys); var cells = Util.ExpandFootprint(footprint.Keys, true).Except(footprint.Keys);
return cells.ToDictionary(c => c, c => PreviewsAt(c).Select(p => p.Info.Name).ToArray()); return cells.ToDictionary(c => c, c => PreviewsAt(c).Select(p => p.Info.Name).ToArray());
} }

View File

@@ -10,12 +10,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using OpenRA.Activities;
using OpenRA.Support; using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA.Traits namespace OpenRA.Mods.Common
{ {
public static class Util public static class Util
{ {

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.D2k.Traits; using OpenRA.Mods.D2k.Traits;