Skip to content

Commit

Permalink
fix guarded locations showing in OG, improve font scaling performance…
Browse files Browse the repository at this point in the history
…, improve overlay server memory usage
  • Loading branch information
TalicZealot committed Mar 18, 2024
1 parent 6727d97 commit 5cbacdd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 99 deletions.

This file was deleted.

1 change: 0 additions & 1 deletion SotnRandoTools/src/RandoTracker/Models/Extension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace SotnRandoTools.RandoTracker.Models
{
Expand Down
3 changes: 2 additions & 1 deletion SotnRandoTools/src/RandoTracker/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ private void LoadLocks(string presetFilePath, bool outOfLogic = false, bool over
spreadExtension = true;
classicExtension = true;
break;
case "False":
case "false":
classicExtension = true;
guardedExtension = false;
break;
default:
if (!LoadExtension(Paths.PresetPath + preset.RelicLocationsExtension + ".json"))
Expand Down
33 changes: 19 additions & 14 deletions SotnRandoTools/src/RandoTracker/TrackerRendererGDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ internal sealed class TrackerRendererGDI : ITrackerRenderer
private const int ImageSize = 14;
private const int CellPadding = 2;
private const int Columns = 8;
private const int SeedInfoFontSize = 18;
private const int SeedInfoFontSize = 19;
private const int CellSize = ImageSize + CellPadding;
private const double PixelPerfectSnapMargin = 0.18;
private Color DefaultBackground = Color.FromArgb(17, 00, 17);
private readonly Color DefaultBackground = Color.FromArgb(17, 00, 17);
private readonly SolidBrush textBrush = new SolidBrush(Color.White);
private Font infoFont = new Font("Tahoma", SeedInfoFontSize);

private IGraphics formGraphics;
private readonly IToolConfig toolConfig;
Expand All @@ -28,9 +30,6 @@ internal sealed class TrackerRendererGDI : ITrackerRenderer
private List<Item>? progressionItems;
private List<Item>? thrustSwords;

private List<Bitmap> relicImages = new List<Bitmap>();
private List<Bitmap> progressionItemImages = new List<Bitmap>();

private Bitmap texture;
private Bitmap greyscaleTexture;

Expand Down Expand Up @@ -98,9 +97,6 @@ public void ChangeGraphics(IGraphics formGraphics)

public void CalculateGrid(int width, int height)
{
if (width < 100 || width > 800) throw new ArgumentOutOfRangeException(nameof(width));
if (height < 100 || height > 800) throw new ArgumentOutOfRangeException(nameof(height));

int adjustedColumns = (int) (Columns * (((float) width / (float) height)));
if (adjustedColumns < 5)
{
Expand Down Expand Up @@ -163,6 +159,7 @@ public void CalculateGrid(int width, int height)
progressionItemSlots.Add(new Rectangle((int) (CellPadding + (col * (ImageSize + CellPadding) * scale)), LabelOffset + (int) (row * (ImageSize + CellPadding) * scale), (int) (ImageSize * scale), (int) (ImageSize * scale)));
col++;
}
ResizeInfo();
}

public void Render()
Expand All @@ -180,20 +177,20 @@ public void Render()
{
CollectedRender();
}
DrawSeedInfo();
formGraphics.DrawString(SeedInfo, infoFont, textBrush, TextPadding, TextPadding);

Refreshed = true;
}

private void DrawSeedInfo()
private void ResizeInfo()
{
int fontSize = SeedInfoFontSize;
while (formGraphics.MeasureString(SeedInfo, new Font("Tahoma", fontSize)).Width > (toolConfig.Tracker.Width - (TextPadding * 3)))
infoFont = new Font("Tahoma", fontSize);
while (formGraphics.MeasureString(SeedInfo, infoFont).Width > (toolConfig.Tracker.Width - (TextPadding * 3)))
{
fontSize--;
infoFont = new Font("Tahoma", fontSize);
}

formGraphics.DrawString(SeedInfo, new Font("Tahoma", fontSize), new SolidBrush(Color.White), TextPadding, TextPadding);
}

private void GridRender()
Expand All @@ -209,7 +206,15 @@ private void GridRender()
formGraphics.DrawImage(relics[i].Collected ? texture : greyscaleTexture, relicSlots[normalRelicCount], 20 * i, 0, ImageSize, ImageSize, GraphicsUnit.Pixel);
normalRelicCount++;
}
var thrustSword = thrustSwords.Where(x => x.Status).FirstOrDefault();
Item? thrustSword = null;
for (int i = 0; i < thrustSwords.Count; i++)
{
if (thrustSwords[i].Status)
{
thrustSword = thrustSwords[i];
break;
}
}
formGraphics.DrawImage(thrustSword is not null ? texture : greyscaleTexture, relicSlots[normalRelicCount], 680, 0, ImageSize, ImageSize, GraphicsUnit.Pixel);

