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/RelativeMoveAction.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/RelativeMoveAction.java')
| -rw-r--r-- | NET/worlds/scape/RelativeMoveAction.java | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/NET/worlds/scape/RelativeMoveAction.java b/NET/worlds/scape/RelativeMoveAction.java new file mode 100644 index 0000000..8d59804 --- /dev/null +++ b/NET/worlds/scape/RelativeMoveAction.java @@ -0,0 +1,196 @@ +package NET.worlds.scape; + +import NET.worlds.core.Std; +import java.io.IOException; + +public class RelativeMoveAction extends Action { + int startTime; + public int cycleTime = 1000; + public int cycles = 1; + public boolean loopInfinite = false; + public Point3 extentPoint = new Point3(); + public Point3 extentScale = new Point3(1.0F, 1.0F, 1.0F); + public Point3 extentSpin = new Point3(0.0F, 0.0F, -1.0F); + public float extentRotation = 0.0F; + public float accumulatedRotation; + public Point3 accumulatedScale; + public Point3 accumulatedPoint; + protected Persister activeID; + private static Object classCookie = new Object(); + + @Override + public Persister trigger(Event e, Persister seqID) { + Object owner = this.getOwner(); + if (owner != null && owner instanceof WObject) { + WObject o = (WObject)owner; + if (seqID == null) { + if (this.activeID != null) { + return this.activeID; + } + + this.startTime = Std.getRealTime(); + this.activeID = new SuperRoot(); + seqID = this.activeID; + this.accumulatedRotation = 0.0F; + this.accumulatedPoint = new Point3(0.0F, 0.0F, 0.0F); + this.accumulatedScale = new Point3(1.0F, 1.0F, 1.0F); + } + + if (seqID != this.activeID) { + return null; + } else { + int currentTime = Std.getRealTime(); + int cycleNo = (currentTime - this.startTime) / this.cycleTime; + float frameLoc = 1.0F; + if (cycleNo >= this.cycles && !this.loopInfinite) { + this.activeID = null; + } else { + frameLoc = (float)((currentTime - this.startTime) % this.cycleTime) / this.cycleTime; + } + + float tmpSpin = this.extentRotation * frameLoc; + o.spin(this.extentSpin, tmpSpin - this.accumulatedRotation); + this.accumulatedRotation = tmpSpin; + Point3 tmpScale = new Point3( + (float)Math.pow(this.extentScale.x, frameLoc), (float)Math.pow(this.extentScale.y, frameLoc), (float)Math.pow(this.extentScale.z, frameLoc) + ); + o.scale(Point3Temp.make(tmpScale).dividedBy(this.accumulatedScale)); + this.accumulatedScale = tmpScale; + Point3 tmpPoint = new Point3(Point3Temp.make(this.extentPoint).times(frameLoc)); + o.moveBy(Point3Temp.make(tmpPoint).minus(this.accumulatedPoint)); + this.accumulatedPoint = tmpPoint; + return this.activeID; + } + } else { + return null; + } + } + + @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 = FloatPropertyEditor.make(new Property(this, index, "Cycle Time (in seconds)")); + } else if (mode == 1) { + ret = new Float(this.cycleTime / 1000.0F); + } else if (mode == 2) { + this.cycleTime = (int)(1000.0F * (Float)value); + } + break; + case 1: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "Cycles")); + } else if (mode == 1) { + ret = new Integer(this.cycles); + } else if (mode == 2) { + this.cycles = (Integer)value; + } + break; + case 2: + if (mode == 0) { + ret = BooleanPropertyEditor.make(new Property(this, index, "Loop Infinite"), "False", "True"); + } else if (mode == 1) { + ret = new Boolean(this.loopInfinite); + } else if (mode == 2) { + this.loopInfinite = (Boolean)value; + } + break; + case 3: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "Translation Extent")); + } else if (mode == 1) { + ret = new Point3(this.extentPoint); + } else if (mode == 2) { + this.extentPoint.copy((Point3)value); + } + break; + case 4: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "Scale Extent")); + } else if (mode == 1) { + ret = new Point3(this.extentScale); + } else if (mode == 2) { + this.extentScale.copy((Point3)value); + } + break; + case 5: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "Spin Axis For Extent")); + } else if (mode == 1) { + Point3 p = new Point3(this.extentSpin); + p.x = Math.round(p.x * 10000.0F) / 10000.0F; + p.y = Math.round(p.y * 10000.0F) / 10000.0F; + p.z = Math.round(p.z * 10000.0F) / 10000.0F; + ret = p; + } else if (mode == 2) { + this.extentSpin.copy((Point3)value); + } + break; + case 6: + if (mode == 0) { + ret = FloatPropertyEditor.make(new Property(this, index, "Extent Rotation Amount")); + } else if (mode == 1) { + ret = new Float(this.extentRotation); + } else if (mode == 2) { + this.extentRotation = (Float)value; + } + break; + default: + ret = super.properties(index, offset + 7, mode, value); + } + + return ret; + } + + @Override + public String toString() { + String retVal = super.toString() + "[cycleTime " + this.cycleTime / 1000.0F + ", cycles " + this.cycles + ", "; + if (!this.loopInfinite) { + retVal = retVal + " NOT"; + } + + return retVal + " Infinite]"; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveVersion(5, classCookie); + super.saveState(s); + s.saveBoolean(this.loopInfinite); + s.saveInt(this.cycleTime); + s.saveInt(this.cycles); + s.save(this.extentPoint); + s.save(this.extentScale); + s.save(this.extentSpin); + s.saveFloat(this.extentRotation); + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + switch (r.restoreVersion(classCookie)) { + case 4: + super.restoreState(r); + this.cycleTime = r.restoreInt(); + this.cycles = r.restoreInt(); + this.extentPoint = (Point3)r.restore(); + this.extentScale = (Point3)r.restore(); + this.extentSpin = (Point3)r.restore(); + this.extentRotation = r.restoreFloat(); + break; + case 5: + super.restoreState(r); + this.loopInfinite = r.restoreBoolean(); + this.cycleTime = r.restoreInt(); + this.cycles = r.restoreInt(); + this.extentPoint = (Point3)r.restore(); + this.extentScale = (Point3)r.restore(); + this.extentSpin = (Point3)r.restore(); + this.extentRotation = r.restoreFloat(); + break; + default: + throw new TooNewException(); + } + } +} |