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

Prevent big messages #12

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion ScummVmBrowser/CLIScumm/ScummGameService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ ScummWeb::ScummService::Marshalling::ScummGameService::ScummGameService(IConfigu
soundOptions.restAudioTime = configureStore->GetValue<int>(SoundSettings::RestAudioTime);

NativeScummWrapperOptions nativeScummWrapperOptions;
nativeScummWrapperOptions.ScreenBufferCacheSize = configureStore->GetValue<int>(CliScummSettings::ScreenBufferCacheSize);
nativeScummWrapperOptions.screenBufferCacheSize = configureStore->GetValue<int>(CliScummSettings::ScreenBufferCacheSize);
nativeScummWrapperOptions.noBuffersBeforeWholeScreen = configureStore->GetValue<int>(CliScummSettings::NoBuffersBeforeWholeScreen);

_paletteManager = new NativeScummWrapperPaletteManager();
_graphics = new NativeScummWrapperGraphics(static_cast<f_SendScreenBuffers>(Marshal::GetFunctionPointerForDelegate(imageUpdated).ToPointer()), _paletteManager, nativeScummWrapperOptions);
Expand Down
7 changes: 6 additions & 1 deletion ScummVmBrowser/ChunkedSoundManager/SoundThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void ScummWeb::ScummService::Sound::SoundThreadManager::StartSound() {
//TODO: Log
}

std::chrono::milliseconds sleepAmount = std::chrono::milliseconds(_soundOptions.soundPollingFrequencyMs);
std::chrono::milliseconds sleepAmount = std::chrono::milliseconds(_soundOptions.soundPollingFrequencyMs);
if (_soundIsResting) {
WaitForSingleObject(_stopSoundMutex, INFINITE);
if (_soundIsResting) {
Expand All @@ -67,6 +67,11 @@ void ScummWeb::ScummService::Sound::SoundThreadManager::StartSound() {
ReleaseSemaphore(_stopSoundMutex, 1, NULL);
}

WaitForSingleObject(_stopSoundMutex, INFINITE);
sleepAmount = std::chrono::milliseconds(_soundOptions.restAudioTime);
_soundIsResting = false;
ReleaseSemaphore(_stopSoundMutex, 1, NULL);

std::this_thread::sleep_for(sleepAmount);
}
});
Expand Down
56 changes: 32 additions & 24 deletions ScummVmBrowser/DotNetScummTests/FrameCaptureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public abstract class FrameCaptureTests
public const string KingsQuest4OnMountain = "KingsQuest4OnMountain";
public const string KingsQuest6BeforeBeautySpeaks = "KingsQuest6BeforeBeautySpeaks";
public const string Kq5CanStart = "Kq5CanStart";
public const string SteelDoomed = "SteelDoomed";
public const string Kq3JustOutsideOffice = "Kq3JustOutsideOffice";

protected static ResourceManager ResourceManager = DotNetScummTests.Properties.Resources.ResourceManager;
private object _clearLock;

private int _noCaptured;

Bitmap _b;

Expand All @@ -68,6 +70,7 @@ protected FrameCaptureTests()
_screenBuffers = new Dictionary<string, byte[]>();
_screenBuffersAddOrder = new Queue<string>();
_configStore = new JsonConfigStore();
_noCaptured = 0;
}

protected void InitBitmapByGame(AvailableGames game)
Expand Down Expand Up @@ -160,6 +163,7 @@ public bool AssertThatExpectedFrameIsSeen(string expectedResourceName)
bool arePicturesEqual = ArePicturesEqual(expectedBitmap, actualBitmap);
expectedFrameFound = arePicturesEqual;
}
_capturedFrames = new ConcurrentQueue<Bitmap>();
return expectedFrameFound;
}
}
Expand All @@ -174,16 +178,23 @@ protected bool ArePicturesEqual(string expectedBitmapName, Bitmap actualBitmap)

private static bool ArePicturesEqual(Bitmap expectedBitmap, Bitmap actualBitmap)
{
bool frameCouldBeExpected = true;
for (int x = 0; x < actualBitmap.Size.Width && frameCouldBeExpected; x++)
float diff = 0;

for (int y = 0; y < expectedBitmap.Height; y++)
{
for (int y = 0; y < actualBitmap.Size.Height && frameCouldBeExpected; y++)
for (int x = 0; x < expectedBitmap.Width; x++)
{
frameCouldBeExpected = expectedBitmap.GetPixel(x, y) == actualBitmap.GetPixel(x, y);
Color pixel1 = expectedBitmap.GetPixel(x, y);
Color pixel2 = actualBitmap.GetPixel(x, y);

if(pixel1.R != pixel2.R || pixel1.G != pixel2.G || pixel1.B != pixel2.B)
{
diff++;
}
}
}

return frameCouldBeExpected;
return (diff / (expectedBitmap.Width * expectedBitmap.Height * 3)) * 100 <= 5;
}

protected async Task WaitForFrame(int frame)
Expand All @@ -204,7 +215,7 @@ protected async Task WaitAdditionalFrames(int additionalFrames, bool soundOff =
}
}

