summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/ScapePicMovie.java
blob: 773e72dd95ab4c6985220b4153950c2a7b9e2803 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.network.URL;
import java.io.IOException;
import java.util.Hashtable;

public class ScapePicMovie implements Persister {
   private static Hashtable movieDict = new Hashtable();
   private ScapePicTexture[] movie;
   private String localName;
   private URL url;
   private int frameCount;
   private int width;
   private int height;
   private static Object classCookie = new Object();

   static {
      nativeInit();
   }

   public ScapePicMovie() {
   }

   public ScapePicMovie(String localName, URL url) {
      this.localName = localName;
      this.url = url;
      this.movie = this.getAll();
   }

   public static native void nativeInit();

   public int getW() {
      return this.width;
   }

   public int getH() {
      return this.height;
   }

   public int length() {
      return this.frameCount;
   }

   public URL getURL() {
      return this.url;
   }

   public ScapePicTexture getTexture(int frameNumber) {
      ScapePicTexture ret = null;
      if (this.movie != null) {
         ret = this.movie[frameNumber];
         this.movie[frameNumber] = null;
         int i = 0;

         while (i < this.frameCount && this.movie[i] == null) {
            i++;
         }

         if (i == this.frameCount) {
            this.movie = null;
         }
      }

      return ret;
   }

   public ScapePicTexture[] getTextures() {
      ScapePicTexture[] ret = this.movie;
      this.movie = null;
      return ret;
   }

   private synchronized ScapePicTexture[] getAll() {
      String name = this.url.getAbsolute();
      ScapePicMovie proto = (ScapePicMovie)movieDict.get(name);
      ScapePicTexture[] a = (ScapePicTexture[])null;
      if (proto != null) {
         this.frameCount = proto.length();
         this.width = proto.getW();
         this.height = proto.getH();
         a = this.lookupTextures(name, this.frameCount, this.width, this.height);
      }

      if (a == null) {
         a = this.makeTextures(this.localName, name);
         if (a != null && proto == null) {
            this.frameCount = a.length;
            this.width = a[0].getW();
            this.height = a[0].getH();
            movieDict.put(name, this);
         }
      }

      return a;
   }

   private native ScapePicTexture[] lookupTextures(String var1, int var2, int var3, int var4);

   private native ScapePicTexture[] makeTextures(String var1, String var2);

   @Override
   public void saveState(Saver s) throws IOException {
      Console.println(Console.message("Obs-ScapePicMov") + this.url);
      s.saveVersion(2, classCookie);
      this.url.save(s);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      switch (r.restoreVersion(classCookie)) {
         case 0:
            this.localName = r.restoreString();
            this.url = URL.make(this.localName);
            r.restoreBoolean();
            break;
         case 1:
            this.localName = r.restoreString();
            this.url = URL.make(this.localName);
            break;
         case 2:
            this.url = URL.restore(r);
            this.localName = this.url.unalias();
            break;
         default:
            throw new TooNewException();
      }

      this.movie = this.getAll();
   }

   @Override
   public void postRestore(int version) {
   }

   @Override
   public String toString() {
      return this.url.getAbsolute();
   }
}