def load_command_file(self, file): try: f = open(file) for line in f.readlines(): line = line.strip() if line == "" or line[0] == '#': continue items = line.split(' ') time_stamp = int(items[0]) event_type = items[1] num_args = len(items) - 2 if event_type == EVENT_TYPE.PRINT: Event_Queue.Post( Event(time_stamp, event_type, self, "".join(items[2:]))) elif num_args < 0 or num_args > 3: sys.stderr.write(line) raise BufferError elif num_args == 0: Event_Queue.Post(Event(time_stamp, event_type, self)) elif num_args == 1: Event_Queue.Post( Event(time_stamp, event_type, self, int(items[2]))) elif num_args == 2: Event_Queue.Post( Event(time_stamp, event_type, self, int(items[2]), int(items[3]))) elif num_args == 3: Event_Queue.Post( Event(time_stamp, event_type, self, int(items[2]), int(items[3]), int(items[4]))) f.close() except IOError as e: print("Can not open file " + file) print(e) sys.exit(-1) except BufferError: print("File with wrong format " + file) sys.exit(-1) except Exception as e: print("File with wrong format " + file) print(e) traceback.print_exc() sys.exit(-1)
def post_send_link(self, node, neighbor, latency): Event_Queue.Post( Event( Get_Time(), EVENT_TYPE.SEND_LINK, self, node, neighbor, latency ) )
def send_to_neighbor(self, node, neighbor, m): if (node, neighbor) not in self.__g.edges: return Event_Queue.Post( Event( Get_Time() + int(self.__g[node][neighbor]['latency']), EVENT_TYPE.ROUTING_MESSAGE_ARRIVAL, self, neighbor, m ) )
from simulator.event import Event world_size = simulator.get_world_size() window = pyglet.window.Window(world_size[0], world_size[1]) batch = pyglet.graphics.Batch() circle = shapes.Circle(700, 150, 100, color=(50, 225, 30), batch=batch) particles = [ Particle((50, 225, 30), (10, 100)), Particle((70, 200, 40), (100, 10)) ] start_event = Event(particles[0], particles[1], (100, 100)) @window.event def on_key_press(symbol, modifiers): print('A key was pressed') @window.event def on_draw(): window.clear() batch.draw() def run_event(dt, event): print(dt)