definition.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include "../destination/definition.h"
  6. namespace sunrise::state::activity::forced {
  7. /** The bubble number picks one of the 64 wire slots. */
  8. inline constexpr std::uint8_t kMaximumBubble = 63;
  9. /** The slice-set index is a 10-bit bias-1 wire field, so this is the largest it can hold. */
  10. inline constexpr std::uint16_t kMaximumSliceSet = 1'022;
  11. /** The set normal arrivals use. */
  12. inline constexpr std::uint32_t kDefaultSpawnSetHash = 0x2EA8FB98U;
  13. /**
  14. * The hash that names no set, so the Client searches the loaded world itself.
  15. * A set belongs to the map, not the bubble. Send one the bubble lacks and nothing spawns.
  16. */
  17. inline constexpr std::uint32_t kAbsentSpawnSetHash = 0x811C9DC5U;
  18. /**
  19. * One operator-chosen destination that replaces what the client asked for.
  20. * Nothing here is saved. The process starts with no selection and the switch off.
  21. */
  22. struct ForcedDestination {
  23. /** Destination package name, without its `:scenario_client` suffix. */
  24. std::array<char, destination::kPackageNameCapacity> packageName{};
  25. std::uint8_t packageNameLength{};
  26. std::uint8_t bubble{};
  27. std::uint16_t sliceSet{};
  28. /** Spawn-set name hash, used only when one was chosen. */
  29. std::uint32_t spawnSetHash{};
  30. bool hasBubble{};
  31. bool hasSliceSet{};
  32. bool hasSpawnSetHash{};
  33. /** The global switch. Off means the client's own selection stands. */
  34. bool enabled{};
  35. };
  36. /**
  37. * Tests whether a forced destination names enough to replace a client selection.
  38. * The spawn set is the one optional part. Without it the Client picks its own point.
  39. * @param value Candidate selection.
  40. * @return True when the switch is on and the destination, bubble, and slice set are all named.
  41. */
  42. [[nodiscard]] constexpr bool active(const ForcedDestination& value) noexcept {
  43. return value.enabled && value.packageNameLength != 0
  44. && value.packageNameLength <= value.packageName.size() && value.hasBubble
  45. && value.bubble <= kMaximumBubble && value.hasSliceSet
  46. && value.sliceSet <= kMaximumSliceSet;
  47. }
  48. /**
  49. * Tests whether a candidate can be stored, complete or not.
  50. * A partial selection is kept so the interface can set one field at a time.
  51. * @param value Candidate selection.
  52. * @return True when every named field is inside its wire range.
  53. */
  54. [[nodiscard]] constexpr bool storable(const ForcedDestination& value) noexcept {
  55. return value.packageNameLength <= value.packageName.size()
  56. && (!value.hasBubble || value.bubble <= kMaximumBubble)
  57. && (!value.hasSliceSet || value.sliceSet <= kMaximumSliceSet);
  58. }
  59. } // namespace sunrise::state::activity::forced