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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import java.awt.Color;
import java.io.IOException;
import java.text.MessageFormat;
public class Surface extends WObject implements Animatable {
private int[] polygonIDs;
protected Material material;
private static Object classCookie = new Object();
static {
nativeInit();
}
public Surface(Material m) {
if (m != null && m.getOwner() != null) {
m = (Material)m.clone();
}
this.setMaterial(m);
}
Surface() {
}
public static native void nativeInit();
@Override
public void loadInit() {
this.setMaterial(null);
}
@Override
protected void markVoid() {
super.markVoid();
this.polygonIDs = null;
this.material.markVoid();
}
@Override
public void recursiveAddRwChildren(WObject container) {
this.material.addRwChildren();
super.recursiveAddRwChildren(container);
int hres = this.material.getHRes();
int vres = this.material.getVRes();
int numVerts = this.getNumVerts();
if (numVerts != 4 || !this.material.getHiRes() && !this.uvOutOfRange()) {
assert numVerts > 0;
int[] vi = new int[numVerts];
for (int i = 0; i < numVerts; i++) {
vi[i] = i + 1;
}
this.polygonIDs = new int[1];
this.addPolygon(vi);
} else {
int numTiles = this.addSubPolys(hres, vres);
if (numTiles >= 100 && Console.getFrame().isShaperVisible()) {
Object[] arguments = new Object[]{new Integer(numTiles), new String(this.getRoom().getName()), new String(this.getName())};
Console.println(MessageFormat.format(Console.message("Memory-hog"), arguments));
}
}
this.nativeSetMaterial();
this.doneWithEditing();
}
protected void setVFlip(boolean b) {
if (b) {
this.flags |= 1048576;
} else {
this.flags &= -1048577;
}
}
protected void setUFlip(boolean b) {
if (b) {
this.flags |= 524288;
} else {
this.flags &= -524289;
}
}
protected boolean getUFlip() {
return (this.flags & 524288) != 0;
}
protected boolean getVFlip() {
return (this.flags & 1048576) != 0;
}
@Override
public void setMaterial(Material m) {
this.setMaterial(m, false);
}
public void setMaterial(Material m, boolean forceReload) {
if (m == null) {
m = new Material(new Color((int)(Math.random() * 1.6777216E7)));
} else if (this.material == m && !forceReload) {
return;
}
boolean sameSize = this.polygonIDs != null
&& this.polygonIDs.length >= 1
&& this.material.getHRes() == m.getHRes()
&& this.material.getVRes() == m.getVRes();
if (this.material != m) {
if (this.material != null) {
this.material.detach();
}
this.add(m);
this.material = m;
}
if (this.polygonIDs != null) {
if (sameSize) {
this.nativeSetMaterial();
} else {
this.reclump();
}
}
}
private native void nativeSetMaterial();
private native boolean uvOutOfRange();
public Material getMaterial() {
return this.material;
}
native void addVertex(float var1, float var2, float var3, float var4, float var5);
native void addPolygon(int[] var1);
private native int addSubPolys(int var1, int var2);
@Override
public void getChildren(DeepEnumeration d) {
super.getChildren(d);
d.addChildElement(this.material);
}
@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, "Material");
} else if (mode == 1) {
ret = this.material;
}
break;
default:
ret = super.properties(index, offset + 1, mode, value);
}
return ret;
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(1, classCookie);
super.saveState(s);
s.save(this.material);
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 0:
super.restoreState(r);
this.setMaterial(Material.restore(r));
break;
case 1:
super.restoreState(r);
this.setMaterial((Material)r.restore());
break;
default:
throw new TooNewException();
}
}
}
|