home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch18 / multi / Reaper.java < prev    next >
Encoding:
Java Source  |  1997-02-21  |  890 b   |  37 lines

  1. // Thread that goes through and removes entities we haven't heard from lately
  2.  
  3. // Written by Bernie Roehl, December 1996
  4.  
  5. package multi;
  6.  
  7. import java.util.*;
  8.  
  9. class Reaper extends Thread {
  10.  
  11.     World world;
  12.  
  13.     public Reaper(World wrld) {
  14.         world = wrld;
  15.         setPriority(NORM_PRIORITY-1);
  16.         start();
  17.     }
  18.  
  19.     public void run() {
  20.         while (true) {
  21.             try { sleep(5000); }   // five seconds
  22.             catch (InterruptedException e) { }
  23.             for (int i = 0; i < world.entities.size(); ++i) {
  24.                 Entity e = (Entity) world.entities.elementAt(i);
  25.                 if (e != null) {
  26.                     if (e.getState() == Entity.DEAD)
  27.                         world.entities.setElementAt(null, i);
  28.                     else
  29.                         e.age();
  30.                 }
  31.             }
  32.         }
  33.     }
  34.  
  35. }
  36.  
  37.