entity_identities.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "../../middleware/gameplay/external/external_entity_codec.h"
  3. #include "../../state/activity_sdk/runtime.h"
  4. #include "../../state/gameplay/external/entity_identity.h"
  5. namespace sunrise::server::gameplay::entity_identities {
  6. namespace identities = state::gameplay::entity_identity;
  7. /** Release before peer or host callbacks; accepted identity batches take the exclusive lock. */
  8. class PublicationLease final {
  9. public:
  10. PublicationLease() noexcept = default;
  11. ~PublicationLease();
  12. PublicationLease(const PublicationLease&) = delete;
  13. PublicationLease& operator=(const PublicationLease&) = delete;
  14. void release() noexcept;
  15. [[nodiscard]] bool held() const noexcept {
  16. return held_;
  17. }
  18. private:
  19. friend identities::Result begin_publication(const identities::Source&,
  20. std::vector<identities::Identity>&,
  21. PublicationLease&) noexcept;
  22. bool held_{};
  23. };
  24. /** Pins exact-source identities until the publication copies its staged bytes. */
  25. [[nodiscard]] identities::Result begin_publication(const identities::Source& source,
  26. std::vector<identities::Identity>& output,
  27. PublicationLease& lease) noexcept;
  28. /** Observations enter only after the complete external packet is accepted. */
  29. void observe(const identities::Source& source,
  30. const middleware::gameplay::external::EntityBatch& batch,
  31. const state::activity_sdk::Snapshot& catalog,
  32. std::uint16_t packetSequence,
  33. bool hasPacketSequence,
  34. std::uint64_t ordinal,
  35. std::uint64_t tick,
  36. std::uint8_t allocationEpoch = 0,
  37. bool hasAllocationEpoch = false,
  38. std::uint64_t allocationDomain = 0) noexcept;
  39. /** Exact-source lookup never selects another peer's entity with the same slot number. */
  40. [[nodiscard]] identities::Result lookup(const identities::Source& source,
  41. identities::Token token,
  42. identities::Identity& output) noexcept;
  43. /** Returns the source count; output storage may hold a bounded prefix. */
  44. [[nodiscard]] std::size_t sources(std::uint64_t activitySessionId,
  45. std::uint64_t activityRevision,
  46. std::span<identities::Source> output) noexcept;
  47. /** Copies all exact-source slots atomically, including tombstones and conflicts. */
  48. [[nodiscard]] identities::Result
  49. snapshot_source(const identities::Source& source,
  50. std::vector<identities::Identity>& output) noexcept;
  51. /** Advances only the exact source allocation domain after a committed host purge. */
  52. [[nodiscard]] bool advance_epoch(const identities::Source&,
  53. std::uint8_t expected,
  54. std::uint8_t next,
  55. std::uint64_t nextDomain) noexcept;
  56. void reset_group(std::uint64_t groupSessionId) noexcept;
  57. /** Call only after publication and after releasing the identity lease. */
  58. [[nodiscard]] std::size_t retire(const identities::Source& source,
  59. std::span<const identities::RetiredLifetime> lifetimes) noexcept;
  60. void reset_source(const identities::Source& source) noexcept;
  61. void reset() noexcept;
  62. } // namespace sunrise::server::gameplay::entity_identities