Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into native
Browse files Browse the repository at this point in the history
# Conflicts:
#	MonoGame.Framework/Graphics/GraphicsDevice.cs
#	MonoGame.Framework/Platform/Native/Mouse.Native.cs
  • Loading branch information
tomspilman committed Jul 6, 2024
2 parents d828bef + 079fb68 commit b6a7322
Show file tree
Hide file tree
Showing 186 changed files with 3,800 additions and 16,659 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
"cwd": "${workspaceFolder}/Artifacts/MonoGame.Content.Builder.Editor/Mac/Debug",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": "Attach to Process",
"type": "coreclr",
"request": "attach",
"processId": "${input.processid}",
}
],
"inputs": [
{
"id": "processid",
"type": "promptString",
"default": "0",
"description": "Enter Process Id of process to attach to."
}
]
}
37 changes: 36 additions & 1 deletion MonoGame.Framework.Content.Pipeline/Builder/XmlColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,67 @@ public class XmlColor
{
private Color _color;

/// <summary>
/// Creates a new instance of XmlColor with <see cref="Color.Empty"/> color.
/// </summary>
public XmlColor()
{
}

/// <summary>
/// Creates a new instance of XmlColor with provided color
/// </summary>
/// <param name="c">Color to be stored</param>
public XmlColor(Color c)
{
_color = c;
}

/// <summary>
/// Implicit XmlColor -> Color conversion
/// </summary>
public static implicit operator Color(XmlColor x)
{
return x._color;
}

/// <summary>
/// Implicit Color -> XmlColor conversion
/// </summary>
public static implicit operator XmlColor(Color c)
{
return new XmlColor(c);
}

/// <summary>
/// Returns a string representation of the supplied <see cref="Color"/>.
/// </summary>
/// <remarks>
/// This string value can be used in <see cref="ToColor(string)"/> to get identical color object.
/// </remarks>
/// <param name="color">Color to be converted.</param>
/// <returns>
/// The predefined name of the color, if it's named,
/// or a string in the format <b>"R, G, B, A"</b>, if the color is not named,
/// with every component in the [0..255] range.
/// </returns>
public static string FromColor(Color color)
{
if (color.IsNamedColor)
return color.Name;
return string.Format("{0}, {1}, {2}, {3}", color.R, color.G, color.B, color.A);
}

/// <summary>
/// Returns a new <see cref="Color"/> object from its string representation.
/// </summary>
/// <param name="value">
/// A predefined color name,
/// OR a string in the format <b>"R, G, B, A"</b>, where each component is in the [0..255] range.<para/>
/// </param>
public static Color ToColor(string value)
{
if (!value.Contains(","))
if (!value.Contains(','))
return Color.FromName(value);

int r, g, b, a;
Expand All @@ -55,6 +87,9 @@ public static Color ToColor(string value)
return Color.FromArgb(a, r, g, b);
}

/// <summary>
/// Default color value as a string, used for serialization and deserialization.
/// </summary>
[XmlText]
public string Default
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class ContentStatsCollection
private readonly object _locker = new object();
private readonly Dictionary<string, ContentStats> _statsBySource = new Dictionary<string, ContentStats>(1024);

/// <summary>
/// The file extension used by the content pipeline after building to store the content statistics.
/// <remarks><para>Read only - cannot be assigned to</para></remarks>
/// </summary>
public static readonly string Extension = ".mgstats";

/// <summary>
Expand Down Expand Up @@ -180,7 +184,7 @@ public static ContentStatsCollection Read(string outputPath)
collection._statsBySource.Add(stats.SourceFile, stats);
}
}
catch (Exception ex)
catch
{
// Assume the file didn't exist or was incorrectly
// formatted... either way we start from fresh data.
Expand Down
26 changes: 13 additions & 13 deletions MonoGame.Framework.Content.Pipeline/Graphics/MeshHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;

Expand Down Expand Up @@ -71,8 +71,8 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting

var aa = geom.Vertices.Positions[ia];
var bb = geom.Vertices.Positions[ib];
var cc = geom.Vertices.Positions[ic];
var cc = geom.Vertices.Positions[ic];

var faceNormal = Vector3.Cross(cc - bb, bb - aa);
var len = faceNormal.Length();
if (len > 0.0f)
Expand All @@ -95,9 +95,9 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting
// by Shuangshuang Jin, Robert R. Lewis, David West.
//

normals[positionIndices[ia]] += faceNormal;
normals[positionIndices[ib]] += faceNormal;
normals[positionIndices[ic]] += faceNormal;
normals[ia] += faceNormal;
normals[ib] += faceNormal;
normals[ic] += faceNormal;
}
}

