# Objective - Remove all the `.system()` possible. - Check for remaining missing cases. ## Solution - Remove all `.system()`, fix compile errors - 32 calls to `.system()` remains, mostly internals, the few others should be removed after #2446
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
use bevy::{ecs::system::SystemParam, prelude::*};
 | 
						|
 | 
						|
/// This example creates a SystemParam struct that counts the number of players
 | 
						|
fn main() {
 | 
						|
    App::new()
 | 
						|
        .insert_resource(PlayerCount(0))
 | 
						|
        .add_startup_system(spawn)
 | 
						|
        .add_system(count_players)
 | 
						|
        .run();
 | 
						|
}
 | 
						|
 | 
						|
pub struct Player;
 | 
						|
pub struct PlayerCount(usize);
 | 
						|
 | 
						|
/// The SystemParam struct can contain any types that can also be included in a
 | 
						|
/// system function signature.
 | 
						|
///
 | 
						|
/// In this example, it includes a query and a mutable resource.
 | 
						|
#[derive(SystemParam)]
 | 
						|
struct PlayerCounter<'a> {
 | 
						|
    players: Query<'a, &'static Player>,
 | 
						|
    count: ResMut<'a, PlayerCount>,
 | 
						|
}
 | 
						|
 | 
						|
impl<'a> PlayerCounter<'a> {
 | 
						|
    fn count(&mut self) {
 | 
						|
        self.count.0 = self.players.iter().len();
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
/// Spawn some players to count
 | 
						|
fn spawn(mut commands: Commands) {
 | 
						|
    commands.spawn().insert(Player);
 | 
						|
    commands.spawn().insert(Player);
 | 
						|
    commands.spawn().insert(Player);
 | 
						|
}
 | 
						|
 | 
						|
/// The SystemParam can be used directly in a system argument.
 | 
						|
fn count_players(mut counter: PlayerCounter) {
 | 
						|
    counter.count();
 | 
						|
 | 
						|
    println!("{} players in the game", counter.count.0);
 | 
						|
}
 |