Пример #1
0
    def __init__(self):
        """Creates an empty Entity"""
        #collection that holds all the components indexed by their ComponentType index
        self.components = {}

        #auxiliary array for user access to all the components of an entity
        self.components_array = []

        #a flag that can be used to bit mask this entity (user managed)
        self.flags = 0

        #will dispatch an event when a component is added
        self.component_added = Signal()

        #will dispatch an event when a component is removed
        self.component_removed = Signal()

        #describing all the components in this entity for quick matching
        self.component_bits = Bits()

        #describing all the systems this entity was matched with
        self.family_bits = Bits()

        self.index = Entity.next_index
        Entity.next_index += 1
Пример #2
0
	def test_signal_lambda(self):
		global SIGNAL_RECIEVED
		global OBJECT_RECIEVED

		s = Signal()
		l = Listener(lambda s, o: self.assign(s, o))

		s.append(l)
		s(10)
		self.assertEqual(SIGNAL_RECIEVED, s)
		self.assertEqual(OBJECT_RECIEVED, 10)

		reset_recieved()
Пример #3
0
	def test_signal_remove_while_dispatch(self):
		signal = Signal()
		dummy = Dummy()
		listenerA = RemoveWhileDispatchListenerMock()
		listenerB = ListenerMock()

		signal.append(listenerA)
		signal.append(listenerB)

		self.assertEqual(len(signal), 2)

		signal(dummy)

		self.assertEqual(listenerA.count, 1)
		self.assertEqual(listenerB.count, 1)

		self.assertEqual(len(signal), 1)
Пример #4
0
	def test_signal_class(self):
		global SIGNAL_RECIEVED
		global OBJECT_RECIEVED
	
		s = Signal()
		l = TestListener()
		s.append(l)
		s(10)
		self.assertEqual(SIGNAL_RECIEVED, s)
		self.assertEqual(OBJECT_RECIEVED, 10)
	
		reset_recieved()
		s.remove(l)
		s(10)
		self.assertEqual(SIGNAL_RECIEVED, None)
		self.assertEqual(OBJECT_RECIEVED, None)

		reset_recieved()