Fix character flying from origin when detached in a frame after Update was already perfomed
This commit is contained in:
parent
2d6d280f8c
commit
f1770f372d
@ -67,6 +67,18 @@ void game::Character::SendInitData(Player& player, net::OutMessage& msg) const
|
|||||||
msg.WriteAt(fields_pos, fields);
|
msg.WriteAt(fields_pos, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game::Character::Attach(net::EntNum parentnum)
|
||||||
|
{
|
||||||
|
Super::Attach(parentnum);
|
||||||
|
|
||||||
|
// remake these if already updated
|
||||||
|
if (IsUpToDate())
|
||||||
|
{
|
||||||
|
UpdateSyncState();
|
||||||
|
SendUpdateMsg();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void game::Character::EnablePhysics(bool enable)
|
void game::Character::EnablePhysics(bool enable)
|
||||||
{
|
{
|
||||||
if (enable && !controller_)
|
if (enable && !controller_)
|
||||||
|
|||||||
@ -52,6 +52,8 @@ public:
|
|||||||
virtual void Update() override;
|
virtual void Update() override;
|
||||||
virtual void SendInitData(Player& player, net::OutMessage& msg) const override;
|
virtual void SendInitData(Player& player, net::OutMessage& msg) const override;
|
||||||
|
|
||||||
|
virtual void Attach(net::EntNum parentnum) override;
|
||||||
|
|
||||||
const CharacterTuning& GetTuning() const { return tuning_; }
|
const CharacterTuning& GetTuning() const { return tuning_; }
|
||||||
|
|
||||||
void EnablePhysics(bool enable);
|
void EnablePhysics(bool enable);
|
||||||
|
|||||||
@ -12,7 +12,7 @@ void game::Entity::SendInitData(Player& player, net::OutMessage& msg) const
|
|||||||
|
|
||||||
void game::Entity::Update()
|
void game::Entity::Update()
|
||||||
{
|
{
|
||||||
upd_time_ = world_.GetTime();
|
up_to_date_ = true;
|
||||||
|
|
||||||
// ensure parent is updated
|
// ensure parent is updated
|
||||||
parent_ = nullptr;
|
parent_ = nullptr;
|
||||||
@ -32,8 +32,7 @@ void game::Entity::Update()
|
|||||||
|
|
||||||
bool game::Entity::TryUpdate()
|
bool game::Entity::TryUpdate()
|
||||||
{
|
{
|
||||||
int64_t time = world_.GetTime();
|
if (IsUpToDate())
|
||||||
if (time == upd_time_)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
@ -44,6 +43,7 @@ void game::Entity::FinalizeFrame()
|
|||||||
{
|
{
|
||||||
ResetMsg();
|
ResetMsg();
|
||||||
DiscardUpdateMsg();
|
DiscardUpdateMsg();
|
||||||
|
up_to_date_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game::Entity::SetNametag(const std::string& nametag)
|
void game::Entity::SetNametag(const std::string& nametag)
|
||||||
|
|||||||
@ -29,8 +29,8 @@ public:
|
|||||||
virtual void SendInitData(Player& player, net::OutMessage& msg) const;
|
virtual void SendInitData(Player& player, net::OutMessage& msg) const;
|
||||||
|
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
|
bool IsUpToDate() const { return up_to_date_; }
|
||||||
bool TryUpdate(); // if not already updated
|
bool TryUpdate(); // if not already updated
|
||||||
int64_t GetUpdateTime() const { return upd_time_; }
|
|
||||||
|
|
||||||
std::span<const char> GetUpdateMsg() const { return update_msg_buf_; }
|
std::span<const char> GetUpdateMsg() const { return update_msg_buf_; }
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
void SetNametag(const std::string& nametag);
|
void SetNametag(const std::string& nametag);
|
||||||
|
|
||||||
void Attach(net::EntNum parentnum);
|
virtual void Attach(net::EntNum parentnum);
|
||||||
net::EntNum GetParentNum() const { return parentnum_; }
|
net::EntNum GetParentNum() const { return parentnum_; }
|
||||||
|
|
||||||
void PlaySound(const std::string& name, float volume = 1.0f, float pitch = 1.0f);
|
void PlaySound(const std::string& name, float volume = 1.0f, float pitch = 1.0f);
|
||||||
@ -78,7 +78,7 @@ protected:
|
|||||||
bool removed_ = false;
|
bool removed_ = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64_t upd_time_ = -1;
|
bool up_to_date_ = false;
|
||||||
|
|
||||||
std::vector<char> update_msg_buf_;
|
std::vector<char> update_msg_buf_;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user