macro_rules! build_player_feature_adder {
($struct_name:ident, $prop_getter:expr, $( $column_names:expr ),* $(,)?) => { ... };
}Expand description
This macro creates a player feature adder struct and implements the
necessary traits to add the calculated player-specific features to the data
matrix. The macro exports a struct with the same name as passed in the
parameter. The number of column names and the length of the feature array
returned by $prop_getter are checked at compile time to ensure they match,
in line with the LengthCheckedPlayerFeatureAdder trait. The output
struct also provides an implementation of the PlayerFeatureAdder trait
via the impl_player_feature_adder! macro, allowing it to be used in
contexts where a PlayerFeatureAdder object is required.
§Parameters
$struct_name: The name of the struct to be created.$prop_getter: The function or closure used to calculate the features.$( $column_names:expr ),*: A comma-separated list of column names as strings.
§Example
use subtr_actor::*;
fn u8_get_f32(v: u8) -> SubtrActorResult<f32> {
v.try_into().map_err(convert_float_conversion_error)
}
build_player_feature_adder!(
PlayerJump,
|_,
player_id: &PlayerId,
processor: &ReplayProcessor,
_frame,
_frame_number,
_current_time: f32| {
convert_all_floats!(
processor
.get_dodge_active(player_id)
.and_then(u8_get_f32)
.unwrap_or(0.0),
processor
.get_jump_active(player_id)
.and_then(u8_get_f32)
.unwrap_or(0.0),
processor
.get_double_jump_active(player_id)
.and_then(u8_get_f32)
.unwrap_or(0.0),
)
},
"dodge active",
"jump active",
"double jump active"
);This will create a struct named PlayerJump and implement necessary
traits to calculate features using the provided closure. The player-specific
features will be added under the column names “dodge active”,
“jump active”, and “double jump active” respectively.