Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't release planes with a plane master #1599

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions OpenDreamClient/Rendering/DreamPlane.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
using OpenDreamShared.Dream;
using Robust.Client.Graphics;
using Robust.Client.Graphics;
using Robust.Shared.Utility;

namespace OpenDreamClient.Rendering;

internal sealed class DreamPlane {
public IRenderTexture RenderTarget => _temporaryRenderTarget ?? _mainRenderTarget;
internal sealed class DreamPlane(IRenderTexture mainRenderTarget) : IDisposable {
public IRenderTexture RenderTarget => _temporaryRenderTarget ?? mainRenderTarget;
public RendererMetaData? Master;

public readonly List<Action<Vector2i>> IconDrawActions = new();
public readonly List<Action<Vector2i>> MouseMapDrawActions = new();

private IRenderTexture _mainRenderTarget;
private IRenderTexture? _temporaryRenderTarget;

public DreamPlane(IRenderTexture renderTarget) {
_mainRenderTarget = renderTarget;
}

public void Clear() {
Master = null;
IconDrawActions.Clear();
MouseMapDrawActions.Clear();
_temporaryRenderTarget = null;
}

public void Dispose() {
mainRenderTarget.Dispose();
Clear();
}

/// <summary>
/// Sets this plane's main render target<br/>
/// Persists through calls to <see cref="Clear()"/>
/// </summary>
public void SetMainRenderTarget(IRenderTexture renderTarget) {
_mainRenderTarget.Dispose();
_mainRenderTarget = renderTarget;
mainRenderTarget.Dispose();
mainRenderTarget = renderTarget;
}

/// <summary>
Expand All @@ -47,17 +46,17 @@ public void SetTemporaryRenderTarget(IRenderTexture renderTarget) {
/// </summary>
public void Draw(DreamViewOverlay overlay, DrawingHandleWorld handle) {
// Draw all icons
handle.RenderInRenderTarget(_mainRenderTarget, () => {
handle.RenderInRenderTarget(mainRenderTarget, () => {
foreach (Action<Vector2i> iconAction in IconDrawActions)
iconAction(_mainRenderTarget.Size);
iconAction(mainRenderTarget.Size);
}, new Color());

if (_temporaryRenderTarget != null) {
// Draw again, but with the color applied
handle.RenderInRenderTarget(_temporaryRenderTarget, () => {
handle.UseShader(overlay.GetBlendAndColorShader(Master, useOverlayMode: true));
handle.SetTransform(overlay.CreateRenderTargetFlipMatrix(_temporaryRenderTarget.Size, Vector2.Zero));
handle.DrawTextureRect(_mainRenderTarget.Texture, new Box2(Vector2.Zero, _mainRenderTarget.Size));
handle.DrawTextureRect(mainRenderTarget.Texture, new Box2(Vector2.Zero, mainRenderTarget.Size));
handle.SetTransform(Matrix3.Identity);
handle.UseShader(null);
}, new Color());
Expand Down
4 changes: 3 additions & 1 deletion OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ private void ClearPlanes() {
var plane = pair.Value;

// We can remove the plane if there was nothing on it last frame
if (plane.IconDrawActions.Count == 0 && plane.MouseMapDrawActions.Count == 0) {
if (plane.IconDrawActions.Count == 0 && plane.MouseMapDrawActions.Count == 0 && plane.Master == null) {
plane.Dispose();
_planes.Remove(pair.Key);
continue;
}
Expand All @@ -625,6 +626,7 @@ private DreamPlane GetPlane(int planeIndex, Vector2i viewportSize) {

plane = new(renderTarget);
_planes.Add(planeIndex, plane);
_sawmill.Info($"Created plane {planeIndex}");
return plane;
}

Expand Down
Loading