diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/Surface.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/Surface.java')
| -rw-r--r-- | NET/worlds/scape/Surface.java | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/NET/worlds/scape/Surface.java b/NET/worlds/scape/Surface.java new file mode 100644 index 0000000..61fce10 --- /dev/null +++ b/NET/worlds/scape/Surface.java @@ -0,0 +1,190 @@ +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(); + } + } +} |