源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.9 KiB

пре 1 месец
  1. SceneConnectMap = SceneConnectMap or BaseClass()
  2. function SceneConnectMap:__init()
  3. if SceneConnectMap.Instance ~= nil then
  4. LogError("attempt to create singleton twice!")
  5. end
  6. SceneConnectMap.Instance = self
  7. self.scene_map = {}
  8. if Config.SceneDoors == nil then
  9. return
  10. end
  11. for scene_id, scene_info in pairs(Config.SceneDoors) do
  12. self.scene_map[scene_id] = {}
  13. self.scene_map[scene_id].to_scene_info = scene_info
  14. end
  15. end
  16. function SceneConnectMap:ClearPath()
  17. for scene_id, scene_info in pairs(self.scene_map) do
  18. scene_info.parent = nil
  19. scene_info.visit = false
  20. end
  21. end
  22. function SceneConnectMap:FindPath(src_scene_id, tgt_scene_id)
  23. self:ClearPath()
  24. local rlt_path = List.New()
  25. if src_scene_id == tgt_scene_id then
  26. List.PushFront(rlt_path, tgt_scene_id)
  27. List.PushFront(rlt_path, src_scene_id)
  28. return rlt_path
  29. end
  30. local visit_queue = List.New()
  31. local handle_scene_info = self.scene_map[src_scene_id]
  32. if not handle_scene_info then
  33. return rlt_path
  34. end
  35. handle_scene_info.visit = true
  36. List.PushBack(visit_queue, src_scene_id)
  37. local is_find = false
  38. while not List.Empty(visit_queue) do
  39. local handle_scene_id = List.PopFront(visit_queue)
  40. local handle_scene_info = self.scene_map[handle_scene_id]
  41. if handle_scene_id == tgt_scene_id then
  42. is_find = true
  43. break
  44. end
  45. for _,to_scene_id in pairs(handle_scene_info.to_scene_info) do
  46. local to_scene_info = self.scene_map[to_scene_id]
  47. if to_scene_info and not to_scene_info.visit then
  48. to_scene_info.visit = true
  49. to_scene_info.parent = handle_scene_id
  50. List.PushBack(visit_queue, to_scene_id)
  51. end
  52. end
  53. end
  54. -- 返回查找列表
  55. if is_find then
  56. local cur_scene_info = self.scene_map[tgt_scene_id]
  57. List.PushFront(rlt_path, tgt_scene_id)
  58. while cur_scene_info.parent do
  59. List.PushFront(rlt_path, cur_scene_info.parent)
  60. cur_scene_info = self.scene_map[cur_scene_info.parent]
  61. end
  62. end
  63. return rlt_path
  64. end