diff --git a/cpp/tiledmap.cc b/cpp/tiledmap.cc index 1396c4f..faafd70 100644 --- a/cpp/tiledmap.cc +++ b/cpp/tiledmap.cc @@ -30,7 +30,7 @@ namespace f8 return itr != prop_hash.end(); } - bool TiledMap::LoadTmxFile(const std::string& filename, bool new_tmx_format) + bool TiledMap::LoadTmxFile(const std::string& filename) { a8::XObject xobj; if (!xobj.ReadFromXmlFile(filename)) { @@ -110,7 +110,6 @@ namespace f8 } } - return true; } @@ -284,7 +283,8 @@ namespace f8 } } - bool TiledMap::CalcCurrPos(std::vector& path_points, int old_pos_x, int old_pos_y, int time_ms, int& curr_pos_x, int& curr_pos_y) + bool TiledMap::CalcCurrPos(std::vector& path_points, int old_pos_x, int old_pos_y, int time_ms, + int& curr_pos_x, int& curr_pos_y) { if (path_points.size() < 2) { return false; @@ -463,9 +463,36 @@ namespace f8 } } - void TiledMap::LoadWayPointsData() + void TiledMap::LoadWayPointsData(const std::string& filename) { + a8::XObject waypoints_json; + if (!waypoints_json.ReadFromJsonFile(filename)) { + abort(); + return; + } + for (auto& pair : stage_object_hash) { + int stage_id = pair.first; + StagePoint& stage = pair.second; + for (int relation_point : stage.relation_list) { + std::string path_name = a8::Format("%d-%d", {stage_id, relation_point}); + std::shared_ptr points_xobj = waypoints_json.At(path_name); + if (!points_xobj) { + abort(); + } + if (stage_path_hash.find(path_name) != stage_path_hash.end()) { + abort(); + } + stage_path_hash[path_name] = std::vector(); + std::vector& path_points = stage_path_hash[path_name]; + for (int i = 0; i < points_xobj->Size(); ++i) { + int x = points_xobj->At(i)->At(0)->AsXValue(); + int y = points_xobj->At(i)->At(1)->AsXValue(); + int index = (y-1)*tile_columns + x; + path_points.push_back(&grid_cell_list[index]); + } + } + } } } diff --git a/cpp/tiledmap.h b/cpp/tiledmap.h index 8185507..21a6148 100644 --- a/cpp/tiledmap.h +++ b/cpp/tiledmap.h @@ -60,7 +60,8 @@ namespace f8 int tile_rows = 0; //行 int tile_columns = 0; //列 - bool LoadTmxFile(const std::string& filename, bool new_tmx_format = false); + bool LoadTmxFile(const std::string& filename); + void LoadWayPointsData(const std::string& filename); std::list* GetObjectGroup(const std::string& object_class_name); void Dump(); void Init(); @@ -76,9 +77,6 @@ namespace f8 //速度设置 void SetGridCellSpeedByAreaId(std::map& area_speed_hash);//key:area_id value:speed - private: - void LoadWayPointsData(); - private: std::map> layer_hash; std::map> object_group_hash; @@ -89,6 +87,5 @@ namespace f8 std::vector grid_cell_list; //所有的格子数组 size = x * y std::map> grid_cell_hash; //key 11|2 坐标 - std::map>> waypoint_hash_; //路点数据 }; }