Expand All @@ -115,7 +115,7 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting

// TODO: We could maybe void this by a better algorithm
// above for generating the normals.

// We have a zero length normal. You can argue that putting
// anything here is better than nothing, but by leaving it to
// zero it allows the caller to detect this and react to it.
Expand All @@ -125,7 +125,7 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting

// Set the new normals on the vertex channel.
for (var i = 0; i < channel.Count; i++)
channel[i] = normals[geom.Vertices.PositionIndices[i]];
channel[i] = normals[i];
}

/// <summary>
Expand All @@ -138,7 +138,7 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting
public static void CalculateTangentFrames(MeshContent mesh, string textureCoordinateChannelName, string tangentChannelName, string binormalChannelName)
{
foreach (var geom in mesh.Geometry)
CalculateTangentFrames(geom, textureCoordinateChannelName, tangentChannelName, binormalChannelName);
CalculateTangentFrames(geom, textureCoordinateChannelName, tangentChannelName, binormalChannelName);
}

/// <summary>
Expand Down Expand Up @@ -344,7 +344,7 @@ public static BoneContent FindSkeleton(NodeContent node)
foreach (var nodeContent in node.Children)
{
var bone = nodeContent as BoneContent;
if (bone == null)
if (bone == null)
continue;

// If we found a bone
Expand Down Expand Up @@ -456,7 +456,7 @@ public static void MergeDuplicateVertices(GeometryContent geometry)
PositionIndex = verts.PositionIndices[vIndex],
ChannelData = new object[verts.Channels.Count]
};

for (var channel = 0; channel < verts.Channels.Count; channel++)
iData.ChannelData[channel] = verts.Channels[channel][vIndex];

Expand Down Expand Up @@ -513,7 +513,7 @@ public static void OptimizeForCache(MeshContent mesh)
{
// We don't throw here as non-optimized still works.
}

/// <summary>
/// Reverses the triangle winding order of the mesh.
/// </summary>
Expand Down Expand Up @@ -646,7 +646,7 @@ public bool ContentEquals(VertexData other)

for (var i = 0; i < ChannelData.Length; i++)
{
if (!Equals(ChannelData[i], other.ChannelData[i]))
if (!Equals(ChannelData[i], other.ChannelData[i]))
return false;
}

