home *** CD-ROM | disk | FTP | other *** search
- import browser.*;
- import browser.audio.*;
- import awt.*;
- import java.util.*;
- import java.io.*;
- import java.lang.*;
- import net.www.html.*;
-
- #include "anim.h";
-
- class Schedular extends Thread {
-
- AnimationPlayer parent;
- int id;
- IDChain sleepList;
- Thread kicker = null;
-
- public Schedular(AnimationPlayer sa, int myid) {
- parent = sa;
- id = myid;
- sleepList = new IDChain();
- }
-
- public int getID() {return id;}
-
- public void start() {
- if (kicker != null) {
- return;
- }
- kicker = new Thread(this);
- kicker.start();
- }
-
- public void run() {
- long curTime;
- IDChain p;
- while (kicker != null) {
- curTime = System.currentTimeMillis();
- p = sleepList.getNext();
-
- if (p == null) {
- sleep(5000);
- } else {
- if (p.getTime() < curTime) {
- while ((p=sleepList.getNext()) != null &&
- p.getTime() < curTime) {
- int id = p.getID();
- AnimationData ad = parent.getAnimationData(id);
- ad.nextFrame();
- int type = ad.getType();
- if (ad.isSoundFrame() &&
- (type == TY_AUTO || type == TY_CLICK ||
- type == TY_ONCE || type == TY_TOGGLE)) {
- ad.playSound();
- }
- if ((type == TY_CLICK && ad.getCurFrame() == 0) ||
- (type == TY_ONCE &&
- ad.getCurFrame() == ad.getLastFrame()) ||
- (type == TY_TOGGLE &&
- (ad.getCurFrame() == 0 ||
- ad.getCurFrame() == ad.getLastFrame()))) {
- sleepList.remove();
- parent.removeSchedular(id);
- kicker = null;
- break;
- } else {
- reschedule(id);
- sleepList.remove();
- }
- }
- parent.repaint();
- } else {
- int sleeptime = (int)(p.getTime() - curTime);
- sleep(sleeptime);
- }
- }
- }
- }
-
- public void stop() {
- kicker = null;
- }
-
- public void reschedule(int id) {
- boolean ontime = (kicker != null);
- long curTime = System.currentTimeMillis();
-
- AnimationData ad = parent.getAnimationData(id);
- int type = ad.getType();
-
- if (type == TY_AUTO || type == TY_CLICK ||
- (type == TY_ONCE && ad.getCurFrame() >= 0 &&
- ad.getCurFrame() < ad.getLastFrame()) ||
- (type == TY_TOGGLE &&
- ((ad.getReverse() && ad.getCurFrame() > 0) ||
- (!ad.getReverse() && ad.getCurFrame() < ad.getLastFrame())))) {
- sleepList.insertByTime(
- new IDChain(id,curTime+(long)ad.getFrameTime(),0));
- }
- }
-
- // For debug
- public void dump() {
- IDChain p;
-
- System.out.println("Schedular dump, curTime="+System.currentTimeMillis());
- for (p=sleepList.getNext();p != null; p = p.getNext()) {
- System.out.println(" id=" + p.getID() + ", time=" + p.getTime() +
- ", depth=" + p.getDepth());
- }
- System.out.flush();
- }
-
- }
-