unlocks_runtime.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <cstdint>
  3. #include "definition.h"
  4. namespace sunrise::state::unlocks {
  5. /**
  6. * Seeds the live unlock banks from the boot policy.
  7. * @param table Complete authored policy.
  8. */
  9. void publish(const Table& table) noexcept;
  10. /** @return The live unlock banks. Every writer runs on the server thread. */
  11. [[nodiscard]] const Table& get() noexcept;
  12. /** Restores empty unlock banks. */
  13. void clear() noexcept;
  14. /**
  15. * Runs one write over the live banks under the exclusive lock.
  16. * The callback must not re-enter this module.
  17. * @param context Passed through untouched.
  18. * @param apply Called once with the live banks.
  19. */
  20. void mutate(void* context, void (*apply)(void*, Table&) noexcept) noexcept;
  21. /** @param index Account flag bank row. @return True when the flag is set. */
  22. [[nodiscard]] bool account_flag_set(std::uint16_t index) noexcept;
  23. /** @param index Character object flag bank row. @return True when the flag is set. */
  24. [[nodiscard]] bool character_object_flag_set(std::uint16_t index) noexcept;
  25. /**
  26. * Writes one account acquired flag.
  27. * @param index Account flag bank row.
  28. * @param value Biased flag value.
  29. * @return False when the row is outside the bank.
  30. */
  31. bool set_account_flag(std::uint16_t index, std::uint8_t value) noexcept;
  32. /** @param index Account value bank row. @return The value, or zero outside the bank. */
  33. [[nodiscard]] std::int32_t objective_value(std::uint16_t index) noexcept;
  34. /**
  35. * Writes one account objective value.
  36. * @param index Account value bank row.
  37. * @param value Replicated value.
  38. * @return False when the row is outside the bank.
  39. */
  40. bool set_objective_value(std::uint16_t index, std::int32_t value) noexcept;
  41. /**
  42. * Adds to one account objective value.
  43. * @param index Account value bank row.
  44. * @param amount Signed delta.
  45. * @return False when the row is outside the bank or the sum would overflow.
  46. */
  47. bool add_objective_value(std::uint16_t index, std::int32_t amount) noexcept;
  48. /**
  49. * Writes one selected-character object flag.
  50. * @param index Character object flag bank row.
  51. * @param value Biased flag value.
  52. * @return False when the row is outside the bank.
  53. */
  54. bool set_character_object_flag(std::uint16_t index, std::uint8_t value) noexcept;
  55. /**
  56. * Writes one selected-character object value.
  57. * @param index Character object value bank row.
  58. * @param value Replicated value.
  59. * @return False when the row is outside the bank.
  60. */
  61. bool set_character_object_value(std::uint16_t index, std::int32_t value) noexcept;
  62. /** @param definitionIndex Native progression row. @return Lane 0, or zero outside the bank. */
  63. [[nodiscard]] std::int32_t account_progression(std::uint16_t definitionIndex) noexcept;
  64. /**
  65. * Writes lane 0 of one account progression.
  66. * @param definitionIndex Native progression row.
  67. * @param value Progress the level walk reads.
  68. * @return False when the row is outside the bank.
  69. */
  70. bool set_account_progression(std::uint16_t definitionIndex, std::int32_t value) noexcept;
  71. } // namespace sunrise::state::unlocks