mission_script_lua_value_internal.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <array>
  3. #include <cstdint>
  4. #include <string_view>
  5. #include "../../../middleware/bap/activity_message/squad_auth_body.h"
  6. #include "mission_script_lua_types.h"
  7. #include "mission_script_vm_internal.h"
  8. namespace sunrise::server::activity::mission::lua_vm::detail {
  9. // Metatable names that lock the value userdata shapes a program may hold.
  10. inline constexpr char kUnitScalarMetatable[] = "sunrise.sdk.unit_scalar";
  11. inline constexpr char kSquadModeMetatable[] = "sunrise.sdk.squad_mode";
  12. inline constexpr char kSquadModeCollectionMetatable[] = "sunrise.sdk.squad_modes";
  13. inline constexpr char kSquadCountVectorMetatable[] = "sunrise.sdk.squad_counts";
  14. /** Every device lane clamps to this closed range, so a named transition picks one endpoint. */
  15. inline constexpr float kUnitLaneLow = 0.0F;
  16. inline constexpr float kUnitLaneHigh = 1.0F;
  17. /** The requested-count array the client indexes holds this many elements. */
  18. inline constexpr std::size_t kSquadCountCapacity =
  19. middleware::bap::activity_message::squad_auth::kMaximumRequestedCountLength;
  20. /** One normalized lane value. The mint is the only place the range is compared. */
  21. struct UnitScalarHandle final {
  22. float value{};
  23. };
  24. /** One squad placement mode. The wire lane is wider than the two named values. */
  25. struct SquadModeHandle final {
  26. std::uint8_t mode{};
  27. };
  28. struct SquadModeCollectionHandle final {
  29. std::uint8_t marker{};
  30. };
  31. /**
  32. * One squad's requested counts, bound to the squad that minted it.
  33. * The length is the squad's member count, so no caller ever writes a count lane.
  34. */
  35. struct SquadCountVectorHandle final {
  36. std::array<std::int32_t, kSquadCountCapacity> counts{};
  37. std::uint32_t squadRow{};
  38. std::uint8_t count{};
  39. };
  40. /** @return The Lua spelling of one named squad mode, or "unknown". */
  41. [[nodiscard]] std::string_view squad_mode_name(std::uint8_t mode) noexcept;
  42. void push_unit_scalar(lua_State* state, float value);
  43. void push_squad_mode(lua_State* state, std::uint8_t mode);
  44. void push_squad_count_vector(lua_State* state, const SquadCountVectorHandle& value);
  45. /** Mints one count vector prefilled from the squad's authored defaults. */
  46. [[nodiscard]] int squad_counts(lua_State* state);
  47. /** Registers every locked value userdata shape. */
  48. void register_value_metatables(lua_State* state);
  49. /** Pushes one recognized ActivityView value member and returns whether the key was owned. */
  50. [[nodiscard]] bool push_value_activity_member(lua_State* state, std::string_view key);
  51. } // namespace sunrise::server::activity::mission::lua_vm::detail