|
|
- SceneConnectMap = SceneConnectMap or BaseClass()
-
- function SceneConnectMap:__init()
- if SceneConnectMap.Instance ~= nil then
- LogError("attempt to create singleton twice!")
- end
-
- SceneConnectMap.Instance = self
-
- self.scene_map = {}
- if Config.SceneDoors == nil then
- return
- end
- for scene_id, scene_info in pairs(Config.SceneDoors) do
- self.scene_map[scene_id] = {}
- self.scene_map[scene_id].to_scene_info = scene_info
- end
- end
-
- function SceneConnectMap:ClearPath()
- for scene_id, scene_info in pairs(self.scene_map) do
- scene_info.parent = nil
- scene_info.visit = false
- end
- end
-
- function SceneConnectMap:FindPath(src_scene_id, tgt_scene_id)
-
- self:ClearPath()
-
- local rlt_path = List.New()
-
- if src_scene_id == tgt_scene_id then
- List.PushFront(rlt_path, tgt_scene_id)
- List.PushFront(rlt_path, src_scene_id)
- return rlt_path
- end
-
- local visit_queue = List.New()
-
- local handle_scene_info = self.scene_map[src_scene_id]
- if not handle_scene_info then
- return rlt_path
- end
-
- handle_scene_info.visit = true
- List.PushBack(visit_queue, src_scene_id)
-
- local is_find = false
- while not List.Empty(visit_queue) do
- local handle_scene_id = List.PopFront(visit_queue)
- local handle_scene_info = self.scene_map[handle_scene_id]
-
- if handle_scene_id == tgt_scene_id then
- is_find = true
- break
- end
-
- for _,to_scene_id in pairs(handle_scene_info.to_scene_info) do
- local to_scene_info = self.scene_map[to_scene_id]
- if to_scene_info and not to_scene_info.visit then
- to_scene_info.visit = true
- to_scene_info.parent = handle_scene_id
- List.PushBack(visit_queue, to_scene_id)
- end
- end
- end
-
- -- 返回查找列表
- if is_find then
- local cur_scene_info = self.scene_map[tgt_scene_id]
- List.PushFront(rlt_path, tgt_scene_id)
- while cur_scene_info.parent do
- List.PushFront(rlt_path, cur_scene_info.parent)
- cur_scene_info = self.scene_map[cur_scene_info.parent]
- end
- end
- return rlt_path
- end
-
-
|