def spawn(self): print 'spawn: %d' % self.entity_id new_id = self.get_new_id() new_attributes = copy.deepcopy(self.attributes) new_attributes.update({'age':0.0,'food':5.0}) entity = Entity({new_id:new_attributes}) entity.connect('update',entity.update_tx) entity.connect('spawn',entity.spawn) message_rx.connect('new_message',entity.observe_other_entity) event.add_timer(0.1,entity.behaviour.do,'entity%d'%new_id)
def run(entity_params_list): global message_rx message_rx = messagebus.MessageRx() global message_tx message_tx = messagebus.MessageTx() for i,entity_params in enumerate(entity_params_list): entity = Entity({i:entity_params}) entity.connect('update',entity.update_tx) entity.connect('spawn',entity.spawn) message_rx.connect('new_message',entity.observe_other_entity) event.add_timer(0.1,entity.behaviour.do,'entity%d'%i) event.add_io_watcher(message_rx.sock,message_rx.receive) event.mainloop()
def main(): timer1 = TimerTest('timer1') timer2 = TimerTest('timer2') sock1 = SocketTest(10001) sock2 = SocketTest(10002) sock1.connect('test', sock2.send) sock1.connect('stop', timer1.stop) sock1.connect('stop', timer2.stop) sock1.connect('modifytimer', timer1.modify_timer) sock1.connect('modifytimer', timer2.modify_timer) event.add_timer(1, timer1.hello, name='timer1') event.add_timer(3, timer2.hello, name='timer2') event.add_io_watcher(sock1.sock, sock1.receive) event.add_io_watcher(sock2.sock, sock2.receive) event.mainloop()
def main(): timer1 = TimerTest('timer1') timer2 = TimerTest('timer2') sock1 = SocketTest(10001) sock2 = SocketTest(10002) sock1.connect('test',sock2.send) sock1.connect('stop',timer1.stop) sock1.connect('stop',timer2.stop) sock1.connect('modifytimer',timer1.modify_timer) sock1.connect('modifytimer',timer2.modify_timer) event.add_timer(1,timer1.hello,name='timer1') event.add_timer(3,timer2.hello,name='timer2') event.add_io_watcher(sock1.sock,sock1.receive) event.add_io_watcher(sock2.sock,sock2.receive) event.mainloop()
def start(self): event.add_timer(0.02, self.draw) event.add_io_watcher(self.message_rx.sock, self.message_rx.receive) event.mainloop()
def start(self): event.add_timer(0.02,self.draw) event.add_io_watcher(self.message_rx.sock,self.message_rx.receive) event.mainloop()