Merge pull request #1536 from Ashafix/sleep

Added sleep functions for Lua to client module (resolves #1177)
This commit is contained in:
adelikat 2019-04-12 12:51:25 -05:00 committed by GitHub
commit 8132afec8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -7,6 +7,8 @@ using NLua;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using System.Threading;
using System.Diagnostics;
// ReSharper disable StringLiteralTypo
// ReSharper disable UnusedMember.Global
@ -474,5 +476,30 @@ namespace BizHawk.Client.EmuHawk
{
GlobalWin.MainForm.FlushSaveRAM();
}
[LuaMethodExample("client.sleep( 50 );")]
[LuaMethod("sleep", "sleeps for n milliseconds")]
public void Sleep(int millis)
{
Thread.Sleep(millis);
}
[LuaMethodExample("client.exactsleep( 50 );")]
[LuaMethod("exactsleep", "sleeps exactly for n milliseconds")]
public void ExactSleep(int millis)
{
Stopwatch stopwatch = Stopwatch.StartNew();
while (millis - stopwatch.ElapsedMilliseconds > 100)
{
Thread.Sleep(50);
}
while (true)
{
if (stopwatch.ElapsedMilliseconds >= millis)
{
break;
}
}
}
}
}