protected virtual void CaptureAndQuitWholeFrame(List<ScreenBuffer> screenBuffers, int noFrames, string expectedFrameName)
protected virtual void CaptureAndQuitWholeFrame(List<ScreenBuffer> screenBuffers, string expectedFrameName)
{
_b = new Bitmap(DisplayDefaultWidth, DisplayDefaultHeight);
screenBuffers.Where(b => b.PaletteBuffer != null).ToList().ForEach(b => UpdatePalettes(b.PaletteHash, b.PaletteBuffer));
Expand All @@ -219,14 +230,14 @@ protected virtual void CaptureAndQuitWholeFrame(List<ScreenBuffer> screenBuffers

}

CaptureAndQuit(_screenBuffers[screenBuffer.ScreenBufferHash], screenBuffer.IgnoreColour, screenBuffer.PaletteHash, screenBuffer.X, screenBuffer.Y, screenBuffer.W, screenBuffer.H, noFrames, expectedFrameName);
CaptureAndQuit(_screenBuffers[screenBuffer.ScreenBufferHash], screenBuffer.IgnoreColour, screenBuffer.PaletteHash, screenBuffer.X, screenBuffer.Y, screenBuffer.W, screenBuffer.H, expectedFrameName);
}
}

protected unsafe virtual void CaptureAndQuit(byte[] picBuff, int ignoreColour, UInt32 paletteHash, int x, int y, int w, int h, int noFrames, string expectedFrameName)
protected unsafe virtual void CaptureAndQuit(byte[] picBuff, int ignoreColour, UInt32 paletteHash, int x, int y, int w, int h, string expectedFrameName)
{
SetBitmapData(picBuff, _b, ignoreColour, paletteHash, x, y, w, h);
CaptureAndQuit(_b, noFrames, expectedFrameName);
CaptureAndQuit(_b, expectedFrameName);
}

protected unsafe void SetBitmapData(byte[] picBuff, Bitmap bitmap, int ignoreColour, uint paletteHash, int x, int y, int w, int h)
Expand Down Expand Up @@ -274,28 +285,23 @@ protected unsafe void SetBitmapData(byte[] picBuff, Bitmap bitmap, int ignoreCol
}
}

private void CaptureAndQuit(Bitmap bitmap, int noFrames, string expectedFrameName)
private void CaptureAndQuit(Bitmap bitmap, string expectedFrameName)
{
if (_capturedFrames.Count < noFrames)
{

if (saveEnabled)
{
if (Cropping != null)
{
bitmap = Crop(bitmap);
}
bitmap.Save($"C:\\temp\\First100\\{expectedFrameName}_{_capturedFrames.Count}.bmp");
bitmap.Save($"C:\\temp\\First100\\{expectedFrameName}_{_noCaptured}.bmp");
_noCaptured++;
}
CopyRectToQueue(bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), bitmap.PixelFormat));
}
else if (_capturedFrames.Count == noFrames && !hasSentQuit)
{
Quit();
hasSentQuit = true;
}

}

protected void CaptureAndQuit(List<ScreenBuffer> screenBuffers, int noFrames, string expectedFrameName)
protected void CaptureAndQuit(List<ScreenBuffer> screenBuffers, string expectedFrameName)
{
screenBuffers.Where(b => b.PaletteBuffer != null).ToList().ForEach(b => UpdatePalettes(b.PaletteHash, b.PaletteBuffer));

Expand All @@ -319,7 +325,7 @@ protected void CaptureAndQuit(List<ScreenBuffer> screenBuffers, int noFrames, st
Assert.IsTrue(screenBuffer.PictureBuffer == null || screenBuffer.PictureBuffer.Length == 0);
}

CaptureAndQuit(_screenBuffers[screenBuffer.ScreenBufferHash], screenBuffer.IgnoreColour, screenBuffer.PaletteHash, screenBuffer.X, screenBuffer.Y, screenBuffer.W, screenBuffer.H, noFrames, expectedFrameName);
CaptureAndQuit(_screenBuffers[screenBuffer.ScreenBufferHash], screenBuffer.IgnoreColour, screenBuffer.PaletteHash, screenBuffer.X, screenBuffer.Y, screenBuffer.W, screenBuffer.H, expectedFrameName);
}
}

Expand Down Expand Up @@ -396,7 +402,7 @@ public void CopyRectToQueue(Bitmap bitmap)
}
}

protected virtual async Task WaitForExpectedFrameAndQuit(string expectedFrameName, int noFrames, Task completeWhenQuit, int delay = 240000, int quitDelay = 240000)
protected virtual async Task WaitForExpectedFrameAndQuit(string expectedFrameName, Task completeWhenQuit, int delay = 240000, int quitDelay = 240000)
{
Task checkForFrame = Task.Run(async () =>
{
Expand All @@ -410,14 +416,16 @@ protected virtual async Task WaitForExpectedFrameAndQuit(string expectedFrameNam

if (!checkForFrame.IsCompleted)
{
throw new Exception($"Did not display first {noFrames} frames in time");
throw new Exception($"Did not display first frames in time");
}

if (checkForFrame.IsFaulted)
{
throw checkForFrame.Exception;
}

Quit();

await Task.WhenAny(completeWhenQuit, Task.Delay(quitDelay));

if (!completeWhenQuit.IsCompleted)
Expand Down
18 changes: 18 additions & 0 deletions ScummVmBrowser/DotNetScummTests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading