Jazz2::Compatibility::EventConverter class

Maps original events to extended event descriptions.

Holds a registry of per-event conversion functions that turn an original JJ2 event ID and its packed parameter integer into the engine's native EventType with unpacked parameters. Default converters are registered on construction and can be extended or overridden.

Public types

using ConversionFunction = Function<ConversionResult(JJ2Level* level, std::uint32_t e)>
Signature of a function that converts a single original event.

Public static variables

static std::int32_t OriginalParamBits constexpr
Number of bits of the parameters of an original event.

Public static functions

static auto MakePassthroughEvent(JJ2Event event, std::uint32_t eventParams) -> ConversionResult
Returns an original event as it is, as EventType::PassthroughEvent.
static void ReadPassthroughEvent(const std::uint8_t* params, JJ2Event& event, std::uint32_t& eventParams)
Returns the original event and its parameters of the parameters of EventType::PassthroughEvent.
static auto CanKeepOriginalParams(EventType type) -> bool
Returns whether the last bytes of the parameters of a converted event can keep the parameters of the original.
static auto KeepOriginalParams(EventType type, std::uint8_t* params, std::uint32_t eventParams) -> bool
Keeps the parameters of the original event in the last bytes of the converted one, for the scripts of JJ2+.
static auto ReadOriginalParams(EventType type, const std::uint8_t* params, std::uint32_t& eventParams) -> bool
Returns the parameters of the original event kept in a converted one, see KeepOriginalParams().
static void ConvertParamInt(std::uint32_t paramInt, const ArrayView<const Pair<std::int32_t, std::int32_t>>& paramTypes, std::uint8_t eventParams[16])
Decodes a packed parameter integer into individual event parameters.
static void ConvertParamInt(std::uint32_t paramInt, const std::initializer_list<const Pair<std::int32_t, std::int32_t>> paramTypes, std::uint8_t eventParams[16])

Constructors, destructors, conversion operators

EventConverter()
Creates a new instance.

Public functions

auto TryConvert(JJ2Level* level, JJ2Event old, std::uint32_t eventParams) -> ConversionResult
Converts the specified original event to an extended event description.
void Add(JJ2Event originalEvent, ConversionFunction&& converter)
Registers a converter for the specified original event.
void Override(JJ2Event originalEvent, ConversionFunction&& converter)
Registers a converter for the specified original event, replacing any existing one.
auto NoParamList(EventType ev) -> ConversionFunction
Returns a converter that maps to the specified event with no parameters.
auto ConstantParamList(EventType ev, const std::array<std::uint8_t, 16>& eventParams) -> ConversionFunction
Returns a converter that maps to the specified event with constant parameters.
auto ParamIntToParamList(EventType ev, const std::array<Pair<std::int32_t, std::int32_t>, 6>& paramDefs) -> ConversionFunction
Returns a converter that maps to the specified event by extracting parameters from the original parameter integer.

Function documentation

static bool Jazz2::Compatibility::EventConverter::KeepOriginalParams(EventType type, std::uint8_t* params, std::uint32_t eventParams)

Keeps the parameters of the original event in the last bytes of the converted one, for the scripts of JJ2+.

The game reads none of the last three bytes of the parameters of any event, but the name of the music of EventType::AreaActivateBoss, so the 20 bits of the original are kept there - scripts store data of their own in the bits the game ignores. The converted event's own parameters take precedence, they aren't kept if it uses those bytes. Returns false if they aren't kept.

static bool Jazz2::Compatibility::EventConverter::ReadOriginalParams(EventType type, const std::uint8_t* params, std::uint32_t& eventParams)

Returns the parameters of the original event kept in a converted one, see KeepOriginalParams().

Returns false if there are none, a level converted before they were kept has none, and none are kept of an original event of no parameters.

static void Jazz2::Compatibility::EventConverter::ConvertParamInt(std::uint32_t paramInt, const std::initializer_list<const Pair<std::int32_t, std::int32_t>> paramTypes, std::uint8_t eventParams[16])

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

ConversionResult Jazz2::Compatibility::EventConverter::TryConvert(JJ2Level* level, JJ2Event old, std::uint32_t eventParams)

Converts the specified original event to an extended event description.

An event the game has no use for is kept as it is, see MakePassthroughEvent(). Only JJ2Event::EMPTY gives EventType::Empty.