Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1.  
  2.  
  3. drs9999 wrote:
  4.  
  5.  
  6.  
  7. Rseding91 wrote:
  8. Removed the per-tree-type tree growing table and replaced it with 4 different tables of trees that are each called once per tick per 15 ticks - this spaces the tree growth out over one seconds worth of ticks instead of all at once at the end of each second
  9.  
  10. Why do you think that all trees are checked once each second?
  11. Imo it works (or least it should work) like the following:
  12. I have x tables for growing entities, where x is the number of different tree-types ( x = 1 in the "vanilla" mod-version). Each table is sorted depending on the next update. So each tick I only check the first element of the each table. There is no need to run through all entities. That should be much more performant than checking all entities once in a second as you assumed and more performant than your attempt with 4 tables. Btw the same apllies to the update-cycles of the farms.
  13.  
  14. That makes sense but the performance overhead of keeping that table sorted in LUA far outweights the savings of only having to check one tree (the first in the table). Every time a tree is planted or advances one stage the table is shifted to move the next-to-be-ticked tree to the top and put the new random growth time tree somewhere near the end but most likely not at the end.
  15.  
  16.  
  17.  
  18.  
  19. drs9999 wrote:
  20.  
  21.  
  22.  
  23. Rseding91 wrote:
  24. Reworked the tree growth mechanic so when a given table of trees is checked it simply loops through all the trees in that table checking if tick > updateTime where tick is an exact copy of game.tick
  25.  
  26. See post above
  27.  
  28. This method is actually where most of the performance gain came from. LUA is horrible at re-sorting arrays as well as the memory overhead of removing and re-adding elements from anywhere but the end of the table.
  29.  
  30.  
  31.  
  32.  
  33. drs9999 wrote:
  34.  
  35.  
  36.  
  37. Rseding91 wrote:
  38. Reworked trees so on full growth they check all existing farms to see if they're within range of the farm and the farm's active/valid and either mark them self for deconstruction or harvest into the MK1 farm.
  39.  
  40. That sounds good, it might be even better when the tree is assigned to a farm directly after planting, so there is no need to check all exisiting farms.[*]
  41.  
  42. I was thinking of doing that but the number of tree farms is going to be small (< 20 normally) and storing the entity of a farm in a tree seemed like extra space that didn't need to get saved every time auto-save is triggered.
  43.  
  44.  
  45. Have you tested out the modified version? If you watch the "Script Update" time on the debug screen (F4, enable update times then hit F5) you can see the marked performance improvement the changes made.
  46.  
  47. On my game with 6 MK2 tree farms running it went from 0.62~ MS/tick update time to 0.055~ MS/tick update time - a 1000%~ improvement. I've since planted 7 more MK2 farms for a new total of 13 MK2 farms and the update time hasn't gone above 0.075~ MS/tick.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement