Esempio n. 1
0
 /** Cleans garbage (Tilecleanup) */
 public synchronized void garbageCollect() {
   long startTime = getTime();
   int curMemory =
       (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000;
   for (int i = 0; i < Instance.getWorld().tiles.length; i++) {
     for (int in = 0; in < Instance.getWorld().tiles[i].length; in++) {
       ActiveTile tile = Instance.getWorld().tiles[i][in];
       if (tile != null) {
         if (!tile.hasGameObject() && !tile.hasItems() && !tile.hasNpcs() && !tile.hasPlayers()) {
           Instance.getWorld().tiles[i][in] = null;
         }
       }
     }
   }
   Runtime.getRuntime().gc();
   int newMemory =
       (int) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000;
   Logger.println("GARBAGE COLLECT | Executing Memory Cleanup");
   Logger.println(
       "GARBAGE COLLECT | Memory before: "
           + curMemory
           + "kb"
           + " Memory after: "
           + newMemory
           + " (Freed: "
           + (curMemory - newMemory)
           + "kb)");
   Logger.println("GARBAGE COLLECT | Cleanup took " + (updateTime() - startTime) + "ms");
 }
Esempio n. 2
0
 /** Cleans snapshots of entries over 60 seconds old (executed every second) */
 public void cleanSnapshotDeque() {
   long curTime = GameEngine.getTimestamp(); // We need to compare
   // timestamps
   if (curTime - lastCleanedChatlogs > 1000) { // Every second
     lastCleanedChatlogs = curTime;
     lastCleanedChatlogsOutput++;
     if (lastCleanedChatlogsOutput > 60 * 5) {
       Logger.println("----------------------------------------------");
       Logger.println(world.getSnapshots().size() + " items on deque");
     }
     Iterator<Snapshot> i = world.getSnapshots().descendingIterator();
     Snapshot s = null;
     while (i.hasNext()) {
       s = i.next();
       if (curTime - s.getTimestamp() > 60000) {
         i.remove();
         s = null;
       } else {
         s = null;
       }
     }
     i = null;
     if (lastCleanedChatlogsOutput > 60 * 5) {
       Logger.println(world.getSnapshots().size() + " items on deque AFTER CLEANUP");
       Logger.println("----------------------------------------------");
       lastCleanedChatlogsOutput = 0;
     }
   }
 }
  public void sessionCreated(IoSession session) {
    session
        .getFilterChain()
        .addFirst("protocolFilter", new ProtocolCodecFilter(new RSCCodecFactory()));

    Logger.println(
        "Connection from: "
            + ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
  }
Esempio n. 4
0
  /** The thread execution process. */
  public void run() {
    Logger.println("GameEngine now running");
    time = System.nanoTime() / 1000000000;

    eventHandler.add(
        new DelayedEvent(null, Config.GARBAGE_COLLECT_INTERVAL) { // Ran
          // every
          // 50*2
          // minutes
          @Override
          public void run() {
            new Thread(
                    new Runnable() {
                      public void run() {
                        garbageCollect();
                      }
                    })
                .start();
          }
        });
    eventHandler.add(
        new DelayedEvent(null, Config.SAVE_INTERVAL) {
          public void run() {
            long now = GameEngine.getTime();
            for (Player p : world.getPlayers()) {
              if (now - p.getLastSaveTime() >= Config.SAVE_INTERVAL) {
                p.save();
                p.setLastSaveTime(now);
              }
            }
            Instance.getServer().getLoginConnector().getActionSender().saveProfiles();
          }
        });
    while (running) {
      try {
        Thread.sleep(50);
      } catch (InterruptedException ie) {
      }
      long deltaTime = updateTime();
      processLoginServer();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processLoginServer is taking longer than it should, exactly " + deltaTime + "ms");
      processIncomingPackets();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processIncomingPackets is taking longer than it should, exactly " + deltaTime + "ms");
      processEvents();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processEvents is taking longer than it should, exactly " + deltaTime + "ms");
      processClients();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processClients is taking longer than it should, exactly " + deltaTime + "ms");
      cleanSnapshotDeque();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processSnapshotDeque is taking longer than it should, exactly " + deltaTime + "ms");
    }
  }
Esempio n. 5
0
 public void kill() {
   Logger.println("Terminating GameEngine");
   running = false;
 }