From 8e58095243702619490e5ef56547bb4eab0a8a90 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 26 Aug 2018 19:34:06 +0800 Subject: [PATCH] 1 --- cpp/tiledmap.cc | 97 ++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/cpp/tiledmap.cc b/cpp/tiledmap.cc index 88ccd96..37c48ec 100644 --- a/cpp/tiledmap.cc +++ b/cpp/tiledmap.cc @@ -278,62 +278,66 @@ bool TiledMap::CalcCurrPos(std::vector& path_points, int old_pos_x, int old if (path_points.size() < 2) { return false; } - std::string path_point; std::vector stage_path_list; - bool path_start = true; - std::vector grid_all_list; - for (auto& point : path_points) { - if (path_start) { - path_point = a8::XValue(point).GetString(); - path_start = !path_start; - } else { - std::string point_str = a8::XValue(point).GetString(); - path_point += "-" + point_str; - stage_path_list.push_back(path_point); - path_point = point_str; - } - } - - bool exc_once = true; - for (auto& stage_path : stage_path_list) { - std::vector* grid_list = nullptr; - - std::string stage_path_reverse; - std::vector split_list; - a8::Split(stage_path,split_list,'-'); - if (split_list.size() != 2) { - return false; - } - StagePoint* sp = GetStageObject(a8::XValue(split_list.at(0))); - if (sp == nullptr) { - return false; - } - grid_list = GetStagePath(stage_path); - if (grid_list == nullptr) { - stage_path_reverse = split_list[1] + "-" + split_list[0]; - grid_list = GetStagePath(stage_path_reverse); - if (grid_list == nullptr) { - return false; + { + std::string path_point; + bool path_start = true; + for (auto& point : path_points) { + if (path_start) { + path_point = a8::XValue(point).GetString(); + path_start = !path_start; + } else { + std::string point_str = a8::XValue(point).GetString(); + path_point += "-" + point_str; + stage_path_list.push_back(path_point); + path_point = point_str; } } + } + std::vector grid_all_list; + { + bool exc_once = true; + for (auto& stage_path : stage_path_list) { + std::vector* grid_list = nullptr; - std::vector grid_sort_list = SortGridList(grid_list,sp); - if (grid_sort_list.empty()){ - return false; - } - if (exc_once) { - grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin(),grid_sort_list.end()); - exc_once = false; - } else { - grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin()+1,grid_sort_list.end()); + std::string stage_path_reverse; + std::vector split_list; + a8::Split(stage_path,split_list,'-'); + if (split_list.size() != 2) { + return false; + } + StagePoint* sp = GetStageObject(a8::XValue(split_list.at(0))); + if (sp == nullptr) { + return false; + } + grid_list = GetStagePath(stage_path); + if (grid_list == nullptr) { + stage_path_reverse = split_list[1] + "-" + split_list[0]; + grid_list = GetStagePath(stage_path_reverse); + if (grid_list == nullptr) { + return false; + } + } + + std::vector grid_sort_list = SortGridList(grid_list,sp); + if (grid_sort_list.empty()){ + return false; + } + if (exc_once) { + grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin(),grid_sort_list.end()); + exc_once = false; + } else { + grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin()+1,grid_sort_list.end()); + } } } if (grid_all_list.empty()) { return false; } - int grid_all_count = grid_all_list.size(); - for (int i = 0; i < grid_all_count-1; ++i) { + { + int grid_all_count = grid_all_list.size(); + for (int i = 0; i < grid_all_count-1; ++i) { GridCell* gc_first = grid_all_list[i]; GridCell* gc_second = grid_all_list[i+1]; int speed = gc_first->speed; @@ -354,6 +358,7 @@ bool TiledMap::CalcCurrPos(std::vector& path_points, int old_pos_x, int old if (time_ms < 0) { return true; } + } } if (time_ms > 0) { return true;