Exemplo n.º 1
0
  @Override
  public void simpleInitApp() {
    MessageUtils.registerDataClasses();
    MessageUtils.registerMessages();

    Serializer.registerClass(ReplayHeader.class);
    Serializer.registerClass(ReplayCmdData.class);
    Serializer.registerClass(ReplayData.class);

    Globals.assets = getAssetManager();
    Globals.app = this;
    world = new World();
    game = new ServerGame();
    physics = new BulletAppState();
    physics.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    flyCam.setEnabled(false);

    int port = Settings.get().General().getPort();
    if (port <= 0 || port > 65535) {
      System.out.println("Port must be between 0 and 65535");
      System.exit(1);
    }

    try {
      server = Network.createServer(port, port);
      server.start();
    } catch (IOException ex) {
      System.exit(1);
    }

    receiver = new DefaultReceiver();
    server.addMessageListener(receiver, OneTrueMessage.class);

    sender = new RecordingServerSender(server);
    AbstractBuff.setSender(sender);

    receiver.registerCommandHandler(sender);

    listenerManager = new ServerNetListener(this, server);
    sync = new Sync(this);

    ServerInput input = ServerInput.get();

    receiver.registerCommandHandler(listenerManager);
    receiver.registerCommandHandler(input);
    receiver.registerCommandHandler(sync);

    stateManager.attach(sender);
    stateManager.attach(receiver);
    stateManager.attach(sync);
    stateManager.attach(world);
    stateManager.attach(game);
    stateManager.attach(physics);

    sender.setWorld(world);
    // Accuracy should be > 45 or projectiles might "disappear" before
    // exploding. This is because of FogOfWar
    physics.getPhysicsSpace().setAccuracy(1f / Settings.get().General().getPhysicsTicksPerSecond());
  }
Exemplo n.º 2
0
 @Override
 public void destroy() {
   server.close();
   sender.saveToFile();
   super.destroy();
 }