添加路点数据读取

This commit is contained in:
aozhiwei 2019-06-01 19:13:46 +08:00
parent c8007e81dd
commit 270d04b9fa
2 changed files with 33 additions and 9 deletions

View File

@ -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<int>& 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<int>& 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<a8::XObject> 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<GridCell*>();
std::vector<GridCell*>& 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]);
}
}
}
}
}

View File

@ -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<TiledObject>* GetObjectGroup(const std::string& object_class_name);
void Dump();
void Init();
@ -76,9 +77,6 @@ namespace f8
//速度设置
void SetGridCellSpeedByAreaId(std::map<int,int>& area_speed_hash);//key:area_id value:speed
private:
void LoadWayPointsData();
private:
std::map<std::string, std::list<TiledLayer>> layer_hash;
std::map<std::string, std::list<TiledObject>> object_group_hash;
@ -89,6 +87,5 @@ namespace f8
std::vector<GridCell> grid_cell_list; //所有的格子数组 size = x * y
std::map<std::string, std::vector<GridCell>> grid_cell_hash; //key 11|2 坐标
std::map<std::string, std::vector<std::tuple<int, int>>> waypoint_hash_; //路点数据
};
}