diff --git a/src/game/character.cpp b/src/game/character.cpp index e0d1426..cea70df 100644 --- a/src/game/character.cpp +++ b/src/game/character.cpp @@ -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_) diff --git a/src/game/character.hpp b/src/game/character.hpp index 4e7fc83..9ece261 100644 --- a/src/game/character.hpp +++ b/src/game/character.hpp @@ -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); diff --git a/src/game/entity.cpp b/src/game/entity.cpp index 50c6a6c..e424f8e 100644 --- a/src/game/entity.cpp +++ b/src/game/entity.cpp @@ -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) diff --git a/src/game/entity.hpp b/src/game/entity.hpp index 13fcc72..436e9a7 100644 --- a/src/game/entity.hpp +++ b/src/game/entity.hpp @@ -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 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 update_msg_buf_; std::string nametag_;