Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill Bizware .NET Framework deps #3702

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f0ea198
Kill Bizware .NET Framework deps
CasualPokePlayer Jul 11, 2023
a1457a9
remove unfinished d3d11 backend (didn't mean to commit this)
CasualPokePlayer Jul 14, 2023
7bcd581
oops
CasualPokePlayer Jul 14, 2023
d9fbe15
Try to fix crashing, also print out some debug info about sdl gamepad…
CasualPokePlayer Jul 14, 2023
eab4d6c
better debug printing
CasualPokePlayer Jul 14, 2023
e22f2bf
fix up nonsensical logging, try to reduce freezing from SDL?
CasualPokePlayer Jul 15, 2023
aae3379
more logging + reduce sdl event loop thread frequency
CasualPokePlayer Jul 15, 2023
0e7d607
remove some threading bullshit, maybe this will play nicer?
CasualPokePlayer Jul 15, 2023
865916d
be less clever with this hack
CasualPokePlayer Jul 15, 2023
bb900f8
debug this, i guess?
CasualPokePlayer Jul 15, 2023
355d9f9
move this up
CasualPokePlayer Jul 15, 2023
8cdc63b
try disabling DirectInput? maybe this is interfering with SDL lol?
CasualPokePlayer Jul 16, 2023
017c43e
maybe this will work?
CasualPokePlayer Jul 16, 2023
992afc7
do some logging for pressing buttons, will report errors as they occur
CasualPokePlayer Jul 16, 2023
02e13df
try this also log this?
CasualPokePlayer Jul 16, 2023
0fcdfcd
meh?
CasualPokePlayer Jul 16, 2023
37aa94a
log this i guess?
CasualPokePlayer Jul 16, 2023
4954b60
try SDL_INIT_EVERYTHING maybe?
CasualPokePlayer Jul 16, 2023
e14d539
dont try to rumble, maybe that's causing issues?
CasualPokePlayer Jul 16, 2023
4ef25aa
check for not 0 instead of 1, perhaps that'll be better?
CasualPokePlayer Jul 16, 2023
f47e89e
commit in different dll (from SDL-CS's builds)
CasualPokePlayer Jul 16, 2023
6b0faa1
remove SDL window creation in D3D9, let's see if this fixes things...
CasualPokePlayer Jul 16, 2023
4fdce66
bleh i hate this
CasualPokePlayer Jul 16, 2023
db9dffe
remove earlier crap, add in the proper fix for SDL bullshit
CasualPokePlayer Jul 16, 2023
11bd4db
test sdl init in FirstInitAll (it will be init again later on, but if…
CasualPokePlayer Jul 16, 2023
cac6a8d
flip Y axis for SDL game controllers
CasualPokePlayer Jul 17, 2023
d982b05
SDL2 rumble works fine so DirectInput gamepads are the only ones wher…
CasualPokePlayer Jul 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Assets/dll/OpenTK.dll.config

This file was deleted.

Binary file modified Assets/dll/SDL2.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/dll/Silk.NET.Core.dll.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<configuration>
<!-- Hack until https://github.com/dotnet/Silk.NET/commit/d5f1f295966c0790abc215ab6e900f810f464443 is in a NuGet release -->
<dllmap os="linux" dll="libdl" target="libdl.so.2"/>
</configuration>
Binary file added Assets/dll/libSDL2.so
Binary file not shown.
35 changes: 21 additions & 14 deletions BizHawk.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 16.0.28729.10
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Client.Common", "src\BizHawk.Client.Common\BizHawk.Client.Common.csproj", "{24A0AA3C-B25F-4197-B23D-476D6462DBA0}"
EndProject
Expand All @@ -20,11 +21,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Emulation", "Emulation", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Emulation.Cores", "src\BizHawk.Emulation.Cores\BizHawk.Emulation.Cores.csproj", "{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Bizware.BizwareGL", "src\BizHawk.Bizware.BizwareGL\BizHawk.Bizware.BizwareGL.csproj", "{9F84A0B2-861E-4EF4-B89B-5E2A3F38A465}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Bizware.Audio", "src\BizHawk.Bizware.Audio\BizHawk.Bizware.Audio.csproj", "{9F84A0B2-861E-4EF4-B89B-5E2A3F38A465}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Bizware.DirectX", "src\BizHawk.Bizware.DirectX\BizHawk.Bizware.DirectX.csproj", "{A914D063-9E4B-4086-B156-7B3F39E33DB2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Bizware.Input", "src\BizHawk.Bizware.Input\BizHawk.Bizware.Input.csproj", "{17E7D20D-198C-4728-ACEC-065DE834FF02}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Bizware.OpenTK3", "src\BizHawk.Bizware.OpenTK3\BizHawk.Bizware.OpenTK3.csproj", "{1FF433CC-96E1-4F14-B673-CDA7190169C9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Bizware.Graphics", "src\BizHawk.Bizware.Graphics\BizHawk.Bizware.Graphics.csproj", "{368BC91D-48CD-492A-B6CF-B5B77F7FE7D4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.Bizware.BizwareGL", "src\BizHawk.Bizware.BizwareGL\BizHawk.Bizware.BizwareGL.csproj", "{658BB7AA-74A1-496F-A6AA-B7D3DD9C7CBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BizHawk.BizInvoke", "src\BizHawk.BizInvoke\BizHawk.BizInvoke.csproj", "{E5D76DC1-84A8-47AF-BE25-E76F06D2FBBC}"
EndProject
Expand Down Expand Up @@ -72,14 +75,18 @@ Global
{9F84A0B2-861E-4EF4-B89B-5E2A3F38A465}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F84A0B2-861E-4EF4-B89B-5E2A3F38A465}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F84A0B2-861E-4EF4-B89B-5E2A3F38A465}.Release|Any CPU.Build.0 = Release|Any CPU
{A914D063-9E4B-4086-B156-7B3F39E33DB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A914D063-9E4B-4086-B156-7B3F39E33DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A914D063-9E4B-4086-B156-7B3F39E33DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A914D063-9E4B-4086-B156-7B3F39E33DB2}.Release|Any CPU.Build.0 = Release|Any CPU
{1FF433CC-96E1-4F14-B673-CDA7190169C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FF433CC-96E1-4F14-B673-CDA7190169C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FF433CC-96E1-4F14-B673-CDA7190169C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FF433CC-96E1-4F14-B673-CDA7190169C9}.Release|Any CPU.Build.0 = Release|Any CPU
{17E7D20D-198C-4728-ACEC-065DE834FF02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17E7D20D-198C-4728-ACEC-065DE834FF02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17E7D20D-198C-4728-ACEC-065DE834FF02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17E7D20D-198C-4728-ACEC-065DE834FF02}.Release|Any CPU.Build.0 = Release|Any CPU
{368BC91D-48CD-492A-B6CF-B5B77F7FE7D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{368BC91D-48CD-492A-B6CF-B5B77F7FE7D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{368BC91D-48CD-492A-B6CF-B5B77F7FE7D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{368BC91D-48CD-492A-B6CF-B5B77F7FE7D4}.Release|Any CPU.Build.0 = Release|Any CPU
{658BB7AA-74A1-496F-A6AA-B7D3DD9C7CBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{658BB7AA-74A1-496F-A6AA-B7D3DD9C7CBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{658BB7AA-74A1-496F-A6AA-B7D3DD9C7CBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{658BB7AA-74A1-496F-A6AA-B7D3DD9C7CBE}.Release|Any CPU.Build.0 = Release|Any CPU
{E5D76DC1-84A8-47AF-BE25-E76F06D2FBBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5D76DC1-84A8-47AF-BE25-E76F06D2FBBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5D76DC1-84A8-47AF-BE25-E76F06D2FBBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Binary file removed References/x64/SlimDX.dll
Binary file not shown.
19 changes: 19 additions & 0 deletions src/BizHawk.Bizware.Audio/BizHawk.Bizware.Audio.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Silk.NET.OpenAL" Version="2.17.1" />
<PackageReference Include="Silk.NET.OpenAL.Extensions.Creative" Version="2.17.1" />
<PackageReference Include="Silk.NET.OpenAL.Extensions.Enumeration" Version="2.17.1" />
<PackageReference Include="Vortice.MediaFoundation" Version="2.4.2" />
<PackageReference Include="Vortice.XAudio2" Version="2.4.2" />
<PackageReference Include="SharpDX.DirectSound" Version="4.2.0" />
<ProjectReference Include="$(ProjectDir)../BizHawk.Client.Common/BizHawk.Client.Common.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;

using BizHawk.Client.Common;

using SlimDX.DirectSound;
using SlimDX.Multimedia;
using SharpDX;
using SharpDX.DirectSound;
using SharpDX.Multimedia;

namespace BizHawk.Bizware.DirectX
namespace BizHawk.Bizware.Audio
{
public sealed class DirectSoundSoundOutput : ISoundOutput
{
Expand All @@ -27,8 +29,8 @@ public DirectSoundSoundOutput(IHostAudioManager sound, IntPtr mainWindowHandle,
_sound = sound;
_retryCounter = 5;

var deviceInfo = DirectSound.GetDevices().FirstOrDefault(d => d.Description == soundDevice);
_device = deviceInfo != null ? new DirectSound(deviceInfo.DriverGuid) : new DirectSound();
var deviceInfo = DirectSound.GetDevices().Find(d => d.Description == soundDevice);
_device = deviceInfo != null ? new(deviceInfo.DriverGuid) : new();
_device.SetCooperativeLevel(mainWindowHandle, CooperativeLevel.Priority);
}

Expand All @@ -53,31 +55,31 @@ public static IEnumerable<string> GetDeviceNames()

public int MaxSamplesDeficit { get; private set; }

private bool IsPlaying => _deviceBuffer != null && (_deviceBuffer.Status & BufferStatus.BufferLost) == 0 && (_deviceBuffer.Status & BufferStatus.Playing) == BufferStatus.Playing;
private bool IsPlaying => _deviceBuffer != null &&
((BufferStatus)_deviceBuffer.Status & BufferStatus.BufferLost) == 0 &&
((BufferStatus)_deviceBuffer.Status & BufferStatus.Playing) == BufferStatus.Playing;

private void StartPlaying()
{
_actualWriteOffsetBytes = -1;
_filledBufferSizeBytes = 0;
_lastWriteTime = 0;
_lastWriteCursor = 0;
int attempts = _retryCounter;
var attempts = _retryCounter;
while (!IsPlaying && attempts > 0)
{
attempts--;
try
{
if (_deviceBuffer == null)
{
var format = new WaveFormat
{
SamplesPerSecond = _sound.SampleRate,
BitsPerSample = (short) (_sound.BytesPerSample * 8),
Channels = (short) _sound.ChannelCount,
FormatTag = WaveFormatTag.Pcm,
BlockAlignment = (short) _sound.BlockAlign,
AverageBytesPerSecond = _sound.SampleRate * _sound.BlockAlign
};
var format = WaveFormat.CreateCustomFormat(
tag: WaveFormatEncoding.Pcm,
sampleRate: _sound.SampleRate,
channels: _sound.ChannelCount,
averageBytesPerSecond: _sound.SampleRate * _sound.BlockAlign,
blockAlign: _sound.BlockAlign,
bitsPerSample: _sound.BytesPerSample * 8);

var desc = new SoundBufferDescription
{
Expand All @@ -87,23 +89,20 @@ private void StartPlaying()
BufferFlags.Software |
BufferFlags.GetCurrentPosition2 |
BufferFlags.ControlVolume,
SizeInBytes = BufferSizeBytes
BufferBytes = BufferSizeBytes
};

_deviceBuffer = new SecondarySoundBuffer(_device, desc);
_deviceBuffer = new(_device, desc);
}

_deviceBuffer.Play(0, PlayFlags.Looping);
}
catch (DirectSoundException)
catch (SharpDXException)
{
if (_deviceBuffer != null)
{
_deviceBuffer.Restore();
}
_deviceBuffer?.Restore();
if (attempts > 0)
{
System.Threading.Thread.Sleep(10);
Thread.Sleep(10);
}
}
}
Expand All @@ -125,10 +124,10 @@ public void ApplyVolumeSettings(double volume)
try
{
// I'm not sure if this is "technically" correct but it works okay
int range = (int)Volume.Maximum - (int)Volume.Minimum;
_deviceBuffer.Volume = (int)(Math.Pow(volume, 0.1) * range) + (int)Volume.Minimum;
const int range = Volume.Maximum - Volume.Minimum;
_deviceBuffer.Volume = (int)(Math.Pow(volume, 0.1) * range) + Volume.Minimum;
}
catch (DirectSoundException)
catch (SharpDXException)
{
}
}
Expand All @@ -144,7 +143,7 @@ public void StartSound()
// severe glitches. At least on my Windows 8 machines, the distance between the
// play and write cursors can be up to 30 milliseconds, so that would be the
// absolute minimum we could use here.
int minBufferFullnessMs = Math.Min(35 + ((_sound.ConfigBufferSizeMs - 60) / 2), 65);
var minBufferFullnessMs = Math.Min(35 + (_sound.ConfigBufferSizeMs - 60) / 2, 65);
MaxSamplesDeficit = BufferSizeSamples - _sound.MillisecondsToSamples(minBufferFullnessMs);

StartPlaying();
Expand All @@ -158,32 +157,32 @@ public void StopSound()
{
_deviceBuffer.Stop();
}
catch (DirectSoundException)
catch (SharpDXException)
{
}
}

_deviceBuffer.Dispose();
_deviceBuffer = null;
BufferSizeSamples = 0;
}

public int CalculateSamplesNeeded()
{
int samplesNeeded = 0;
var samplesNeeded = 0;
if (IsPlaying)
{
try
{
long currentWriteTime = Stopwatch.GetTimestamp();
int playCursor = _deviceBuffer.CurrentPlayPosition;
int writeCursor = _deviceBuffer.CurrentWritePosition;
bool isInitializing = _actualWriteOffsetBytes == -1;
bool detectedUnderrun = false;
var currentWriteTime = Stopwatch.GetTimestamp();
_deviceBuffer.GetCurrentPosition(out var playCursor, out var writeCursor);
var isInitializing = _actualWriteOffsetBytes == -1;
var detectedUnderrun = false;
if (!isInitializing)
{
double elapsedSeconds = (currentWriteTime - _lastWriteTime) / (double)Stopwatch.Frequency;
double bufferSizeSeconds = (double) BufferSizeSamples / _sound.SampleRate;
int cursorDelta = CircularDistance(_lastWriteCursor, writeCursor, BufferSizeBytes);
var elapsedSeconds = (currentWriteTime - _lastWriteTime) / (double)Stopwatch.Frequency;
var bufferSizeSeconds = (double) BufferSizeSamples / _sound.SampleRate;
var cursorDelta = CircularDistance(_lastWriteCursor, writeCursor, BufferSizeBytes);
cursorDelta += BufferSizeBytes * (int) Math.Round((elapsedSeconds - (cursorDelta / (double) (_sound.SampleRate * _sound.BlockAlign))) / bufferSizeSeconds);
_filledBufferSizeBytes -= cursorDelta;
detectedUnderrun = _filledBufferSizeBytes < 0;
Expand All @@ -201,15 +200,15 @@ public int CalculateSamplesNeeded()
_lastWriteTime = currentWriteTime;
_lastWriteCursor = writeCursor;
}
catch (DirectSoundException)
catch (SharpDXException)
{
samplesNeeded = 0;
}
}
return samplesNeeded;
}

private int CircularDistance(int start, int end, int size)
private static int CircularDistance(int start, int end, int size)
{
return (end - start + size) % size;
}
Expand All @@ -227,18 +226,15 @@ public void WriteSamples(short[] samples, int sampleOffset, int sampleCount)
_actualWriteOffsetBytes = (_actualWriteOffsetBytes + (sampleCount * _sound.BlockAlign)) % BufferSizeBytes;
_filledBufferSizeBytes += sampleCount * _sound.BlockAlign;
}
catch (DirectSoundException)
catch (SharpDXException)
{
_deviceBuffer.Restore();
StartPlaying();
}
}
else
{
if (_deviceBuffer != null)
{
_deviceBuffer.Restore();
}
_deviceBuffer?.Restore();
StartPlaying();
}
}
Expand Down
Loading