diff options
Diffstat (limited to 'NET/worlds/scape/PeriodicTimeSensor.java')
| -rw-r--r-- | NET/worlds/scape/PeriodicTimeSensor.java | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/NET/worlds/scape/PeriodicTimeSensor.java b/NET/worlds/scape/PeriodicTimeSensor.java new file mode 100644 index 0000000..f02b1c3 --- /dev/null +++ b/NET/worlds/scape/PeriodicTimeSensor.java @@ -0,0 +1,131 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.core.Std; +/* */ import java.io.IOException; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class PeriodicTimeSensor +/* */ extends Sensor +/* */ implements FrameHandler +/* */ { +/* 27 */ private float timeInterval = 1.0F; +/* */ +/* */ +/* */ +/* */ private long lastTrigger; +/* */ +/* */ +/* */ +/* */ public PeriodicTimeSensor(Action act) +/* */ { +/* 37 */ if (act != null) { +/* 38 */ addAction(act); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public PeriodicTimeSensor() {} +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean handle(FrameEvent e) +/* */ { +/* 55 */ long now = 0L; +/* 56 */ if (e == null) { +/* 57 */ now = Std.getFastTime(); +/* */ } else { +/* 59 */ now = e.time; +/* */ } +/* */ +/* 62 */ if (now - this.lastTrigger > (1000.0F * this.timeInterval)) { +/* 63 */ this.lastTrigger = now; +/* 64 */ trigger(e); +/* */ } +/* */ +/* 67 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Object properties(int index, int offset, int mode, Object value) +/* */ throws NoSuchPropertyException +/* */ { +/* 77 */ Object ret = null; +/* 78 */ switch (index - offset) { +/* */ case 0: +/* 80 */ if (mode == 0) { +/* 81 */ ret = FloatPropertyEditor.make( +/* 82 */ new Property(this, index, "Time Interval (s)")); +/* 83 */ } else if (mode == 1) { +/* 84 */ ret = new Float(this.timeInterval); +/* 85 */ } else if (mode == 2) { +/* 86 */ this.timeInterval = ((Float)value).floatValue(); +/* */ } +/* 88 */ break; +/* */ default: +/* 90 */ ret = super.properties(index, offset + 1, mode, value); +/* */ } +/* 92 */ return ret; +/* */ } +/* */ +/* */ +/* 96 */ private static Object classCookie = new Object(); +/* */ +/* */ public void saveState(Saver s) throws IOException +/* */ { +/* 100 */ s.saveVersion(1, classCookie); +/* 101 */ super.saveState(s); +/* 102 */ s.saveFloat(this.timeInterval); +/* */ } +/* */ +/* */ public void restoreState(Restorer r) throws IOException, TooNewException +/* */ { +/* 107 */ switch (r.restoreVersion(classCookie)) { +/* */ case 1: +/* 109 */ super.restoreState(r); +/* 110 */ this.timeInterval = r.restoreFloat(); +/* 111 */ break; +/* */ default: +/* 113 */ throw new TooNewException(); +/* */ } +/* */ +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public String toString() +/* */ { +/* 123 */ return "*every " + this.timeInterval + " s"; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\PeriodicTimeSensor.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |