Treefarms and Co-Routines
Re: Treefarms and Co-Routines
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.
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.
Re: Treefarms and Co-Routines
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.
Thanks for the suggestions!
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.
Re: Treefarms and Co-Routines
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.
Re: Treefarms and Co-Routines
Those hitches will most likely disappear with luajit in 0.13
Re: Treefarms and Co-Routines
They would be reduced significantly for sureZeblote wrote:Those hitches will most likely disappear with luajit in 0.13
Re: Treefarms and Co-Routines
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.
Last edited by Fatmice on Sat Mar 12, 2016 4:31 pm, edited 1 time in total.
Maintainer and developer of Atomic Power. See here for more information.
Current release: 0.6.6 - Requires 0.14.x
Example build - Requires 0.14.x
Current release: 0.6.6 - Requires 0.14.x
Example build - Requires 0.14.x
Re: Treefarms and Co-Routines
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.
With jit lua is no longer interpreted but compiled - should net significant speed increase. That would mean that any spikes are significantly shorter = less stuttering.
Re: Treefarms and Co-Routines
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.
Would prefer performance over new features.
Re: Treefarms and Co-Routines
That's not what I meant. =) Who told you that luajit will be replacing the lua interpreter? I thought the current lua interpreter is lua 5.3 with os module removed. Code written currently might break with luajit in its place since 2.1-beta1 is compatible with lua 5.1 and not lua 5.3. There are many differences between the subversion of lua.
Regarding spikes, they are only stuttering if the execution takes longer than 1/60th of a second, in which case, optimization on the code can be done right now to remove/reduce that even without luajit.
Regarding spikes, they are only stuttering if the execution takes longer than 1/60th of a second, in which case, optimization on the code can be done right now to remove/reduce that even without luajit.
Maintainer and developer of Atomic Power. See here for more information.
Current release: 0.6.6 - Requires 0.14.x
Example build - Requires 0.14.x
Current release: 0.6.6 - Requires 0.14.x
Example build - Requires 0.14.x
Re: Treefarms and Co-Routines
Well, /c game.local_player.print(_VERSIONI) says 5.2 so that's where I got that it doesn't use 5.3.
For luajit, look at the to do list here: https://www.factorio.com/blog/post/fff-111
For luajit, look at the to do list here: https://www.factorio.com/blog/post/fff-111
Re: Treefarms and Co-Routines
Ah I see. I missed that bit about luajit from my recollection of that FF. Looking at it again, it was written "Lua jit" and not "luajit". My brain does this thing where joined words are associated differently than non joined words...
Maintainer and developer of Atomic Power. See here for more information.
Current release: 0.6.6 - Requires 0.14.x
Example build - Requires 0.14.x
Current release: 0.6.6 - Requires 0.14.x
Example build - Requires 0.14.x
Re: Treefarms and Co-Routines
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.
EDIT: Doesnt treefarm already store the x/y of the last plant attempt and iterate over x then y with each attempt, stopping when it finds a place it can plant?
I thought that was the point of this:
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
Re: Treefarms and Co-Routines
I really dont get it. Why do you do the treefarm so complicated??
Just make ist a static field with some small trees and some big trees, wich functions as a normal factory. This factory needs 1 seed every x seconds and produces 5 peaces of wood in the same time. No need for scanning the field, planting, growing, harvesting etc. This is NOT a high res simulation, it is a tactical game, no need for the highest grafics/animations...
Just make ist a static field with some small trees and some big trees, wich functions as a normal factory. This factory needs 1 seed every x seconds and produces 5 peaces of wood in the same time. No need for scanning the field, planting, growing, harvesting etc. This is NOT a high res simulation, it is a tactical game, no need for the highest grafics/animations...
Re: Treefarms and Co-Routines
Yeah, thats how the greenhouses mod works: an assembly machine with seeds as input and wood as output.
Treefarm is more visually appealing to some folks. I guess people like watching trees grow. Or at least, being able to see it happen as they walk past. It helps that its not that complicated.
Treefarm is more visually appealing to some folks. I guess people like watching trees grow. Or at least, being able to see it happen as they walk past. It helps that its not that complicated.