viewtopic.php?f=44&t=19124&p=133153#p133153
However it isn't working at the moment, there's a bug he doesn't have time to try and locate. It is on github if anyone would like to contribute and help try to bring about a high performance TreeFarm.

For the second suggestion you made, about how to selectively scan the treefarm for the next location to plant - Does this really improve performance all that much? Compared to scanning the whole treefarm on each attempt - which only happens once every 60 ticks anyway?Rseding91 wrote:As for the planting of trees on farms: store the x/y of the last plant attempt and increment y each attempt. If y > a column reset it to 0 and increment x. If x > then a row reset both to 0 and restart. That way it scans the entire area 1 tile per growth attempt (or how ever many you decide per attempt) and it doesn't need to re-scan the entire area each time.
The above changes when I tested TreeFarm showed a constant 1/10th tick time as before the changes. That means that before it would take 2 MS/tick to run X tree farms and after it would take 0.2 MS/tick to run the same tree farms.
The bug in question is fixed, but thanks anyway. With that said I welcome PRs, I am very new to Lua and scripting in general. Cheers!roy7 wrote:Blu3wolf has started a project to fold in Rseding91's suggestions, info is here:
viewtopic.php?f=44&t=19124&p=133153#p133153
However it isn't working at the moment, there's a bug he doesn't have time to try and locate. It is on github if anyone would like to contribute and help try to bring about a high performance TreeFarm.I don't know LUA so I'm kinda useless in that regard.
Main reason behind this idea is to not cause game to stutter. You need to spread out the work among game ticks to keep it happening with lower speed but constantly. Scanning 60 locations at once causes "spike" of CPU time usage on mod that might be visible as stuttering.Blu3wolf wrote:For the second suggestion you made, about how to selectively scan the treefarm for the next location to plant - Does this really improve performance all that much? Compared to scanning the whole treefarm on each attempt - which only happens once every 60 ticks anyway?Rseding91 wrote:As for the planting of trees on farms: store the x/y of the last plant attempt and increment y each attempt. If y > a column reset it to 0 and increment x. If x > then a row reset both to 0 and restart. That way it scans the entire area 1 tile per growth attempt (or how ever many you decide per attempt) and it doesn't need to re-scan the entire area each time.
The above changes when I tested TreeFarm showed a constant 1/10th tick time as before the changes. That means that before it would take 2 MS/tick to run X tree farms and after it would take 0.2 MS/tick to run the same tree farms.
They would be reduced significantly for sureZeblote wrote:Those hitches will most likely disappear with luajit in 0.13
It's about the premise of luajit. Not sure what version difference means in practical use here.Fatmice wrote:Who told you that? luajit hasn't been updated to 5.3 and the difference between 5.1 and 5.3 is quite a lot. Luajit 2.1-beta1 is compatible with lua 5.1 code only.
Factorio doesn't use 5.3 anyways, and the difference between 5.1 and 5.2 is not that much..Fatmice wrote:Who told you that? luajit hasn't been updated to lua 5.3 and the difference between 5.1 and 5.3 is quite a lot. Luajit 2.1-beta1 is compatible with lua 5.1 code only.
I can appreciate it being the case that the CPU gets extra load once every 60 frames that way. How many treefarms do you need before that becomes a problem, though? I can see that spreading it out would prevent it from becoming a problem so quickly, at least. By a factor of 60 I guess.Rseding91 wrote:As for the planting of trees on farms: store the x/y of the last plant attempt and increment y each attempt. If y > a column reset it to 0 and increment x. If x > then a row reset both to 0 and restart. That way it scans the entire area 1 tile per growth attempt (or how ever many you decide per attempt) and it doesn't need to re-scan the entire area each time.
Code: Select all
local seedPos = false
if seedInInv.name ~= "DUMMY" then
local fieldPos = fieldObj.entity.position
local placed = false
local lastPos = fieldObj.lastSeedPos
for dx = lastPos.x, 8 do
for dy = 0, 6 do
if (game.get_surface("nauvis").can_place_entity{name = "tf-germling", position = {fieldPos.x + dx - 0.5, fieldPos.y + dy - 0.5}}) then
seedPos = {x = fieldPos.x + dx - 0.5, y = fieldPos.y + dy - 0.5}
placed = true
fieldObj.lastSeedPos = {x = dx, y = dy}
break
end
end
if placed == true then
break
end
end
if (placed == false) and (lastPos.x ~= 2) then
for dx = 2, lastPos.x - 1 do
for dy = 0, 6 do
if (game.get_surface("nauvis").can_place_entity{name = "tf-germling", position = {fieldPos.x + dx - 0.5, fieldPos.y + dy - 0.5}}) then
seedPos = {x = fieldPos.x + dx - 0.5, y = fieldPos.y + dy - 0.5}
placed = true
fieldObj.lastSeedPos = {x = dx, y = dy}
break
end
end
if placed == true then
break
end
end
end