Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Feb 15, 2023
1 parent f2af58a commit 2592062
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions AcManager.Tools/Data/PatchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class PatchHelper {
public static readonly string FeatureCustomRenderingModes = "CUSTOM_RENDERING_MODES";
public static readonly string FeatureJoypadIndexAware = "JOYPAD_INDEX_AWARE";
public static readonly string FeatureHasShowroomMode = "RACEINI_SETUP_SUPPORT";
public static readonly string FeatureDualShockSupport = "PS4_DUALSHOCK_SUPPORT";
public static readonly string FeatureDualSenseSupport = "PS5_DUALSENSE_SUPPORT";
public static readonly string FeatureCarPreviews = "CAR_PREVIEWS";

Expand Down
8 changes: 7 additions & 1 deletion AcManager.Tools/Helpers/AcSettings/ControlsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ public int ControllerDeviceIndex {
set => Apply(value, ref _controllerDeviceIndex, () => {
OnPropertyChanged(nameof(DisplayControllerDeviceIndex));
OnPropertyChanged(nameof(ControllerUseDualSense));
OnPropertyChanged(nameof(ControllerUseDualShock));
});
}

Expand All @@ -1078,10 +1079,15 @@ public int DisplayControllerDeviceIndex {
}

public bool ControllerUseDualSense {
get => _controllerDeviceIndex > 3;
get => _controllerDeviceIndex > 3 && _controllerDeviceIndex <= 7;
set => ControllerDeviceIndex = _controllerDeviceIndex % 4 + (value ? 4 : 0);
}

public bool ControllerUseDualShock {
get => _controllerDeviceIndex > 7;
set => ControllerDeviceIndex = _controllerDeviceIndex % 4 + (value ? 8 : 0);
}

private double _controllerSteeringGamma;

public double ControllerSteeringGamma {
Expand Down
28 changes: 22 additions & 6 deletions AcManager/CustomShowroom/CmPreviewsTools.AcUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
using AcTools.Utils;
using AcTools.Utils.Helpers;
using FirstFloor.ModernUI.Dialogs;
using FirstFloor.ModernUI.Helpers;
using JetBrains.Annotations;

namespace AcManager.CustomShowroom {
public partial class CmPreviewsTools {
public static int OptionBatchSize = 10;
public static int OptionBatchSize = 20;

private class AcUpdater : UpdaterBase {
public AcUpdater([NotNull] IReadOnlyList<ToUpdatePreview> entries, [NotNull] DarkPreviewsOptions options, [CanBeNull] string presetName,
Expand All @@ -42,8 +41,12 @@ private static void CleanUpStates(string[] carIds) {

protected override async Task RunAsyncOverride() {
progressReport?.Report(new AsyncProgressEntry("Launching Assetto Corsa in background…", double.Epsilon));

var carIds = Items.Select(x => x.Car.Id).ToArray();
var totalSkins = Items.Sum(x => x.Skins.Count);
var readySkins = 0;
var multiCarRun = Items.Count > 1;

CleanUpStates(carIds);
using (new ActionAsDisposable(() => CleanUpStates(carIds))) {
var extension = Path.GetExtension(Options.PreviewName);
Expand Down Expand Up @@ -72,7 +75,6 @@ Task ShotWrapperAsync(int currentRun, IEnumerable<Tuple<string, string, string>>
});
}


foreach (var car in Items) {
foreach (var skins in SplitIntoBatches(car.Skins, OptionBatchSize, (int)(OptionBatchSize * 1.5))) {
var currentRun = ++runIndex[0];
Expand All @@ -82,7 +84,7 @@ Task ShotWrapperAsync(int currentRun, IEnumerable<Tuple<string, string, string>>
FilesStorage.Instance.GetTemporaryFilename("Previews", $"{x.Item1}__{x.Item2}{extension}")).ToList();
await Task.Run(() => temporaryDestinations.ForEach(x => FileUtils.TryToDelete(x)));
if (Cancel()) return;
if (acError != null) {
if (acError != null && !multiCarRun) {
throw new Exception(acError.Or(timeouted ? "Assetto Corsa took too long" : "Assetto Corsa closed down unexpectedly"));
}

Expand Down Expand Up @@ -110,6 +112,10 @@ await Task.Run(() => {
shutdownStopwatch.Restart();
PreviewReadyCallback(skins[expectedIndex]);
ReportShotSkin();

++readySkins;
progressReport?.Report(new AsyncProgressEntry("Waiting for Assetto Corsa to make shots…", readySkins, totalSkins));

if (++expectedIndex == temporaryDestinations.Count) {
++currentRun;
break;
Expand All @@ -120,7 +126,17 @@ await Task.Run(() => {
}))()
}.WhenAll();
if (Cancel()) return;
if (acError != null) throw new Exception(acError.Or("Assetto Corsa closed down unexpectedly"));

if (acError != null) {
var errorMessage = acError.Or("Assetto Corsa closed down unexpectedly");
if (multiCarRun) {
for (var i = expectedIndex; i < items.Count; ++i) {
ReportFailedSkin(errorMessage, null);
}
} else {
throw new Exception(errorMessage);
}
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions AcManager/CustomShowroom/CmPreviewsTools.Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AcTools.Render.Kn5SpecificForwardDark;
using FirstFloor.ModernUI.Dialogs;
using JetBrains.Annotations;
using OxyPlot.Reporting;

namespace AcManager.CustomShowroom {
public partial class CmPreviewsTools {
Expand Down Expand Up @@ -57,10 +58,11 @@ protected override async Task RunAsyncOverride() {
await _updater.ShotAsync(currentCar.Id, currentSkin.Id, filename, currentCar.AcdData,
GetInformation(currentCar, currentSkin, PresetName, checksum), () => PreviewReadyCallback(currentSkin),
cancellation: CancellationToken);
ReportShotSkin();
} catch (Exception e) {
RegisterError(e, entry);
ReportFailedSkin(null, e);
continue;
}
ReportShotSkin();
}
}
} finally {
Expand Down
17 changes: 14 additions & 3 deletions AcManager/CustomShowroom/CmPreviewsTools.UpdaterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ protected void ReportShotSkin() {
}
}

protected void ReportFailedSkin(string errorMessage, Exception exception) {
if (_entryIndex >= Items.Count) return;
RegisterError(errorMessage, exception, Items[_entryIndex]);
_shotSkins++;
if (++_skinIndex == Items[_entryIndex].Skins.Count) {
_skinIndex = 0;
if (++_entryIndex == Items.Count) _finished = true;
}
}

protected async Task<string> GetDestinationAsync(CarSkinObject skin, double subprogress) {
var ret = _destinationOverrideCallback?.Invoke(skin) ?? Path.Combine(skin.Location, Options.PreviewName);
if (_destinationOverrideCallback == null && SettingsHolder.CustomShowroom.PreviewsRecycleOld && File.Exists(ret)) {
Expand All @@ -123,10 +133,11 @@ protected UpdaterBase([NotNull] IReadOnlyList<ToUpdatePreview> entries, [NotNull
_cancellationToken = cancellation;
}

protected void RegisterError(Exception e, ToUpdateSolved entry) {
protected void RegisterError([CanBeNull] string errorMessage, [CanBeNull] Exception exception, ToUpdateSolved entry) {
if (_errors.All(x => x.ToUpdate != entry.Source)) {
Logging.Warning(e);
_errors.Add(new UpdatePreviewError(entry.Source, e.Message, null));
var errorData = errorMessage ?? exception?.ToString() ?? "Unknown error";
Logging.Warning(errorData);
_errors.Add(new UpdatePreviewError(entry.Source, errorData, null));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
mui:BetterTextBox.Maximum="4" Content="Gamepad ID" />
<Slider Minimum="1" Maximum="4" TickFrequency="1" TickPlacement="BottomRight" Value="{Binding Controls.DisplayControllerDeviceIndex}" />
</DockPanel>
<CheckBox IsChecked="{Binding Controls.ControllerUseDualShock}" c:FeatureIsAvailable.Feature="{x:Static t:PatchHelper.FeatureDualShockSupport}"
ToolTip="Requires CSP 0.1.80">
<Label Content="Use PlayStation 4 DualShock gamepad" />
</CheckBox>
<CheckBox IsChecked="{Binding Controls.ControllerUseDualSense}" c:FeatureIsAvailable.Feature="{x:Static t:PatchHelper.FeatureDualSenseSupport}"
ToolTip="Requires CSP 0.1.79">
<Label Content="Use PlayStation 5 DualSense gamepad" />
</CheckBox>
<c:MessageBlock Visibility="{Binding Controls.ControllerUseDualSense, Converter={StaticResource BooleanToVisibilityConverter}}">
<c:MessageBlock c:FeatureIsAvailable.Feature="{x:Static t:PatchHelper.FeatureDualSenseSupport}">
<mui:BbCodeBlock Style="{StaticResource Small}"
Text="With CSP active, use built-in Controller Tweaks app to change buttons live with DualSense gamepads (or any other gamepads)." />
Text="With CSP active, use built-in Controller Tweaks app to change buttons live with DualShock or DualSense gamepads (or any other gamepads)." />
</c:MessageBlock>
</StackPanel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ protected override void DrawSceneToBuffer() {

if (AoDebug) {
DeviceContext.Rasterizer.SetViewports(InnerBuffer.Viewport);
if (_aoBuffer?.Format == Format.R8_UNorm) {
if (_aoBuffer.Format == Format.R8_UNorm) {
DeviceContextHolder.GetHelper<CopyHelper>().DrawFromRed(DeviceContextHolder, _aoBuffer.View, InnerBuffer.TargetView);
} else {
DeviceContextHolder.GetHelper<CopyHelper>().Draw(DeviceContextHolder, _aoBuffer.View, InnerBuffer.TargetView);
Expand Down

0 comments on commit 2592062

Please sign in to comment.