Lua bytecode builder, cdrom fixes
This commit is contained in:
@@ -12,6 +12,13 @@ namespace SplashEdit.RuntimeCode
|
||||
/// </summary>
|
||||
public static class PSXSceneWriter
|
||||
{
|
||||
/// <summary>
|
||||
/// Pre-compiled Lua bytecode, keyed by Lua source text.
|
||||
/// When populated, Write() packs bytecode instead of source text.
|
||||
/// Set by the build pipeline after running luac_psx, cleared after export.
|
||||
/// </summary>
|
||||
public static Dictionary<string, byte[]> CompiledLuaBytecode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All scene data needed to produce a .bin file.
|
||||
/// Populated by PSXSceneExporter before calling <see cref="Write"/>.
|
||||
@@ -239,7 +246,12 @@ namespace SplashEdit.RuntimeCode
|
||||
{
|
||||
luaOffset.PlaceholderPositions.Add(writer.BaseStream.Position);
|
||||
writer.Write((int)0); // placeholder
|
||||
writer.Write((uint)Encoding.UTF8.GetByteCount(luaFile.LuaScript));
|
||||
|
||||
// Use compiled bytecode length if available, otherwise source length
|
||||
if (CompiledLuaBytecode != null && CompiledLuaBytecode.TryGetValue(luaFile.LuaScript, out byte[] bytecode))
|
||||
writer.Write((uint)bytecode.Length);
|
||||
else
|
||||
writer.Write((uint)Encoding.UTF8.GetByteCount(luaFile.LuaScript));
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────
|
||||
@@ -429,12 +441,26 @@ namespace SplashEdit.RuntimeCode
|
||||
// Data sections
|
||||
// ══════════════════════════════════════════════════════
|
||||
|
||||
// Lua data
|
||||
// Lua data (bytecode if compiled, source text otherwise)
|
||||
int luaIdx = 0;
|
||||
log?.Invoke($"CompiledLuaBytecode: {(CompiledLuaBytecode != null ? CompiledLuaBytecode.Count + " entries" : "null")}", LogType.Log);
|
||||
foreach (LuaFile luaFile in luaFiles)
|
||||
{
|
||||
AlignToFourBytes(writer);
|
||||
luaOffset.DataOffsets.Add(writer.BaseStream.Position);
|
||||
writer.Write(Encoding.UTF8.GetBytes(luaFile.LuaScript));
|
||||
|
||||
if (CompiledLuaBytecode != null && CompiledLuaBytecode.TryGetValue(luaFile.LuaScript, out byte[] bytecode))
|
||||
{
|
||||
log?.Invoke($" Lua [{luaIdx}]: using bytecode ({bytecode.Length} bytes)", LogType.Log);
|
||||
writer.Write(bytecode);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] srcBytes = Encoding.UTF8.GetBytes(luaFile.LuaScript);
|
||||
log?.Invoke($" Lua [{luaIdx}]: FALLBACK to source ({srcBytes.Length} bytes, script hash={luaFile.LuaScript.GetHashCode()})", LogType.Warning);
|
||||
writer.Write(srcBytes);
|
||||
}
|
||||
luaIdx++;
|
||||
}
|
||||
|
||||
// Mesh data
|
||||
|
||||
Reference in New Issue
Block a user