package NET.worlds.scape; import java.awt.Color; import java.io.IOException; public class RoomEnvironment extends WObject { private int lightid = 0; private int lightid2 = 0; int nextVertex = 1; boolean wasEdited = false; private static Object classCookie = new Object(); private int sceneID; static { nativeInit(); } RoomEnvironment() { } public static native void nativeInit(); @Override protected void addRwChildren(WObject parent) { this.createClump(); Room r = (Room)this.getOwner(); this.createScene(r); this.newRwChildHelper(); this.addLight(r.getLightPosition(), r.getLightColor()); } @Override protected void noteAddingTo(SuperRoot owner) { Room r = (Room)owner; } private void addLight(Point3Temp pos, Color c) { assert this.lightid == 0; float red = c.getRed() / 256.0F; float green = c.getGreen() / 256.0F; float blue = c.getBlue() / 256.0F; this.lightid = Room.addLight(this.sceneID, pos.x, pos.y, pos.z, red, green, blue); this.lightid2 = Room.addLight(this.sceneID, -pos.x, -pos.y, -pos.z, red * 0.5F, green * 0.5F, blue * 0.5F); } void setLightPosition(float x, float y, float z) { if (this.lightid != 0) { Room.setLightPosition(this.lightid, x, y, z); } if (this.lightid2 != 0) { Room.setLightPosition(this.lightid2, -x, -y, -z); } } void setLightColor(float red, float green, float blue) { if (this.lightid != 0) { Room.setLightColor(this.lightid, red, green, blue); } if (this.lightid2 != 0) { Room.setLightColor(this.lightid2, red * 0.5F, green * 0.5F, blue * 0.5F); } } @Override public BoundBoxTemp getBoundBox() { return BoundBoxTemp.make(Point3Temp.make(), Point3Temp.make()); } @Override protected void markVoid() { super.markVoid(); this.destroyScene(); this.lightid = 0; this.lightid2 = 0; } public void markClumpEdited() { this.wasEdited = true; } public void prerender() { if (this.wasEdited) { this.wasEdited = false; this.doneWithEditing(); } } @Override public void saveState(Saver s) throws IOException { s.saveVersion(1, classCookie); super.saveState(s); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { switch (r.restoreVersion(classCookie)) { case 0: r.setOldFlag(); super.restoreState(r); r.restore(); break; case 1: super.restoreState(r); break; default: throw new TooNewException(); } } native void createScene(Room var1); native void destroyScene(); }