Skip to content
Discussion options

You must be logged in to vote

After some further discussion, ended up with this (which doesn't share orders between units and uses a VecDeque instead of the "linked list" approach":

use std::collections::VecDeque;

use bevy::ecs::system::EntityCommands;
use bevy::prelude::*;

trait Order: Send + Sync {
    fn add_to(&self, entity: &mut EntityCommands);
    fn remove_from(&self, entity: &mut EntityCommands);
}

impl<B: Bundle + Clone> Order for B {
    fn add_to(&self, commands: &mut EntityCommands) {
        commands.insert_bundle(self.clone());
    }

    fn remove_from(&self, commands: &mut EntityCommands) {
        commands.remove_bundle::<B>();
    }
}

struct Orderable {
    queue: VecDeque<Box<dyn Order>>,
    idle

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@SorteKanin
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@afonsolage
Comment options

@SorteKanin
Comment options

Answer selected by SorteKanin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants