/* */ 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 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 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 */