weixin_39542514 2020-11-30 05:27
浏览 0

Entity deletion is broken somehow (MetaTable seems to be the culprit)

The following code:


    let mut world = World::new();
    struct DeleteSys {
        pub entity: Option<entity>,
    };

    impl System for DeleteSys {
        type SystemData = Entities;

        fn run(&mut self, entities: Self::SystemData) {
            if let Some(entity) = self.entity {
                if let Err(err) = entities.delete(entity) {
                    println!("Failed deleting entity: {}", err);
                }
            }
            self.entity = None;
        }
    }

    let mut delete = DeleteSys { entity: None };

    struct PrintSys;

    impl System for PrintSys {
        type SystemData = (
            Entities,
            ReadStorage,
            ReadStorage,
        );

        fn run(&mut self, (entities, ints, bools): Self::SystemData) {
            println!("Without entities: {}", (&ints, &bools).join().count());
            println!("With entities: {}", (&*entities, &ints, &bools).join().count());
        }
    }

    let mut print = PrintSys;
    System::setup(&mut print, &mut world.res);

    let _e1 = world
        .create_entity()
        .with(CompInt(12))
        .with(CompBool(true))
        .build();

    let e2 = world
        .create_entity()
        .with(CompInt(12))
        .with(CompBool(true))
        .build();

    let _e3 = world
        .create_entity()
        .with(CompInt(12))
        .with(CompBool(true))
        .build();

    world.maintain();
    print.run_now(&world.res);
    delete.entity = Some(e2);
    delete.run_now(&world.res);
    world.maintain();
    print.run_now(&world.res);
</entity>

prints the following


Without entities: 3
With entities: 3
Without entities: 3
With entities: 2

该提问来源于开源项目:amethyst/specs

  • 写回答

7条回答 默认 最新

  • weixin_39542514 2020-11-30 05:27
    关注

    Basically, what this means is that joining on storages without involving Entities in the join returns data for deleted entities. This persists for a "while", it seems connected to the number of recent deleted entities somehow, atleast that's the feeling I get running the rhusics examples. Eventually it gets cleaned up.

    评论

报告相同问题?