This commit is contained in:
aozhiwei 2023-06-26 16:44:16 +08:00
parent 9e0351ff12
commit a8e99b62d5
3 changed files with 59 additions and 59 deletions

View File

@ -30,16 +30,36 @@ bool Movement::UpdatePosition()
owner_->room->map_instance->CheckTerrain(owner_, curr_point.same_polys_flags, curr_point.spec_polys);
}
if (owner_->GetPos().Distance2D2(curr_point.src_pos) - curr_point.distance >= 0.0001f) {
#ifdef DEBUG1
if (owner_->IsPlayer()) {
a8::XPrintf("UpdatePosition curr_pos:%f %f %f tar_pos:%f %f %f\n",
{
curr_point.curr_pos.GetX(),
curr_point.curr_pos.GetY(),
curr_point.curr_pos.GetZ(),
curr_point.tar_pos.GetX(),
curr_point.tar_pos.GetY(),
curr_point.tar_pos.GetZ()
});
}
#endif
curr_point.tar_pos.SetY(curr_point.curr_pos.GetY());
owner_->SetPos(curr_point.tar_pos);
++path_index_;
if (path_index_ < paths_.size()) {
MovePathPoint& next_point = paths_[path_index_];
if (IsFindPath()) {
owner_->SetMoveDir(next_point.dir);
owner_->SetAttackDir(next_point.dir);
}
#if 0
glm::vec3 dir = next_point.tar_pos.ToGlmVec3() - owner_->GetPos().ToGlmVec3();
GlmHelper::Normalize(dir);
next_point.dir.x = dir.x;
next_point.dir.y = dir.y;
next_point.dir.z = dir.z;
#endif
}
}
owner_->AdjustPos();
@ -168,50 +188,6 @@ void Movement::ClearPath()
paths_.clear();
}
void Movement::AddPaths(const glm::vec3& start, std::vector<glm::vec3>& paths)
{
if (paths.empty()) {
abort();
return;
}
glm::vec3 last_pos;
last_pos.x = start.x;
last_pos.y = start.y;
last_pos.z = start.z;
size_t i = 0;
if (std::abs(last_pos.x - paths[0].x) < 0.00001f &&
std::abs(last_pos.z - paths[0].z) < 0.00001f) {
if (paths.size() < 2) {
abort();
}
++i;
}
for (; i < paths.size(); ++i) {
MovePathPoint p;
p.src_pos.FromGlmVec3(owner_->room->map_instance->UnScaleEx(last_pos));
p.tar_pos.FromGlmVec3(owner_->room->map_instance->UnScaleEx(paths[i]));
p.dir = p.tar_pos.ToGlmVec3() - p.src_pos.ToGlmVec3();
GlmHelper::Normalize(p.dir);
p.curr_pos = p.src_pos;
last_pos = paths[i];
#ifdef DEBUG1
a8::XPrintf("AddPaths size:%d i:%d src_pos:%f,%f tar_pos:%f:%f\n",
{
paths.size(),
i,
src_pos.x,
src_pos.y,
tar_pos.x,
tar_pos.y});
#endif
paths_.push_back(p);
}
is_find_path_ = true;
}
size_t Movement::GetPathSize()
{
return paths_.size();
@ -225,24 +201,49 @@ bool Movement::FindPath(const glm::vec3& target_pos, float distance)
glm::vec3 end = target_pos;
std::vector<glm::vec3> paths;
owner_->room->map_instance->Scale(start);
owner_->room->map_instance->Scale(end);
owner_->room->map_instance->FindStraightPath(start, end, paths);
if (paths.size() > 0) {
glm::vec3 last_pos = owner_->GetPos().ToGlmVec3();
for (const glm::vec3& pos : paths) {
glm::vec3 dir = pos - last_pos;
GlmHelper::Normalize(dir);
MovePathPoint point;
point.src_pos.FromGlmVec3(last_pos);
point.dir.x = dir.x;
point.dir.y = dir.y;
point.dir.z = dir.z;
point.distance -= GlmHelper::Norm(pos - last_pos);
point.tar_pos.FromGlmVec3(pos);
paths_.push_back(point);
for (const glm::vec3& pos1 : paths) {
glm::vec3 pos = pos1;
last_pos = pos;
owner_->room->map_instance->UnScale(pos);
if (!GlmHelper::IsEqual2D(pos, last_pos)) {
glm::vec3 dir = pos - last_pos;
GlmHelper::Normalize(dir);
MovePathPoint point;
point.src_pos.FromGlmVec3(last_pos);
point.curr_pos.FromGlmVec3(last_pos);
point.dir.x = dir.x;
point.dir.y = dir.y;
point.dir.z = dir.z;
point.distance = GlmHelper::Norm2D(pos - last_pos);
point.tar_pos.FromGlmVec3(pos);
paths_.push_back(point);
last_pos = pos;
#ifdef DEBUG1
a8::XPrintf("src_pos:%f %f %f tar_pos:%f %f %f distance:%f\n",
{
last_pos.x,
last_pos.y,
last_pos.z,
pos.x,
pos.y,
pos.z,
point.distance
});
#endif
}
}
is_find_path_ = true;
if (!paths_.empty()) {
owner_->SetMoveDir(paths_.at(0).dir);
owner_->SetAttackDir(paths_.at(0).dir);
}
}
return !paths.empty();
return !paths_.empty();
}

View File

@ -25,7 +25,6 @@ class Movement
bool UpdatePosition();
void CalcTargetPos(float distance);
void ClearPath();
void AddPaths(const glm::vec3& start, std::vector<glm::vec3>& paths);
size_t GetPathSize();
bool IsFindPath() { return is_find_path_; }
bool FindPath(const glm::vec3& target_pos, float distance);

View File

@ -799,7 +799,7 @@ void RoomMgr::AdjustCMJoin(cs::CMJoin* msg)
#endif
#endif
#endif
#ifdef DEBUG
#ifdef DEBUG1
if (DebugCmd::Enable()) {
msg->set_room_mode(kPvpRankMode);
}