@Xiaomi So yes your right, i think I'm approaching the ceiling on what can be done, although I'm sure there are always clever tricks to go further.
Do bare in mind though that, that trace is a 64k air battle, the normal balance of the game simply doesn't run in to that kind of unit count, even if you played with 64 players.
I do think a lua thread pool api could be introduced similar to love2d , but that would really only help with big chunks of work like ai and such.
with this i would imagine some task api where you opt in to certain data (unit position, eco, intel, etc...) to be copied over to an isolated lua thread, then you would set a duration of ticks for the work to be completed in, such that it remains deterministic, if it hasn't completed in time the sim would wait.
something a bit like this in the sim (this is pseudo code just to illustrate the idea)
-- Plain-data arguments, deep-copied at post time
local taskArgs = {
thing = 5,
}
local dueInTicks = 10
-- Which parts of the sim to copy over
local unitsView = {
fields = { 'Position', 'Army', 'BlueprintId', 'Health' },
categories = categories.MOBILE,
armies = 'enemies',
}
local access = {
Units = unitsView,
Terrain = true,
PathGrid = { 'Land', 'Amphibious' },
Economy = 'own',
}
-- Which task to run: a module path and a function in it
local taskModule = '/mods/myai/lua/tasks/threat.lua'
local taskFunction = 'Compute'
local pending = Pool.PostTask(taskModule, taskFunction, taskArgs, dueInTicks, access)
-- do more stuff
local ok, result = Pool.WaitForTask(pending) -- resumes at exactly post tick + 10
then the worker script
function Compute(args, View)
local units = View.Units
local count = units.Count()
for i = 1, count do
local position = units.Position(i)
local health = units.Health(i)
-- do stuff thats slow...
end
return args.thing * 42 -- plain data, handed back at the due tick
end
This has the advantage of allowing devs in the lua to break up work in to as many threads as they see fit, and with so many cores now available, more tasks are always better.
https://love2d.org/wiki/love.thread
There is also robloxs thread model where you can have read only access in parallel, and write access is then serialised.
https://create.roblox.com/docs/scripting/multithreading
but yes you are right, it is in conflict with how supcom was made, perhaps another possibility would be to allow some wasm runtime (still allowing scripting of a sorts, just compiled), but I'm not sure if those are actually that much faster than the luau vm.
of course you could move the whole game to native code, but then you lose modding and such...
interesting none the less