1
This commit is contained in:
parent
8e64f163ec
commit
409eaf6efe
@ -969,10 +969,20 @@ void Bullet::Raycast()
|
|||||||
sender.Get()->room->map_instance->Scale(start);
|
sender.Get()->room->map_instance->Scale(start);
|
||||||
sender.Get()->room->map_instance->Scale(end);
|
sender.Get()->room->map_instance->Scale(end);
|
||||||
bool ret = sender.Get()->room->map_instance->Raycast(0, start, end, hit_point, hit_result);
|
bool ret = sender.Get()->room->map_instance->Raycast(0, start, end, hit_point, hit_result);
|
||||||
if (ret) {
|
if (ret && hit_result) {
|
||||||
raycast_hited = true;
|
raycast_hited = true;
|
||||||
sender.Get()->room->map_instance->UnScale(hit_point);
|
sender.Get()->room->map_instance->UnScale(hit_point);
|
||||||
raycast_hit_point_ = hit_point;
|
raycast_hit_point_ = hit_point;
|
||||||
raycast_len_ = GlmHelper::Norm(hit_point - born_pos.ToGlmVec3());
|
raycast_len_ = GlmHelper::Norm(hit_point - born_pos.ToGlmVec3());
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("bullet.raycast ret:%d hit_result:%d raycast_hit_point_:%f,%f,%f\n",
|
||||||
|
{
|
||||||
|
ret,
|
||||||
|
hit_result,
|
||||||
|
raycast_hit_point_.x,
|
||||||
|
raycast_hit_point_.y,
|
||||||
|
raycast_hit_point_.z,
|
||||||
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -2546,22 +2546,20 @@ void Creature::AutoNavigation(const glm::vec3& target_pos, float speed,
|
|||||||
struct NavContext
|
struct NavContext
|
||||||
{
|
{
|
||||||
CreatureWeakPtr c;
|
CreatureWeakPtr c;
|
||||||
Position src_pos;
|
glm::vec3 src_pos;
|
||||||
glm::vec3 target_pos;
|
glm::vec3 target_pos;
|
||||||
glm::vec3 dir;
|
glm::vec3 dir;
|
||||||
int exec_frameno = 0;
|
int exec_frameno = 0;
|
||||||
float speed = 0.0f;
|
float speed = 0.0f;
|
||||||
float distance = 0.0f;
|
|
||||||
std::function<void (Creature*)> cb;
|
std::function<void (Creature*)> cb;
|
||||||
};
|
};
|
||||||
std::shared_ptr<NavContext> context = std::make_shared<NavContext>();
|
std::shared_ptr<NavContext> context = std::make_shared<NavContext>();
|
||||||
context->c = GetWeakPtrRef();
|
context->c = GetWeakPtrRef();
|
||||||
context->src_pos = GetPos();
|
context->src_pos = GetPos().ToGlmVec3();
|
||||||
context->target_pos = target_pos;
|
context->target_pos = target_pos;
|
||||||
context->dir = target_pos - GetPos().ToGlmVec3();
|
context->dir = target_pos - GetPos().ToGlmVec3();
|
||||||
GlmHelper::Normalize(context->dir);
|
GlmHelper::Normalize(context->dir);
|
||||||
context->speed = speed;
|
context->speed = speed;
|
||||||
context->distance = distance;
|
|
||||||
context->cb = cb;
|
context->cb = cb;
|
||||||
|
|
||||||
IncDisableMoveTimes();
|
IncDisableMoveTimes();
|
||||||
@ -2571,46 +2569,47 @@ void Creature::AutoNavigation(const glm::vec3& target_pos, float speed,
|
|||||||
{
|
{
|
||||||
if (a8::TIMER_EXEC_EVENT == event) {
|
if (a8::TIMER_EXEC_EVENT == event) {
|
||||||
++context->exec_frameno;
|
++context->exec_frameno;
|
||||||
|
if (context->c.Get()) {
|
||||||
|
Room* room = context->c.Get()->room;
|
||||||
|
Creature* c = context->c.Get();
|
||||||
|
|
||||||
Room* room = context->c.Get()->room;
|
glm::vec3 curr_pos = context->src_pos +
|
||||||
Creature* c = context->c.Get();
|
context->dir * (context->speed / FRAME_RATE_MS) * (float)context->exec_frameno;
|
||||||
|
Global::Instance()->verify_set_pos = 1;
|
||||||
glm::vec3 dir = context->target_pos - c->GetPos().ToGlmVec3();
|
c->GetMutablePos().FromGlmVec3(curr_pos);
|
||||||
GlmHelper::Normalize(dir);
|
Global::Instance()->verify_set_pos = 0;
|
||||||
Position old_pos = c->GetPos();
|
room->grid_service->MoveCreature(c);
|
||||||
float move_length = context->speed / (float)SERVER_FRAME_RATE;
|
|
||||||
float move_distance = std::min(move_length * context->exec_frameno, context->distance);
|
|
||||||
Position new_pos = context->src_pos;
|
|
||||||
new_pos.AddGlmVec3(dir * move_distance);
|
|
||||||
Global::Instance()->verify_set_pos = 1;
|
|
||||||
c->SetPos(new_pos);
|
|
||||||
Global::Instance()->verify_set_pos = 0;
|
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
if (GlmHelper::Norm(context->target_pos - context->src_pos) <=
|
||||||
|
GlmHelper::Norm(curr_pos - context->src_pos)) {
|
||||||
|
Global::Instance()->verify_set_pos = 1;
|
||||||
|
c->GetMutablePos().FromGlmVec3(context->target_pos);
|
||||||
|
Global::Instance()->verify_set_pos = 0;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
a8::XPrintf("speed:%d src_pos:%f,%f,%f new_pos:%f,%f,%f move_distance:%f src_distance:%f "
|
a8::XPrintf("speed:%d src_pos:%f,%f,%f curr_pos:%f,%f,%f "
|
||||||
"target_pos:%f,%f,%f\n",
|
"target_pos:%f,%f,%f\n",
|
||||||
{
|
{
|
||||||
context->speed,
|
context->speed,
|
||||||
context->src_pos.x,
|
context->src_pos.x,
|
||||||
context->src_pos.y,
|
context->src_pos.y,
|
||||||
context->src_pos.z,
|
context->src_pos.z,
|
||||||
new_pos.x,
|
curr_pos.x,
|
||||||
new_pos.y,
|
curr_pos.y,
|
||||||
new_pos.z,
|
curr_pos.z,
|
||||||
move_distance,
|
context->target_pos.x,
|
||||||
context->distance,
|
context->target_pos.y,
|
||||||
context->target_pos.x,
|
context->target_pos.z
|
||||||
context->target_pos.y,
|
});
|
||||||
context->target_pos.z
|
|
||||||
});
|
|
||||||
#endif
|
#endif
|
||||||
bool ok = std::abs(move_distance - context->distance) < 0.0001f;
|
|
||||||
room->grid_service->MoveCreature(c);
|
|
||||||
|
|
||||||
if (ok || c->dead) {
|
if (ok || c->dead) {
|
||||||
context->cb(c);
|
context->cb(c);
|
||||||
c->DecDisableMoveTimes();
|
c->DecDisableMoveTimes();
|
||||||
room->xtimer.DeleteCurrentTimer();
|
room->xtimer.DeleteCurrentTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -435,7 +435,7 @@ bool MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& en
|
|||||||
memset(hit_normal_, 0, sizeof(hit_normal_));
|
memset(hit_normal_, 0, sizeof(hit_normal_));
|
||||||
navmesh_query_->raycast(startRef, spos, epos, &filter, &t, hit_normal_, polys_, &npolys, MAX_POLYS);
|
navmesh_query_->raycast(startRef, spos, epos, &filter, &t, hit_normal_, polys_, &npolys, MAX_POLYS);
|
||||||
|
|
||||||
#ifdef DEBUG1
|
#ifdef DEBUG
|
||||||
{
|
{
|
||||||
std::string dbg_data = a8::Format("npolys:%d t:%f ", {npolys, t});
|
std::string dbg_data = a8::Format("npolys:%d t:%f ", {npolys, t});
|
||||||
for (int i = 0; i < npolys; ++i) {
|
for (int i = 0; i < npolys; ++i) {
|
||||||
@ -485,8 +485,6 @@ bool MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& en
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ok){
|
if (!ok){
|
||||||
ok = true;
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
hit_pos_copy[0] -= dir.x;
|
hit_pos_copy[0] -= dir.x;
|
||||||
hit_pos_copy[2] -= dir.z;
|
hit_pos_copy[2] -= dir.z;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user