Merge pull request #1536 from Ashafix/sleep
Added sleep functions for Lua to client module (resolves #1177)
This commit is contained in:
commit
8132afec8b
|
@ -7,6 +7,8 @@ using NLua;
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
// ReSharper disable StringLiteralTypo
|
// ReSharper disable StringLiteralTypo
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
@ -474,5 +476,30 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
GlobalWin.MainForm.FlushSaveRAM();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue