summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/BackgroundLoaderQueue.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/BackgroundLoaderQueue.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/scape/BackgroundLoaderQueue.java')
-rw-r--r--NET/worlds/scape/BackgroundLoaderQueue.java501
1 files changed, 501 insertions, 0 deletions
diff --git a/NET/worlds/scape/BackgroundLoaderQueue.java b/NET/worlds/scape/BackgroundLoaderQueue.java
new file mode 100644
index 0000000..d691573
--- /dev/null
+++ b/NET/worlds/scape/BackgroundLoaderQueue.java
@@ -0,0 +1,501 @@
+/* */ package NET.worlds.scape;
+/* */
+/* */ import NET.worlds.console.Main;
+/* */ import NET.worlds.console.MainCallback;
+/* */ import java.util.Enumeration;
+/* */ import java.util.Hashtable;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ class BackgroundLoaderQueue
+/* */ implements MainCallback
+/* */ {
+/* */ private Room activeRoom;
+/* */ private int itemsInQueue;
+/* 284 */ private BackgroundLoaderVector inAllRooms = new BackgroundLoaderVector();
+/* */
+/* */
+/* 287 */ private BackgroundLoaderVector inUnknownRoom = new BackgroundLoaderVector();
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 294 */ private Hashtable<Room, BackgroundLoaderVector> rooms = new Hashtable();
+/* */ private boolean mainRan;
+/* */
+/* */ synchronized void activeRoomChanged(Room room)
+/* */ {
+/* 299 */ this.activeRoom = room;
+/* */ }
+/* */
+/* */ public boolean hasHighPriorityItems()
+/* */ {
+/* 304 */ return this.inAllRooms.size() > 0;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ synchronized void add(BackgroundLoaderElement e)
+/* */ {
+/* 313 */ if (!addHelper(e, false)) {
+/* 314 */ if (e.inAllRooms()) {
+/* 315 */ this.inAllRooms.insertElementAt(e, 0);
+/* */ } else {
+/* 317 */ this.inUnknownRoom.addElement(e);
+/* */ }
+/* */ }
+/* */
+/* 321 */ this.itemsInQueue += 1;
+/* 322 */ notify();
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ private boolean addHelper(BackgroundLoaderElement e, boolean isMainThread)
+/* */ {
+/* 335 */ Room r = e.getRoom(isMainThread);
+/* 336 */ if ((r != null) && (r.isActive())) {
+/* 337 */ BackgroundLoaderVector v = (BackgroundLoaderVector)this.rooms.get(r);
+/* 338 */ if (v == null)
+/* 339 */ this.rooms.put(r, v = new BackgroundLoaderVector());
+/* 340 */ v.addElement(e);
+/* 341 */ return true;
+/* */ }
+/* 343 */ return false;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ private BackgroundLoaderElement getHelper(Room r)
+/* */ {
+/* 355 */ BackgroundLoaderElement e = null;
+/* 356 */ BackgroundLoaderVector v = (BackgroundLoaderVector)this.rooms.get(r);
+/* 357 */ if (v != null) {
+/* 358 */ e = v.removeFirst();
+/* 359 */ if (v.isEmpty())
+/* 360 */ this.rooms.remove(r);
+/* */ }
+/* 362 */ return e;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ synchronized BackgroundLoaderElement getItem()
+/* */ {
+/* 374 */ BackgroundLoaderElement e = null;
+/* */
+/* */ for (;;)
+/* */ {
+/* 378 */ if (this.itemsInQueue != 0)
+/* */ {
+/* */
+/* 381 */ if (this.inAllRooms.size() != 0) {
+/* 382 */ e = this.inAllRooms.removeFirst();
+/* 383 */ break;
+/* */ }
+/* */
+/* */
+/* */
+/* 388 */ if ((this.activeRoom != null) &&
+/* 389 */ ((e = getHelper(this.activeRoom)) != null)) {
+/* */ break;
+/* */ }
+/* */
+/* 393 */ this.mainRan = false;
+/* 394 */ Main.register(this);
+/* 395 */ while (!this.mainRan) {
+/* */ try {
+/* 397 */ wait();
+/* */ }
+/* */ catch (InterruptedException localInterruptedException) {}
+/* */ }
+/* */
+/* 402 */ if ((this.inAllRooms.size() == 0) && ((this.activeRoom == null) ||
+/* 403 */ (this.rooms.get(this.activeRoom) == null)))
+/* */ {
+/* */
+/* */
+/* 407 */ if ((e = getClosestObject()) != null) {
+/* */ break;
+/* */ }
+/* */
+/* 411 */ if (this.inUnknownRoom.size() != 0) {
+/* 412 */ e = this.inUnknownRoom.removeFirst();
+/* 413 */ break;
+/* */ }
+/* */
+/* */
+/* 417 */ Enumeration<Room> k = this.rooms.keys();
+/* 418 */ assert (k.hasMoreElements());
+/* 419 */ e = getHelper((Room)k.nextElement());
+/* 420 */ if (($assertionsDisabled) || (e != null)) break; throw new AssertionError();
+/* */ }
+/* */ }
+/* */ else
+/* */ {
+/* */ try {
+/* 426 */ wait();
+/* */ }
+/* */ catch (InterruptedException localInterruptedException1) {}
+/* */ }
+/* */ }
+/* */
+/* 432 */ assert (e != null);
+/* 433 */ this.itemsInQueue -= 1;
+/* 434 */ assert (this.itemsInQueue >= 0);
+/* */
+/* 436 */ return e;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ private BackgroundLoaderElement getClosestObject()
+/* */ {
+/* 449 */ synchronized (Pilot.visibleRooms) {
+/* 450 */ float minDist = Float.MAX_VALUE;
+/* 451 */ int minEle = -1;
+/* 452 */ int count = Pilot.visibleRoomInfo.size();
+/* 453 */ for (int i = 0; i < count; i++) {
+/* 454 */ RoomSubscribeInfo s =
+/* 455 */ (RoomSubscribeInfo)Pilot.visibleRoomInfo.elementAt(i);
+/* 456 */ if ((s.d < minDist) &&
+/* 457 */ (this.rooms.get(Pilot.visibleRooms.elementAt(i)) != null))
+/* */ {
+/* 459 */ minDist = s.d;
+/* 460 */ minEle = i;
+/* */ }
+/* */ }
+/* */
+/* 464 */ if (minEle == -1) {
+/* 465 */ return null;
+/* */ }
+/* 467 */ return getHelper((Room)Pilot.visibleRooms.elementAt(minEle));
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public synchronized void mainCallback()
+/* */ {
+/* 480 */ int count = this.inUnknownRoom.size();
+/* 481 */ int i = 0;
+/* 482 */ while (count-- != 0) {
+/* 483 */ BackgroundLoaderElement e =
+/* 484 */ (BackgroundLoaderElement)this.inUnknownRoom.get(i);
+/* 485 */ if (addHelper(e, true)) {
+/* 486 */ this.inUnknownRoom.removeElementAt(i);
+/* */ } else {
+/* 488 */ i++;
+/* */ }
+/* */ }
+/* 491 */ this.mainRan = true;
+/* 492 */ Main.unregister(this);
+/* 493 */ notify();
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\BackgroundLoaderQueue.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file