Expand Down
27 changes: 13 additions & 14 deletions MonoGame.Framework.Content.Pipeline/Processors/EffectProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Microsoft.Xna.Framework.Content.Pipeline.Processors
[ContentProcessor(DisplayName = "Effect - MonoGame")]
public class EffectProcessor : ContentProcessor<EffectContent, CompiledEffectContent>
{
private static readonly Regex errorOrWarning = new(@"(.*)\((\d*,\d*(?>,\d*,\d*)?)\):\s*(.*)", RegexOptions.Compiled);
EffectProcessorDebugMode debugMode;
string defines;

Expand Down Expand Up @@ -109,21 +110,20 @@ private static void ProcessErrorsAndWarnings(bool buildFailed, string shaderErro
var errorsAndWarningArray = shaderErrorsAndWarnings.Split(new[] { "\n", "\r", Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);

var errorOrWarning = new Regex(@"(.*)\(([0-9]*(,[0-9]+(-[0-9]+)?)?)\)\s*:\s*(.*)", RegexOptions.Compiled);
ContentIdentity identity = null;
var allErrorsAndWarnings = string.Empty;
var allErrorsAndWarnings = new System.Text.StringBuilder();

// Process all the lines.
for (var i = 0; i < errorsAndWarningArray.Length; i++)
foreach (var errorOrWarningLine in errorsAndWarningArray)
{
var match = errorOrWarning.Match(errorsAndWarningArray[i]);
var match = errorOrWarning.Match(errorOrWarningLine);
if (!match.Success || match.Groups.Count != 4)
{
// Just log anything we don't recognize as a warning.
if (buildFailed)
allErrorsAndWarnings += errorsAndWarningArray[i] + Environment.NewLine;
allErrorsAndWarnings.AppendLine(errorOrWarningLine);
else
context.Logger.LogWarning(string.Empty, input.Identity, errorsAndWarningArray[i]);
context.Logger.LogWarning(string.Empty, input.Identity, errorOrWarningLine);

continue;
}
Expand All @@ -141,27 +141,26 @@ private static void ProcessErrorsAndWarnings(bool buildFailed, string shaderErro
fileName = Path.Combine(folder, fileName);
}

var newIdentity = new ContentIdentity(fileName, input.Identity.SourceTool, lineAndColumn);

// If we got an exception then we'll be throwing an exception
// below, so just gather the lines to throw later.
if (buildFailed)
{
if (identity == null)
{
identity = new ContentIdentity(fileName, input.Identity.SourceTool, lineAndColumn);
allErrorsAndWarnings = errorsAndWarningArray[i] + Environment.NewLine;
identity = newIdentity;
allErrorsAndWarnings.AppendLine(message);
}
else
allErrorsAndWarnings += errorsAndWarningArray[i] + Environment.NewLine;
allErrorsAndWarnings.AppendLine(errorOrWarningLine);
}
else
{
identity = new ContentIdentity(fileName, input.Identity.SourceTool, lineAndColumn);
context.Logger.LogWarning(string.Empty, identity, message, string.Empty);
}
context.Logger.LogWarning(string.Empty, newIdentity, message);
}

if (buildFailed)
throw new InvalidContentException(allErrorsAndWarnings, identity ?? input.Identity);
throw new InvalidContentException(allErrorsAndWarnings.ToString(), identity ?? input.Identity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

namespace Microsoft.Xna.Framework.Content.Pipeline.Processors
{
/// <summary>
/// A collection of <see cref="ModelMeshPartContent"/> objects.
/// This class cannot be inherited.
/// </summary>
public sealed class ModelMeshContentCollection : ReadOnlyCollection<ModelMeshContent>
{
internal ModelMeshContentCollection(IList<ModelMeshContent> list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace Microsoft.Xna.Framework.Content.Pipeline.Processors
{
/// <summary>
/// Stores design-time data for a <see cref="ModelMeshPart"/> asset.
/// </summary>
public sealed class ModelMeshPartContent
{
private IndexCollection _indexBuffer;
Expand All @@ -30,39 +33,64 @@ internal ModelMeshPartContent(VertexBufferContent vertexBuffer, IndexCollection
_primitiveCount = primitiveCount;
}


/// <summary>
/// Gets the collection of indices for this mesh part.
/// </summary>
public IndexCollection IndexBuffer
{
get { return _indexBuffer; }
}

/// <summary>
/// Gets the material of this mesh part.
/// </summary>
public MaterialContent Material
{
get { return _material; }
set { _material = value; }
}

/// <summary>
/// Gets the number of vertices used in this mesh part.
/// </summary>
public int NumVertices
{
get { return _numVertices; }
}

/// <summary>
/// Gets the number of primitives to render for this mesh part.
/// </summary>
public int PrimitiveCount
{
get { return _primitiveCount; }
}

/// <summary>
/// Gets the location in the index buffer at which to start reading vertices.
/// </summary>
public int StartIndex
{
get { return _startIndex; }
}

/// <summary>
/// Gets a user-defined tag object.
/// </summary>
public object Tag { get; set; }

/// <summary>
/// Gets the collection of vertices for this mesh part.
/// </summary>
public VertexBufferContent VertexBuffer
{
get { return _vertexBuffer; }
}

/// <summary>
/// Gets the offset from the start of the index buffer to the first vertex index.
/// </summary>
public int VertexOffset
{
get { return _vertexOffset; }
Expand Down
Loading

0 comments on commit b6a7322

Please sign in to comment.