if (vladProgression)
Expand Down
9 changes: 3 additions & 6 deletions SotnRandoTools/src/RandoTracker/TrackerRendererOpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ internal sealed class TrackerRendererOpenGL : ITrackerRenderer
private const int ImageSize = 14;
private const int CellPadding = 2;
private const int Columns = 8;
private const int SeedInfoFontSize = 18;
private const int SeedInfoFontSize = 19;
private const int CellSize = ImageSize + CellPadding;
private const double PixelPerfectSnapMargin = 0.18;
private Color DefaultBackground = Color.FromArgb(17, 00, 17);
private readonly Color DefaultBackground = Color.FromArgb(17, 00, 17);
private int Width = 100;
private int Height = 100;

Expand All @@ -37,7 +37,7 @@ internal sealed class TrackerRendererOpenGL : ITrackerRenderer
private Texture2d greyscaleTexture;
private Texture2d infoTexture;
private Bitmap seedInfoBitmap;
private SolidBrush textBrush;
private readonly SolidBrush textBrush = new SolidBrush(Color.White);

private List<Rectangle> relicSlots = new List<Rectangle>();
private List<Rectangle> vladRelicSlots = new List<Rectangle>();
Expand Down Expand Up @@ -111,8 +111,6 @@ public void CalculateGrid(int width, int height)
{
this.Width = width;
this.Height = height;
if (width < 100 || width > 800) throw new ArgumentOutOfRangeException(nameof(width));
if (height < 100 || height > 800) throw new ArgumentOutOfRangeException(nameof(height));

int adjustedColumns = (int) (Columns * (((float) width / (float) height)));
if (adjustedColumns < 5)
Expand Down Expand Up @@ -301,7 +299,6 @@ private void LoadImages()
{
Bitmap textureBitmap = new Bitmap(Paths.CombinedTexture);
Bitmap greyscaleTextureBitmap = new Bitmap(Paths.CombinedTexture);
textBrush = new SolidBrush(Color.White);
for (int i = 0; i < greyscaleTextureBitmap.Width; i++)
{
for (int j = 0; j < greyscaleTextureBitmap.Height; j++)
Expand Down
47 changes: 29 additions & 18 deletions SotnRandoTools/src/Services/OverlaySocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SotnApi.Constants.Addresses.Alucard;
using SotnRandoTools.Configuration.Interfaces;
using SotnRandoTools.Constants;
using SotnRandoTools.Services.Interfaces;
using WatsonWebsocket;

namespace SotnRandoTools.Services
{
internal sealed class TrackerObjects
{
[JsonProperty("relics")]
public int Relics { get; set; }
[JsonProperty("irems")]
public int Items { get; set; }
[JsonProperty("type")]
public string Type { get; } = "relics";
}
internal sealed class TrackerSlots
{
[JsonProperty("slots")]
public List<List<int>> Slots { get; set; }
[JsonProperty("type")]
public string Type { get; } = "slots";
}
internal sealed class OverlaySocketServer : IOverlaySocketServer
{
private readonly IToolConfig toolConfig;
private WatsonWsServer socketServer;
private readonly List<string> clients = new();
private TrackerObjects trackerObjects = new();
private TrackerSlots trackerSlots = new();
public OverlaySocketServer(IToolConfig toolConfig)
{
this.toolConfig = toolConfig ?? throw new ArgumentNullException(nameof(toolConfig));
Expand All @@ -22,6 +42,7 @@ public OverlaySocketServer(IToolConfig toolConfig)
socketServer.ClientConnected += ClientConnected;
socketServer.ClientDisconnected += ClientDisconnected;
socketServer.MessageReceived += MessageReceived;
trackerSlots.Slots = toolConfig.Tracker.OverlaySlots;
}

public void StartServer()
Expand All @@ -42,38 +63,28 @@ public void StopServer()

public void UpdateTracker(int relics, int items)
{
JObject data = JObject.FromObject(new
{
relics = relics,
items = items,
type = "relics"
});
trackerObjects.Relics = relics;
trackerObjects.Items = items;

foreach (var client in socketServer.ListClients())
for (int i = 0; i < clients.Count; i++)
{
socketServer.SendAsync(client, data.ToString());
socketServer.SendAsync(clients[i], JsonConvert.SerializeObject(trackerObjects));
}
}

private void ClientConnected(object sender, ClientConnectedEventArgs args)
{
Console.WriteLine("Client connected: " + args.IpPort);

JObject data = JObject.FromObject(new
{
slots = toolConfig.Tracker.OverlaySlots,
type = "slots"
});
clients.Add(args.IpPort);

foreach (var client in socketServer.ListClients())
for (int i = 0; i < clients.Count; i++)
{
socketServer.SendAsync(client, data.ToString());
socketServer.SendAsync(clients[i], JsonConvert.SerializeObject(trackerSlots));
}
}

private void ClientDisconnected(object sender, ClientDisconnectedEventArgs args)
{
Console.WriteLine("Client disconnected: " + args.IpPort);
clients.Remove(args.IpPort);
}

private void MessageReceived(object sender, MessageReceivedEventArgs args)
Expand Down

0 comments on commit 5cbacdd

Please sign in to comment.