summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/MCIThread.java
blob: e63518aee22209d09ae6a5f03cc6f510435b3b95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package NET.worlds.scape;

import NET.worlds.console.Main;
import NET.worlds.console.MainCallback;
import NET.worlds.console.MainTerminalCallback;
import java.util.Vector;

class MCIThread implements MainCallback, MainTerminalCallback {
   private Vector queue = new Vector();
   private int frameNum;

   public MCIThread() {
      Main.register(this);
   }

   public synchronized void pushCommand(MCISoundCommand c) {
      this.queue.addElement(c);
      c.onQueue(true);
      c.frameNum = this.frameNum + 2;
   }

   @Override
   public synchronized void mainCallback() {
      this.frameNum++;

      while (this.queue.size() > 0) {
         MCISoundCommand command = (MCISoundCommand)this.queue.elementAt(0);
         if (command.frameNum > this.frameNum) {
            return;
         }

         command.onQueue(false);
         this.queue.removeElementAt(0);
         command.run();
      }
   }

   @Override
   public synchronized void terminalCallback() {
      MCISoundPlayer.shutdown();
      ASFSoundPlayer.shutdown();
      Main.unregister(this);
   }
}