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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (enable && !controller_)
|
||||
|
||||
@ -52,6 +52,8 @@ public:
|
||||
virtual void Update() override;
|
||||
virtual void SendInitData(Player& player, net::OutMessage& msg) const override;
|
||||
|
||||
virtual void Attach(net::EntNum parentnum) override;
|
||||
|
||||
const CharacterTuning& GetTuning() const { return tuning_; }
|
||||
|
||||
void EnablePhysics(bool enable);
|
||||
|
||||
@ -12,7 +12,7 @@ void game::Entity::SendInitData(Player& player, net::OutMessage& msg) const
|
||||
|
||||
void game::Entity::Update()
|
||||
{
|
||||
upd_time_ = world_.GetTime();
|
||||
up_to_date_ = true;
|
||||
|
||||
// ensure parent is updated
|
||||
parent_ = nullptr;
|
||||
@ -32,8 +32,7 @@ void game::Entity::Update()
|
||||
|
||||
bool game::Entity::TryUpdate()
|
||||
{
|
||||
int64_t time = world_.GetTime();
|
||||
if (time == upd_time_)
|
||||
if (IsUpToDate())
|
||||
return false;
|
||||
|
||||
Update();
|
||||
@ -44,6 +43,7 @@ void game::Entity::FinalizeFrame()
|
||||
{
|
||||
ResetMsg();
|
||||
DiscardUpdateMsg();
|
||||
up_to_date_ = false;
|
||||
}
|
||||
|
||||
void game::Entity::SetNametag(const std::string& nametag)
|
||||
|
||||
@ -29,8 +29,8 @@ public:
|
||||
virtual void SendInitData(Player& player, net::OutMessage& msg) const;
|
||||
|
||||
virtual void Update();
|
||||
bool IsUpToDate() const { return up_to_date_; }
|
||||
bool TryUpdate(); // if not already updated
|
||||
int64_t GetUpdateTime() const { return upd_time_; }
|
||||
|
||||
std::span<const char> GetUpdateMsg() const { return update_msg_buf_; }
|
||||
|
||||
@ -38,7 +38,7 @@ public:
|
||||
|
||||
void SetNametag(const std::string& nametag);
|
||||
|
||||
void Attach(net::EntNum parentnum);
|
||||
virtual void Attach(net::EntNum parentnum);
|
||||
net::EntNum GetParentNum() const { return parentnum_; }
|
||||
|
||||
void PlaySound(const std::string& name, float volume = 1.0f, float pitch = 1.0f);
|
||||
@ -78,8 +78,8 @@ protected:
|
||||
bool removed_ = false;
|
||||
|
||||
private:
|
||||
int64_t upd_time_ = -1;
|
||||
|
||||
bool up_to_date_ = false;
|
||||
|
||||
std::vector<char> update_msg_buf_;
|
||||
|
||||
std::string nametag_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user