Make init logs nicer
This commit is contained in:
@@ -20,8 +20,11 @@ local function RunFolder(folder, rootFolder, package)
|
|||||||
local s = search[i]:gsub("\\", "/")
|
local s = search[i]:gsub("\\", "/")
|
||||||
|
|
||||||
if EndsWith(s, ".lua") then
|
if EndsWith(s, ".lua") then
|
||||||
print(string.format("%s: Executing %s", package.Name, GetFileName(s)))
|
local time = os.clock()
|
||||||
local ok, result = pcall(ExecuteProtected, s, rootFolder)
|
local ok, result = pcall(ExecuteProtected, s, rootFolder)
|
||||||
|
local diff = os.clock() - time
|
||||||
|
|
||||||
|
print(string.format(" - %s (Took %.5fms)", GetFileName(s), diff))
|
||||||
if not ok then
|
if not ok then
|
||||||
printerror(result)
|
printerror(result)
|
||||||
end
|
end
|
||||||
@@ -36,8 +39,7 @@ local function AssertTypes(expectedTypes, ...)
|
|||||||
#args == #expectedTypes,
|
#args == #expectedTypes,
|
||||||
string.format(
|
string.format(
|
||||||
"Assertion failed: incorrect number of args\n\texpected = %s\n\tgot = %s",
|
"Assertion failed: incorrect number of args\n\texpected = %s\n\tgot = %s",
|
||||||
#expectedTypes,
|
#expectedTypes, #args
|
||||||
#args
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for i = 1, #args do
|
for i = 1, #args do
|
||||||
@@ -47,9 +49,7 @@ local function AssertTypes(expectedTypes, ...)
|
|||||||
type(arg) == expectedType,
|
type(arg) == expectedType,
|
||||||
string.format(
|
string.format(
|
||||||
"Assertion failed: incorrect argument type (arg #%d)\n\texpected = %s\n\tgot = %s",
|
"Assertion failed: incorrect argument type (arg #%d)\n\texpected = %s\n\tgot = %s",
|
||||||
i,
|
i, expectedType, type(arg)
|
||||||
expectedType,
|
|
||||||
type(arg)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@@ -59,30 +59,21 @@ local function ExecutionQueue()
|
|||||||
local queue = {}
|
local queue = {}
|
||||||
local function processQueueFIFO()
|
local function processQueueFIFO()
|
||||||
while queue[1] ~= nil do
|
while queue[1] ~= nil do
|
||||||
RunFolder(
|
local folder, rootFolder, package = table.unpack(table.remove(queue, 1))
|
||||||
table.unpack(
|
print(string.format("%s %s", package.Name, package.ModVersion))
|
||||||
table.remove(
|
RunFolder(folder, rootFolder, package)
|
||||||
queue,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function queueExecutionFIFO(...)
|
local function queueExecutionFIFO(...)
|
||||||
AssertTypes(
|
AssertTypes({ 'string', 'string', 'userdata' }, ...)
|
||||||
{ 'string', 'string', 'userdata' },
|
table.insert(queue, table.pack(...))
|
||||||
...
|
|
||||||
)
|
|
||||||
table.insert(
|
|
||||||
queue,
|
|
||||||
table.pack(...)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return queueExecutionFIFO, processQueueFIFO
|
return queueExecutionFIFO, processQueueFIFO
|
||||||
end
|
end
|
||||||
|
|
||||||
local QueueAutorun, ProcessAutorun = ExecutionQueue()
|
local QueueAutorun, ProcessAutorun = ExecutionQueue()
|
||||||
local QueueForcedAutorun, ProcessForcedAutorun = ExecutionQueue()
|
local QueueForcedAutorun, ProcessForcedAutorun = ExecutionQueue()
|
||||||
|
|
||||||
local function ProcessPackages(packages, fn)
|
local function ProcessPackages(packages, fn)
|
||||||
@@ -154,8 +145,8 @@ setmodulepaths = nil
|
|||||||
ProcessAutorun()
|
ProcessAutorun()
|
||||||
ProcessForcedAutorun()
|
ProcessForcedAutorun()
|
||||||
|
|
||||||
Hook.Add("stop", "luaSetup.stop", function ()
|
Hook.Add("stop", "luaSetup.stop", function()
|
||||||
print("Stopping Lua...")
|
print("Stopping Lua...")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Hook.Call("loaded")
|
Hook.Call("loaded")
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (rtValue == RunType.Standard && isEnabled)
|
if (rtValue == RunType.Standard && isEnabled)
|
||||||
{
|
{
|
||||||
LuaCsSetup.PrintCsMessage($"Standard run C# of {cp.Name}");
|
LuaCsSetup.PrintCsMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Standard)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (rtValue == RunType.Forced)
|
else if (rtValue == RunType.Forced)
|
||||||
{
|
{
|
||||||
LuaCsSetup.PrintCsMessage($"Forced run C# of {cp.Name}");
|
LuaCsSetup.PrintCsMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Forced)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (rtValue == RunType.None)
|
else if (rtValue == RunType.None)
|
||||||
@@ -71,7 +71,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (isEnabled)
|
if (isEnabled)
|
||||||
{
|
{
|
||||||
LuaCsSetup.PrintCsMessage($"Assumed run C# of {cp.Name}");
|
LuaCsSetup.PrintCsMessage($"Added {cp.Name} {cp.ModVersion} to Cs compilation. (Assumed)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -124,7 +124,9 @@ namespace Barotrauma
|
|||||||
GameMain.Server.SendDirectChatMessage(ChatMessage.Create("", subStr, ChatMessageType.Console, null, textColor: Color.MediumPurple), c);
|
GameMain.Server.SendDirectChatMessage(ChatMessage.Create("", subStr, ChatMessageType.Console, null, textColor: Color.MediumPurple), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !DEBUG
|
||||||
GameServer.Log(prefix + subStr, ServerLog.MessageType.ServerMessage);
|
GameServer.Log(prefix + subStr, ServerLog.MessageType.ServerMessage);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Runtime.CompilerServices;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsScriptAssembly, AllInternalsVisible = true)]
|
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsScriptAssembly, AllInternalsVisible = true)]
|
||||||
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsOneTimeScriptAssembly, AllInternalsVisible = true)]
|
[assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.CsOneTimeScriptAssembly, AllInternalsVisible = true)]
|
||||||
@@ -346,6 +347,8 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Stopwatch compilationTime = new Stopwatch();
|
||||||
|
compilationTime.Start();
|
||||||
var modTypes = CsScriptLoader.Compile();
|
var modTypes = CsScriptLoader.Compile();
|
||||||
modTypes.ForEach(t =>
|
modTypes.ForEach(t =>
|
||||||
{
|
{
|
||||||
@@ -358,6 +361,8 @@ namespace Barotrauma
|
|||||||
HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
HandleException(ex, LuaCsMessageOrigin.CSharpMod);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
compilationTime.Stop();
|
||||||
|
PrintCsMessage($"Took {compilationTime.ElapsedMilliseconds}ms to compile and run Cs Scripts.");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user