Package com.captiveimagination.jgn.synchronization

Examples of com.captiveimagination.jgn.synchronization.SynchronizationManager


      return;
    }
   
    JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
   
    SynchronizationManager syncManager = new SynchronizationManager(server, controller); //create the server that will send and receive sync messages
    syncManager.addSyncObjectManager(this);
   
    JGN.createThread(server).start(); //create a new thread for the server and start it
    JGN.createThread(syncManager).start(); //create and start a thread for the synchronization manager
   
    //register our sphere and make sure ot include its color
    try {
      syncManager.register(localSphere, new ColoredSynchronizeCreateMessage(localSphere.getColor()), 50);
    } catch (IOException e) {
      System.err.println("Could not register the local PlayerSphere:");
      e.printStackTrace();
      return;
    }
View Full Code Here


    JGN.createThread(client).start(); //create a new thread for the client and start it
   
    JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
   
    //create the sync manager, register ourselves with it, and start its thread
    SynchronizationManager syncManager = new SynchronizationManager(client, controller);
    syncManager.addSyncObjectManager(this);
    JGN.createThread(syncManager).start();
   
    //connect to the server
    System.out.println("Connecting...");
    try {
      client.connectAndWait(serverReliable, serverFast, 5000);
    } catch (IOException e) {
      //Show an error message that we couldn't connect and print detailed info to standard error
      JOptionPane.showMessageDialog(null, "Could not connect to server.", "Connection Error", JOptionPane.ERROR_MESSAGE);
      System.err.println("Error while connecting to server:");
      e.printStackTrace();
      return;
    } catch (InterruptedException e) {
      //Show an error message that we couldn't connect and print detailed info to standard error
      JOptionPane.showMessageDialog(null, "Could not connect to server.", "Connection Error", JOptionPane.ERROR_MESSAGE);
      System.err.println("Error while connecting to server:");
      e.printStackTrace();
      return;
    }
    System.out.println("Connected!");
   
    //attach a MessageListener so that we can get more detailed information about what the server is doing
    client.getServerConnection().getReliableClient().addMessageListener(new MessageListener() {
              public void messageCertified(Message message) {
                  System.out.println("Message Certified: " + message);
              }
  
              public void messageFailed(Message message) {
                  System.out.println("Message Failed: " + message);
              }
  
              public void messageReceived(Message message) {
                  System.out.println("Message Received: " + message);
              }

              public void messageSent(Message message) {
                  System.out.println("Message Sent: " + message);
              }
          });
   
    //register our sphere and make sure ot include its color
    try {
      syncManager.register(localSphere, new ColoredSynchronizeCreateMessage(localSphere.getColor()), 50);
    } catch (IOException e) {
      System.err.println("Could not register local PlayerSphere:");
      e.printStackTrace();
      return;
    }
View Full Code Here

    JGN.createThread(client).start(); //create a new thread for the client and start it
   
    JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
   
    //create the sync manager, register ourselves with it, and start its thread
    SynchronizationManager syncManager = new SynchronizationManager(client, controller);
    syncManager.addSyncObjectManager(this);
    JGN.createThread(syncManager).start();
   
    //get localSphere from the game
    Field field = ExampleGame.class.getDeclaredField("localSphere");
    field.setAccessible(true);
    PlayerSphere player = null;
    while((player = (PlayerSphere)field.get(app)) == null) {
      try {
        Thread.sleep(100);
      }catch(Exception e) {
        System.err.println("Error while thread sleeping to get field:");
        e.printStackTrace();
      }
    }
   
    //get rootNode from the game
    field = ExampleGame.class.getDeclaredField("scene");
    field.setAccessible(true);
    Node scene = (Node)field.get(app);
    setScene(scene);
   
    //connect to the server
    System.out.println("Connecting...");
    client.connectAndWait(serverReliable, serverFast, 5000);
    System.out.println("Connected!");
   
     client.getServerConnection().getReliableClient().addMessageListener(new MessageListener() {
              public void messageCertified(Message message) {
                  System.out.println("Message Certified: " + message);
              }
  
              public void messageFailed(Message message) {
                  System.out.println("Message Failed: " + message);
              }
  
              public void messageReceived(Message message) {
                  System.out.println("Message Received: " + message);
              }

              public void messageSent(Message message) {
                  System.out.println("Message Sent: " + message);
              }
          });
   
    //register our sphere
    syncManager.register(player, new SynchronizeCreateMessage(), 50);
  }
