home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Japan / NTT / DM- / hotjava / classes / src / Schedular.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  2.6 KB  |  127 lines

  1. import browser.*;
  2. import browser.audio.*;
  3. import awt.*;
  4. import java.util.*;
  5. import java.io.*;
  6. import java.lang.*;
  7. import net.www.html.*;
  8.  
  9. // Animation Data Type
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. // AnimationData ID
  18.  
  19.  
  20. // Animation Depth for no image (i.e. sound only data)
  21.  
  22.  
  23. class Schedular extends Thread {
  24.  
  25. AnimationPlayer    parent;
  26. int        id;
  27. IDChain        sleepList;
  28. Thread        kicker = null;
  29.  
  30. public Schedular(AnimationPlayer sa, int myid) {
  31.     parent = sa;
  32.     id = myid;
  33.     sleepList = new IDChain();
  34. }
  35.  
  36. public int getID() {return id;}
  37.  
  38. public void start() {
  39.     if (kicker != null) {
  40.     return;
  41.     }
  42.     kicker = new Thread(this);
  43.     kicker.start();
  44. }
  45.  
  46. public void run() {
  47.     long curTime;
  48.     IDChain p;
  49.     while (kicker != null) {
  50.     curTime = System.currentTimeMillis();
  51.     p = sleepList.getNext();
  52.  
  53.     if (p == null) {
  54.         sleep(5000);
  55.     } else {
  56.         if (p.getTime() < curTime) {
  57.             while ((p=sleepList.getNext()) != null && 
  58.                         p.getTime() < curTime) {
  59.             int id = p.getID();
  60.             AnimationData ad = parent.getAnimationData(id);
  61.             ad.nextFrame();
  62.             int type = ad.getType();
  63.             if (ad.isSoundFrame() && 
  64.             (type == 1 || type == 2 || 
  65.              type == 3 || type == 4)) {
  66.             ad.playSound();
  67.             }
  68.             if ((type == 2 && ad.getCurFrame() == 0) ||
  69.             (type == 3 && 
  70.                 ad.getCurFrame() == ad.getLastFrame()) ||
  71.             (type == 4 && 
  72.                 (ad.getCurFrame() == 0 || 
  73.                  ad.getCurFrame() == ad.getLastFrame()))) {
  74.                 sleepList.remove();
  75.             parent.removeSchedular(id);
  76.             kicker = null;
  77.             break;
  78.             } else {
  79.                 reschedule(id);
  80.                 sleepList.remove();
  81.             }
  82.         }
  83.         parent.repaint();
  84.         } else {
  85.         int sleeptime = (int)(p.getTime() - curTime);
  86.         sleep(sleeptime);
  87.         }
  88.     }
  89.     }
  90. }
  91.  
  92. public void stop() {
  93.     kicker = null;
  94. }
  95.  
  96. public void reschedule(int id) {
  97.     boolean ontime = (kicker != null);
  98.     long curTime = System.currentTimeMillis();
  99.  
  100.     AnimationData ad = parent.getAnimationData(id);
  101.     int type = ad.getType();
  102.  
  103.     if (type == 1 || type == 2 || 
  104.     (type == 3 && ad.getCurFrame() >= 0 && 
  105.                 ad.getCurFrame() < ad.getLastFrame()) ||
  106.     (type == 4 && 
  107.        ((ad.getReverse() && ad.getCurFrame() > 0) ||
  108.         (!ad.getReverse() && ad.getCurFrame() < ad.getLastFrame())))) {
  109.     sleepList.insertByTime(
  110.             new IDChain(id,curTime+(long)ad.getFrameTime(),0));
  111.     }
  112. }
  113.  
  114. // For debug
  115. public void dump() {
  116.     IDChain p;
  117.     
  118.     System.out.println("Schedular dump, curTime="+System.currentTimeMillis());
  119.     for (p=sleepList.getNext();p != null; p = p.getNext()) {
  120.     System.out.println("  id=" + p.getID() + ", time=" + p.getTime() + 
  121.         ", depth=" + p.getDepth());
  122.     }
  123.     System.out.flush();
  124. }
  125.  
  126. }
  127.