package de.hems.trafficsim;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

import java.util.ConcurrentModificationException;

public class Worker extends Thread {
    protected Track track;
    protected boolean stop;
    protected MainActivity gui;
    protected Renderer renderer;
    protected int frameskip;

    public Worker(Track track, MainActivity gui, Renderer renderer, int frameskip) {
        super();
        this.track = track;
        this.stop = false;
        this.gui = gui;
        this.renderer = renderer;
        this.frameskip = frameskip;
    }

    public void setStop(boolean stop) {
        this.stop = stop;
    }

    public void setFrameskip(int frames) {
        this.frameskip = frames;
    }

    public int getFrameskip() { return this.frameskip; }

    @Override
    public void run() {
        Canvas canvas = null;
        int i = 0;
        while (!stop) {
            this.track.timeElapse();
            this.gui.updateStats();
            if (i >= this.frameskip) {
                this.renderer.draw();
                i=0;
            }
            i++;
        }
    }

}


