/* * Copyright 2010 Aalto University, ComNet * Released under GPLv3. See LICENSE.txt for details. */ package core; import input.EventQueue; import input.ExternalEvent; import java.util.List; /** * World contains all the nodes and is responsible for updating their * location and connections. */ public class ConnectedWorld extends World { /** * Constructor. */ public ConnectedWorld(List hosts, int sizeX, int sizeY, double updateInterval, List updateListeners, boolean simulateConnections, List eventQueues) { super(hosts, sizeY, sizeY, updateInterval, updateListeners, simulateConnections, eventQueues); } /** * Update (connect, disconnect etc.) all hosts in the world. * Runs all external events that are due between the time when * this method is called and after one update interval. */ @Override public void update () { double runUntil = SimClock.getTime() + this.updateInterval; setNextEventQueue(); /* process all events that are due until next interval update */ while (super.nextQueueEventTime <= runUntil) { simClock.setTime(this.nextQueueEventTime); ExternalEvent ee = this.nextEventQueue.nextEvent(); ee.processEvent(this); updateHosts(); // update all hosts after every event setNextEventQueue(); } // The difference between connected World and World is that we dont consider movement // moveHosts(this.updateInterval); simClock.setTime(runUntil); updateHosts(); /* inform all update listeners */ for (UpdateListener ul : this.updateListeners) { ul.updated(this.hosts); } } }