1
This commit is contained in:
parent
93495e51e0
commit
ea813bf43c
@ -701,94 +701,91 @@ void MapInstance::MarkMapAreaPolys()
|
||||
|
||||
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");
|
||||
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();
|
||||
}
|
||||
{
|
||||
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::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)});
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)GetMapMeta()->map_width() % MAP_HEIGHT_GRID_SIZE != 0 ||
|
||||
(int)GetMapMeta()->map_height() % MAP_HEIGHT_GRID_SIZE != 0 ) {
|
||||
abort();
|
||||
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)});
|
||||
}
|
||||
}
|
||||
|
||||
grid_width_ = GetMapMeta()->map_width() / MAP_HEIGHT_GRID_SIZE;
|
||||
grid_height_ = GetMapMeta()->map_height() / MAP_HEIGHT_GRID_SIZE;
|
||||
if ((int)GetMapMeta()->map_width() % MAP_HEIGHT_GRID_SIZE != 0 ||
|
||||
(int)GetMapMeta()->map_height() % MAP_HEIGHT_GRID_SIZE != 0 ) {
|
||||
abort();
|
||||
}
|
||||
|
||||
height_datas_.resize(grid_width_ * grid_height_);
|
||||
{
|
||||
int curr_x = 0;
|
||||
int curr_y = 0;
|
||||
for (auto& itr : list.datas()) {
|
||||
if (itr.x() != curr_x) {
|
||||
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()) {
|
||||
grid_width_ = GetMapMeta()->map_width() / MAP_HEIGHT_GRID_SIZE;
|
||||
grid_height_ = GetMapMeta()->map_height() / MAP_HEIGHT_GRID_SIZE;
|
||||
|
||||
height_datas_.resize(grid_width_ * grid_height_);
|
||||
{
|
||||
int curr_x = 0;
|
||||
int curr_y = 0;
|
||||
for (auto& itr : list.datas()) {
|
||||
if (itr.x() != curr_x) {
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user