blob: a0e899ed2515954cdca646977c9516fdf19055ce (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package NET.worlds.console;
import NET.worlds.scape.FrameEvent;
import NET.worlds.scape.FrameHandler;
import NET.worlds.scape.Point3;
import NET.worlds.scape.Point3Temp;
import NET.worlds.scape.Restorer;
import NET.worlds.scape.Saver;
import NET.worlds.scape.SuperRoot;
import NET.worlds.scape.TooNewException;
import NET.worlds.scape.WObject;
import java.io.IOException;
import java.util.Enumeration;
public class Conveyor extends SuperRoot implements FrameHandler {
private Point3 vector;
private static Object classCookie = new Object();
public Conveyor(Point3Temp direction, float speed) {
this.vector = new Point3(direction.normalize().times(speed));
}
public Conveyor(Point3Temp v) {
this.vector = new Point3(v);
}
@Override
public boolean handle(FrameEvent e) {
Enumeration<WObject> stuff = (Enumeration<WObject>)e.receiver.getContents();
Point3Temp delta = this.vector;
delta.times(e.dt / 1000.0F);
while (stuff.hasMoreElements()) {
WObject thing = stuff.nextElement();
thing.moveThrough(delta);
}
return true;
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(1, classCookie);
super.saveState(s);
s.save(this.vector);
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 1:
super.restoreState(r);
case 0:
this.vector = (Point3)r.restore();
return;
default:
throw new TooNewException();
}
}
}
|