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(); } }