Separate files per thread
This commit is contained in:
parent
6099589f8b
commit
faccd03b82
3 changed files with 53 additions and 35 deletions
4
pool.lua
4
pool.lua
|
@ -411,13 +411,13 @@ local function loadFile(filename, after)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local contents = file:read("*all")
|
local contents = file:read("*all")
|
||||||
local obj, err = serpent.load(libDeflate:DecompressDeflate(contents:sub(11, #contents - 8)))
|
local obj, err = loadstring(libDeflate:DecompressDeflate(contents:sub(11, #contents - 8)))
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
message(string.format("Error parsing: %s", err), 0x00990000)
|
message(string.format("Error parsing: %s", err), 0x00990000)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
pool = obj
|
pool = obj()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function savePool()
|
local function savePool()
|
||||||
|
|
|
@ -2,12 +2,19 @@ local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*[/\\])(.*)", "%1")
|
||||||
|
|
||||||
local Runner = dofile(base.."/runner.lua")
|
local Runner = dofile(base.."/runner.lua")
|
||||||
local serpent = dofile(base.."/serpent.lua")
|
local serpent = dofile(base.."/serpent.lua")
|
||||||
|
local util = dofile(base.."/util.lua")
|
||||||
|
|
||||||
|
local runnerDataFile = io.open(os.getenv("RUNNER_DATA"), 'r')
|
||||||
|
local runnerData, err = loadstring(runnerDataFile:read('*a'))
|
||||||
|
runnerDataFile:close()
|
||||||
|
|
||||||
local runnerData, err = serpent.load(os.getenv("RUNNER_DATA"))
|
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
|
print(err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
runnerData = runnerData()
|
||||||
|
|
||||||
local speciesIndex = runnerData[3]
|
local speciesIndex = runnerData[3]
|
||||||
|
|
||||||
local filename = runnerData[4]
|
local filename = runnerData[4]
|
||||||
|
|
|
@ -64,12 +64,20 @@ return function()
|
||||||
end
|
end
|
||||||
|
|
||||||
_M.run = function(species, generationIdx, speciesIdx, genomeCallback, finishCallback)
|
_M.run = function(species, generationIdx, speciesIdx, genomeCallback, finishCallback)
|
||||||
local trunc = io.open(tmpFileName, 'w')
|
|
||||||
trunc:close()
|
|
||||||
|
|
||||||
local poppets = {}
|
local poppets = {}
|
||||||
for i=1,#species,1 do
|
for i=1,#species,1 do
|
||||||
local poppet = io.popen("RUNNER_DATA='"..serpent.dump({species[i], generationIdx, speciesIdx + i - 1, tmpFileName}).."' lsnes --rom="..base.."/rom.sfc --unpause --lua="..base.."/runner-process.lua", 'r')
|
local outputFileName = tmpFileName..'_output_'..i
|
||||||
|
local trunc = io.open(outputFileName, 'w')
|
||||||
|
trunc:close()
|
||||||
|
|
||||||
|
local inputFileName = tmpFileName.."_input_"..i
|
||||||
|
local inputFile = io.open(inputFileName, 'w')
|
||||||
|
inputFile:write(serpent.dump({species[i], generationIdx, speciesIdx + i - 1, outputFileName}))
|
||||||
|
inputFile:close()
|
||||||
|
|
||||||
|
local cmd = "RUNNER_DATA=\""..inputFileName.."\" lsnes \"--rom="..base.."/rom.sfc\" --unpause \"--lua="..base.."/runner-process.lua\""
|
||||||
|
message(_M, cmd)
|
||||||
|
local poppet = io.popen(cmd, 'r')
|
||||||
table.insert(poppets, poppet)
|
table.insert(poppets, poppet)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -79,36 +87,39 @@ return function()
|
||||||
poppet:close()
|
poppet:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local tmpFile = io.open(tmpFileName, "r")
|
for i=1,#species,1 do
|
||||||
local line = ""
|
local outputFileName = tmpFileName..'_output_'..i
|
||||||
repeat
|
local outputFile = io.open(outputFileName, "r")
|
||||||
local obj, err = serpent.load(line)
|
local line = ""
|
||||||
if err ~= nil then
|
repeat
|
||||||
goto continue
|
local obj, err = loadstring(line)
|
||||||
end
|
if err ~= nil then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
if obj.type == 'onMessage' then
|
obj = obj()
|
||||||
message(_M, obj.msg, obj.color)
|
|
||||||
elseif obj.type == 'onLoad' then
|
|
||||||
load(_M, obj.filename)
|
|
||||||
elseif obj.type == 'onSave' then
|
|
||||||
save(_M, obj.filename)
|
|
||||||
elseif obj.type == 'onGenome' then
|
|
||||||
species[obj.speciesIndex - speciesIdx + 1].genomes[obj.genomeIndex] = obj.genome
|
|
||||||
genomeCallback(obj.genome, obj.index)
|
|
||||||
elseif obj.type == 'onFinish' then
|
|
||||||
finishCallback()
|
|
||||||
end
|
|
||||||
|
|
||||||
::continue::
|
if obj == nil then
|
||||||
line = tmpFile:read()
|
goto continue
|
||||||
until(line == "")
|
end
|
||||||
tmpFile:close()
|
|
||||||
local ok, err = os.remove(tmpFileName)
|
if obj.type == 'onMessage' then
|
||||||
if err ~= nil then
|
message(_M, obj.msg, obj.color)
|
||||||
message(_M, err)
|
elseif obj.type == 'onLoad' then
|
||||||
elseif ok ~= true then
|
load(_M, obj.filename)
|
||||||
message(_M, 'UNSPECIFIED ERROR ON REMOVAL')
|
elseif obj.type == 'onSave' then
|
||||||
|
save(_M, obj.filename)
|
||||||
|
elseif obj.type == 'onGenome' then
|
||||||
|
species[obj.speciesIndex - speciesIdx + 1].genomes[obj.genomeIndex] = obj.genome
|
||||||
|
genomeCallback(obj.genome, obj.index)
|
||||||
|
elseif obj.type == 'onFinish' then
|
||||||
|
finishCallback()
|
||||||
|
end
|
||||||
|
|
||||||
|
::continue::
|
||||||
|
line = outputFile:read()
|
||||||
|
until(line == "" or line == nil)
|
||||||
|
outputFile:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue