Skip to content

Commit

Permalink
Remove DrawIconFast()
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Jun 5, 2024
1 parent a52fb0e commit fae05b8
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,27 @@ public void DrawIcon(DrawingHandleWorld handle, Vector2i renderTargetSize, Rende
if (iconMetaData.MainIcon != null)
pixelPosition += iconMetaData.MainIcon.TextureRenderOffset;

DrawIconFast(handle, renderTargetSize, frame, pixelPosition, iconMetaData.TransformToApply,
GetBlendAndColorShader(iconMetaData, ignoreColor: true));

handle.UseShader(GetBlendAndColorShader(iconMetaData, ignoreColor: true));

Check notice

Code scanning / InspectCode

Incorrect blank lines: Blank lines are redundant elsewhere

Blank lines are redundant, expected maximum 1 instead of 2

//extract scale component of transform
var transform = iconMetaData.TransformToApply;
Vector2 scaleFactors = new Vector2(
MathF.Sqrt(MathF.Pow(transform.R0C0,2) + MathF.Pow(transform.R0C1,2)),
MathF.Sqrt(MathF.Pow(transform.R1C0,2) + MathF.Pow(transform.R1C1,2))
);
transform.R0C0 /= scaleFactors.X;
transform.R0C1 /= scaleFactors.X;
transform.R1C0 /= scaleFactors.Y;
transform.R1C1 /= scaleFactors.Y;

handle.SetTransform(
Matrix3.CreateTranslation(-frame.Size/2) //translate to origin
* transform //rotate and translate
* Matrix3.CreateTranslation(frame.Size/2) //translate back to original position
* Matrix3.CreateScale(scaleFactors) //scale
* CreateRenderTargetFlipMatrix(renderTargetSize, pixelPosition-((scaleFactors-Vector2.One)*frame.Size/2))); //flip and apply scale-corrected translation
handle.DrawTextureRect(frame, Box2.FromDimensions(Vector2.Zero, frame.Size));
}

/// <summary>
Expand Down Expand Up @@ -777,32 +796,6 @@ private Texture ProcessKeepTogether(DrawingHandleWorld handle, RendererMetaData
return ktTexture.Texture;
}

/// <summary>
/// Render a texture without applying any filters, making this faster and cheaper.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DrawIconFast(DrawingHandleWorld handle, Vector2i renderTargetSize, Texture texture, Vector2 pos, Matrix3 transform, ShaderInstance? shader) {
handle.UseShader(shader);

//extract scale component of transform
Vector2 scaleFactors = new Vector2(
MathF.Sqrt(MathF.Pow(transform.R0C0,2) + MathF.Pow(transform.R0C1,2)),
MathF.Sqrt(MathF.Pow(transform.R1C0,2) + MathF.Pow(transform.R1C1,2))
);
transform.R0C0 /= scaleFactors.X;
transform.R0C1 /= scaleFactors.X;
transform.R1C0 /= scaleFactors.Y;
transform.R1C1 /= scaleFactors.Y;

handle.SetTransform(
Matrix3.CreateTranslation(-texture.Size/2) //translate to origin
* transform //rotate and translate
* Matrix3.CreateTranslation(texture.Size/2) //translate back to original position
* Matrix3.CreateScale(scaleFactors) //scale
* CreateRenderTargetFlipMatrix(renderTargetSize, pos-((scaleFactors-Vector2.One)*texture.Size/2))); //flip and apply scale-corrected translation
handle.DrawTextureRect(texture, Box2.FromDimensions(Vector2.Zero, texture.Size));
}

/// <summary>
/// Creates a transformation matrix that counteracts RT's
/// <see cref="DrawingHandleBase.RenderInRenderTarget(IRenderTarget,Action,System.Nullable{Robust.Shared.Maths.Color})"/> quirks
Expand Down

0 comments on commit fae05b8

Please sign in to comment.