/** * Load game state from file * * @param path Path to file */ public void deserialize(String path) { try { for (int i = 0; i < getVehicles().size(); i++) { getVehicles().get(i).stopThread(); } for (int i = 0; i < getIntersections().size(); i++) { getIntersections().get(i).stopThread(); } Passenger p = passengers.poll(); while (p != null) { p.stopThread(); p = passengers.poll(); } vehicles = null; intersections = null; passengers = null; // DrawPanel.getInstance() = null; // VehicleInspector.getInstance() = null; _instance = null; // Just to make sure things are right Thread.sleep(500); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(path))); _instance = (WorldManager) in.readObject(); in.close(); Thread.sleep(500); announceWorldChange(); System.out.println("Deserialized!"); } catch (Exception e) { e.printStackTrace(); } }