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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
|
package NET.worlds.scape;
import NET.worlds.console.Main;
import NET.worlds.core.Std;
import NET.worlds.network.Galaxy;
import NET.worlds.network.NetworkRoom;
import java.awt.Color;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
public class Room extends WObject implements TeleportStatus {
public WObject highlightTarget;
private int sceneID;
public Point3 defaultPosition = new Point3(100.0F, 100.0F, 120.0F);
public Point3 defaultOrientationAxis = new Point3(0.0F, 0.0F, -1.0F);
public float defaultOrientation = 0.0F;
String teleportChain = "home:avatargallery/avatar.world#[email protected],145.0,150.0,89.0";
int roomLoadTime = 0;
int teleportInterval = -1;
boolean teleported = false;
private RoomEnvironment environment;
private Vector<Portal> outgoingPortals = new Vector<Portal>();
private Vector<AudibilityFilter> aFilters = new Vector<AudibilityFilter>();
private Point3 lightPosition = new Point3(-1.0F, 1.0F, -1.0F);
private Color lightColor = new Color(255, 255, 255);
private int lightid = 0;
private int lightid2 = 0;
private int renderStamp;
private static int timeoutAge = 15000;
private Vector<FrameHandler> frameHandlers = new Vector<FrameHandler>();
private Vector<WObject> frameHandlerWObjects = new Vector<WObject>();
private Color skyColor;
private Color groundColor;
private Vector<Prerenderable> prerenderHandlers = new Vector<Prerenderable>();
private Vector<Postrenderable> postrenderHandlers = new Vector<Postrenderable>();
private static int isRendering = 4;
private static int isVIPOnly = 262144;
private static int isVIPViewOnly = 524288;
private NetworkRoom _netRoom;
private static String[] skyOptions = new String[]{"Blue Sky"};
private static String[] groundOptions = new String[]{"Green Ground"};
private boolean allowTeleport = true;
private static Object classCookie = new Object();
private RoomEnvironment infiniteBackground;
static {
nativeInit();
}
public Room(World world, String name) {
this.setName(name);
this.environment = new RoomEnvironment();
this.infiniteBackground = new RoomEnvironment();
super.add(this.environment);
super.add(this.infiniteBackground);
if (world != null) {
world.addRoom(this);
}
}
public Room() {
}
public static native void nativeInit();
@Override
public void getChildren(DeepEnumeration d) {
if (this.infiniteBackground != null) {
d.addChildElement(this.infiniteBackground);
}
if (this.environment != null) {
d.addChildElement(this.environment);
}
super.getChildren(d);
}
@Override
public void setName(String newName) {
String oldName = this.getName();
super.setName(newName);
World world = this.getWorld();
if (world != null) {
world.renameRoom(oldName, this.getName(), this);
}
if (!oldName.equals(newName)) {
synchronized (this) {
if (this._netRoom != null) {
this._netRoom.setName(newName);
}
}
}
}
synchronized void register() {
assert this._netRoom == null;
this._netRoom = new NetworkRoom(this);
}
@Override
public void detach() {
if (this.hasClump()) {
System.out.println("Detaching clumped room " + this.getName());
this.markVoid();
}
assert this._netRoom != null;
boolean subscribed = Pilot.getActive().removeSubscribedRoom(this);
if (subscribed) {
this._netRoom.unsubscribe();
}
synchronized (this) {
this._netRoom.detach();
this._netRoom = null;
}
this.getWorld().removeRoom(this);
super.detach();
}
@Override
public void discard() {
this.environment.discard();
this.infiniteBackground.discard();
super.discard();
this.frameHandlers.removeAllElements();
this.frameHandlerWObjects.removeAllElements();
this.outgoingPortals.removeAllElements();
this.aFilters.removeAllElements();
this.prerenderHandlers.removeAllElements();
this.postrenderHandlers.removeAllElements();
}
int getSceneID() {
return this.sceneID;
}
public Point3Temp getDefaultPosition() {
return Point3Temp.make(this.defaultPosition);
}
public Point3Temp getDefaultOrientationAxis() {
return Point3Temp.make(this.defaultOrientationAxis);
}
public float getDefaultOrientation() {
return this.defaultOrientation;
}
@Override
protected final void noteAddingTo(SuperRoot s) {
World w = (World)s;
}
public RoomEnvironment getEnvironment() {
return this.environment;
}
public Vector<Portal> getOutgoingPortals() {
return this.outgoingPortals;
}
public void addOutgoingPortal(Portal p) {
if (!this.outgoingPortals.contains(p)) {
this.outgoingPortals.addElement(p);
for (int index = 0; index < this.aFilters.size(); index++) {
this.aFilters.elementAt(index).moveEmitter();
}
}
}
public void removeOutgoingPortal(Portal p) {
this.outgoingPortals.removeElement(p);
Vector<AudibilityFilter> v = this.getAFilters();
for (int v_index = 0; v_index < v.size(); v_index++) {
v.elementAt(v_index).moveEmitter();
}
}
public Vector<AudibilityFilter> getAFilters() {
return this.aFilters;
}
public void addAFilter(AudibilityFilter p) {
this.aFilters.addElement(p);
}
public void removeAFilter(AudibilityFilter a) {
this.aFilters.removeElement(a);
}
public void move(Room from, Room to) {
Vector<AudibilityFilter> v = from.getAFilters();
for (int index = 0; index < v.size(); index++) {
v.elementAt(index).updateListenerState();
}
v = to.getAFilters();
for (int index = 0; index < v.size(); index++) {
v.elementAt(index).updateListenerState();
}
}
static native int addLight(int var0, float var1, float var2, float var3, float var4, float var5, float var6);
static native void setLightPosition(int var0, float var1, float var2, float var3);
static native void setLightColor(int var0, float var1, float var2, float var3);
private void setLightPosition(float x, float y, float z) {
if (this.lightid != 0) {
setLightPosition(this.lightid, x, y, z);
}
if (this.lightid2 != 0) {
setLightPosition(this.lightid2, -x, -y, -z);
}
}
private void setLightColor(float red, float green, float blue) {
if (this.lightid != 0) {
setLightColor(this.lightid, red, green, blue);
}
if (this.lightid2 != 0) {
setLightColor(this.lightid2, red / 2.0F, green / 2.0F, blue / 2.0F);
}
}
public void setLightPosition(Point3Temp p) {
this.lightPosition.set(p.x, p.y, p.z);
this.setLightPosition(p.x, p.y, p.z);
RoomEnvironment re = this.getEnvironment();
if (re != null) {
re.setLightPosition(p.x, p.y, p.z);
}
re = this.getInfiniteBackground();
if (re != null) {
re.setLightPosition(p.x, p.y, p.z);
}
}
public void setLightColor(Color c) {
this.lightColor = new Color(c.getRGB());
float r = c.getRed() / 256.0F;
float g = c.getGreen() / 256.0F;
float b = c.getBlue() / 256.0F;
this.setLightColor(r, g, b);
RoomEnvironment re = this.getEnvironment();
if (re != null) {
re.setLightColor(r, g, b);
}
re = this.getInfiniteBackground();
if (re != null) {
re.setLightColor(r, g, b);
}
}
public Point3Temp getLightPosition() {
return Point3Temp.make(this.lightPosition);
}
public Color getLightColor() {
return new Color(this.lightColor.getRGB());
}
public void noteRef() {
this.renderStamp = Std.getRealTime();
World w = this.getWorld();
if (w != null) {
w.incRef();
}
}
public void discardIfOld() {
if (this.hasClump()) {
int age = Std.getFastTime() - this.renderStamp;
if (age > timeoutAge) {
this.markVoid();
}
}
}
public void generateFrameEvents(FrameEvent f) {
this.noteRef();
if (Main.profile != 0) {
for (int i = 0; i < this.frameHandlers.size(); i++) {
FrameHandler fh = this.frameHandlers.elementAt(i);
WObject fhw = this.frameHandlerWObjects.elementAt(i);
int start = Std.getRealTime();
long startBytes = Runtime.getRuntime().freeMemory();
f.retargetAndDeliver(fh, fhw);
int dur = Std.getRealTime() - start;
long used = startBytes - Runtime.getRuntime().freeMemory();
if (dur > Main.profile) {
if (fh instanceof SuperRoot) {
System.out.println("Took " + dur + "ms and " + used + " bytes to call frameHandler " + ((SuperRoot)fh).getName() + " of " + fhw.getName());
} else {
System.out.println("Took " + dur + "ms and " + used + " bytes to call frameHandler " + fh + " of " + fhw.getName());
}
}
}
} else {
for (int ix = 0; ix < this.frameHandlers.size(); ix++) {
f.retargetAndDeliver(this.frameHandlers.elementAt(ix), this.frameHandlerWObjects.elementAt(ix));
}
}
if (this.teleportChain != null && this.teleportInterval != -1 && !this.teleported && Std.getSynchronizedTime() % this.teleportInterval == 0) {
this.teleported = true;
TeleportAction.teleport(this.teleportChain, this);
}
}
@Override
public void teleportStatus(String err, String dest) {
if (err != null) {
this.teleported = false;
}
}
private int findFrameHandler(FrameHandler h, WObject o) {
int next = 0;
while (true) {
next = this.frameHandlers.indexOf(h, next);
if (next == -1) {
return -1;
}
if (this.frameHandlerWObjects.elementAt(next) == o) {
return next;
}
next++;
}
}
void addFrameHandler(FrameHandler h, WObject o) {
int i = this.findFrameHandler(h, o);
if (i < 0) {
this.frameHandlers.addElement(h);
this.frameHandlerWObjects.addElement(o);
}
}
void removeFrameHandler(FrameHandler h, WObject o) {
int i = this.findFrameHandler(h, o);
if (i >= 0) {
this.frameHandlers.removeElementAt(i);
this.frameHandlerWObjects.removeElementAt(i);
}
}
native void createScene();
native void destroyScene();
@Override
protected void markVoid() {
this.infiniteBackground.markVoid();
this.environment.markVoid();
super.markVoid();
this.destroyScene();
this.lightid = 0;
this.lightid2 = 0;
}
@Override
protected void noteTransformChange() {
super.noteTransformChange();
this.getInfiniteBackground().setTransform(this);
this.getEnvironment().setTransform(this);
int i = this.outgoingPortals.size();
while (--i >= 0) {
this.outgoingPortals.elementAt(i).discardTransform();
}
}
public void setSkyColor(Color c) {
this.skyColor = c;
}
public Color getSkyColor() {
return this.skyColor;
}
public void setGroundColor(Color c) {
this.groundColor = c;
}
public Color getGroundColor() {
return this.groundColor;
}
public boolean getVIPOnly() {
return (this.flags & isVIPOnly) != 0;
}
public void prerender(Camera cam, float x, float y, float z, float d) {
this.flags = this.flags | isRendering;
this.infiniteBackground.prerender();
this.environment.prerender();
Pilot.addVisibleRoom(this, x, y, z, d);
int end = this.prerenderHandlers.size();
for (int i = 0; i < end; i++) {
Prerenderable p = this.prerenderHandlers.elementAt(i);
p.prerender(cam);
}
}
public void addPrerenderHandler(Prerenderable o) {
assert (this.flags & isRendering) == 0;
if (!this.prerenderHandlers.contains(o)) {
this.prerenderHandlers.addElement(o);
}
}
public void prependPrerenderHandler(Prerenderable o) {
assert (this.flags & isRendering) == 0;
if (!this.prerenderHandlers.contains(o)) {
this.prerenderHandlers.insertElementAt(o, 0);
}
}
public void removePrerenderHandler(Prerenderable o) {
assert (this.flags & isRendering) == 0;
this.prerenderHandlers.removeElement(o);
}
public void postrender(Camera cam, float x, float y, float z, float d) {
Pilot.addVisibleRoom(this, x, y, z, d);
int i = this.postrenderHandlers.size();
while (--i >= 0) {
Postrenderable p = this.postrenderHandlers.elementAt(i);
p.postrender(cam);
}
this.flags = this.flags & ~isRendering;
}
public void addPostrenderHandler(Postrenderable o) {
assert (this.flags & isRendering) == 0;
if (!this.postrenderHandlers.contains(o)) {
this.postrenderHandlers.addElement(o);
}
}
public void prependPostrenderHandler(Postrenderable o) {
assert (this.flags & isRendering) == 0;
if (!this.postrenderHandlers.contains(o)) {
this.postrenderHandlers.insertElementAt(o, 0);
}
}
public void removePostrenderHandler(Postrenderable o) {
assert (this.flags & isRendering) == 0;
this.postrenderHandlers.removeElement(o);
}
@Override
public void detectBump(BumpEventTemp b) {
if (this.environment.getBumpable()) {
this.environment.detectBump(b);
}
super.detectBump(b);
}
@Override
public BoundBoxTemp getBoundBox() {
return BoundBoxTemp.make(Point3Temp.make(), Point3Temp.make());
}
@Override
public World getWorld() {
return (World)this.getOwner();
}
@Override
public Room getRoom() {
return this;
}
@Override
public Room getRoomFromClump() {
return this;
}
@Override
public Room getRoomNotFromClump() {
return this;
}
public Galaxy getGalaxy() {
World w = this.getWorld();
return w == null ? null : w.getConsole().getGalaxy();
}
public String getURL() {
return this.getWorld().getSourceURL().getAbsolute() + "#" + this.getName();
}
public boolean registerShare(WObject w) {
w.notifyRegister(1);
return true;
}
private void processPendingRegistrations() {
this.notifyRegister(1);
}
public NetworkRoom getNetworkRoom() {
return this._netRoom;
}
void subscribe(RoomSubscribeInfo info) {
assert this._netRoom != null;
this._netRoom.subscribe(info);
}
void subscribeDist(RoomSubscribeInfo info) {
assert this._netRoom != null;
this._netRoom.subscribeDist(info);
}
void unsubscribe() {
if (this._netRoom != null) {
this._netRoom.unsubscribe();
} else {
System.out.println(this + ": unsubscribing from bad room?");
new Exception().printStackTrace(System.out);
}
}
public boolean getAllowTeleport() {
return this.allowTeleport;
}
@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, "Environment");
} else if (mode == 1) {
ret = this.environment;
}
break;
case 1:
if (mode == 0) {
ret = new Property(this, index, "Infinite Background");
} else if (mode == 1) {
ret = this.infiniteBackground;
}
break;
case 2:
if (mode == 0) {
ret = ColorPropertyEditor.make(new Property(this, index, "Sky Color").allowSetNull());
if (this.getSkyColor() == null) {
ret = MaybeNullPropertyEditor.make((Property)ret, Color.blue);
}
} else if (mode == 1) {
ret = this.getSkyColor();
} else if (mode == 2) {
this.setSkyColor((Color)value);
}
break;
case 3:
if (mode == 0) {
ret = ColorPropertyEditor.make(new Property(this, index, "Ground Color").allowSetNull());
if (this.getGroundColor() == null) {
ret = MaybeNullPropertyEditor.make((Property)ret, Color.green);
}
} else if (mode == 1) {
ret = this.getGroundColor();
} else if (mode == 2) {
this.setGroundColor((Color)value);
}
break;
case 4:
if (mode == 0) {
ret = Point3PropertyEditor.make(new Property(this, index, "Default Position"));
} else if (mode == 1) {
ret = new Point3(this.getDefaultPosition());
} else if (mode == 2) {
this.defaultPosition = (Point3)value;
}
break;
case 5:
if (mode == 0) {
ret = Point3PropertyEditor.make(new Property(this, index, "Default Orientation Axis"));
} else if (mode == 1) {
ret = new Point3(this.getDefaultOrientationAxis());
} else if (mode == 2) {
this.defaultOrientationAxis = (Point3)value;
}
break;
case 6:
if (mode == 0) {
ret = FloatPropertyEditor.make(new Property(this, index, "Default Orientation Angle"));
} else if (mode == 1) {
ret = new Float(this.getDefaultOrientation());
} else if (mode == 2) {
this.defaultOrientation = (Float)value;
}
break;
case 7:
if (mode == 0) {
ret = BooleanPropertyEditor.make(new Property(this, index, "VIP only"), "No", "Yes");
} else if (mode == 1) {
ret = new Boolean((this.flags & isVIPOnly) != 0);
} else if (mode == 2) {
if ((Boolean)value) {
this.flags = this.flags | isVIPOnly;
} else {
this.flags = this.flags & ~isVIPOnly;
}
}
break;
case 8:
if (mode == 0) {
ret = BooleanPropertyEditor.make(new Property(this, index, "Visible to VIP only"), "No", "Yes");
} else if (mode == 1) {
ret = new Boolean((this.flags & isVIPViewOnly) != 0);
} else if (mode == 2) {
if ((Boolean)value) {
this.flags = this.flags | isVIPViewOnly;
} else {
this.flags = this.flags & ~isVIPViewOnly;
}
}
break;
case 9:
if (mode == 0) {
ret = Point3PropertyEditor.make(new Property(this, index, "Light Source Direction"));
} else if (mode == 1) {
ret = this.lightPosition;
} else if (mode == 2) {
this.setLightPosition((Point3)value);
}
break;
case 10:
if (mode == 0) {
ret = ColorPropertyEditor.make(new Property(this, index, "Light Color"));
} else if (mode == 1) {
ret = this.lightColor;
} else if (mode == 2) {
this.setLightColor((Color)value);
}
break;
case 11:
if (mode == 0) {
ret = IntegerPropertyEditor.make(new Property(this, index, "Time To Auto-Teleport (seconds, -1 = never)"));
} else if (mode == 1) {
ret = new Integer(this.teleportInterval);
} else if (mode == 2) {
this.teleportInterval = (Integer)value;
}
break;
case 12:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Auto-Teleport destination"));
} else if (mode == 1) {
ret = this.teleportChain;
} else if (mode == 2) {
this.teleportChain = new String((String)value);
}
break;
case 13:
if (mode == 0) {
ret = BooleanPropertyEditor.make(new Property(this, index, "Allow Teleporting"), "No", "Yes");
} else if (mode == 1) {
ret = new Boolean(this.allowTeleport);
} else if (mode == 2) {
this.allowTeleport = (Boolean)value;
}
break;
default:
ret = super.properties(index, offset + 14, mode, value);
}
return ret;
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(7, classCookie);
super.saveState(s);
if (this.skyColor != null) {
s.saveBoolean(true);
s.saveInt(this.skyColor.getRGB());
} else {
s.saveBoolean(false);
}
if (this.groundColor != null) {
s.saveBoolean(true);
s.saveInt(this.groundColor.getRGB());
} else {
s.saveBoolean(false);
}
s.save(this.defaultPosition);
s.save(this.defaultOrientationAxis);
s.saveFloat(this.defaultOrientation);
s.save(this.lightPosition);
s.saveInt(this.lightColor.getRGB());
s.save(this.environment);
s.save(this.infiniteBackground);
s.saveString(this.teleportChain);
s.saveInt(this.teleportInterval);
s.saveBoolean(this.allowTeleport);
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 0:
r.setOldFlag();
super.restoreState(r);
this.setName(r.restoreString());
r.restore();
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
r.restoreMaybeNull();
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
r.restoreVector();
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = new RoomEnvironment();
break;
case 1:
r.setOldFlag();
super.restoreState(r);
r.restore();
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
r.restoreMaybeNull();
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = new RoomEnvironment();
break;
case 2:
r.setOldFlag();
super.restoreState(r);
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
r.restoreMaybeNull();
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = new RoomEnvironment();
break;
case 3:
r.setOldFlag();
super.restoreState(r);
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
r.restoreMaybeNull();
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = (RoomEnvironment)r.restore();
break;
case 4:
r.setOldFlag();
super.restoreState(r);
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = (RoomEnvironment)r.restore();
break;
case 5:
super.restoreState(r);
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.setLightPosition((Point3)r.restore());
this.setLightColor(new Color(r.restoreInt()));
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = (RoomEnvironment)r.restore();
break;
case 6:
super.restoreState(r);
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.setLightPosition((Point3)r.restore());
this.setLightColor(new Color(r.restoreInt()));
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = (RoomEnvironment)r.restore();
this.teleportChain = r.restoreString();
this.teleportInterval = r.restoreInt();
this.roomLoadTime = Std.getFastTime() / 1000;
break;
case 7:
super.restoreState(r);
if (r.restoreBoolean()) {
this.skyColor = new Color(r.restoreInt());
}
if (r.restoreBoolean()) {
this.groundColor = new Color(r.restoreInt());
}
this.defaultPosition = (Point3)r.restore();
this.defaultOrientationAxis = (Point3)r.restore();
this.defaultOrientation = r.restoreFloat();
this.setLightPosition((Point3)r.restore());
this.setLightColor(new Color(r.restoreInt()));
this.environment = (RoomEnvironment)r.restore();
this.infiniteBackground = (RoomEnvironment)r.restore();
this.teleportChain = r.restoreString();
this.teleportInterval = r.restoreInt();
this.roomLoadTime = Std.getFastTime() / 1000;
this.allowTeleport = r.restoreBoolean();
break;
default:
throw new TooNewException();
}
super.add(this.environment);
super.add(this.infiniteBackground);
}
public void aboutToDraw() {
if (!this.hasClump() && this.getOwner() instanceof World) {
this.recursiveAddRwChildren(null);
}
}
@Override
protected void addRwChildren(WObject parent) {
assert parent == null;
this.createClump();
this.createScene();
this.newRwChildHelper();
float red = this.lightColor.getRed() / 256.0F;
float green = this.lightColor.getGreen() / 256.0F;
float blue = this.lightColor.getBlue() / 256.0F;
this.lightid = addLight(this.sceneID, this.lightPosition.x, this.lightPosition.y, this.lightPosition.z, red, green, blue);
this.lightid2 = addLight(this.sceneID, -this.lightPosition.x, -this.lightPosition.y, -this.lightPosition.z, red * 0.5F, green * 0.5F, blue * 0.5F);
}
@Override
public void recursiveAddRwChildren(WObject parent) {
super.recursiveAddRwChildren(parent);
this.environment.recursiveAddRwChildren(this);
this.infiniteBackground.recursiveAddRwChildren(this);
}
public final float floorHeight(float x, float y) {
return this.floorHeight(x, y, 120.0F);
}
public float floorHeight(float x, float y, float z) {
Transform inverse = this.getObjectToWorldMatrix().invert();
Point3Temp p = Point3Temp.make(x, y, z).times(inverse);
inverse.recycle();
x = p.x;
y = p.y;
z = p.z;
float height = 0.0F;
boolean patchFound = false;
Enumeration<Object> e = (Enumeration<Object>)this.getContents();
while (e.hasMoreElements()) {
Object o = e.nextElement();
if (o instanceof FloorPatch && ((FloorPatch)o).inPatch(x, y)) {
float patchHeight = ((FloorPatch)o).floorHeight(x, y);
if (patchHeight <= z && (patchHeight > height || !patchFound)) {
patchFound = true;
height = ((FloorPatch)o).floorHeight(x, y);
}
}
}
return height;
}
public Point3 surfaceNormal(float x, float y, float z) {
Point3 normal = new Point3(0.0F, 0.0F, 1.0F);
FloorPatch patch = null;
float height = 0.0F;
boolean patchFound = false;
Enumeration<Object> e = (Enumeration<Object>)this.getContents();
while (e.hasMoreElements()) {
Object o = e.nextElement();
if (o instanceof FloorPatch && ((FloorPatch)o).inPatch(x, y)) {
float patchHeight = ((FloorPatch)o).floorHeight(x, y);
if (patchHeight <= z && (patchHeight > height || !patchFound)) {
patchFound = true;
height = ((FloorPatch)o).floorHeight(x, y);
patch = (FloorPatch)o;
}
}
}
if (patch != null) {
normal = patch.surfaceNormal(x, y);
}
normal.vectorTimes(this.getObjectToWorldMatrix());
return normal;
}
public RoomEnvironment getInfiniteBackground() {
return this.infiniteBackground;
}
@Override
public String toString() {
return this.getWorld() + "#" + this.getName();
}
}
|