This commit is contained in:
aozhiwei 2023-05-30 15:45:57 +08:00
parent 95c606490f
commit f173868aae
3 changed files with 23 additions and 0 deletions

View File

@ -76,3 +76,10 @@ bool GlmHelper::IsEqual2D(const glm::vec3& v1, const glm::vec3& v2)
{
return std::abs(v1.x - v2.x) < 0.00001f && std::abs(v1.z - v2.z) < 0.00001f;
}
bool GlmHelper::IsEqual3D(const glm::vec3& v1, const glm::vec3& v2)
{
return std::abs(v1.x - v2.x) < 0.00001f &&
std::abs(v1.y - v2.y) < 0.00001f &&
std::abs(v1.z - v2.z) < 0.00001f;
}

View File

@ -14,6 +14,7 @@ class GlmHelper
static bool IsZero(const glm::vec3& v);
static bool IsEqual2D(const glm::vec3& v1, const glm::vec3& v2);
static bool IsEqual3D(const glm::vec3& v1, const glm::vec3& v2);
static float CalcAngle(const glm::vec3& v1, const glm::vec3& v2);

View File

@ -2146,5 +2146,20 @@ void Room::NotifyNewsTicker(int msg_type, std::vector<std::string> msg_content)
void SyncObject::FillSMSyncPosition(cs::SMSyncPosition& sync_msg)
{
if (!c.Get()) {
return;
}
bool need_sync = !GlmHelper::IsEqual3D(c.Get()->GetPos().ToGlmVec3(), pos) ||
!GlmHelper::IsEqual3D(c.Get()->GetAttackDir(), dir) ||
c.Get()->room->GetFrameNo() - last_sync_frameno > SERVER_FRAME_RATE * 10;
if (need_sync) {
auto obj = sync_msg.add_obj_list();
obj->set_obj_uniid(obj_uniid);
TypeConvert::ToPb(c.Get()->GetPos().ToGlmVec3(), obj->mutable_pos());
TypeConvert::ToPb(c.Get()->GetAttackDir(), obj->mutable_dir());
pos = c.Get()->GetPos().ToGlmVec3();
dir = c.Get()->GetAttackDir();
last_sync_frameno = c.Get()->room->GetFrameNo();
}
}