blob: 97eacd91c4cf7889aa207b5fe04bcaaef5e5d246 (
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
|
package NET.worlds.scape;
import NET.worlds.console.Main;
import NET.worlds.console.MainCallback;
import java.util.Enumeration;
import java.util.Hashtable;
class BackgroundLoaderQueue implements MainCallback {
private Room activeRoom;
private int itemsInQueue;
private BackgroundLoaderVector inAllRooms = new BackgroundLoaderVector();
private BackgroundLoaderVector inUnknownRoom = new BackgroundLoaderVector();
private Hashtable rooms = new Hashtable();
private boolean mainRan;
synchronized void activeRoomChanged(Room room) {
this.activeRoom = room;
}
public boolean hasHighPriorityItems() {
return this.inAllRooms.size() > 0;
}
synchronized void add(BackgroundLoaderElement e) {
if (!this.addHelper(e, false)) {
if (e.inAllRooms()) {
this.inAllRooms.insertElementAt(e, 0);
} else {
this.inUnknownRoom.addElement(e);
}
}
this.itemsInQueue++;
this.notify();
}
private boolean addHelper(BackgroundLoaderElement e, boolean isMainThread) {
Room r = e.getRoom(isMainThread);
if (r != null && r.isActive()) {
BackgroundLoaderVector v = (BackgroundLoaderVector)this.rooms.get(r);
if (v == null) {
this.rooms.put(r, v = new BackgroundLoaderVector());
}
v.addElement(e);
return true;
} else {
return false;
}
}
private BackgroundLoaderElement getHelper(Room r) {
BackgroundLoaderElement e = null;
BackgroundLoaderVector v = (BackgroundLoaderVector)this.rooms.get(r);
if (v != null) {
e = v.removeFirst();
if (v.isEmpty()) {
this.rooms.remove(r);
}
}
return e;
}
synchronized BackgroundLoaderElement getItem() {
BackgroundLoaderElement e = null;
while (true) {
while (this.itemsInQueue == 0) {
try {
this.wait();
} catch (InterruptedException var3) {
}
}
if (this.inAllRooms.size() != 0) {
e = this.inAllRooms.removeFirst();
break;
}
if (this.activeRoom != null && (e = this.getHelper(this.activeRoom)) != null) {
break;
}
this.mainRan = false;
Main.register(this);
while (!this.mainRan) {
try {
this.wait();
} catch (InterruptedException var4) {
}
}
if (this.inAllRooms.size() == 0 && (this.activeRoom == null || this.rooms.get(this.activeRoom) == null)) {
if ((e = this.getClosestObject()) == null) {
if (this.inUnknownRoom.size() != 0) {
e = this.inUnknownRoom.removeFirst();
} else {
Enumeration k = this.rooms.keys();
assert k.hasMoreElements();
e = this.getHelper((Room)k.nextElement());
assert e != null;
}
}
break;
}
}
assert e != null;
this.itemsInQueue--;
assert this.itemsInQueue >= 0;
return e;
}
private BackgroundLoaderElement getClosestObject() {
synchronized (Pilot.visibleRooms) {
float minDist = Float.MAX_VALUE;
int minEle = -1;
int count = Pilot.visibleRoomInfo.size();
for (int i = 0; i < count; i++) {
RoomSubscribeInfo s = Pilot.visibleRoomInfo.elementAt(i);
if (s.d < minDist && this.rooms.get(Pilot.visibleRooms.elementAt(i)) != null) {
minDist = s.d;
minEle = i;
}
}
return minEle == -1 ? null : this.getHelper(Pilot.visibleRooms.elementAt(minEle));
}
}
@Override
public synchronized void mainCallback() {
int count = this.inUnknownRoom.size();
int i = 0;
while (count-- != 0) {
BackgroundLoaderElement e = (BackgroundLoaderElement)this.inUnknownRoom.get(i);
if (this.addHelper(e, true)) {
this.inUnknownRoom.removeElementAt(i);
} else {
i++;
}
}
this.mainRan = true;
Main.unregister(this);
this.notify();
}
}
|