added sleep functions for Lua to client module
This commit is contained in:
parent
b2584145d7
commit
598723266e
|
@ -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
|
||||
|
@ -472,5 +474,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue