areastore.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ---@meta
  2. ---AreaStore
  3. ------------
  4. -- AreaStore is a data structure to calculate intersections of 3D cuboid volumes
  5. -- and points.
  6. --
  7. -- Despite its name, mods must take care of persisting AreaStore data.
  8. -- They may use the provided load and write functions for this.
  9. ---@class mt.AreaStore
  10. ---@field data string Mod-relevant information to the specified area.
  11. ---@operator call: fun(type_name:string|nil):mt.AreaStore
  12. local AreaStore = {}
  13. ---@alias mt.AreaID string|number
  14. ---@class mt.AreaInfo
  15. ---@field min mt.Vector|nil Position (if `include_corners` == `true`).
  16. ---@field max mt.Vector|nil Position (if `include_corners` == `true`).
  17. ---@field data string|nil (if `include_data` == `true`)
  18. -- * Returns the area information about the specified ID.
  19. -- * Returns nil if area not found.
  20. -- * Returns boolean if `include_corners` and `include_data` are not true.
  21. ---@param id mt.AreaID
  22. ---@param include_corners boolean|nil
  23. ---@param include_data boolean|nil
  24. ---@return nil|true|mt.AreaInfo
  25. function AreaStore:get_area(id, include_corners, include_data) end
  26. -- Returns all areas as table, indexed by the area ID.
  27. ---@param pos mt.Vector
  28. ---@param include_corners boolean|nil
  29. ---@param include_data boolean|nil
  30. ---@return table<mt.AreaID, mt.AreaInfo>
  31. function AreaStore:get_areas_for_pos(pos, include_corners, include_data) end
  32. -- Returns all areas that contain all nodes inside the area specified by
  33. -- `corner1` and `corner2` (inclusive).
  34. ---@param corner1 mt.Vector
  35. ---@param corner2 mt.Vector
  36. ---@param accept_overlap boolean|nil If `true`, areas are returned that have nodes in common (intersect) with the specified area.
  37. ---@param include_corners boolean|nil
  38. ---@param include_data boolean|nil
  39. ---@return table<mt.AreaID, mt.AreaInfo>
  40. function AreaStore:get_areas_in_area(corner1, corner2, accept_overlap, include_corners, include_data) end
  41. -- * Returns the new area's ID, or nil if the insertion failed.
  42. -- * The (inclusive) positions `corner1` and `corner2` describe the area.
  43. ---@param corner1 mt.Vector
  44. ---@param corner2 mt.Vector
  45. ---@param data string
  46. ---@param id mt.AreaID|nil Will be used as the internal area ID if it is an unique number between 0 and 2^32-2.
  47. ---@return mt.AreaID|nil
  48. function insert_area(corner1, corner2, data, id) end
  49. -- * Requires SpatialIndex, no-op function otherwise.
  50. -- * Reserves resources for `count` many contained areas to improve efficiency
  51. -- when working with many area entries. Additional areas can still be inserted
  52. -- afterwards at the usual complexity.
  53. ---@param count number|function
  54. function AreaStore:reserve(count) end
  55. -- Removes the area with the given id from the store, returns success.
  56. ---@param id mt.AreaID
  57. ---@return boolean
  58. function AreaStore:remove_area(id) end
  59. ---@class mt.AreaCacheParams
  60. -- Whether to enable, default `true`.
  61. ---@field enabled boolean
  62. -- The radius (in nodes) of the areas the cache enerates prefiltered lists for,
  63. -- minimum 16, default 64.
  64. ---@field block_radius integer
  65. -- The cache size, minimum 20, default 1000
  66. ---@field limit integer
  67. -- Sets params for the included prefiltering cache.
  68. -- Calling invalidates the cache, so that its elements have to be newly generated.
  69. ---@param params mt.AreaCacheParams
  70. function AreaStore:set_cache_params(params) end
  71. -- Experimental. Returns area store serialized as a (binary) string.
  72. ---@return string
  73. function AreaStore:to_string() end
  74. -- Experimental. Like `to_string()`, but writes the data to a file.
  75. ---@param filename string
  76. function AreaStore:to_file(filename) end
  77. -- Experimental. Deserializes string and loads it into the
  78. -- AreaStore. Returns success and, optionally, an error message.
  79. ---@param str string
  80. ---@return boolean success, string|nil error
  81. function AreaStore:from_string(str) end
  82. -- Experimental. Like `from_string()`, but reads the data from a file.
  83. ---@param filename string
  84. ---@return unknown
  85. function AreaStore:from_file(filename) end