chore: examples simple way

This commit is contained in:
2024-02-06 16:40:00 +01:00
parent ed98651cfc
commit 7cf7d4fe7d
8 changed files with 469 additions and 417 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = ["crate/*"] members = ["crate/*"]
+6 -1
View File
@@ -23,4 +23,9 @@ strum = "0.25.0"
strum_macros = "0.25.3" strum_macros = "0.25.3"
[dev-dependencies] [dev-dependencies]
env_logger = "0.10.1" env_logger = "0.10.1"
[[example]]
name = "basic"
path = "example/basic/src/main.rs"
doc-scrape-examples = true
@@ -0,0 +1,8 @@
[package]
name = "basic"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
+176 -176
View File
@@ -1,176 +1,176 @@
use std::hash::Hash; use std::hash::Hash;
use bevy_ecs::{system::Resource, schedule::States}; use bevy_ecs::{system::Resource, schedule::States};
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
#[cfg(feature = "inspector-egui")] #[cfg(feature = "inspector-egui")]
use bevy_inspector_egui::inspector_options::InspectorOptionsType; use bevy_inspector_egui::inspector_options::InspectorOptionsType;
// #[cfg(all(feature = "reflect", feature = "serialize"))] // #[cfg(all(feature = "reflect", feature = "serialize"))]
// use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; // use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
#[cfg(feature = "serialize")] #[cfg(feature = "serialize")]
use serde::{Serialize, de::DeserializeOwned}; use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "reflect")] #[cfg(feature = "reflect")]
use bevy_reflect::{Reflect, TypePath, FromReflect}; use bevy_reflect::{Reflect, TypePath, FromReflect};
use crate::resource::PlayerInputs; use crate::resource::PlayerInputs;
pub trait ActionInner: 'static + std::marker::Sync + std::marker::Send + PartialEq + Eq + Hash + IntoEnumIterator + Clone + Copy { } pub trait ActionInner: 'static + std::marker::Sync + std::marker::Send + PartialEq + Eq + Hash + IntoEnumIterator + Clone + Copy { }
pub trait GameStateInner: 'static + std::marker::Sync + std::marker::Send + States { } pub trait GameStateInner: 'static + std::marker::Sync + std::marker::Send + States { }
pub trait InputsContainerInner<A: Action>: 'static + std::marker::Sync + std::marker::Send + Resource { pub trait InputsContainerInner<A: Action>: 'static + std::marker::Sync + std::marker::Send + Resource {
/// The method returning an iterator over references to the PlayerInputs. /// The method returning an iterator over references to the PlayerInputs.
/// Note: the use of 'a for both the method's lifetime and the returned Iterator's lifetime. /// Note: the use of 'a for both the method's lifetime and the returned Iterator's lifetime.
fn iter_inputs<'a>(&'a self) -> Box<dyn Iterator<Item = &'a PlayerInputs<A>> + 'a>; fn iter_inputs<'a>(&'a self) -> Box<dyn Iterator<Item = &'a PlayerInputs<A>> + 'a>;
/// The method returning an player inputs of this client. /// The method returning an player inputs of this client.
fn me<'a>(&self) -> Option<&'a PlayerInputs<A>>; fn me<'a>(&self) -> Option<&'a PlayerInputs<A>>;
/// The method returning an mutable player inputs of this client. /// The method returning an mutable player inputs of this client.
fn me_mut<'a>(&self) -> Option<&'a mut PlayerInputs<A>>; fn me_mut<'a>(&self) -> Option<&'a mut PlayerInputs<A>>;
} }
#[cfg(feature = "serialize")] #[cfg(feature = "serialize")]
pub trait SerializeImpl: Serialize + DeserializeOwned { } pub trait SerializeImpl: Serialize + DeserializeOwned { }
#[cfg(feature = "reflect")] #[cfg(feature = "reflect")]
pub trait ReflectImpl: Reflect + TypePath + FromReflect { } pub trait ReflectImpl: Reflect + TypePath + FromReflect { }
#[cfg(feature = "inspector-egui")] #[cfg(feature = "inspector-egui")]
pub trait InspectorEguiImpl: InspectorOptionsType { } pub trait InspectorEguiImpl: InspectorOptionsType { }
// ===== Action ===== // ===== Action =====
// SAFATY: inspector-egui includes reflect // SAFATY: inspector-egui includes reflect
#[cfg(all(not(feature = "serialize"), not(feature = "reflect"), not(feature = "inspector-egui")))] #[cfg(all(not(feature = "serialize"), not(feature = "reflect"), not(feature = "inspector-egui")))]
pub trait Action: ActionInner {} pub trait Action: ActionInner {}
#[cfg(all(feature = "serialize", not(feature = "reflect"), not(feature = "inspector-egui")))] #[cfg(all(feature = "serialize", not(feature = "reflect"), not(feature = "inspector-egui")))]
pub trait Action: ActionInner + SerializeImpl {} pub trait Action: ActionInner + SerializeImpl {}
#[cfg(all(not(feature = "serialize"), feature = "reflect", not(feature = "inspector-egui")))] #[cfg(all(not(feature = "serialize"), feature = "reflect", not(feature = "inspector-egui")))]
pub trait Action: ActionInner + ReflectImpl {} pub trait Action: ActionInner + ReflectImpl {}
#[cfg(all(feature = "serialize", feature = "reflect", not(feature = "inspector-egui")))] #[cfg(all(feature = "serialize", feature = "reflect", not(feature = "inspector-egui")))]
pub trait Action: ActionInner + SerializeImpl + ReflectImpl{} pub trait Action: ActionInner + SerializeImpl + ReflectImpl{}
#[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))] #[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))]
pub trait Action: ActionInner + ReflectImpl + InspectorEguiImpl {} pub trait Action: ActionInner + ReflectImpl + InspectorEguiImpl {}
#[cfg(all(feature = "serialize", feature = "inspector-egui"))] #[cfg(all(feature = "serialize", feature = "inspector-egui"))]
pub trait Action: ActionInner + SerializeImpl + ReflectImpl + InspectorEguiImpl {} pub trait Action: ActionInner + SerializeImpl + ReflectImpl + InspectorEguiImpl {}
// ===== GameState ===== // ===== GameState =====
// SAFATY: inspector-egui includes reflect // SAFATY: inspector-egui includes reflect
#[cfg(all(not(feature = "serialize"), not(feature = "reflect"), not(feature = "inspector-egui")))] #[cfg(all(not(feature = "serialize"), not(feature = "reflect"), not(feature = "inspector-egui")))]
pub trait GameState: GameStateInner {} pub trait GameState: GameStateInner {}
#[cfg(all(feature = "serialize", not(feature = "reflect"), not(feature = "inspector-egui")))] #[cfg(all(feature = "serialize", not(feature = "reflect"), not(feature = "inspector-egui")))]
pub trait GameState: GameStateInner + SerializeImpl {} pub trait GameState: GameStateInner + SerializeImpl {}
#[cfg(all(not(feature = "serialize"), feature = "reflect", not(feature = "inspector-egui")))] #[cfg(all(not(feature = "serialize"), feature = "reflect", not(feature = "inspector-egui")))]
pub trait GameState: GameStateInner + ReflectImpl {} pub trait GameState: GameStateInner + ReflectImpl {}
#[cfg(all(feature = "serialize", feature = "reflect", not(feature = "inspector-egui")))] #[cfg(all(feature = "serialize", feature = "reflect", not(feature = "inspector-egui")))]
pub trait GameState: GameStateInner + SerializeImpl + ReflectImpl{} pub trait GameState: GameStateInner + SerializeImpl + ReflectImpl{}
#[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))] #[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))]
pub trait GameState: GameStateInner + ReflectImpl + InspectorEguiImpl {} pub trait GameState: GameStateInner + ReflectImpl + InspectorEguiImpl {}
#[cfg(all(feature = "serialize", feature = "inspector-egui"))] #[cfg(all(feature = "serialize", feature = "inspector-egui"))]
pub trait GameState: GameStateInner + SerializeImpl + ReflectImpl + InspectorEguiImpl {} pub trait GameState: GameStateInner + SerializeImpl + ReflectImpl + InspectorEguiImpl {}
// ===== InputsContainer ===== // ===== InputsContainer =====
// SAFATY: inspector-egui includes reflect // SAFATY: inspector-egui includes reflect
#[cfg(all(not(feature = "serialize"), not(feature = "reflect"), not(feature = "inspector-egui")))] #[cfg(all(not(feature = "serialize"), not(feature = "reflect"), not(feature = "inspector-egui")))]
pub trait InputsContainer<A: Action>: InputsContainerInner<A> {} pub trait InputsContainer<A: Action>: InputsContainerInner<A> {}
#[cfg(all(feature = "serialize", not(feature = "reflect"), not(feature = "inspector-egui")))] #[cfg(all(feature = "serialize", not(feature = "reflect"), not(feature = "inspector-egui")))]
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl {} pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl {}
#[cfg(all(not(feature = "serialize"), feature = "reflect", not(feature = "inspector-egui")))] #[cfg(all(not(feature = "serialize"), feature = "reflect", not(feature = "inspector-egui")))]
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + ReflectImpl {} pub trait InputsContainer<A: Action>: InputsContainerInner<A> + ReflectImpl {}
#[cfg(all(feature = "serialize", feature = "reflect", not(feature = "inspector-egui")))] #[cfg(all(feature = "serialize", feature = "reflect", not(feature = "inspector-egui")))]
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl + ReflectImpl{} pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl + ReflectImpl{}
#[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))] #[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))]
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + ReflectImpl + InspectorEguiImpl {} pub trait InputsContainer<A: Action>: InputsContainerInner<A> + ReflectImpl + InspectorEguiImpl {}
#[cfg(all(feature = "serialize", feature = "inspector-egui"))] #[cfg(all(feature = "serialize", feature = "inspector-egui"))]
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl + ReflectImpl + InspectorEguiImpl {} pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl + ReflectImpl + InspectorEguiImpl {}
// #[cfg(test)] // #[cfg(test)]
// mod test { // mod test {
// use bevy_ecs::{entity::Entity, schedule::States}; // use bevy_ecs::{entity::Entity, schedule::States};
// use bevy_utils::{HashMap, prelude::default}; // use bevy_utils::{HashMap, prelude::default};
// use strum_macros::EnumIter; // use strum_macros::EnumIter;
// #[cfg(feature = "serialize")] // #[cfg(feature = "serialize")]
// use serde::{Serialize, Deserialize}; // use serde::{Serialize, Deserialize};
// use crate::{hashmap, resource::PlayerInputs, common_traits_conditions}; // use crate::{hashmap, resource::PlayerInputs, common_traits_conditions};
// common_traits_conditions! { // common_traits_conditions! {
// #[derive(Debug, Clone, PartialEq)] // #[derive(Debug, Clone, PartialEq)]
// #[cfg_attr(feature = "reflect", reflect(Resource))] // #[cfg_attr(feature = "reflect", reflect(Resource))]
// pub struct Lobby { // pub struct Lobby {
// pub me: PlayerId, // pub me: PlayerId,
// pub players: HashMap<PlayerId, Player>, // pub players: HashMap<PlayerId, Player>,
// } // }
// } // }
// impl Default for Lobby { // impl Default for Lobby {
// fn default() -> Self { // fn default() -> Self {
// Self { // Self {
// me: PlayerId::Host, // me: PlayerId::Host,
// players: hashmap! { // players: hashmap! {
// PlayerId::Host => Player::default() // PlayerId::Host => Player::default()
// }, // },
// } // }
// } // }
// } // }
// common_traits_conditions! { // common_traits_conditions! {
// #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] // #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
// pub enum PlayerId { // pub enum PlayerId {
// /// Host or alone // /// Host or alone
// Host, // Host,
// /// Client // /// Client
// Client(()), // Client(()),
// } // }
// #[derive(Default, Debug, PartialEq, Clone)] // #[derive(Default, Debug, PartialEq, Clone)]
// pub struct Player { // pub struct Player {
// /// Client do not need to know about other clients // /// Client do not need to know about other clients
// #[cfg_attr(feature = "serialize", serde(skip))] // #[cfg_attr(feature = "serialize", serde(skip))]
// pub inputs: PlayerInputs<Action>, // pub inputs: PlayerInputs<Action>,
// #[cfg_attr(feature = "serialize", serde(skip))] // #[cfg_attr(feature = "serialize", serde(skip))]
// pub entity: Option<Entity>, // pub entity: Option<Entity>,
// } // }
// } // }
// #[derive(Debug, PartialEq, Clone, States, Default, Hash, Eq)] // #[derive(Debug, PartialEq, Clone, States, Default, Hash, Eq)]
// pub enum GameState { // pub enum GameState {
// #[default] // #[default]
// LevelEditor, // LevelEditor,
// InGame, // InGame,
// } // }
// impl super::GameState for GameState {} // impl super::GameState for GameState {}
// // TODO: it is just plug, it must be a trait // // TODO: it is just plug, it must be a trait
// /// Actions that can be performed by player // /// Actions that can be performed by player
// #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug, EnumIter)] // #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug, EnumIter)]
// pub enum Action { // pub enum Action {
// /// Move forward // /// Move forward
// LeverEditorForward, // LeverEditorForward,
// /// Move backward // /// Move backward
// LevelEditorBackward, // LevelEditorBackward,
// /// Move left // /// Move left
// LevelEditorLeft, // LevelEditorLeft,
// /// Move right // /// Move right
// LevelEditorRight, // LevelEditorRight,
// LevelEditorFly, // LevelEditorFly,
// } // }
// impl super::Action for Action {} // impl super::Action for Action {}
// } // }
+237 -237
View File
@@ -1,238 +1,238 @@
use bevy_app::{Plugin, App, Update}; use bevy_app::{Plugin, App, Update};
use bevy_ecs::{system::{Res, ResMut}, schedule::State}; use bevy_ecs::{system::{Res, ResMut}, schedule::State};
use bevy_input::{Input, keyboard::KeyCode, mouse::MouseButton}; use bevy_input::{Input, keyboard::KeyCode, mouse::MouseButton};
use crate::{resource::*, contract::{Action, GameState, InputsContainer}}; use crate::{resource::*, contract::{Action, GameState, InputsContainer}};
pub struct ControlsPlugin<Action, InputsContainer, GameState> { pub struct ControlsPlugin<Action, InputsContainer, GameState> {
_action: std::marker::PhantomData<Action>, _action: std::marker::PhantomData<Action>,
_inputs_container: std::marker::PhantomData<InputsContainer>, _inputs_container: std::marker::PhantomData<InputsContainer>,
_game_state: std::marker::PhantomData<GameState>, _game_state: std::marker::PhantomData<GameState>,
} }
impl< impl<
A: Action, A: Action,
Ic: InputsContainer<A>, Ic: InputsContainer<A>,
Gs: GameState Gs: GameState
> Plugin for ControlsPlugin<A, Ic, Gs> { > Plugin for ControlsPlugin<A, Ic, Gs> {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_resource::<Controls<A, Gs>>() app.init_resource::<Controls<A, Gs>>()
.add_systems(Update, Self::save_input); .add_systems(Update, Self::save_input);
#[cfg(feature = "reflect")] #[cfg(feature = "reflect")]
app.register_type::<Controls<A, Gs>>(); app.register_type::<Controls<A, Gs>>();
} }
} }
impl< impl<
A: Action, A: Action,
Ic: InputsContainer<A>, Ic: InputsContainer<A>,
Gs: GameState Gs: GameState
> ControlsPlugin<A, Ic, Gs> { > ControlsPlugin<A, Ic, Gs> {
/// Process all hard inputs and bindings to update [`PlayerInputs`] /// Process all hard inputs and bindings to update [`PlayerInputs`]
fn save_input( fn save_input(
keyboard_input: Res<Input<KeyCode>>, keyboard_input: Res<Input<KeyCode>>,
mouse_input: Res<Input<MouseButton>>, mouse_input: Res<Input<MouseButton>>,
lobby: ResMut<Ic>, lobby: ResMut<Ic>,
controls: Res<Controls<A, Gs>>, controls: Res<Controls<A, Gs>>,
game_state: Res<State<Gs>>, game_state: Res<State<Gs>>,
) { ) {
if let Some(inputs) = lobby.me_mut() { if let Some(inputs) = lobby.me_mut() {
for (action, config) in controls.iter() { for (action, config) in controls.iter() {
'bindings_loop: for binding in config.bindings.iter() { 'bindings_loop: for binding in config.bindings.iter() {
for condition in &binding.conditions { for condition in &binding.conditions {
match condition { match condition {
BindingCondition::InGameState(state) => { BindingCondition::InGameState(state) => {
if *state != *game_state.get() { if *state != *game_state.get() {
continue 'bindings_loop; continue 'bindings_loop;
} }
} }
} }
} }
match &binding.input { match &binding.input {
ButtonCombination::Single(button) => match button { ButtonCombination::Single(button) => match button {
InputType::Keyboard(key) => { InputType::Keyboard(key) => {
inputs.forced_set(*action, keyboard_input.pressed(*key)); inputs.forced_set(*action, keyboard_input.pressed(*key));
} }
InputType::Mouse(input) => { InputType::Mouse(input) => {
match input { match input {
MouseInput::Axis(_axis) => { MouseInput::Axis(_axis) => {
todo!(); todo!();
} }
MouseInput::Button(button) => { MouseInput::Button(button) => {
if !mouse_input if !mouse_input
.get_pressed() .get_pressed()
.any(|b| b == button) .any(|b| b == button)
{ {
continue 'bindings_loop; continue 'bindings_loop;
} }
} }
MouseInput::Wheel(_axis) => { MouseInput::Wheel(_axis) => {
todo!(); todo!();
} }
} }
} }
}, },
ButtonCombination::Chord(buttons) => { ButtonCombination::Chord(buttons) => {
// If any button in chord is not pressed we skip this `binding` // If any button in chord is not pressed we skip this `binding`
for button in buttons { for button in buttons {
match button { match button {
InputType::Keyboard(key) => { InputType::Keyboard(key) => {
if !keyboard_input.pressed(*key) { if !keyboard_input.pressed(*key) {
continue 'bindings_loop; continue 'bindings_loop;
} }
} }
InputType::Mouse(input) => { InputType::Mouse(input) => {
match input { match input {
MouseInput::Axis(_axis) => { MouseInput::Axis(_axis) => {
todo!(); todo!();
} }
MouseInput::Button(button) => { MouseInput::Button(button) => {
if !mouse_input if !mouse_input
.get_pressed() .get_pressed()
.any(|b| b == button) .any(|b| b == button)
{ {
continue 'bindings_loop; continue 'bindings_loop;
} }
} }
MouseInput::Wheel(_axis) => { MouseInput::Wheel(_axis) => {
todo!(); todo!();
} }
} }
} }
} }
} }
// TODO: should be [`Chord`](ButtonCombination::Chord) only [`Boolean`](InputValue::Boolean) type // TODO: should be [`Chord`](ButtonCombination::Chord) only [`Boolean`](InputValue::Boolean) type
inputs.forced_set(*action, true); inputs.forced_set(*action, true);
} }
} }
} }
} }
} else { } else {
log::error!("cannot find me in inputs container") log::error!("cannot find me in inputs container")
} }
} }
} }
// #[cfg(test)] // #[cfg(test)]
// mod performance_test { // mod performance_test {
// use crate::{ util::test::{enable_loggings, measure_time, Times}, resource::PlayerInputs}; // use crate::{ util::test::{enable_loggings, measure_time, Times}, resource::PlayerInputs};
// use super::Controls; // use super::Controls;
// use std::time::Duration; // use std::time::Duration;
// /// Test for execution time for [`Controls`] get // /// Test for execution time for [`Controls`] get
// /// // ///
// /// Example: // /// Example:
// /// ``` // /// ```
// /// cargo test --package pih-pah-app --lib --features "dev, ui_egui" -- controls::test::controls_get --exact --nocapture // /// cargo test --package pih-pah-app --lib --features "dev, ui_egui" -- controls::test::controls_get --exact --nocapture
// /// ``` // /// ```
// #[test] // #[test]
// fn controls_get() { // fn controls_get() {
// enable_loggings(); // enable_loggings();
// let controls = Controls::default(); // let controls = Controls::default();
// let duration = measure_time( // let duration = measure_time(
// || { // || {
// controls.get(Action::LeverEditorForward); // controls.get(Action::LeverEditorForward);
// controls.get(Action::LevelEditorBackward); // controls.get(Action::LevelEditorBackward);
// controls.get(Action::LevelEditorLeft); // controls.get(Action::LevelEditorLeft);
// controls.get(Action::LevelEditorRight); // controls.get(Action::LevelEditorRight);
// }, // },
// Times::default(), // Times::default(),
// ); // );
// log::info!("time: {:?}", duration); // log::info!("time: {:?}", duration);
// } // }
// /// Test for execution speed for [`PlayerInputs`] get // /// Test for execution speed for [`PlayerInputs`] get
// fn player_inputs_get() -> Duration { // fn player_inputs_get() -> Duration {
// enable_loggings(); // enable_loggings();
// let inputs = PlayerInputs::default(); // let inputs = PlayerInputs::default();
// let duration = measure_time( // let duration = measure_time(
// || { // || {
// inputs.get(Action::LeverEditorForward); // inputs.get(Action::LeverEditorForward);
// inputs.get(Action::LevelEditorBackward); // inputs.get(Action::LevelEditorBackward);
// inputs.get(Action::LevelEditorLeft); // inputs.get(Action::LevelEditorLeft);
// inputs.get(Action::LevelEditorRight); // inputs.get(Action::LevelEditorRight);
// }, // },
// Times::default(), // Times::default(),
// ); // );
// duration // duration
// } // }
// /// Test for execution speed for [`PlayerInputs`] get_many // /// Test for execution speed for [`PlayerInputs`] get_many
// fn player_inputs_get_many() -> Duration { // fn player_inputs_get_many() -> Duration {
// enable_loggings(); // enable_loggings();
// let inputs = PlayerInputs::default(); // let inputs = PlayerInputs::default();
// let duration = measure_time( // let duration = measure_time(
// || { // || {
// inputs.get_many(vec![ // inputs.get_many(vec![
// Action::LeverEditorForward, // Action::LeverEditorForward,
// Action::LevelEditorBackward, // Action::LevelEditorBackward,
// Action::LevelEditorLeft, // Action::LevelEditorLeft,
// Action::LevelEditorRight, // Action::LevelEditorRight,
// ]); // ]);
// }, // },
// Times::default(), // Times::default(),
// ); // );
// duration // duration
// } // }
// /// Test for execution speed for [`PlayerInputs`] get and get_many // /// Test for execution speed for [`PlayerInputs`] get and get_many
// /// // ///
// /// Example: // /// Example:
// /// ``` // /// ```
// /// cargo test --package pih-pah-app --lib --features "dev, ui_egui" -- controls::test::compare_player_inputs_get_and_get_many --exact --nocapture // /// cargo test --package pih-pah-app --lib --features "dev, ui_egui" -- controls::test::compare_player_inputs_get_and_get_many --exact --nocapture
// /// ``` // /// ```
// #[test] // #[test]
// fn compare_player_inputs_get_and_get_many() { // fn compare_player_inputs_get_and_get_many() {
// let get = player_inputs_get(); // let get = player_inputs_get();
// let get_many = player_inputs_get_many(); // let get_many = player_inputs_get_many();
// log::info!("get: {:?}", get); // log::info!("get: {:?}", get);
// log::info!("get_many: {:?}", get_many); // log::info!("get_many: {:?}", get_many);
// } // }
// /// Test for execution speed for [`InputValue`] casting // /// Test for execution speed for [`InputValue`] casting
// #[test] // #[test]
// fn action_casting() { // fn action_casting() {
// enable_loggings(); // enable_loggings();
// let inputs = PlayerInputs::default(); // let inputs = PlayerInputs::default();
// let duration = measure_time( // let duration = measure_time(
// || { // || {
// let _ = (inputs.get(Action::LeverEditorForward).as_boolean() as i8 // let _ = (inputs.get(Action::LeverEditorForward).as_boolean() as i8
// - inputs.get(Action::LevelEditorBackward).as_boolean() as i8) // - inputs.get(Action::LevelEditorBackward).as_boolean() as i8)
// as f32; // as f32;
// }, // },
// 10000000.into(), // 10000000.into(),
// ); // );
// log::info!("with casting: {:?}", duration); // log::info!("with casting: {:?}", duration);
// let inputs = PlayerInputs::default(); // let inputs = PlayerInputs::default();
// let duration = measure_time( // let duration = measure_time(
// || { // || {
// let _ = inputs.get(Action::LeverEditorForward); // let _ = inputs.get(Action::LeverEditorForward);
// let _ = inputs.get(Action::LevelEditorBackward); // let _ = inputs.get(Action::LevelEditorBackward);
// }, // },
// 10000000.into(), // 10000000.into(),
// ); // );
// log::info!("without casting: {:?}", duration); // log::info!("without casting: {:?}", duration);
// } // }
// } // }
+36
View File
@@ -0,0 +1,36 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = (pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
nativeBuildInputs = with pkgs; [ rustToolchain pkg-config ];
buildInputs = with pkgs; [
openssl
];
in
with pkgs;
{
devShells.default = mkShell {
inherit buildInputs nativeBuildInputs;
};
}
);
}
+1 -1
View File
@@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = '1.72.0' channel = '1.72.0'