This commit is contained in:
aozhiwei 2023-02-01 14:35:36 +08:00
parent 93495e51e0
commit ea813bf43c

View File

@ -701,94 +701,91 @@ void MapInstance::MarkMapAreaPolys()
void MapInstance::LoadHeightData() void MapInstance::LoadHeightData()
{ {
#if 1 FILE *fp = fopen(("main3d_mapHeight.txt"), "rb");
if (!fp) {
A8_ABORT();
}
fseek(fp, 0, SEEK_END);
size_t file_size = ftell(fp);
char *p = (char*)malloc(file_size);
fseek(fp, 0, SEEK_SET);
fread(p, 1, file_size, fp);
navmesh::HeightList list;
list.ParseFromArray(p, file_size);
if (list.width() != (int)GetMapMeta()->map_width() ||
list.height() != (int)GetMapMeta()->map_height()) {
A8_ABORT();
}
{ {
FILE *fp = fopen(("main3d_mapHeight.txt"), "rb"); std::map<int, int> height_hash;
if (!fp) { for (auto& itr : list.datas()) {
A8_ABORT(); for (auto& itr2 : itr.infos()) {
} auto itr3 = height_hash.find(itr2.h());
fseek(fp, 0, SEEK_END); if (itr3 != height_hash.end()) {
size_t file_size = ftell(fp); height_hash[itr2.h()] += 1;
char *p = (char*)malloc(file_size); } else {
fseek(fp, 0, SEEK_SET); height_hash[itr2.h()] = 1;
fread(p, 1, file_size, fp);
navmesh::HeightList list;
list.ParseFromArray(p, file_size);
if (list.width() != (int)GetMapMeta()->map_width() ||
list.height() != (int)GetMapMeta()->map_height()) {
A8_ABORT();
}
{
std::map<int, int> height_hash;
for (auto& itr : list.datas()) {
for (auto& itr2 : itr.infos()) {
auto itr3 = height_hash.find(itr2.h());
if (itr3 != height_hash.end()) {
height_hash[itr2.h()] += 1;
} else {
height_hash[itr2.h()] = 1;
}
} }
} }
std::vector<std::tuple<int, int>> height_sorted;
for (auto& pair : height_hash) {
height_sorted.push_back(std::make_tuple((int)pair.first, (int)pair.second));
}
std::sort(height_sorted.begin(), height_sorted.end(),
[] (std::tuple<int, int>& a, std::tuple<int, int>& b)
{
return std::get<1>(a) > std::get<1>(b);
});
for (auto& tuple : height_sorted) {
a8::XPrintf("%d,%d\n", {std::get<0>(tuple), std::get<1>(tuple)});
}
} }
std::vector<std::tuple<int, int>> height_sorted;
if ((int)GetMapMeta()->map_width() % MAP_HEIGHT_GRID_SIZE != 0 || for (auto& pair : height_hash) {
(int)GetMapMeta()->map_height() % MAP_HEIGHT_GRID_SIZE != 0 ) { height_sorted.push_back(std::make_tuple((int)pair.first, (int)pair.second));
abort();
} }
std::sort(height_sorted.begin(), height_sorted.end(),
[] (std::tuple<int, int>& a, std::tuple<int, int>& b)
{
return std::get<1>(a) > std::get<1>(b);
});
for (auto& tuple : height_sorted) {
a8::XPrintf("%d,%d\n", {std::get<0>(tuple), std::get<1>(tuple)});
}
}
grid_width_ = GetMapMeta()->map_width() / MAP_HEIGHT_GRID_SIZE; if ((int)GetMapMeta()->map_width() % MAP_HEIGHT_GRID_SIZE != 0 ||
grid_height_ = GetMapMeta()->map_height() / MAP_HEIGHT_GRID_SIZE; (int)GetMapMeta()->map_height() % MAP_HEIGHT_GRID_SIZE != 0 ) {
abort();
}
height_datas_.resize(grid_width_ * grid_height_); grid_width_ = GetMapMeta()->map_width() / MAP_HEIGHT_GRID_SIZE;
{ grid_height_ = GetMapMeta()->map_height() / MAP_HEIGHT_GRID_SIZE;
int curr_x = 0;
int curr_y = 0; height_datas_.resize(grid_width_ * grid_height_);
for (auto& itr : list.datas()) { {
if (itr.x() != curr_x) { int curr_x = 0;
abort(); int curr_y = 0;
} for (auto& itr : list.datas()) {
if (itr.y() != curr_y) { if (itr.x() != curr_x) {
abort();
}
curr_x = itr.x() + 1;
if (itr.has_endx()) {
curr_x = itr.endx() + 1;
}
//a8::XPrintf("x:%d y:%d end_x:%d\n", {itr.x(), itr.y(), itr.endx()});
if (curr_x > (int)GetMapMeta()->map_width()) {
abort();
}
if (curr_x == (int)GetMapMeta()->map_width()) {
curr_x = 0;
++curr_y;
}
if (curr_y > (int)GetMapMeta()->map_height()) {
abort();
}
for (auto& itr2 : itr.infos()) {
}
}
if (curr_y != (int)GetMapMeta()->map_height()) {
abort(); abort();
} }
if (itr.y() != curr_y) {
abort();
}
curr_x = itr.x() + 1;
if (itr.has_endx()) {
curr_x = itr.endx() + 1;
}
//a8::XPrintf("x:%d y:%d end_x:%d\n", {itr.x(), itr.y(), itr.endx()});
if (curr_x > (int)GetMapMeta()->map_width()) {
abort();
}
if (curr_x == (int)GetMapMeta()->map_width()) {
curr_x = 0;
++curr_y;
}
if (curr_y > (int)GetMapMeta()->map_height()) {
abort();
}
for (auto& itr2 : itr.infos()) {
}
}
if (curr_y != (int)GetMapMeta()->map_height()) {
abort();
} }
free(p);
fclose(fp);
} }
#endif
free(p);
fclose(fp);
} }