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.jpp < prev    next >
Encoding:
Text File  |  2017-09-21  |  2.5 KB  |  115 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. #include "anim.h";
  10.  
  11. class Schedular extends Thread {
  12.  
  13. AnimationPlayer    parent;
  14. int        id;
  15. IDChain        sleepList;
  16. Thread        kicker = null;
  17.  
  18. public Schedular(AnimationPlayer sa, int myid) {
  19.     parent = sa;
  20.     id = myid;
  21.     sleepList = new IDChain();
  22. }
  23.  
  24. public int getID() {return id;}
  25.  
  26. public void start() {
  27.     if (kicker != null) {
  28.     return;
  29.     }
  30.     kicker = new Thread(this);
  31.     kicker.start();
  32. }
  33.  
  34. public void run() {
  35.     long curTime;
  36.     IDChain p;
  37.     while (kicker != null) {
  38.     curTime = System.currentTimeMillis();
  39.     p = sleepList.getNext();
  40.  
  41.     if (p == null) {
  42.         sleep(5000);
  43.     } else {
  44.         if (p.getTime() < curTime) {
  45.             while ((p=sleepList.getNext()) != null && 
  46.                         p.getTime() < curTime) {
  47.             int id = p.getID();
  48.             AnimationData ad = parent.getAnimationData(id);
  49.             ad.nextFrame();
  50.             int type = ad.getType();
  51.             if (ad.isSoundFrame() && 
  52.             (type == TY_AUTO || type == TY_CLICK || 
  53.              type == TY_ONCE || type == TY_TOGGLE)) {
  54.             ad.playSound();
  55.             }
  56.             if ((type == TY_CLICK && ad.getCurFrame() == 0) ||
  57.             (type == TY_ONCE && 
  58.                 ad.getCurFrame() == ad.getLastFrame()) ||
  59.             (type == TY_TOGGLE && 
  60.                 (ad.getCurFrame() == 0 || 
  61.                  ad.getCurFrame() == ad.getLastFrame()))) {
  62.                 sleepList.remove();
  63.             parent.removeSchedular(id);
  64.             kicker = null;
  65.             break;
  66.             } else {
  67.                 reschedule(id);
  68.                 sleepList.remove();
  69.             }
  70.         }
  71.         parent.repaint();
  72.         } else {
  73.         int sleeptime = (int)(p.getTime() - curTime);
  74.         sleep(sleeptime);
  75.         }
  76.     }
  77.     }
  78. }
  79.  
  80. public void stop() {
  81.     kicker = null;
  82. }
  83.  
  84. public void reschedule(int id) {
  85.     boolean ontime = (kicker != null);
  86.     long curTime = System.currentTimeMillis();
  87.  
  88.     AnimationData ad = parent.getAnimationData(id);
  89.     int type = ad.getType();
  90.  
  91.     if (type == TY_AUTO || type == TY_CLICK || 
  92.     (type == TY_ONCE && ad.getCurFrame() >= 0 && 
  93.                 ad.getCurFrame() < ad.getLastFrame()) ||
  94.     (type == TY_TOGGLE && 
  95.        ((ad.getReverse() && ad.getCurFrame() > 0) ||
  96.         (!ad.getReverse() && ad.getCurFrame() < ad.getLastFrame())))) {
  97.     sleepList.insertByTime(
  98.             new IDChain(id,curTime+(long)ad.getFrameTime(),0));
  99.     }
  100. }
  101.  
  102. // For debug
  103. public void dump() {
  104.     IDChain p;
  105.     
  106.     System.out.println("Schedular dump, curTime="+System.currentTimeMillis());
  107.     for (p=sleepList.getNext();p != null; p = p.getNext()) {
  108.     System.out.println("  id=" + p.getID() + ", time=" + p.getTime() + 
  109.         ", depth=" + p.getDepth());
  110.     }
  111.     System.out.flush();
  112. }
  113.  
  114. }
  115.