@Override
    public void run() {
        List<Action> actions;
        long startTime = System.currentTimeMillis(), estimatedTime, timeToWait = 100;

        while (true && !sim.isEnded()) {

            actions = sim.prepareUpdate();

            estimatedTime = System.currentTimeMillis() - startTime;
            System.out.println("### time = " + estimatedTime + " ms");
            try {
                timeToWait = 100 - estimatedTime;
                Thread.sleep(timeToWait < 0 ? 0 : timeToWait);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            startTime = System.currentTimeMillis();
            synchronized (sim) {
                sim.applyUpdate(actions);
                simPanel.repaint();
            }

            while (sim.isPaused()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        }
    }