Giter Site home page Giter Site logo

Comments (3)

nyvs avatar nyvs commented on May 20, 2024 1

Hi! Thank you so much. I now successfully moved from plain queries to all-systems, which works beautifully, and even better: everything works as expected. I must say I love legion.

from legion.

nyvs avatar nyvs commented on May 20, 2024

My current way of removing missiles looks like this:

fn remove_dead_missiles(world: &mut World) {
	let mut entity_list = vec![];
	let mut query = <Entity>::query();
	for entity in query.iter(world) {
		entity_list.push(*entity);
	}
	let mut to_delete = vec![];
	for e in entity_list {
		let ent = world.entry(e).unwrap();
		match ent.get_component::<Missile>() {
			Ok(m) => if m.is_set_off {
				to_delete.push(e);
			},
			Err(_) => (),
		}
	}
	for del in to_delete.iter() {
		world.remove(*del);
	}
}

from legion.

zedrian avatar zedrian commented on May 20, 2024

Hi @nyvs, not sure about the idiomatic way, but I can share with you my approach for solving such tasks.

All my logic is packed into systems generated via #[legion::system] macro (and executed in Schedule), so when I need to add/remove entities or components I simply request my system to access CommandBuffer and record corresponding commands into it.

In your case, such a system can look like this:

use legion::{Query, systems::CommandBuffer, world::SubWorld};

#[legion::system]
fn remove_exploded_missiles(objects: &mut Query<(Entity, &Missile)>,
                            commands: &mut CommandBuffer,
                            world: &mut SubWorld)
{
    for (entity, missile) in objects.iter(world) {
        if missile.is_set_off {
            commands.remove(entity);
        }
    }                    
}

Please let us know if this does not work for you.

from legion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.