예제 #1
0
    def test_dispatch_events_all_pairs(self):
        from grease.collision import dispatch_events, Pair
        world = TestWorld()
        col = world.collision
        entities = [col.set(TestEntity()) for i in range(4)]
        system = TestCollisionSys(pairs=[
            Pair(entities[0], entities[1]),
            Pair(entities[1], entities[2]),
            Pair(entities[0], entities[2]),
        ])
        system.set_world(world)
        dispatch_events(system)
        self.assertEqual(entities[0].collisions, 
            set([(entities[1], None, None), (entities[2], None, None)]))
        self.assertEqual(entities[1].collisions, 
            set([(entities[0], None, None), (entities[2], None, None)]))
        self.assertEqual(entities[2].collisions,
            set([(entities[0], None, None), (entities[1], None, None)]))
        self.assertEqual(entities[3].collisions, set())

        # The handler should tolerate an entity missing from
        # the collision component without complaint
        del col[entities[1]]
        for entity in entities:
            entity.collisions.clear()
        dispatch_events(system)
        self.assertEqual(entities[0].collisions, set([(entities[2], None, None)]))
        self.assertEqual(entities[1].collisions, set([]))
        self.assertEqual(entities[2].collisions, set([(entities[0], None, None)]))
        self.assertEqual(entities[3].collisions, set())
예제 #2
0
 def test_dispatch_events_respects_masks(self):
     from grease.collision import dispatch_events, Pair
     world = TestWorld()
     col = world.collision
     masks = [
         (1, 1),
         (3, 0),
         (2, 7),
         (0, 0),
     ]
     entities = [
         col.set(TestEntity(), from_mask=frmask, into_mask=inmask)
         for frmask, inmask in masks
     ]
     # Create all possible pairs
     pairs = [
         Pair(entities[i], entities[j]) for i in range(len(masks))
         for j in range(len(masks)) if i != j
     ]
     system = TestCollisionSys(pairs=pairs)
     system.set_world(world)
     dispatch_events(system)
     self.assertEqual(entities[0].collisions,
                      set([(entities[1], None, None)]))
     self.assertEqual(entities[1].collisions, set())
     self.assertEqual(
         entities[2].collisions,
         set([(entities[0], None, None), (entities[1], None, None)]))
     self.assertEqual(entities[3].collisions, set())
예제 #3
0
    def test_dispatch_events_all_pairs(self):
        from grease.collision import dispatch_events, Pair
        world = TestWorld()
        col = world.collision
        entities = [col.set(TestEntity()) for i in range(4)]
        system = TestCollisionSys(pairs=[
            Pair(entities[0], entities[1]),
            Pair(entities[1], entities[2]),
            Pair(entities[0], entities[2]),
        ])
        system.set_world(world)
        dispatch_events(system)
        self.assertEqual(
            entities[0].collisions,
            set([(entities[1], None, None), (entities[2], None, None)]))
        self.assertEqual(
            entities[1].collisions,
            set([(entities[0], None, None), (entities[2], None, None)]))
        self.assertEqual(
            entities[2].collisions,
            set([(entities[0], None, None), (entities[1], None, None)]))
        self.assertEqual(entities[3].collisions, set())

        # The handler should tolerate an entity missing from
        # the collision component without complaint
        del col[entities[1]]
        for entity in entities:
            entity.collisions.clear()
        dispatch_events(system)
        self.assertEqual(entities[0].collisions,
                         set([(entities[2], None, None)]))
        self.assertEqual(entities[1].collisions, set([]))
        self.assertEqual(entities[2].collisions,
                         set([(entities[0], None, None)]))
        self.assertEqual(entities[3].collisions, set())
예제 #4
0
 def test_dispatch_events_missing_method(self):
     from grease.collision import dispatch_events, Pair
     world = TestWorld()
     col = world.collision
     class NoEventEntity(object):
         pass
     entities = [col.set(NoEventEntity()) for i in range(4)]
     system = TestCollisionSys(pairs=[
         Pair(entities[0], entities[1]),
         Pair(entities[1], entities[2]),
         Pair(entities[0], entities[2]),
     ])
     system.set_world(world)
     dispatch_events(system)
예제 #5
0
    def test_dispatch_events_missing_method(self):
        from grease.collision import dispatch_events, Pair
        world = TestWorld()
        col = world.collision

        class NoEventEntity(object):
            pass

        entities = [col.set(NoEventEntity()) for i in range(4)]
        system = TestCollisionSys(pairs=[
            Pair(entities[0], entities[1]),
            Pair(entities[1], entities[2]),
            Pair(entities[0], entities[2]),
        ])
        system.set_world(world)
        dispatch_events(system)
예제 #6
0
 def test_dispatch_events_respects_masks(self):
     from grease.collision import dispatch_events, Pair
     world = TestWorld()
     col = world.collision
     masks = [
         (1, 1),
         (3, 0),
         (2, 7),
         (0, 0),
     ]
     entities = [col.set(TestEntity(), from_mask=frmask, into_mask=inmask) 
         for frmask, inmask in masks]
     # Create all possible pairs
     pairs = [Pair(entities[i], entities[j]) for i in range(len(masks)) 
                 for j in range(len(masks)) if i != j]
     system = TestCollisionSys(pairs=pairs)
     system.set_world(world)
     dispatch_events(system)
     self.assertEqual(entities[0].collisions, set([(entities[1], None, None)]))
     self.assertEqual(entities[1].collisions, set())
     self.assertEqual(entities[2].collisions, 
         set([(entities[0], None, None), (entities[1], None, None)]))
     self.assertEqual(entities[3].collisions, set())