Skip to content

Commit

Permalink
Merge pull request #336 from Thraka/develop
Browse files Browse the repository at this point in the history
v10 release
  • Loading branch information
Thraka authored Oct 29, 2023
2 parents 43c21ba + 238ab27 commit 03627ff
Show file tree
Hide file tree
Showing 674 changed files with 101,353 additions and 37,108 deletions.
46 changes: 33 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true
dotnet_style_readonly_field=false:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion

[project.json]
indent_size = 2
Expand Down Expand Up @@ -54,15 +72,15 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
Expand All @@ -72,7 +90,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case
# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
Expand All @@ -81,7 +99,7 @@ dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
# Code style defaults
csharp_using_directive_placement = outside_namespace:suggestion
dotnet_sort_system_directives_first = true
csharp_prefer_braces = false:refactoring
csharp_prefer_braces = false:silent
csharp_preserve_single_line_blocks = true:none
csharp_preserve_single_line_statements = false:none
csharp_prefer_static_local_function = true:suggestion
Expand All @@ -107,14 +125,14 @@ dotnet_style_prefer_conditional_expression_over_return = true:refactoring
csharp_prefer_simple_default_expression = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods =false:silent
csharp_style_expression_bodied_constructors =false:silent
csharp_style_expression_bodied_operators =false:silent
csharp_style_expression_bodied_properties =true:silent
csharp_style_expression_bodied_indexers = true:refactoring
csharp_style_expression_bodied_accessors = true:refactoring
csharp_style_expression_bodied_lambdas = true:refactoring
csharp_style_expression_bodied_local_functions = true:refactoring
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = true:silent

# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
Expand Down Expand Up @@ -156,6 +174,8 @@ csharp_space_between_square_brackets = false

# Analyzers
dotnet_code_quality.ca1802.api_surface = private, internal
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent

# C++ Files
[*.{cpp,h,in}]
Expand All @@ -182,4 +202,4 @@ indent_size = 2
[*.sh]
end_of_line = lf
[*.{cmd, bat}]
end_of_line = crlf
end_of_line = crlf
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ build/
[Bb]in/
[Oo]bj/
[Pp]ackages/
experiments/

!/FNA/library/[dD]ebug/
!/FNA/library/[rR]elease/
Expand Down Expand Up @@ -229,4 +230,5 @@ pip-log.txt

.vs/
releases/
nuget/
nuget/
.vscode/
93 changes: 93 additions & 0 deletions MigrationNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Deserializing objects from v9
-------------------------------------

The built-in fonts incorrectly named themselves IBM_16x8, even though the glyphs were 8x16. The name has been
corrected in SadConsole. If you deserialize an object and it can't find the IBM_16x8 font you have two solutions:

- Edit the json and fix the font name.
- Use the configuration `FixOldFontName()` option.

Themes from v9
----------------------

The theme concept has been removed from v10. If you had a control with its own theme, you
need to migrate the theme code to the control itself. Here are some tips and notes:

- `ControlThemeState` changes to `ThemeState`

- `_colorsLastUsed` was declared by the theme when `RefreshTheme` was called. This member no
longer exists and `RefreshTheme` has changed. If you used this member, instead declare a `Colors` object
in the `UpdateAndRedraw` method: `Colors _colorsLastUsed = FindThemeColors();` This resolves any references
to `_colorsLastUsed`. Next, rename the variable to something more useful like `colors` or `currentColors`.

- If `GetOffColor` is used, this has been moved from `ThemeState` to the `Colors` class, for
example, `currentColors.GetOffColor`

- If your theme declared various properties, variables, and methods, move them to the control. I suggest making the
control a partial class, then creating a new class with the file name `.Theme.cs` appended. For example, SadConsole
has the `Checkbox.cs` and `Checkbox.Theme.cs` files. The "theme" code file contains all of the properties, methods,
and variables used to draw the control.

Drawing a control in v10
-----------------------------

When drawing a control override the `UpdateAndRedraw` method and do the following:

1. Check if `IsDirty == false` and return.
2. Get the current colors for the control `Colors currentColors = FindThemeColors();`
3. Call `RefreshThemeStateColors(currentColors);`

If migrating a v9 theme, override `RefreshThemeStateColors` and copy any code in the theme's `RefreshTheme` method (if overridden).

4. (If migrating a v9 theme)
- Copy any code in the theme's `UpdateAndDraw` method.
- If your code used the `control` parameter or cast `control` to a specific type, do a find and replace operation
with `control.` and a blank value. You no longer need to reference the control since the drawing code now lives
in the control itself.
- Replace references of `ControlThemeState` with `ThemeState`.
5. Draw the control by using the `Surface` property.
6. Set `IsDirty = false`


Here is the drawing code for the button control:
```csharp
public override void UpdateAndRedraw(TimeSpan time)
{
// Step 1
if (!IsDirty) return;

// Step 2
Colors currentColors = FindThemeColors();

// Step 3
RefreshThemeStateColors(currentColors);

// Steps 4 and 5: Draw the control
ColoredGlyph appearance = ThemeState.GetStateAppearance(State);
ColoredGlyph endGlyphAppearance = ThemeState.GetStateAppearance(State);

endGlyphAppearance.Foreground = currentColors.Lines;

int middle = (Height != 1 ? Height / 2 : 0);

// Redraw the control
Surface.Fill(
appearance.Foreground,
appearance.Background,
appearance.Glyph, null);

if (ShowEnds && Width >= 3)
{
Surface.Print(1, middle, Text.Align(TextAlignment, Width - 2));
Surface.SetCellAppearance(0, middle, endGlyphAppearance);
Surface[0, middle].Glyph = LeftEndGlyph;
Surface.SetCellAppearance(Width - 1, middle, endGlyphAppearance);
Surface[Width - 1, middle].Glyph = RightEndGlyph;
}
else
Surface.Print(0, middle, Text.Align(TextAlignment, Width));

// Step 6
IsDirty = false;
}
```
94 changes: 0 additions & 94 deletions MigrationNotes.txt

This file was deleted.

6 changes: 6 additions & 0 deletions PerformanceTests/SadConsole.PerformanceTests/BasicGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BasicGameHost : GameHost
{
public class RenderStep : IRenderStep
{
public string Name => "Nothing";
public uint SortOrder { get => 1; set => throw new NotImplementedException(); }
public void Composing(IRenderer renderer, IScreenSurface screenObject) => throw new NotImplementedException();
public void Dispose() => throw new NotImplementedException();
Expand Down Expand Up @@ -108,5 +109,10 @@ public override void Run()
{
throw new NotImplementedException();
}

public override ITexture CreateTexture(int width, int height)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using BenchmarkDotNet.Attributes;
using SadRogue.Primitives;

namespace SadConsole.PerformanceTests;

public class ScreenSurfaceEffects
{
private BasicGameHost _gameHost;

[Params(10, 100, 200)]
public int Size;

[Params(true, false)]
public bool Clone;

private ICellSurface _surface = null!;

[GlobalSetup]
public void GlobalSetup()
{
_gameHost = new BasicGameHost();

_surface = new CellSurface(Size, Size);
_surface.FillWithRandomGarbage(255);

var fadeEffect = new SadConsole.Effects.Fade
{
AutoReverse = true,
DestinationForeground = new Gradient(Color.Blue, Color.Yellow),
FadeForeground = true,
UseCellForeground = false,
//Repeat = true,
FadeDuration = System.TimeSpan.FromSeconds(0.7d),
RemoveOnFinished = true,
CloneOnAdd = Clone,
RestoreCellOnRemoved = true,
};

foreach (var cell in _surface)
_surface.SetEffect(cell, fadeEffect);

BenchmarkDotNet.Loggers.ConsoleLogger.Ascii.WriteLine(BenchmarkDotNet.Loggers.LogKind.Info, $"Count of effect instances {_surface.Effects.Count}");
}

[GlobalCleanup]
public void GlobalCleanup()
{
BenchmarkDotNet.Loggers.ConsoleLogger.Ascii.WriteLine(BenchmarkDotNet.Loggers.LogKind.Info, $"Count of effect instances {_surface.Effects.Count}");
}

[Benchmark]
public void UpdateHalfSecond()
{
_surface.Effects.UpdateEffects(TimeSpan.FromSeconds(0.5d));
}

[Benchmark]
public void UpdateHalfSecond2Times()
{

_surface.Effects.UpdateEffects(TimeSpan.FromSeconds(0.5d));
_surface.Effects.UpdateEffects(TimeSpan.FromSeconds(0.5d));
}
}
Loading

0 comments on commit 03627ff

Please sign in to comment.