View Full Code Here

        InetSocketAddress serverFast = new InetSocketAddress(InetAddress.getLocalHost(), 1501);
    JGNServer server = new JGNServer(serverReliable, serverFast); //this is our primary server and the addresses it should use
   
    JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
   
    SynchronizationManager syncManager = new SynchronizationManager(server, controller); //create the server that will send and receive sync messages
    syncManager.addSyncObjectManager(this);
   
    JGN.createThread(server).start(); //create a new thread for the server and start it
    JGN.createThread(syncManager).start(); //create and start a thread for the synchronization manager
   
    //get localSphere from the game
    Field field = ExampleGame.class.getDeclaredField("localSphere");
    field.setAccessible(true);
    PlayerSphere player = null;
    while((player = (PlayerSphere)field.get(app)) == null) {
      try {
        Thread.sleep(100);
      }catch(Exception e) {
        System.err.println("Error while thread sleeping to get field:");
        e.printStackTrace();
      }
    }
   
    //get rootNode from the game
    field = ExampleGame.class.getDeclaredField("scene");
    field.setAccessible(true);
    Node scene = (Node)field.get(app);
    setScene(scene);
   
    syncManager.register(player, new SynchronizeCreateMessage(), 50); //register the server's sphere
  }
View Full Code Here

      return;
    }
   
    controller = new JMEGraphicalController(); //in charge of generating and applying sync messages

    syncManager = new SynchronizationManager(server, controller); //create the server that will send and receive sync messages
    syncManager.addSyncObjectManager(this);
   
    Thread tmp = JGN.createThread(server); //create a new thread for the server and start it
    childThreads.add(tmp);
    tmp.start();
View Full Code Here

    tmp.start();
   
    controller = new JMEGraphicalController(); //in charge of generating and applying sync messages

    //create the sync manager, register ourselves with it, and start its thread
    syncManager = new SynchronizationManager(client, controller);
    syncManager.addSyncObjectManager(this);
    tmp = JGN.createThread(syncManager);
    childThreads.add(tmp);
    tmp.start();
  }
View Full Code Here

      return;
    }
   
    JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
   
    SynchronizationManager syncManager = new SynchronizationManager(server, controller); //create the server that will send and receive sync messages
    syncManager.addSyncObjectManager(this);
   
    JGN.createThread(server).start(); //create a new thread for the server and start it
    JGN.createThread(syncManager).start(); //create and start a thread for the synchronization manager
   
    //register our tank and make sure ot include its color
    try {
      syncManager.register(localTank, new ColoredSynchronizeCreateMessage(localTank.getColor()), 50);
    } catch (IOException e) {
      System.err.println("Could not register the local Tank:");
      e.printStackTrace();
      return;
    }
View Full Code Here

    JGN.createThread(client).start(); //create a new thread for the client and start it
   
    JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
   
    //create the sync manager, register ourselves with it, and start its thread
    SynchronizationManager syncManager = new SynchronizationManager(client, controller);
    syncManager.addSyncObjectManager(this);
    JGN.createThread(syncManager).start();
   
    //connect to the server
    System.out.println("Connecting...");
    try {
      client.connectAndWait(serverReliable, serverFast, 5000);
    } catch (IOException e) {
      //Show an error message that we couldn't connect and print detailed info to standard error
      JOptionPane.showMessageDialog(null, "Could not connect to server.", "Connection Error", JOptionPane.ERROR_MESSAGE);
      System.err.println("Error while connecting to server:");
      e.printStackTrace();
      return;
    } catch (InterruptedException e) {
      //Show an error message that we couldn't connect and print detailed info to standard error
      JOptionPane.showMessageDialog(null, "Could not connect to server.", "Connection Error", JOptionPane.ERROR_MESSAGE);
      System.err.println("Error while connecting to server:");
      e.printStackTrace();
      return;
    }
    System.out.println("Connected!");
   
    //attach a MessageListener so that we can get more detailed information about what the server is doing
    client.getServerConnection().getReliableClient().addMessageListener(new MessageListener() {
              public void messageCertified(Message message) {
                  System.out.println("Message Certified: " + message);
              }
  
              public void messageFailed(Message message) {
                  System.out.println("Message Failed: " + message);
              }
  
              public void messageReceived(Message message) {
                  System.out.println("Message Received: " + message);
              }

              public void messageSent(Message message) {
                  System.out.println("Message Sent: " + message);
              }
          });
   
    //register our tank and make sure ot include its color
    try {
      syncManager.register(localTank, new ColoredSynchronizeCreateMessage(localTank.getColor()), 50);
    } catch (IOException e) {
      System.err.println("Could not register local Tank:");
      e.printStackTrace();
      return;
    }
View Full Code Here

TOP

Related Classes of com.captiveimagination.jgn.synchronization.SynchronizationManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.