Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Sep 12, 2021
1 parent b9b8b55 commit fb5217b
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 40 deletions.
3 changes: 2 additions & 1 deletion AcManager.Tools/AcObjectsNew/AcCommonObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using AcManager.Tools.AcErrors;
Expand Down Expand Up @@ -128,7 +129,7 @@ protected set {
}
}

protected override void OnPropertyChanged(string propertyName = null) {
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) {
if (_ignoreChanges) return;
base.OnPropertyChanged(propertyName);
}
Expand Down
3 changes: 1 addition & 2 deletions AcManager.Tools/AcPlugins/Extras/AcLeaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using AcManager.Tools.AcPlugins.Messages;
using AcTools.Processes;
using FirstFloor.ModernUI;
using FirstFloor.ModernUI.Helpers;
using FirstFloor.ModernUI.Presentation;
using JetBrains.Annotations;

Expand Down Expand Up @@ -145,7 +144,7 @@ public void OnCollision(MsgClientEvent msg) {
public void CheckDisconnected() {
foreach (var item in Leaderboard) {
if (item.Driver != null && ++item.SilentFor > 5) {
Logging.Debug("item.SilentFor=" + item.SilentFor);
// Logging.Debug("item.SilentFor=" + item.SilentFor);
ActionExtension.InvokeInMainThread(() => {
item.Driver = null;
item.Reset(true);
Expand Down
3 changes: 3 additions & 0 deletions AcManager.Tools/Helpers/ReplayDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class ReplayDetails {
public int NumberOfFrames;
public bool AllowToOverrideTime;

[JsonConstructor]
public ReplayDetails() { }

private ReplayDetails(string filename) {
try {
using (var reader = new ReplayReader(filename)) {
Expand Down
1 change: 1 addition & 0 deletions AcManager.Tools/Objects/ServerPresetDriverEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ServerPresetDriverEntry([NotNull] ServerSavedDriver saved) {
public string CarId {
get => _carId;
set {
Logging.Debug($"CARID: {value}, {_carId}");
if (value == _carId) return;
_carId = value;
_carSet = false;
Expand Down
2 changes: 2 additions & 0 deletions AcManager.Tools/Objects/ServerPresetObject.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ private void UpdateIndexes() {
}

private void UpdateCarIds() {
Logging.Debug("CAR IDS: " + _driverEntries.Select(x => x.CarId).Distinct().ToArray());
CarIds = _driverEntries.Select(x => x.CarId).Distinct().ToArray();
}

Expand All @@ -778,6 +779,7 @@ private void OnDriverEntriesCollectionChanged(object sender, NotifyCollectionCha
}

private void OnDriverEntryPropertyChanged(object sender, PropertyChangedEventArgs e) {
Logging.Debug($"PROP CHANGED: {e.PropertyName}");
switch (e.PropertyName) {
case nameof(ServerPresetDriverEntry.CarId):
UpdateCarIds();
Expand Down
13 changes: 9 additions & 4 deletions AcManager/Pages/Drive/Online.SortingModes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ int IComparer.Compare(object x, object y) {

public class SortingName : ServerEntrySorter {
public override int Compare(ServerEntry x, ServerEntry y) {
return string.Compare(x.ActualName, y.ActualName, StringComparison.CurrentCultureIgnoreCase);
var v = AlphanumComparatorFast.Compare(x.ActualName, y.ActualName);
if (v != 0) return v;
return AlphanumComparatorFast.Compare(x.Id, y.Id);
}

public override bool IsAffectedBy(string propertyName) {
Expand All @@ -35,8 +37,11 @@ public override bool IsAffectedBy(string propertyName) {

public class SortingCleanedName : ServerEntrySorter {
public override int Compare(ServerEntry x, ServerEntry y) {
// Logging.Debug($"x.SortingName={x.SortingName}, y.SortingName={y.SortingName}");
return string.Compare(x.SortingName, y.SortingName, StringComparison.CurrentCultureIgnoreCase);
var v = AlphanumComparatorFast.Compare(x.SortingName, y.SortingName);
if (v != 0) return v;
v = AlphanumComparatorFast.Compare(x.ActualName, y.ActualName);
if (v != 0) return v;
return AlphanumComparatorFast.Compare(x.Id, y.Id);
}

public override bool IsAffectedBy(string propertyName) {
Expand Down Expand Up @@ -149,4 +154,4 @@ public static ServerEntrySorter GetSorter(string modeKey) {
private static readonly StoredValue<string> DefaultSortingMode = Stored.Get("/Online.DefaultSortingMode", "name");
private static readonly StoredValue<string> DefaultQuickFilters = Stored.Get("/Online.DefaultQuickFilters", "(haserrors- & missing-)");
}
}
}
10 changes: 7 additions & 3 deletions AcManager/Pages/ServerPreset/SelectedPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public string SavedDriversFilter {
}

private void OnCarsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
_busy.Do(() => { SelectedObject.CarIds = Cars.Select(x => x.Id).ToArray(); });
_busy.Do(() => SelectedObject.CarIds = Cars.Select(x => x.Id).ToArray());
}

private DelegateCommand _changeWelcomeMessagePathCommand;
Expand All @@ -350,15 +350,19 @@ public DelegateCommand ChangeWelcomeMessagePathCommand
}));

private void OnAcObjectPropertyChanged(object sender, PropertyChangedEventArgs e) {
Logging.Debug($"prop={e.PropertyName}, busy={_busy.Is}");
switch (e.PropertyName) {
case nameof(SelectedObject.TrackId):
case nameof(SelectedObject.TrackLayoutId):
_busy.Do(() => { Track = TracksManager.Instance.GetLayoutById(SelectedObject.TrackId, SelectedObject.TrackLayoutId); });
_busy.Do(() => Track = TracksManager.Instance.GetLayoutById(SelectedObject.TrackId, SelectedObject.TrackLayoutId));
UpdateWrapperContentTracks();
break;

case nameof(SelectedObject.CarIds):
_busy.Do(() => { Cars.ReplaceEverythingBy(SelectedObject.CarIds.Select(x => CarsManager.Instance.GetById(x))); });
_busy.Do(() => {
Cars.ReplaceEverythingBy(SelectedObject.CarIds.Select(x => CarsManager.Instance.GetById(x)));
OnPropertyChanged(nameof(Car));
});
break;

case nameof(SelectedObject.DriverEntries):
Expand Down
4 changes: 2 additions & 2 deletions AcManager/Pages/ServerPreset/ServerPresetBasic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
CommandParameter="/Pages/ServerPreset/ServerPresetEntryList.xaml" c:ToolTips.Car="{Binding Car}" c:ContextMenus.Car="{Binding Car}"
mui:Draggable.Data="{Binding Car}">
<Grid Margin="-1" ClipToBounds="True" IsHitTestVisible="False">
<mui:BetterImage Filename="{Binding Cars[0].SelectedSkin.PreviewImage}" DecodeWidth="320" Stretch="UniformToFill" />
<mui:BetterImage Filename="{Binding Car.SelectedSkin.PreviewImage}" DecodeWidth="320" Stretch="UniformToFill" />
<TextBlock Padding="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="{DynamicResource DarkStripeBackground}"
Text="{Binding Cars[0].DisplayName}" Foreground="{DynamicResource DarkStripeText}" />
Text="{Binding Car.DisplayName}" Foreground="{DynamicResource DarkStripeText}" />
</Grid>
</Button>
</StackPanel>
Expand Down
2 changes: 1 addition & 1 deletion AcManager/Pages/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@
<!-- Server Source="/Pages/Lists/ServerPresetsListPage.xaml" -->
<mui:LinkGroupFilterable GroupKey="server" DisplayName="{x:Static g:AppStrings.Main_ServerPresets}" Source="/Pages/Lists/ServerPresetsListPage.xaml"
FilterHint="{x:Static c:FilterHints.ServerPresets}" />
<mui:LinkGroupFilterable GroupKey="server" DisplayName="Blacklist" Source="/Pages/Lists/ServerBannedListPage.xaml" />
<mui:LinkGroupFilterable GroupKey="server" DisplayName="Banned drivers" Source="/Pages/Lists/ServerBannedListPage.xaml" />

<!-- Settings -->
<mui:LinkGroupFilterable GroupKey="settings" DisplayName="{x:Static g:AppStrings.Main_Settings}" AddAllLink="False" Source="/Pages/Settings/Search.xaml">
Expand Down
9 changes: 7 additions & 2 deletions AcManager/Tools/ArgumentsHandler.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ private static SharedEntryType GuessEntryType(string data) {
if (data.Contains("\"UserDefinedValues\":")) return SharedEntryType.CarLodsGenerationPreset;
} else if (data.StartsWith("<RealHeadMotion>")) {
return SharedEntryType.RhmPreset;
} else if (data.StartsWith(@"[") && Regex.IsMatch(data, @"\[[A-Z_]+:[A-Z_]+\]")) {
return SharedEntryType.CspSettings;
} else if (data.StartsWith(@"[")) {
if (data.Contains("STEERING_OPPOSITE_DIRECTION_SPEED=") && data.Contains("COMBINE_WITH_KEYBOARD_CONTROL=")) {
return SharedEntryType.ControlsPreset;
}
if (Regex.IsMatch(data, @"\[[A-Z_]+:[A-Z_]+\]")) {
return SharedEntryType.CspSettings;
}
}
Logging.Warning(data);
throw new Exception("Failed to determine CM preset type");
Expand Down
Binary file modified AcTools.Render/Kn5SpecificSpecial/AiLaneObject.cs
Binary file not shown.
57 changes: 57 additions & 0 deletions FirstFloor.ModernUI.Tests/AlphanumComparatorFastTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using FirstFloor.ModernUI.Helpers;
using NUnit.Framework;

namespace FirstFloor.ModernUI.Tests {
[TestFixture]
public class AlphanumComparatorFastTest {
private static void EnsureAboveOf(string a, string b) {
Assert.AreEqual(true, AlphanumComparatorFast.Compare(a, b) < 0);
Assert.AreEqual(true, AlphanumComparatorFast.Compare(b, a) > 0);
}

private static void EnsureBelowOf(string a, string b) {
Assert.AreEqual(true, AlphanumComparatorFast.Compare(a, b) > 0);
Assert.AreEqual(true, AlphanumComparatorFast.Compare(b, a) < 0);
}

private static void EnsureSame(string a, string b) {
Assert.AreEqual(true, AlphanumComparatorFast.Compare(a, b) == 0);
Assert.AreEqual(true, AlphanumComparatorFast.Compare(b, a) == 0);
}

[Test]
public void ServerNamesTest() {
EnsureAboveOf("abc", "def");
EnsureBelowOf("abcc", "abc");
EnsureBelowOf("17-abcc", "17-abc");
EnsureAboveOf("17-abcc", "17-abcd");
EnsureAboveOf("ab99c", "abc0c");
EnsureAboveOf("ab99c", "abc0000c");

EnsureBelowOf("test-15-q", "test-5-q");
EnsureBelowOf("test-15-q", "test-005-q");
EnsureAboveOf("test-15-q", "test-25-q");
EnsureSame("test-15-q", "test-15-q");
EnsureAboveOf("test-15-q-7", "test-15-q-14");
EnsureBelowOf("test-15-q-70", "test-15-q-14");

{
var name1 = "AC-01 (www.assetto-fr.tk) French Nordschleife Endurance (SOL) (KMR)x:xdn566";
var name2 = "AC-02 (www.assetto-fr.tk) French GT2 (Track Rotation) (SOL) (KMR)x:VAJezh";
var name3 = "AC-03 (www.assetto-fr.tk) French GT3 (Track Rotation) (SOL) (KMR)x:JdWnGb";
EnsureBelowOf(name2, name1);
EnsureBelowOf(name3, name1);
EnsureBelowOf(name3, name2);
}

{
var name1 = "AC-01 (www.assetto-fr.tk) French Nordschleife Endurance (SOL) (KMR)x:xdn566";
var name2 = "AC-02 (www.assetto-fr.tk) French GT2 (Track Rotation) (SOL) (KMR)x:VAJezh";
var name3 = "AC-03 (www.assetto-fr.tk) French GT3 (Track Rotation) (SOL) (KMR)x:JdWnGb";
EnsureBelowOf(name2, name1);
EnsureBelowOf(name3, name1);
EnsureBelowOf(name3, name2);
}
}
}
}
1 change: 1 addition & 0 deletions FirstFloor.ModernUI.Tests/FirstFloor.ModernUI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="AlphanumComparatorFastTest.cs" />
<Compile Include="BusyTest.cs" />
<Compile Include="CommandsTest.cs" />
<Compile Include="EmojiTest.cs" />
Expand Down
70 changes: 45 additions & 25 deletions FirstFloor.ModernUI/Helpers/AlphanumComparatorFast.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
using System;
using System.Collections;
using System.Globalization;
using System.Collections.Generic;
using JetBrains.Annotations;

namespace FirstFloor.ModernUI.Helpers {
public class AlphanumComparatorFast : IComparer {
public class AlphanumComparatorFast : IComparer, IComparer<string> {
public static AlphanumComparatorFast Instance { get; } = new AlphanumComparatorFast();

int IComparer.Compare(object x, object y) {
return Compare(x, y);
}

int IComparer<string>.Compare(string x, string y) {
return Compare(x, y);
}

private static bool IsDigit(char c) {
return c >= '0' && c <= '9';
}

private static int CompareBit(char[] a, int al, char[] b, int bl) {
var l = Math.Min(al, bl);
for (var i = 0; i < l; ++i) {
var d = a[i] - b[i];
if (d != 0) return d;
}
return al - bl;
}

private static int CompareNumericBit(char[] a, int al, char[] b, int bl) {
if (al != bl) return al - bl;
for (var i = 0; i < al; ++i) {
var d = a[i] - b[i];
if (d != 0) return d;
}
return 0;
}

public static int Compare([CanBeNull] string x, [CanBeNull] string y) {
if (x == null) return y == null ? 0 : 1;
if (y == null) return -1;
Expand All @@ -18,57 +46,49 @@ public static int Compare([CanBeNull] string x, [CanBeNull] string y) {
var marker1 = 0;
var marker2 = 0;

// Some buffers we can build up characters in for each chunk.
var space1 = new char[len1];
var space2 = new char[len2];

// Walk through two the strings with two markers.
while (marker1 < len1 && marker2 < len2) {
var ch1 = x[marker1];
var ch2 = y[marker2];

// Some buffers we can build up characters in for each chunk.
var space1 = new char[len1];
var loc1 = 0;
var space2 = new char[len2];
var loc2 = 0;

// Walk through all following characters that are digits or
// characters in BOTH strings starting at the appropriate marker.
// Collect char arrays.
var loc1 = 0;
var num1 = IsDigit(ch1);
do {
space1[loc1++] = ch1;
space1[loc1] = ch1;
if (loc1 > 0 || ch1 != '0') ++loc1;
marker1++;

if (marker1 < len1) {
ch1 = x[marker1];
} else {
break;
}
} while (char.IsDigit(ch1) == char.IsDigit(space1[0]));
} while (IsDigit(ch1) == num1);

var loc2 = 0;
var num2 = IsDigit(ch2);
do {
space2[loc2++] = ch2;
space2[loc2] = ch2;
if (loc2 > 0 || ch2 != '0') ++loc2;
marker2++;

if (marker2 < len2) {
ch2 = y[marker2];
} else {
break;
}
} while (char.IsDigit(ch2) == char.IsDigit(space2[0]));
} while (IsDigit(ch2) == num2);

// If we have collected numbers, compare them numerically.
// Otherwise, if we have strings, compare them alphabetically.
var str1 = new string(space1);
var str2 = new string(space2);

int result;

if (char.IsDigit(space1[0]) && char.IsDigit(space2[0])) {
var thisNumericChunk = int.Parse(str1, CultureInfo.InvariantCulture);
var thatNumericChunk = int.Parse(str2, CultureInfo.InvariantCulture);
result = thisNumericChunk.CompareTo(thatNumericChunk);
} else {
result = string.Compare(str1, str2, StringComparison.Ordinal);
}

var result = num1 && num2 ? CompareNumericBit(space1, loc1, space2, loc2) : CompareBit(space1, loc1, space2, loc2);
if (result != 0) {
return result;
}
Expand Down

0 comments on commit fb5217b

Please sign in to comment.