Guest User

Untitled

a guest
Sep 20th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. A threaded pathfinding doesn't bring many benefits due to global lock and it's a source of complex code (more than it needs to be).
  2.  
  3. The computation must be handled with a proper algorithm or we find situations like this one https://forum.minetest.net/viewtopic.php?p=280752&sid=ea546846ac1449335b1ae2ee4d23e67f#p280752 where users with not so new hardware and the computation of a lot of paths can cause a perceptible freeze in the game.
  4.  
  5. there are a lot of games which doesn't require that computation on its own thread but the require to be fast (normally no more than 2 or 3 ms).
  6.  
  7. The best time efficient alternatives are algorithms which use search trees from previous searches to speed up the current search. That implies more RAM usage.
  8.  
  9. RAM is cheap and even more as years go by, I think the better option to prevent blocking is a faster calculation. Here is my proposal for the pathfinding API:
  10.  
  11. -- no cache
  12. minetest.find_path(pos1, pos2, searchdistance, agent definition)
  13. this function doesn't use any cache from previous computations, it will create data for every call, its speed will be the same as in the first call of the pathfinding using cache. I may write a specialized version optimized for this function in the future.
  14.  
  15. -- with cache pool
  16. entities won't reserve cache in the creation, mob mods will have to define which will have cache with the following function:
  17. minetest.register_path_cache(agent definition, entity)
  18.  
  19. 2 registrations of the same entity will cause an override of the previous cache.
  20. 'agent definition' is a table defining the properties of the entity, here is an example of the default values:
  21.  
  22. agent_definition = {
  23. height = 1,
  24. width = 1,
  25. fly = false,
  26. climb_walls = false,
  27. over_ground = true,
  28. diving = false,
  29. swimming_surface = true,
  30. max_jump_height = 1,
  31. max_drop_height = 2,
  32. avoided_nodes = {
  33. "default:lava_source",
  34. "default:lava_flowing",
  35. },
  36. node_cost_list = { -- to define special costs
  37. default:water_source = 20,
  38. default:water_flowing = 20,
  39. },
  40. jump_cost = 20
  41. }
  42.  
  43. Entities will free its cache when deleted of unloaded due to the lack of players in their surroundings, that way we prevent an uncontrolled number of growing cache.
  44. I think we could define some kind of load factor or limit to automatically free part of the ram from time to time.
  45.  
  46. Anyway, mob modders will have a Lua function allowing to free al the cache of a single entity:
  47. minetest.free_path_cache(entity)
  48.  
  49. I have a design doubt, should we pass an ObjectRef or the entity id. I haven't found a method to get the id of an entity from Lua.
  50.  
  51. Well, and finally the function to find the path using the cache reserved previously:
  52. minetest.find_path_with_cache(pos1, pos2, entity, searchdistance)
  53.  
  54. If we try to use that function with an entity without cache it will return nil.
Add Comment
Please, Sign In to add comment