blob: c271e80d5fec87d4d80444af6a20794f86accfcd (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package NET.worlds.console;
import NET.worlds.scape.FrameEvent;
import NET.worlds.scape.FrameHandler;
import NET.worlds.scape.NoSuchPropertyException;
import NET.worlds.scape.Pilot;
import NET.worlds.scape.Point3;
import NET.worlds.scape.Point3Temp;
import NET.worlds.scape.Property;
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 CameraConveyor extends SuperRoot implements FrameHandler {
private Point3 vector;
private static Object classCookie = new Object();
public CameraConveyor() {
}
public CameraConveyor(Point3Temp direction, float speed) {
this.vector = new Point3(direction.normalize().times(speed));
}
public CameraConveyor(Point3Temp v) {
this.vector = new Point3(v);
}
@Override
public boolean handle(FrameEvent e) {
if (e.dt == 0) {
return true;
} else {
Enumeration<WObject> stuff = (Enumeration<WObject>)e.receiver.getContents();
Point3Temp delta = Point3Temp.make(this.vector);
delta.times(e.dt / 1000.0F);
while (stuff.hasMoreElements()) {
WObject thing = stuff.nextElement();
if (thing instanceof Pilot) {
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();
}
}
@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, "Velocity");
} else if (mode == 1) {
ret = this.vector;
}
break;
default:
ret = super.properties(index, offset + 1, mode, value);
}
return ret;
}
}
|