summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/TransAttribute.java
blob: bd74407fa4c7e42c8c4520e361f79b1046518c7c (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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package NET.worlds.scape;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class TransAttribute extends Attribute {
   private Point3 defPos;
   private Point3 defRAxis;
   private float defRotation;
   private Point3 defScale;
   private int _sharingMode = 57344;
   private static Object classCookie = new Object();

   public TransAttribute(int attrID) {
      super(attrID);
   }

   public TransAttribute() {
   }

   @Override
   protected void noteAddingTo(SuperRoot owner) {
      WObject w = (WObject)((Sharer)owner).getOwner();
      w._transformAttribute = this;
      this.initDefault();
   }

   @Override
   public void detach() {
      WObject w = (WObject)((Sharer)this.getOwner()).getOwner();
      w._transformAttribute = null;
      super.detach();
   }

   @Override
   public void noteChange() {
      if (!TCompressor.dontSend) {
         super.noteChange();
      }
   }

   @Override
   public void generateNetData(DataOutputStream s) throws IOException {
      WObject w = (WObject)this.getOwner().getOwner();
      if (this._shorthandVersion == 0) {
         Point3Temp pos = w.getPosition();
         s.writeFloat(pos.x);
         s.writeFloat(pos.y);
         s.writeFloat(pos.z);
         Point3Temp scale = w.getScale();
         s.writeFloat(scale.x);
         s.writeFloat(scale.y);
         s.writeFloat(scale.z);
      } else {
         this.initDefault();
         TCompressor.compress(w, this.defPos, this.defRAxis, this.defRotation, this.defScale, this._sharingMode, s);
      }
   }

   private void initDefault() {
      if (this.defPos == null) {
         WObject w = (WObject)((Sharer)this.getOwner()).getOwner();
         this.defPos = new Point3(w.getPosition());
         this.defRAxis = new Point3();
         this.defRotation = w.getSpin(this.defRAxis);
         this.defScale = new Point3(w.getScale());
      }
   }

   @Override
   public void setFromNetData(DataInputStream ds, int len) throws IOException {
      WObject w = (WObject)this.getOwner().getOwner();
      this.initDefault();

      try {
         TCompressor.decompress(w, this.defPos, this.defRAxis, this.defRotation, this.defScale, this._sharingMode, len, ds);
      } catch (IOException var5) {
         TCompressor.dontSend = false;
         throw var5;
      }
   }

   public boolean getSharingPosition() {
      return (this._sharingMode & 32768) != 0;
   }

   public void setSharingPosition(boolean b) {
      if (b) {
         this._sharingMode |= 32768;
      } else {
         this._sharingMode &= -32769;
      }
   }

   public boolean getSharingRotation() {
      return (this._sharingMode & 16384) != 0;
   }

   public void setSharingRotation(boolean b) {
      if (b) {
         this._sharingMode |= 16384;
      } else {
         this._sharingMode &= -16385;
      }
   }

   public boolean getSharingScale() {
      return (this._sharingMode & 8192) != 0;
   }

   public void setSharingScale(boolean b) {
      if (b) {
         this._sharingMode |= 8192;
      } else {
         this._sharingMode &= -8193;
      }
   }

   @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 = BooleanPropertyEditor.make(new Property(this, index, "Share Position"), "No", "Yes");
            } else if (mode == 1) {
               ret = new Boolean(this.getSharingPosition());
            } else if (mode == 2) {
               this.setSharingPosition((Boolean)value);
            }
            break;
         case 1:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Share Rotation"), "No", "Yes");
            } else if (mode == 1) {
               ret = new Boolean(this.getSharingRotation());
            } else if (mode == 2) {
               this.setSharingRotation((Boolean)value);
            }
            break;
         case 2:
            if (mode == 0) {
               ret = BooleanPropertyEditor.make(new Property(this, index, "Share Scale"), "No", "Yes");
            } else if (mode == 1) {
               ret = new Boolean(this.getSharingScale());
            } else if (mode == 2) {
               this.setSharingScale((Boolean)value);
            }
            break;
         default:
            ret = super.properties(index, offset + 3, mode, value);
      }

      return ret;
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(2, classCookie);
      super.saveState(s);
      this.initDefault();
      s.saveInt(this._sharingMode);
      s.saveFloat(this.defPos.x);
      s.saveFloat(this.defPos.y);
      s.saveFloat(this.defPos.z);
      s.saveFloat(this.defRAxis.x);
      s.saveFloat(this.defRAxis.y);
      s.saveFloat(this.defRAxis.z);
      s.saveFloat(this.defRotation);
      s.saveFloat(this.defScale.x);
      s.saveFloat(this.defScale.y);
      s.saveFloat(this.defScale.z);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      int vers = r.restoreVersion(classCookie);
      switch (vers) {
         case 0:
            super.restoreState(r);
            break;
         case 1:
         case 2:
            this.defPos = new Point3();
            this.defRAxis = new Point3();
            this.defScale = new Point3();
            super.restoreState(r);
            this._sharingMode = r.restoreInt();
            this.defPos.x = r.restoreFloat();
            this.defPos.y = r.restoreFloat();
            this.defPos.z = r.restoreFloat();
            this.defRAxis.x = r.restoreFloat();
            this.defRAxis.y = r.restoreFloat();
            this.defRAxis.z = r.restoreFloat();
            this.defRotation = r.restoreFloat();
            this.defScale.x = r.restoreFloat();
            this.defScale.y = r.restoreFloat();
            this.defScale.z = r.restoreFloat();
            break;
         default:
            throw new TooNewException();
      }

      if (vers < 2) {
         this._shorthandVersion = vers;
      }
   }

   @Override
   public int getMaxShorthandVersion() {
      return 1;
   }
}