1
This commit is contained in:
parent
c451112e94
commit
82ba602486
@ -18,6 +18,7 @@
|
||||
#include "mt/MetaMgr.h"
|
||||
#include "mt/Param.h"
|
||||
#include "mt/Map.h"
|
||||
#include "mt/MapArea.h"
|
||||
|
||||
#include "roommgr.h"
|
||||
|
||||
@ -608,4 +609,25 @@ void MapInstance::MarkMapAreaPolys()
|
||||
if (!tile) {
|
||||
abort();
|
||||
}
|
||||
for (int i = 0; i < tile->header->polyCount; ++i) {
|
||||
dtPoly* poly = &tile->polys[i];
|
||||
const mt::MapArea* last_area_meta = nullptr;
|
||||
if ((poly->flags & SAMPLE_POLYFLAGS_SWIM) == SAMPLE_POLYFLAGS_SWIM) {
|
||||
for (int ii = 0; ii < poly->vertCount; ++ii) {
|
||||
const float* vc = &tile->verts[poly->verts[ii]*3];
|
||||
const mt::MapArea* area_meta = mt::MapArea::GetAreaByPoint
|
||||
(map_meta_->map_id(),
|
||||
vc[0] * GetMapMeta()->scale(),
|
||||
vc[1],
|
||||
vc[2] * GetMapMeta()->scale());
|
||||
if (!area_meta) {
|
||||
abort();
|
||||
}
|
||||
if (last_area_meta && last_area_meta != area_meta) {
|
||||
abort();
|
||||
}
|
||||
last_area_meta = area_meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,34 @@ namespace mt
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(area_center(), strings, ':');
|
||||
if (strings.size() != 2) {
|
||||
abort();
|
||||
}
|
||||
center_ = glm::vec2(a8::XValue(strings[0]).GetDouble(), a8::XValue(strings[1]).GetDouble());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const mt::MapArea*>* MapArea::GetAreas(int map_id)
|
||||
const mt::MapArea* MapArea::GetAreaByPoint(int map_id, float x, float y, float z)
|
||||
{
|
||||
auto itr = map_areas.find(map_id);
|
||||
return itr != map_areas.end() ? &itr->second : nullptr;
|
||||
if (itr != map_areas.end()) {
|
||||
for (auto area_meta : itr->second) {
|
||||
if (x < area_meta->center_.x - area_meta->area_width() / 2) {
|
||||
break;
|
||||
}
|
||||
if (x > area_meta->center_.x + area_meta->area_width() / 2) {
|
||||
break;
|
||||
}
|
||||
if (y < area_meta->center_.y - area_meta->area_height() / 2) {
|
||||
break;
|
||||
}
|
||||
if (y > area_meta->center_.y + area_meta->area_height() / 2) {
|
||||
break;
|
||||
}
|
||||
return area_meta;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,9 +12,8 @@ namespace mt
|
||||
public:
|
||||
|
||||
void Init1();
|
||||
const glm::vec2 GetCenter() { return center_; };
|
||||
|
||||
static std::vector<const mt::MapArea*>* GetAreas(int map_id);
|
||||
static const mt::MapArea* GetAreaByPoint(int map_id, float x, float y, float z);
|
||||
|
||||
private:
|
||||
glm::vec2 center_ = glm::vec2(0.0f, 0.0f);
|
||||
|
Loading…
x
Reference in New Issue
Block a user