use slice deconstruct to name floats
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -550,30 +550,43 @@ fn inference() {
|
||||
);
|
||||
let outputs = model.forward(inputs).into_data().into_vec::<f32>().unwrap();
|
||||
|
||||
let &[
|
||||
move_forward,
|
||||
move_left,
|
||||
move_back,
|
||||
move_right,
|
||||
jump,
|
||||
mouse_dx,
|
||||
mouse_dy,
|
||||
] = outputs.as_slice()
|
||||
else {
|
||||
panic!()
|
||||
};
|
||||
|
||||
macro_rules! set_control {
|
||||
($control:ident,$index:expr) => {
|
||||
($control:ident,$output:expr) => {
|
||||
session.run(
|
||||
time,
|
||||
PhysicsInputInstruction::SetControl(SetControlInstruction::$control(
|
||||
0.5 < outputs[$index],
|
||||
0.5 < $output,
|
||||
)),
|
||||
);
|
||||
};
|
||||
}
|
||||
// MoveForward
|
||||
set_control!(SetMoveForward, 0);
|
||||
set_control!(SetMoveForward, move_forward);
|
||||
// MoveLeft
|
||||
set_control!(SetMoveLeft, 1);
|
||||
set_control!(SetMoveLeft, move_left);
|
||||
// MoveBack
|
||||
set_control!(SetMoveBack, 2);
|
||||
set_control!(SetMoveBack, move_back);
|
||||
// MoveRight
|
||||
set_control!(SetMoveRight, 3);
|
||||
set_control!(SetMoveRight, move_right);
|
||||
// Jump
|
||||
set_control!(SetJump, 4);
|
||||
set_control!(SetJump, jump);
|
||||
|
||||
// mouse_dx
|
||||
// mouse_dy
|
||||
mouse_pos += glam::vec2(outputs[5], outputs[6]).round().as_ivec2();
|
||||
mouse_pos += glam::vec2(mouse_dx, mouse_dy).round().as_ivec2();
|
||||
let next_time = time + STEP;
|
||||
session.run(
|
||||
time,
|
||||
|
||||
Reference in New Issue
Block a user