Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmueller committed Jun 7, 2021
1 parent a85f14d commit 07df1ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
13 changes: 4 additions & 9 deletions FrotzCore/Frotz/Generic/files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal static void ScriptOpen()

if (Main.h_version >= ZMachine.V5 || !ScriptValid)
{
if (!OS.ReadFileName(out var new_name, General.DEFAULT_SCRIPT_NAME, FileTypes.FILE_SCRIPT))
if (!OS.ReadFileName(out string? new_name, General.DEFAULT_SCRIPT_NAME, FileTypes.FILE_SCRIPT))
goto done;

ScriptName = new_name;
Expand Down Expand Up @@ -262,12 +262,7 @@ internal static void ScriptMssgOn()
*
*/

internal static void ScriptMssgOff()
{

ScriptNewLine();

}/* script_mssg_off */
internal static void ScriptMssgOff() => ScriptNewLine();/* script_mssg_off */
#endregion

#region Record
Expand All @@ -280,7 +275,7 @@ internal static void ScriptMssgOff()
internal static void RecordOpen()
{

if (OS.ReadFileName(out var new_name, CommandName, FileTypes.FILE_RECORD))
if (OS.ReadFileName(out string? new_name, CommandName, FileTypes.FILE_RECORD))
{
CommandName = new_name;

Expand Down Expand Up @@ -424,7 +419,7 @@ internal static void RecordWriteInput(ReadOnlySpan<zword> buf, zword key)
internal static void ReplayOpen()
{

if (OS.ReadFileName(out var new_name, CommandName, FileTypes.FILE_PLAYBACK))
if (OS.ReadFileName(out string? new_name, CommandName, FileTypes.FILE_PLAYBACK))
{
CommandName = new_name;

Expand Down
20 changes: 10 additions & 10 deletions FrotzCore/Screen/LineInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class LineInfo : IDisposable
{
private readonly MemoryOwner<char> _chars;
private readonly MemoryOwner<CharDisplayInfo> _styles;
private readonly int _width;
private readonly object _lockObj = new();
private PooledList<FontChanges>? _changes;

public int X { get; set; }
public int Y { get; set; }
public int Width { get; }
public int LastCharSet { get; private set; }

public LineInfo(int lineWidth)
Expand All @@ -26,14 +26,14 @@ public LineInfo(int lineWidth)
_chars.Span.Fill(' ');
_styles.Span.Fill(default);

_width = lineWidth;
Width = lineWidth;

LastCharSet = -1;
}

public void SetChar(int pos, char c, CharDisplayInfo FandS = default)
{
if ((uint)pos >= (uint)_width)
if ((uint)pos >= (uint)Width)
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(pos));

lock (_lockObj)
Expand All @@ -49,10 +49,10 @@ public void SetChar(int pos, char c, CharDisplayInfo FandS = default)

public void SetChars(int pos, ReadOnlySpan<char> chars, CharDisplayInfo FandS = default)
{
if ((uint)pos >= (uint)_width)
if ((uint)pos >= (uint)Width)
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(pos));

if ((uint)pos + chars.Length >= (uint)_width)
if ((uint)pos + chars.Length >= (uint)Width)
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(chars), "Too many chars to fit in line.");

lock (_lockObj)
Expand All @@ -72,7 +72,7 @@ public void ClearLine()
{
lock (_lockObj)
{
for (int i = 0; i < _width; i++)
for (int i = 0; i < Width; i++)
{
ClearChar(i);
}
Expand Down Expand Up @@ -105,16 +105,16 @@ public IReadOnlyList<FontChanges> GetTextWithFontInfo()
{
if (_changes == null)
{
_changes = new PooledList<FontChanges>(_width);
_changes = new PooledList<FontChanges>(Width);
var chars = CurrentChars;

var fc = new FontChanges(-1, 0, new CharDisplayInfo(-1, 0, 0, 0));
var styles = _styles.Span;
for (int i = 0; i < _width; i++)
for (int i = 0; i < Width; i++)
{
if (!styles[i].Equals(fc.FontAndStyle))
{
fc = new FontChanges(i, _width, styles[i]);
fc = new FontChanges(i, Width, styles[i]);
fc.AddChar(chars[i]);
_changes.Add(fc);
}
Expand All @@ -130,7 +130,7 @@ public IReadOnlyList<FontChanges> GetTextWithFontInfo()
return _changes;
}

public ReadOnlySpan<char> GetChars() => _chars.Span[.._width];
public ReadOnlySpan<char> GetChars() => _chars.Span[..Width];

public ReadOnlySpan<char> GetChars(int start, int length) => _chars.Span.Slice(start, length);

Expand Down
6 changes: 3 additions & 3 deletions FrotzCore/Screen/ScreenLines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ScreenLines(int rows, int columns)
_lines = new PooledList<LineInfo>(rows);
for (int i = 0; i < rows; i++)
{
_lines.Add(new LineInfo(columns * 3));
_lines.Add(new (columns * 3));
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ private void AddLines()
{
while (_lines.Count <= Rows * 2)
{
_lines.Add(new LineInfo(Columns * 3));
_lines.Add(new (Columns * 3));
}
}
}
Expand All @@ -109,7 +109,7 @@ public string GetTextToLine(int line, out List<FontChanges> changes)
{
int pos = 0;

changes = new List<FontChanges>();
changes = new List<FontChanges>(line * Columns * 3);
using var sb = new ValueStringBuilder();
for (int i = 0; i < line; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion FrotzCore/Screen/ScreenStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Frotz.Screen
{
public class ZKeyPressEventArgs : EventArgs
public sealed class ZKeyPressEventArgs : EventArgs
{
public char KeyPressed { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion FrotzCore/ZTools/infodump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private static void ShowMap()

/* Sort areas */

areas.Sort(new AreaComparer());
areas.Sort(default(AreaComparer));

/* Print area map */

Expand Down

0 comments on commit 07df1ef

Please sign in to comment.