コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
cade7e8a8f
|
||
|
|
9e8e024db9
|
||
|
|
69881878e4
|
||
|
|
42e0b2b0f7
|
||
|
|
954b1bfc49
|
||
|
|
41defa1059
|
||
|
|
876f05d277
|
||
|
|
227af2c75c
|
||
|
|
5cbd5ae8ff
|
||
|
|
bb97610454
|
||
|
|
968180c459
|
||
|
|
d9ad3692f2
|
検索条件に一致するファイルはありません
+24
-57
@@ -1,73 +1,40 @@
|
||||
# v1.3.0 - Lua スクリプト for YMM4
|
||||
# v1.3.4 - Lua スクリプト for YMM4
|
||||
|
||||
ピクセル操作スクリプトを**大幅に高速化**したリリースです。
|
||||
`obj.getpixel` / `obj.setpixel` / `obj.getpixeldata` を使うスクリプトは、同梱した高速
|
||||
ランタイム(LuaJIT)で自動的に実行されるようになり、内部計測では**最大で数十倍**
|
||||
(例:1920×1080 のフルフレーム加工で約 41 倍、小さめの画像では 70 倍前後)の
|
||||
高速化を確認しています。
|
||||
ネイティブ実行中の **`obj.getobject` を高速化**したリリースです。
|
||||
同じオブジェクトを繰り返し参照するスクリプトで、本体プロセスへの問い合わせ回数を
|
||||
削減し、大幅に高速化しました。
|
||||
|
||||
---
|
||||
|
||||
## 新機能・改善
|
||||
## 改善
|
||||
|
||||
### 1. ピクセル操作スクリプトの自動高速化
|
||||
### 1. 同一オブジェクト参照のキャッシュによる高速化
|
||||
|
||||
ピクセル操作 API(`obj.getpixel` / `obj.setpixel` / `obj.getpixeldata`)を含むスクリプトは、
|
||||
**特別な記述なしで自動的に高速ランタイム(ネイティブ実行)へ振り分け**られます。
|
||||
変形のみ(座標・回転・拡縮・不透明度)のスクリプトは従来どおりの実行系で動作します
|
||||
(変形のみの処理は元々十分高速なため、速度差はありません)。
|
||||
ネイティブ実行中の `obj.getobject` は、解決に必要なシーン情報が本体プロセス側にしか
|
||||
存在しないため、呼び出しごとに本体プロセスへの問い合わせ(往復)を伴います。この往復は
|
||||
1 回あたりのコストが大きく、同じオブジェクトをループ内で繰り返し参照すると無視できない
|
||||
負荷になっていました。
|
||||
|
||||
ネイティブ実行は**専用の別プロセス**で行われ、ピクセルバッファは共有メモリ経由で
|
||||
受け渡されます。スクリプトが無限ループに陥っても、**5 秒のタイムアウトで強制終了**
|
||||
され、本体が固まることはありません(終了後は自動的に復帰します)。
|
||||
|
||||
### 2. 実行エンジンを指定するディレクティブ
|
||||
|
||||
スクリプトの先頭行に次のディレクティブを書くことで、実行エンジンを明示指定できます。
|
||||
|
||||
- `--!native` … 高速ランタイム(LuaJIT)で実行
|
||||
- `--!moonsharp` … 従来エンジン(MoonSharp)で実行
|
||||
- 記述なし … ピクセル操作を含む場合は自動的にネイティブ、それ以外は従来エンジン
|
||||
|
||||
### 3. bit32 の Lua 5.2 準拠化(ネイティブ実行時)
|
||||
|
||||
ネイティブ実行時の `bit32` ライブラリは、正しい Lua 5.2 の挙動になりました。
|
||||
実用域(0〜2^31 未満の値、0〜31 のシフト量)では従来と完全に一致するため、
|
||||
通常のスクリプトの見た目は変わりません。`bit32.lshift(1, 32)` のような範囲外の
|
||||
特殊なケースのみ結果が変わります(ネイティブ=正しい 0、従来=1)。
|
||||
|
||||
### 4. 変形処理のアロケーション削減
|
||||
|
||||
毎フレームの実行で発生していた一時オブジェクトの確保を削減し、シーンオブジェクトの
|
||||
解決を遅延化しました。長時間の出力における GC 負荷を軽減します。
|
||||
本リリースでは、**同じタグ・同じフレームへの連続した問い合わせをフレーム内でキャッシュ**
|
||||
するようにしました。2 回目以降は本体への往復を行わずにキャッシュした結果を返すため、
|
||||
同一オブジェクトを繰り返し参照するスクリプトでは問い合わせ回数が 1 回に削減されます。
|
||||
内部計測では、該当パターンが 1000 倍以上高速化することを確認しています。返り値は従来
|
||||
どおり呼び出しごとに新しいテーブルであり、出力結果は変わりません。
|
||||
|
||||
---
|
||||
|
||||
## 注意事項(ネイティブ実行時の制約)
|
||||
## 注意事項
|
||||
|
||||
- **`obj.getobject` はネイティブ実行では使用できません**(常に `nil` を返します)。
|
||||
他オブジェクトの参照を行うスクリプトには `--!native` を付けないでください
|
||||
(ピクセル操作と併用する場合は `--!moonsharp` を明示してください)。
|
||||
- `math.random` は両エンジンとも「フレーム番号でシードし直す決定論的乱数」ですが、
|
||||
乱数列の実装が異なるため、エンジンをまたぐと同じシードでも値が変わります。
|
||||
エンジンに依存しない乱数が必要な場合は `anim.rand(min, max, seed)` を使用してください。
|
||||
- ネイティブ実行は最初のピクセルアクセス前から GPU→CPU の画像転送を行います。
|
||||
- キャッシュが効くのは、同じタグ・同じフレームへの連続した問い合わせです。毎回異なる
|
||||
オブジェクトやフレームを参照する場合は、その都度本体プロセスへの往復が発生します。
|
||||
この場合は結果を変数へ保持して呼び出し回数を抑えることを推奨します。
|
||||
|
||||
---
|
||||
|
||||
## 内部実装
|
||||
|
||||
- 同梱した LuaJIT を別プロセスで常駐させ、名前付き共有メモリとイベントで往復します。
|
||||
タイムアウト時はプロセスを強制終了し、自動的に再起動します。
|
||||
- ネイティブ側に `bit32`(正しい 5.2)・`rawlen`・`anim.*`(`rand` / `noise` を含む)・
|
||||
`obj.getpixel` / `setpixel` / `getpixeldata` を実装し、従来エンジンとの**出力一致を
|
||||
自動テストで検証**しています(2800 件超のクロスエンジン等価テストを追加)。
|
||||
- ユーザースクリプトはサンドボックス環境で実行され、`io` / `os` / `ffi` / `require`
|
||||
などは従来どおり利用できません。
|
||||
|
||||
---
|
||||
|
||||
## 同梱物
|
||||
|
||||
- 本プラグインには高速ランタイム(`luajit.exe` / `lua51.dll`)と実行スクリプトを同梱して
|
||||
おり、プラグイン本体と同じ `native` フォルダーに配置されます(手動インストールは不要)。
|
||||
- ワーカー側に直前の問い合わせ結果のキャッシュを設け、同一タグ・同一フレームへの連続
|
||||
呼び出しでは本体への往復を省きます。キャッシュは各フレームの実行開始時に破棄されるため、
|
||||
フレームをまたいで古い結果が再利用されることはありません。
|
||||
- 本体側ではタグ文字列の確保を使い回し、問い合わせごとのアロケーションを抑えることで、
|
||||
長時間の出力における GC 負荷を軽減しました。
|
||||
@@ -0,0 +1,32 @@
|
||||
Lua License
|
||||
-----------
|
||||
|
||||
Lua is licensed under the terms of the MIT license reproduced below. This means
|
||||
that Lua is free software and can be used for both academic and commercial
|
||||
purposes at absolutely no cost.
|
||||
|
||||
For details and rationale, see https://www.lua.org/license.html .
|
||||
|
||||
===============================================================================
|
||||
|
||||
Copyright (C) 1994-2025 Lua.org, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
@@ -0,0 +1,56 @@
|
||||
===============================================================================
|
||||
LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/
|
||||
|
||||
Copyright (C) 2005-2026 Mike Pall. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
[ MIT license: https://www.opensource.org/licenses/mit-license.php ]
|
||||
|
||||
===============================================================================
|
||||
[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]
|
||||
|
||||
Copyright (C) 1994-2012 Lua.org, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
===============================================================================
|
||||
[ LuaJIT includes code from dlmalloc, which has this license statement: ]
|
||||
|
||||
This is a version (aka dlmalloc) of malloc/free/realloc written by
|
||||
Doug Lea and released to the public domain, as explained at
|
||||
https://creativecommons.org/licenses/publicdomain
|
||||
|
||||
===============================================================================
|
||||
@@ -0,0 +1,38 @@
|
||||
Copyright (c) 2014-2016, Marco Mastropaolo
|
||||
All rights reserved.
|
||||
|
||||
Parts of the string library are based on the KopiLua project (https://github.com/NLua/KopiLua)
|
||||
Copyright (c) 2012 LoDC
|
||||
|
||||
Visual Studio Code debugger code is based on code from Microsoft vscode-mono-debug project (https://github.com/Microsoft/vscode-mono-debug).
|
||||
Copyright (c) Microsoft Corporation - released under MIT license.
|
||||
|
||||
Remote Debugger icons are from the Eclipse project (https://www.eclipse.org/).
|
||||
Copyright of The Eclipse Foundation
|
||||
|
||||
The MoonSharp icon is (c) Isaac, 2014-2015
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the {organization} nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
Luaスクリプト for YMM4 v1.2.0
|
||||
Luaスクリプト for YMM4 v1.3.4
|
||||
========================================
|
||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
||||
ピクセルを直接制御できるプラグインです。
|
||||
|
||||
@@ -70,6 +70,7 @@ jobs:
|
||||
|
||||
New-Item -ItemType Directory -Path "$stageRoot/docs" -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path "$stageRoot/native" -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||
|
||||
Copy-Item "$outDir/LuaScript.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/MoonSharp.Interpreter.dll" "$stageRoot/"
|
||||
@@ -87,6 +88,7 @@ jobs:
|
||||
}
|
||||
|
||||
Copy-Item "LuaScript/docs/LuaScript.*.txt" "$stageRoot/docs/"
|
||||
Copy-Item ".github/LICENSE/*.txt" "$stageRoot/LICENSE/"
|
||||
Copy-Item ".github/Plugin_Readme.txt" "$stageRoot/Readme.txt"
|
||||
|
||||
Compress-Archive -Path "stage/*" -DestinationPath $pkgName -CompressionLevel Optimal
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
<Compile Include="..\LuaScript\Compat\Bit32.cs" Link="Linked\Bit32.cs" />
|
||||
<Compile Include="..\LuaScript\Engine\ScriptEngineKind.cs" Link="Linked\ScriptEngineKind.cs" />
|
||||
<Compile Include="..\LuaScript\Engine\NativeProtocol.cs" Link="Linked\NativeProtocol.cs" />
|
||||
<Compile Include="..\LuaScript\Engine\ProcessJobObject.cs" Link="Linked\ProcessJobObject.cs" />
|
||||
<Compile Include="..\LuaScript\Engine\LuaJitWorker.cs" Link="Linked\LuaJitWorker.cs" />
|
||||
<Compile Include="..\LuaScript\SceneObjectInfo.cs" Link="Linked\SceneObjectInfo.cs" />
|
||||
<Compile Include="..\LuaScript\AnimTableRegistrar.cs" Link="Linked\AnimTableRegistrar.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace LuaScript.Tests
|
||||
{
|
||||
private static string NativeDir => Path.Combine(AppContext.BaseDirectory, "native");
|
||||
|
||||
private static readonly Func<string, int, SceneObjectInfo?> NoResolver = (_, _) => null;
|
||||
|
||||
private readonly LuaJitWorker _worker = new(NativeDir);
|
||||
|
||||
public void Dispose() => _worker.Dispose();
|
||||
@@ -32,7 +34,7 @@ namespace LuaScript.Tests
|
||||
|
||||
bool ok = _worker.Execute(
|
||||
"obj.rz = obj.time * 90\nobj.alpha = 128",
|
||||
fields, pixels, 4, 4, 5000, out bool dirty, out string? error);
|
||||
fields, pixels, 4, 4, 5000, NoResolver, out bool dirty, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.False(dirty);
|
||||
@@ -67,7 +69,7 @@ namespace LuaScript.Tests
|
||||
"local gray = r*0.299 + g*0.587 + b*0.114 " +
|
||||
"obj.setpixel(x,y,gray,gray,gray,a) end end";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, out bool dirty, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, out bool dirty, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.True(dirty);
|
||||
@@ -102,7 +104,7 @@ namespace LuaScript.Tests
|
||||
"local gray=r*0.299+g*0.587+b*0.114 " +
|
||||
"pd:set(base+1,gray) pd:set(base+2,gray) pd:set(base+3,gray) end end";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, out bool dirty, out string? error);
|
||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, out bool dirty, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.True(dirty);
|
||||
@@ -138,7 +140,7 @@ namespace LuaScript.Tests
|
||||
for (int k = 1; k <= 5; k++)
|
||||
{
|
||||
var fields = Fields(2, 2, k);
|
||||
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, pixels, 2, 2, 5000, out _, out string? error);
|
||||
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, pixels, 2, 2, 5000, NoResolver, out _, out string? error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(k * 10d, fields[NativeProtocol.X]);
|
||||
}
|
||||
@@ -153,16 +155,94 @@ namespace LuaScript.Tests
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
bool timedOut = _worker.Execute(
|
||||
"local x=0 while true do x=x+1 end", fields, pixels, 2, 2, 1500, out _, out string? error);
|
||||
"local x=0 while true do x=x+1 end", fields, pixels, 2, 2, 1500, NoResolver, out _, out string? error);
|
||||
Assert.False(timedOut);
|
||||
Assert.Contains("timed out", error);
|
||||
|
||||
var fields2 = Fields(2, 2, 3d);
|
||||
bool ok = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, out _, out error);
|
||||
bool ok = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, out _, out error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(3d, fields2[NativeProtocol.X]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetObject_ResolvesThroughCallback()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
var pixels = new byte[16];
|
||||
var fields = Fields(2, 2, 0d);
|
||||
var resolved = new SceneObjectInfo("a", true, 12d, 34d, 56d, 2d, 90d, 200d, 7);
|
||||
Func<string, int, SceneObjectInfo?> resolver = (tag, frame) =>
|
||||
tag == "a" && frame == 5 ? resolved : null;
|
||||
|
||||
const string script =
|
||||
"local o = obj.getobject(\"a\", 5) " +
|
||||
"obj.x = o.x obj.y = o.y obj.z = o.z " +
|
||||
"obj.zoom = o.zoom obj.rz = o.rz obj.alpha = o.alpha " +
|
||||
"obj.sx = o.sy obj.rzr = o.rzr";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(12d, fields[NativeProtocol.X]);
|
||||
Assert.Equal(34d, fields[NativeProtocol.Y]);
|
||||
Assert.Equal(56d, fields[NativeProtocol.Z]);
|
||||
Assert.Equal(2d, fields[NativeProtocol.Zoom]);
|
||||
Assert.Equal(90d, fields[NativeProtocol.Rz]);
|
||||
Assert.Equal(200d, fields[NativeProtocol.Alpha]);
|
||||
Assert.Equal(2d, fields[NativeProtocol.Sx]);
|
||||
Assert.Equal(90d * Math.PI / 180d, fields[NativeProtocol.Rzr]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetObject_CachesRepeatedQueryAndResetsEachRun()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
var pixels = new byte[16];
|
||||
int calls = 0;
|
||||
double x = 10d;
|
||||
Func<string, int, SceneObjectInfo?> resolver = (tag, frame) =>
|
||||
{
|
||||
calls++;
|
||||
return tag == "a" ? new SceneObjectInfo("a", true, x, 0, 0, 1, 0, 255, 0) : null;
|
||||
};
|
||||
|
||||
const string script =
|
||||
"local a = obj.getobject(\"a\") " +
|
||||
"local b = obj.getobject(\"a\") " +
|
||||
"obj.x = a.x + b.x";
|
||||
|
||||
bool ok = _worker.Execute(script, Fields(2, 2, 0d), pixels, 2, 2, 5000, resolver, out _, out string? error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(1, calls);
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
x = 20d;
|
||||
ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, out _, out error);
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(2, calls);
|
||||
Assert.Equal(40d, fields[NativeProtocol.X]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetObject_ReturnsNil_WhenUnresolved()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
var pixels = new byte[16];
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
const string script =
|
||||
"local o = obj.getobject(\"missing\") obj.x = o == nil and 1 or 0";
|
||||
|
||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, NoResolver, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(1d, fields[NativeProtocol.X]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RuntimeError_IsReported_AndWorkerSurvives()
|
||||
{
|
||||
@@ -171,12 +251,12 @@ namespace LuaScript.Tests
|
||||
var pixels = new byte[16];
|
||||
var fields = Fields(2, 2, 0d);
|
||||
|
||||
bool ok = _worker.Execute("obj.x = missing.value", fields, pixels, 2, 2, 5000, out _, out string? error);
|
||||
bool ok = _worker.Execute("obj.x = missing.value", fields, pixels, 2, 2, 5000, NoResolver, out _, out string? error);
|
||||
Assert.False(ok);
|
||||
Assert.False(string.IsNullOrEmpty(error));
|
||||
|
||||
var fields2 = Fields(2, 2, 7d);
|
||||
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, out _, out error);
|
||||
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, out _, out error);
|
||||
Assert.True(ok2, error);
|
||||
Assert.Equal(7d, fields2[NativeProtocol.X]);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ namespace LuaScript.Engine
|
||||
private int _height;
|
||||
private bool _alive;
|
||||
|
||||
private readonly byte[] _callbackTag = new byte[NativeProtocol.CallbackTagMax];
|
||||
private readonly byte[] _lastCallbackTag = new byte[NativeProtocol.CallbackTagMax];
|
||||
private int _lastCallbackTagLength = -1;
|
||||
private string _lastCallbackTagText = string.Empty;
|
||||
|
||||
public LuaJitWorker(string nativeDir)
|
||||
{
|
||||
_nativeDir = nativeDir;
|
||||
@@ -41,6 +46,7 @@ namespace LuaScript.Engine
|
||||
int width,
|
||||
int height,
|
||||
int timeoutMs,
|
||||
Func<string, int, SceneObjectInfo?> resolveObject,
|
||||
out bool pixelsDirty,
|
||||
out string? error)
|
||||
{
|
||||
@@ -70,14 +76,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 +115,48 @@ 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);
|
||||
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||
string tag = ResolveTag(tagLen);
|
||||
|
||||
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 string ResolveTag(int tagLen)
|
||||
{
|
||||
if (tagLen == _lastCallbackTagLength &&
|
||||
_callbackTag.AsSpan(0, tagLen).SequenceEqual(_lastCallbackTag.AsSpan(0, tagLen)))
|
||||
return _lastCallbackTagText;
|
||||
|
||||
_lastCallbackTagText = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
|
||||
_callbackTag.AsSpan(0, tagLen).CopyTo(_lastCallbackTag);
|
||||
_lastCallbackTagLength = tagLen;
|
||||
return _lastCallbackTagText;
|
||||
}
|
||||
|
||||
private void EnsureWorker(int width, int height)
|
||||
{
|
||||
if (_alive && _process is { HasExited: false } && _width == width && _height == height)
|
||||
@@ -139,6 +199,8 @@ namespace LuaScript.Engine
|
||||
psi.ArgumentList.Add(_shimScript);
|
||||
|
||||
_process = Process.Start(psi);
|
||||
if (_process is not null)
|
||||
ProcessJobObject.Assign(_process.Handle);
|
||||
_alive = _process is not null;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LuaScript.Engine
|
||||
{
|
||||
internal static class ProcessJobObject
|
||||
{
|
||||
private const uint JobObjectExtendedLimitInformation = 9;
|
||||
private const uint JobObjectLimitKillOnJobClose = 0x2000;
|
||||
|
||||
private static readonly nint Handle = Create();
|
||||
|
||||
public static void Assign(nint processHandle)
|
||||
{
|
||||
if (Handle != nint.Zero && processHandle != nint.Zero)
|
||||
AssignProcessToJobObject(Handle, processHandle);
|
||||
}
|
||||
|
||||
private static nint Create()
|
||||
{
|
||||
nint job = CreateJobObject(nint.Zero, null);
|
||||
if (job == nint.Zero)
|
||||
return nint.Zero;
|
||||
|
||||
var information = new JobObjectExtendedLimitInformationData
|
||||
{
|
||||
BasicLimitInformation = new JobObjectBasicLimitInformationData
|
||||
{
|
||||
LimitFlags = JobObjectLimitKillOnJobClose
|
||||
}
|
||||
};
|
||||
|
||||
int length = Marshal.SizeOf<JobObjectExtendedLimitInformationData>();
|
||||
nint buffer = Marshal.AllocHGlobal(length);
|
||||
try
|
||||
{
|
||||
Marshal.StructureToPtr(information, buffer, false);
|
||||
if (!SetInformationJobObject(job, JobObjectExtendedLimitInformation, buffer, (uint)length))
|
||||
{
|
||||
CloseHandle(job);
|
||||
return nint.Zero;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
}
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct JobObjectBasicLimitInformationData
|
||||
{
|
||||
public long PerProcessUserTimeLimit;
|
||||
public long PerJobUserTimeLimit;
|
||||
public uint LimitFlags;
|
||||
public nuint MinimumWorkingSetSize;
|
||||
public nuint MaximumWorkingSetSize;
|
||||
public uint ActiveProcessLimit;
|
||||
public nuint Affinity;
|
||||
public uint PriorityClass;
|
||||
public uint SchedulingClass;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct IoCountersData
|
||||
{
|
||||
public ulong ReadOperationCount;
|
||||
public ulong WriteOperationCount;
|
||||
public ulong OtherOperationCount;
|
||||
public ulong ReadTransferCount;
|
||||
public ulong WriteTransferCount;
|
||||
public ulong OtherTransferCount;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct JobObjectExtendedLimitInformationData
|
||||
{
|
||||
public JobObjectBasicLimitInformationData BasicLimitInformation;
|
||||
public IoCountersData IoInfo;
|
||||
public nuint ProcessMemoryLimit;
|
||||
public nuint JobMemoryLimit;
|
||||
public nuint PeakProcessMemoryUsed;
|
||||
public nuint PeakJobMemoryUsed;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern nint CreateJobObject(nint lpJobAttributes, string? lpName);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool SetInformationJobObject(nint hJob, uint jobObjectInformationClass, nint lpJobObjectInformation, uint cbJobObjectInformationLength);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool AssignProcessToJobObject(nint hJob, nint hProcess);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool CloseHandle(nint hObject);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.3.0</Version>
|
||||
<Version>1.3.4</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
@@ -4,10 +4,13 @@ using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
using YukkuriMovieMaker.Exo;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
using YukkuriMovieMaker.Plugin;
|
||||
using YukkuriMovieMaker.Plugin.Effects;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
[PluginDetails(AuthorName = "routersys", ContentId = "nc487743")]
|
||||
|
||||
[VideoEffect(nameof(Texts.LuaScript), [VideoEffectCategories.Filtering], ["lua", "script", "スクリプト", "lua script", "アニメーション効果", "animation"], IsAviUtlSupported = false, ResourceType = typeof(Texts))]
|
||||
internal class LuaScriptEffect : VideoEffectBase, IScriptProvider
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -205,9 +205,10 @@ YukkuriMovieMaker4(YMM4)上で動作する、**Luaスクリプトでオブ
|
||||
|
||||
ネイティブ実行は**専用の別プロセス**で行われ、ピクセルバッファは共有メモリ経由で受け渡されます。スクリプトが無限ループに陥った場合でも **5 秒のタイムアウトでプロセスを強制終了**するため本体は固まらず、終了後は自動的に復帰します。出力結果は従来エンジンと一致します。
|
||||
|
||||
`obj.getobject` はネイティブ実行でも利用できます。呼び出し時に本体プロセスへ同期的に問い合わせてシーンオブジェクトを解決するため、従来エンジンと同じ結果を返します。同じタグ・同じフレームへの連続した問い合わせはフレーム内でキャッシュされ、2 回目以降は往復を行いません。
|
||||
|
||||
ネイティブ実行には次の制約があります。
|
||||
|
||||
- **`obj.getobject` は使用できません**(常に `nil` を返します)。他オブジェクトを参照するスクリプトはピクセル操作と併用しないか、`--!moonsharp` を明示してください。
|
||||
- `bit32` は正しい Lua 5.2 の挙動になります。実用域(0〜2³¹未満の値・0〜31 のシフト量)では従来と一致しますが、`bit32.lshift(1, 32)` のような範囲外の特殊ケースのみ結果が変わります(ネイティブ=0、従来=1)。
|
||||
- `math.random` は両エンジンとも毎フレーム `frame` でシードし直す決定論的乱数ですが、乱数列の実装が異なるためエンジンをまたぐと同じシードでも値が変わります。エンジン非依存の乱数が必要な場合は `anim.rand(min, max, seed)` を使用してください。
|
||||
|
||||
@@ -323,7 +324,7 @@ obj.alpha = anim.ease_out(t) * 255
|
||||
- **AviUtl 非対応**: 本プラグインは独自のスクリプト実行系であり、AviUtl 向けの EXO 出力(`.exo`)には対応していません。
|
||||
- **実行タイムアウト**: スクリプトの実行は 5000ms(5秒)でタイムアウトし、超過した場合は強制終了されエラーとして扱われます。無限ループが発生しないよう注意してください。
|
||||
- **利用可能な標準ライブラリの制限**: `table`、`string`、`math`、`bit32` および基本関数のみ利用できます。`io`、`os`、`debug`、`ffi`、`require` は利用できません。
|
||||
- **ピクセル操作の負荷**: `obj.getpixel` / `obj.setpixel` / `obj.getpixeldata` は実際の入力画像にアクセスするため、各フレームで最初に呼び出した際に GPU→CPU へのデータ転送が発生します。不要な場合は呼び出しを省略することで処理を高速化できます。これらを含むスクリプトは高速ランタイム(LuaJIT)で自動実行され大幅に高速化されますが、**ネイティブ実行では `obj.getobject` が使用できません**(`nil` を返します)。他オブジェクトの参照と併用する場合は `--!moonsharp` を明示してください。詳細は[実行エンジンの自動振り分け](#実行エンジンの自動振り分け)を参照。
|
||||
- **ピクセル操作の負荷**: `obj.getpixel` / `obj.setpixel` / `obj.getpixeldata` は実際の入力画像にアクセスするため、各フレームで最初に呼び出した際に GPU→CPU へのデータ転送が発生します。不要な場合は呼び出しを省略することで処理を高速化できます。これらを含むスクリプトは高速ランタイム(LuaJIT)で自動実行され大幅に高速化されます。詳細は[実行エンジンの自動振り分け](#実行エンジンの自動振り分け)を参照。
|
||||
- **`math.random` はフレームごとの決定論的な乱数**: 毎フレーム `frame` の値でシードし直されるため、同一フレームでは常に同じ値になります。フレームをまたいで変化する乱数的な値が必要な場合は `anim.rand` の利用を検討してください。
|
||||
- **`obj.oz` は出力に反映されません**: スクリプト実行後にコンテキストへ読み戻されますが、現在の実装では中心点オフセットの出力計算に使用されていません。
|
||||
- **エクスポートは先頭の1件のみ**: 複数アイテムを選択した状態でも、エクスポートされるスクリプトは先頭のアイテムのもののみです(インポート・クリアは選択中のすべてのアイテムに適用されます)。
|
||||
@@ -344,7 +345,14 @@ obj.alpha = anim.ease_out(t) * 255
|
||||
|
||||
## サードパーティライセンス
|
||||
|
||||
本プラグインは、Luaスクリプトの実行エンジンとして [MoonSharp](https://github.com/moonsharp-devs/moonsharp)(3-Clause BSD License)を使用しています。
|
||||
本プラグインは以下のサードパーティソフトウェアを同梱・使用しています。各ライセンスの全文は、配布パッケージ(`.ymme`)内の `LICENSE` フォルダーおよびリポジトリの [`.github/LICENSE`](.github/LICENSE) に収録しています。
|
||||
|
||||
| ソフトウェア | 用途 | ライセンス |
|
||||
|---|---|---|
|
||||
| [MoonSharp](https://github.com/moonsharp-devs/moonsharp) | 標準のLua実行エンジン(Lua 5.2 互換) | 3-Clause BSD License |
|
||||
| [LuaJIT](https://github.com/LuaJIT/LuaJIT) | ピクセル操作向け高速ランタイム(`native/luajit.exe`・`lua51.dll`) | MIT License |
|
||||
|
||||
### MoonSharp(3-Clause BSD License)
|
||||
|
||||
```
|
||||
Copyright (c) 2014-2016, Marco Mastropaolo
|
||||
@@ -377,6 +385,34 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
```
|
||||
|
||||
### LuaJIT(MIT License)
|
||||
|
||||
同梱の高速ランタイム(`native/luajit.exe`・`native/lua51.dll`)は LuaJIT v2.1 です。LuaJIT 本体は MIT License で配布されており、その中に Lua 5.1/5.2(Copyright © 1994-2012 Lua.org, PUC-Rio、MIT License)および dlmalloc(パブリックドメイン)のコードを含みます。以下は LuaJIT 本体の著作権表示です(Lua・dlmalloc を含む全文は `LICENSE/LuaJIT.txt` を参照)。
|
||||
|
||||
```
|
||||
LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/
|
||||
|
||||
Copyright (C) 2005-2026 Mike Pall. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ライセンス
|
||||
|
||||
+54
-3
@@ -43,11 +43,18 @@ local OFF_HEIGHT = 4
|
||||
local OFF_SCRIPTLEN = 5
|
||||
local OFF_PIXELSDIRTY = 6
|
||||
local OFF_ERRORLEN = 7
|
||||
local OFF_CB_FRAME = 8
|
||||
local OFF_CB_TAGLEN = 9
|
||||
local OFF_CB_FOUND = 10
|
||||
local SCRIPT_OFFSET = 64 + 64 * 8
|
||||
local ERROR_OFFSET = SCRIPT_OFFSET + 128 * 1024
|
||||
local PIXEL_OFFSET = ERROR_OFFSET + 4 * 1024
|
||||
local CB_TAG_OFFSET = ERROR_OFFSET + 4 * 1024
|
||||
local CB_TAG_MAX = 256
|
||||
local CB_RESULT_OFFSET = CB_TAG_OFFSET + CB_TAG_MAX
|
||||
local PIXEL_OFFSET = CB_RESULT_OFFSET + 8 * 8
|
||||
local FIRST_WRITABLE = 8
|
||||
local LAST_WRITABLE = 25
|
||||
local STATUS_CALLBACK = 3
|
||||
|
||||
assert(loadfile(shimPath))()
|
||||
|
||||
@@ -59,6 +66,7 @@ end
|
||||
|
||||
local width, height = 0, 0
|
||||
local pixels = ffi.cast("uint8_t*", base + PIXEL_OFFSET)
|
||||
local cbResult = ffi.cast("double*", base + CB_RESULT_OFFSET)
|
||||
local dirty = false
|
||||
|
||||
local obj = {}
|
||||
@@ -137,7 +145,48 @@ function obj.getpixeldata()
|
||||
end
|
||||
|
||||
function obj.putpixeldata() end
|
||||
function obj.getobject() return nil end
|
||||
|
||||
local cacheTag, cacheFrame, cacheFound
|
||||
local cacheExist, cacheX, cacheY, cacheZ, cacheZoom, cacheRz, cacheAlpha, cacheLayer
|
||||
|
||||
local function buildObject()
|
||||
return {
|
||||
exist = cacheExist,
|
||||
x = cacheX, y = cacheY, z = cacheZ,
|
||||
zoom = cacheZoom, sx = cacheZoom, sy = cacheZoom,
|
||||
rx = 0, ry = 0, rz = cacheRz,
|
||||
rxr = 0, ryr = 0, rzr = cacheRz * math.pi / 180,
|
||||
alpha = cacheAlpha, layer = cacheLayer,
|
||||
}
|
||||
end
|
||||
|
||||
function obj.getobject(tag, frame)
|
||||
if type(tag) ~= "string" then return nil end
|
||||
if frame then frame = math.floor(frame) else frame = math.floor(obj.timelineframe or 0) end
|
||||
if tag == cacheTag and frame == cacheFrame then
|
||||
if cacheFound then return buildObject() end
|
||||
return nil
|
||||
end
|
||||
local len = #tag
|
||||
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||
ffi.copy(base + CB_TAG_OFFSET, tag, len)
|
||||
i32[OFF_CB_TAGLEN] = len
|
||||
i32[OFF_CB_FRAME] = frame
|
||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||
k32.SetEvent(doneEvent)
|
||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||
cacheTag = tag
|
||||
cacheFrame = frame
|
||||
if i32[OFF_CB_FOUND] == 0 then
|
||||
cacheFound = false
|
||||
return nil
|
||||
end
|
||||
cacheFound = true
|
||||
cacheExist = cbResult[0] ~= 0
|
||||
cacheX = cbResult[1]; cacheY = cbResult[2]; cacheZ = cbResult[3]
|
||||
cacheZoom = cbResult[4]; cacheRz = cbResult[5]; cacheAlpha = cbResult[6]; cacheLayer = cbResult[7]
|
||||
return buildObject()
|
||||
end
|
||||
|
||||
local sandbox = {
|
||||
obj = obj, scene = scene, ymm4 = ymm4,
|
||||
@@ -214,6 +263,7 @@ while true do
|
||||
|
||||
if compiledChunk and code == compiledCode then
|
||||
loadFields()
|
||||
cacheTag = nil
|
||||
math.randomseed(f64[31])
|
||||
setfenv(compiledChunk, sandbox)
|
||||
local ok, err = pcall(compiledChunk)
|
||||
@@ -221,13 +271,14 @@ while true do
|
||||
storeFields()
|
||||
i32[OFF_PIXELSDIRTY] = dirty and 1 or 0
|
||||
i32[OFF_STATUS] = 1
|
||||
k32.SetEvent(doneEvent)
|
||||
else
|
||||
local msg = tostring(err)
|
||||
ffi.copy(base + ERROR_OFFSET, msg, math.min(#msg, 4096))
|
||||
i32[OFF_ERRORLEN] = math.min(#msg, 4096)
|
||||
i32[OFF_STATUS] = 2
|
||||
k32.SetEvent(doneEvent)
|
||||
end
|
||||
k32.SetEvent(doneEvent)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする