package NET.worlds.scape; import NET.worlds.console.Console; import java.awt.Color; import java.io.IOException; import java.text.MessageFormat; public class Surface extends WObject implements Animatable { private int[] polygonIDs; protected Material material; private static Object classCookie = new Object(); static { nativeInit(); } public Surface(Material m) { if (m != null && m.getOwner() != null) { m = (Material)m.clone(); } this.setMaterial(m); } Surface() { } public static native void nativeInit(); @Override public void loadInit() { this.setMaterial(null); } @Override protected void markVoid() { super.markVoid(); this.polygonIDs = null; this.material.markVoid(); } @Override public void recursiveAddRwChildren(WObject container) { this.material.addRwChildren(); super.recursiveAddRwChildren(container); int hres = this.material.getHRes(); int vres = this.material.getVRes(); int numVerts = this.getNumVerts(); if (numVerts != 4 || !this.material.getHiRes() && !this.uvOutOfRange()) { assert numVerts > 0; int[] vi = new int[numVerts]; for (int i = 0; i < numVerts; i++) { vi[i] = i + 1; } this.polygonIDs = new int[1]; this.addPolygon(vi); } else { int numTiles = this.addSubPolys(hres, vres); if (numTiles >= 100 && Console.getFrame().isShaperVisible()) { Object[] arguments = new Object[]{new Integer(numTiles), new String(this.getRoom().getName()), new String(this.getName())}; Console.println(MessageFormat.format(Console.message("Memory-hog"), arguments)); } } this.nativeSetMaterial(); this.doneWithEditing(); } protected void setVFlip(boolean b) { if (b) { this.flags |= 1048576; } else { this.flags &= -1048577; } } protected void setUFlip(boolean b) { if (b) { this.flags |= 524288; } else { this.flags &= -524289; } } protected boolean getUFlip() { return (this.flags & 524288) != 0; } protected boolean getVFlip() { return (this.flags & 1048576) != 0; } @Override public void setMaterial(Material m) { this.setMaterial(m, false); } public void setMaterial(Material m, boolean forceReload) { if (m == null) { m = new Material(new Color((int)(Math.random() * 1.6777216E7))); } else if (this.material == m && !forceReload) { return; } boolean sameSize = this.polygonIDs != null && this.polygonIDs.length >= 1 && this.material.getHRes() == m.getHRes() && this.material.getVRes() == m.getVRes(); if (this.material != m) { if (this.material != null) { this.material.detach(); } this.add(m); this.material = m; } if (this.polygonIDs != null) { if (sameSize) { this.nativeSetMaterial(); } else { this.reclump(); } } } private native void nativeSetMaterial(); private native boolean uvOutOfRange(); public Material getMaterial() { return this.material; } native void addVertex(float var1, float var2, float var3, float var4, float var5); native void addPolygon(int[] var1); private native int addSubPolys(int var1, int var2); @Override public void getChildren(DeepEnumeration d) { super.getChildren(d); d.addChildElement(this.material); } @Override public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null; switch (index - offset) { case 0: if (mode == 0) { ret = new Property(this, index, "Material"); } else if (mode == 1) { ret = this.material; } break; default: ret = super.properties(index, offset + 1, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { s.saveVersion(1, classCookie); super.saveState(s); s.save(this.material); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { switch (r.restoreVersion(classCookie)) { case 0: super.restoreState(r); this.setMaterial(Material.restore(r)); break; case 1: super.restoreState(r); this.setMaterial((Material)r.restore()); break; default: throw new TooNewException(); } } }