getobjectをネイティブ実行でも利用可能にした
このコミットが含まれているのは:
6ファイル変更
+163
-17
検索条件に一致するファイルはありません
@@ -41,6 +41,7 @@ namespace LuaScript.Engine
|
||||
int width,
|
||||
int height,
|
||||
int timeoutMs,
|
||||
Func<string, int, SceneObjectInfo?> resolveObject,
|
||||
out bool pixelsDirty,
|
||||
out string? error)
|
||||
{
|
||||
@@ -70,14 +71,26 @@ namespace LuaScript.Engine
|
||||
|
||||
_workEvent!.Set();
|
||||
|
||||
if (!_doneEvent!.WaitOne(timeoutMs))
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
int status;
|
||||
while (true)
|
||||
{
|
||||
KillWorker();
|
||||
error = "native script execution timed out";
|
||||
return false;
|
||||
long remaining = timeoutMs - stopwatch.ElapsedMilliseconds;
|
||||
if (remaining <= 0 || !_doneEvent!.WaitOne((int)remaining))
|
||||
{
|
||||
KillWorker();
|
||||
error = "native script execution timed out";
|
||||
return false;
|
||||
}
|
||||
|
||||
status = view.ReadInt32(NativeProtocol.OffStatus);
|
||||
if (status != NativeProtocol.StatusCallback)
|
||||
break;
|
||||
|
||||
ResolveCallback(view, resolveObject);
|
||||
_workEvent.Set();
|
||||
}
|
||||
|
||||
int status = view.ReadInt32(NativeProtocol.OffStatus);
|
||||
if (status == NativeProtocol.StatusError)
|
||||
{
|
||||
int len = view.ReadInt32(NativeProtocol.OffErrorLen);
|
||||
@@ -97,6 +110,37 @@ namespace LuaScript.Engine
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ResolveCallback(MemoryMappedViewAccessor view, Func<string, int, SceneObjectInfo?> resolveObject)
|
||||
{
|
||||
int frame = view.ReadInt32(NativeProtocol.OffCallbackFrame);
|
||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||
var tagBytes = new byte[tagLen];
|
||||
view.ReadArray(NativeProtocol.CallbackTagOffset, tagBytes, 0, tagLen);
|
||||
string tag = Encoding.UTF8.GetString(tagBytes);
|
||||
|
||||
SceneObjectInfo? info;
|
||||
try { info = resolveObject(tag, frame); }
|
||||
catch { info = null; }
|
||||
|
||||
if (info is { } value)
|
||||
{
|
||||
long result = NativeProtocol.CallbackResultOffset;
|
||||
view.Write(result + NativeProtocol.CbExist * 8, value.Exist ? 1d : 0d);
|
||||
view.Write(result + NativeProtocol.CbX * 8, value.X);
|
||||
view.Write(result + NativeProtocol.CbY * 8, value.Y);
|
||||
view.Write(result + NativeProtocol.CbZ * 8, value.Z);
|
||||
view.Write(result + NativeProtocol.CbZoom * 8, value.Zoom);
|
||||
view.Write(result + NativeProtocol.CbRz * 8, value.Rz);
|
||||
view.Write(result + NativeProtocol.CbAlpha * 8, value.Alpha);
|
||||
view.Write(result + NativeProtocol.CbLayer * 8, (double)value.Layer);
|
||||
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.Write(NativeProtocol.OffCallbackFound, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureWorker(int width, int height)
|
||||
{
|
||||
if (_alive && _process is { HasExited: false } && _width == width && _height == height)
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace LuaScript.Engine
|
||||
public const int StatusIdle = 0;
|
||||
public const int StatusOk = 1;
|
||||
public const int StatusError = 2;
|
||||
public const int StatusCallback = 3;
|
||||
|
||||
public const int OffMagic = 0;
|
||||
public const int OffCommand = 4;
|
||||
@@ -19,6 +20,9 @@ namespace LuaScript.Engine
|
||||
public const int OffScriptLen = 20;
|
||||
public const int OffPixelsDirty = 24;
|
||||
public const int OffErrorLen = 28;
|
||||
public const int OffCallbackFrame = 32;
|
||||
public const int OffCallbackTagLen = 36;
|
||||
public const int OffCallbackFound = 40;
|
||||
|
||||
public const int HeaderSize = 64;
|
||||
|
||||
@@ -31,7 +35,21 @@ namespace LuaScript.Engine
|
||||
public const int ErrorOffset = ScriptOffset + ScriptMax;
|
||||
public const int ErrorMax = 4 * 1024;
|
||||
|
||||
public const int PixelOffset = ErrorOffset + ErrorMax;
|
||||
public const int CallbackTagOffset = ErrorOffset + ErrorMax;
|
||||
public const int CallbackTagMax = 256;
|
||||
public const int CallbackResultOffset = CallbackTagOffset + CallbackTagMax;
|
||||
public const int CallbackResultCount = 8;
|
||||
|
||||
public const int CbExist = 0;
|
||||
public const int CbX = 1;
|
||||
public const int CbY = 2;
|
||||
public const int CbZ = 3;
|
||||
public const int CbZoom = 4;
|
||||
public const int CbRz = 5;
|
||||
public const int CbAlpha = 6;
|
||||
public const int CbLayer = 7;
|
||||
|
||||
public const int PixelOffset = CallbackResultOffset + CallbackResultCount * 8;
|
||||
|
||||
public const int W = 0;
|
||||
public const int H = 1;
|
||||
|
||||
@@ -365,7 +365,9 @@ namespace LuaScript
|
||||
byte[] buffer = LoadInputPixels(bounds, imgW, imgH);
|
||||
|
||||
bool ok = _nativeWorker.Execute(
|
||||
script, _nativeFields, buffer, imgW, imgH, NativeTimeoutMilliseconds, out bool dirty, out string? error);
|
||||
script, _nativeFields, buffer, imgW, imgH, NativeTimeoutMilliseconds,
|
||||
(tag, frame) => ctx.ResolveObject(tag, frame, out var info) ? info : null,
|
||||
out bool dirty, out string? error);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする