You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1KB

  1. package de.hems.trafficsim;
  2. import android.graphics.Canvas;
  3. import android.view.SurfaceHolder;
  4. import java.util.ConcurrentModificationException;
  5. public class Worker extends Thread {
  6. protected Track track;
  7. protected boolean stop;
  8. protected MainActivity gui;
  9. protected Renderer renderer;
  10. protected int frameskip;
  11. public Worker(Track track, MainActivity gui, Renderer renderer, int frameskip) {
  12. super();
  13. this.track = track;
  14. this.stop = false;
  15. this.gui = gui;
  16. this.renderer = renderer;
  17. this.frameskip = frameskip;
  18. }
  19. public void setStop(boolean stop) {
  20. this.stop = stop;
  21. }
  22. public void setFrameskip(int frames) {
  23. this.frameskip = frames;
  24. }
  25. public int getFrameskip() { return this.frameskip; }
  26. @Override
  27. public void run() {
  28. Canvas canvas = null;
  29. int i = 0;
  30. while (!stop) {
  31. this.track.timeElapse();
  32. this.gui.updateStats();
  33. if (i >= this.frameskip) {
  34. this.renderer.draw();
  35. i=0;
  36. }
  37. i++;
  38. }
  39. }
  40. }