1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
8 // FEATURE: reimplement Watcher
9 /** Implements cooperative multitasking */
10 public class Scheduler {
12 private static Scheduler singleton = new Scheduler();
13 public static void run() { singleton.do_run(); }
14 protected Scheduler() { }
16 public static abstract class Task implements Callback { public abstract Object call(Object o); }
18 private static Queue runnable = new Queue(50);
20 public static void add(Task t) { singleton.runnable.append(t); }
21 public void do_run() {
23 Task t = (Task)runnable.remove(true);
26 for(int i=0; i<Surface.allSurfaces.size(); i++)
27 ((Surface)Surface.allSurfaces.elementAt(i)).render();
28 } catch (Exception e) {
29 Log.log(Scheduler.class, "Task threw an exception: " + e);
30 Log.log(Scheduler.class, e);