package NET.worlds.scape; import NET.worlds.network.URL; import java.util.Enumeration; import java.util.Vector; public class ShapeLoader implements BGLoaded { Shape shape; int binaryParam; private int numTexturesLoading; private Vector textures; private boolean wasError; public ShapeLoader(Shape s) { this.shape = s; } @Override public Room getBackgroundLoadRoom() { return this.shape.getRoom(); } @Override public Object asyncBackgroundLoad(String localName, URL remoteName) { if (localName == null) { return null; } else if (remoteName.endsWith(".rwg") || remoteName.endsWith(".RWG")) { this.binaryParam = this.loadBinaryFile(localName, remoteName); return new Object(); } else if (remoteName.endsWith(".rwx") || remoteName.endsWith(".RWX")) { this.loadTextFile(localName, remoteName); return localName; } else { return !remoteName.endsWith(".bod") && !remoteName.endsWith(".BOD") ? null : localName; } } @Override public boolean syncBackgroundLoad(Object o, URL remoteURL) { if (o == null) { return false; } else if (this.numTexturesLoading > 0) { return true; } else { if (!remoteURL.equals(this.shape.realFile)) { this.wasError = true; } else if (!this.shape.hasClump() && this.shape.isDefault) { this.wasError = true; if (!this.shape.isLoaded()) { this.shape.setState(0, null); } } int newModel; if (o instanceof String) { if (!this.wasError) { if (remoteURL.endsWith(".bod")) { newModel = this.loadBodFile((String)o, this.shape.getBodPartNum()); } else { newModel = this.finishLoadingTextFile((String)o); } } else { newModel = 0; } } else { newModel = this.finishLoadingBinaryFile(this.binaryParam, this.wasError); } if (newModel != 0) { this.shape.setState(newModel, this.textures); } if ((newModel == 0 || newModel == -1) && this.textures != null) { Enumeration en = this.textures.elements(); while (en.hasMoreElements()) { en.nextElement().decRef(); } } this.textures = null; return false; } } private void startTextureLoad(String relName, URL remoteName) { this.numTexturesLoading++; BackgroundLoader.get(new ShapeTextureLoader(this), URL.make(remoteName, relName), true); } synchronized void textureLoadEnd(Texture tex) { this.numTexturesLoading--; if (tex != null) { if (this.textures == null) { this.textures = new Vector(); } this.textures.addElement(tex); } else { this.wasError = true; } } private native void loadTextFile(String var1, URL var2); private native int finishLoadingTextFile(String var1); private native int loadBodFile(String var1, int var2); private native int loadBinaryFile(String var1, URL var2); private native int finishLoadingBinaryFile(int var1, boolean var2); }