示例#1
0
  private void initChat() {
    if (chatController != null) {
      return;
    }

    chatController = new ChatController();
    chatController.setListener(this);
    chatController.setAuthToken(broadcastController.getAuthToken());

    if (!chatController.connect(username)) {
      chatController = null;
    }
  }
示例#2
0
  private void shutdownChat() {
    if (chatController == null) {
      return;
    }

    chatController.disconnect();
  }
示例#3
0
  private void loop() {
    long lastFrameTime = 0;

    while (!Display.isCloseRequested()) {
      long now = System.nanoTime();
      long renderFps = 30;
      long nanoPerFrame = 1000000000 / renderFps;

      // update the animation
      if (now - lastFrameTime >= nanoPerFrame) {
        lastFrameTime = now;

        angle += 2.0f;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glPushMatrix();
        glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
        glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
        glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);

        glPushMatrix();
        glTranslatef(-3.0f, -2.0f, 0.0f);
        glRotatef(angle, 0.0f, 0.0f, 1.0f);
        glCallList(gear1);
        glPopMatrix();

        glPushMatrix();
        glTranslatef(3.1f, -2.0f, 0.0f);
        glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
        glCallList(gear2);
        glPopMatrix();

        glPushMatrix();
        glTranslatef(-3.1f, 4.2f, 0.0f);
        glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
        glCallList(gear3);
        glPopMatrix();

        glPopMatrix();

        Display.update();
      }

      handleInput();

      if (broadcastController != null) {
        submitFrame();
        broadcastController.update();
      }

      if (chatController != null) {
        chatController.update();
      }
    }
  }
示例#4
0
  private void handleInput() {
    while (Keyboard.next()) {
      if (Keyboard.isRepeatEvent()) {
        continue;
      }

      if (!Keyboard.getEventKeyState()) {
        continue;
      }

      if (Keyboard.getEventKey() == Keyboard.KEY_A) {
        broadcastController.requestAuthToken(username, password);
      } else if (Keyboard.getEventKey() == Keyboard.KEY_S) {
        broadcastController.setStreamInfo(username, "Java Game", "Fun times");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_P) {
        if (broadcastController.getIsPaused()) {
          broadcastController.resumeBroadcasting();
        } else {
          broadcastController.pauseBroadcasting();
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
        if (broadcastController.getIsBroadcasting()) {
          broadcastController.stopBroadcasting();
        } else {
          VideoParams videoParams =
              broadcastController.getRecommendedVideoParams(
                  Display.getDisplayMode().getWidth(),
                  Display.getDisplayMode().getHeight(),
                  broadcastFramesPerSecond);
          videoParams.verticalFlip = true;

          broadcastController.startBroadcasting(videoParams);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_R) {
        broadcastController.runCommercial();
      } else if (Keyboard.getEventKey() == Keyboard.KEY_I) {
        if (ingestTester != null) {
          broadcastController.cancelIngestTest();
          ingestTester = null;
        } else {
          ingestTester = broadcastController.startIngestTest();
          ingestTester.setListener(this);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_G) {
        broadcastController.requestGameNameList("final");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_1) {
        broadcastController.sendActionMetaData(
            "TestAction",
            broadcastController.getCurrentBroadcastTime(),
            "Something cool happened",
            "{ \"MyValue\" : \"42\" }");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_2) {
        if (metaDataSpanSequenceId == -1) {
          metaDataSpanSequenceId =
              broadcastController.startSpanMetaData(
                  "TestSpan",
                  broadcastController.getCurrentBroadcastTime(),
                  "Something cool just started happening",
                  "{ \"MyValue\" : \"42\" }");
        } else {
          broadcastController.endSpanMetaData(
              "TestSpan",
              broadcastController.getCurrentBroadcastTime(),
              metaDataSpanSequenceId,
              "Something cool just stopped happening",
              "{ \"MyValue\" : \"42\" }");
          metaDataSpanSequenceId = -1;
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_C) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connect(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_V) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connectAnonymous(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_M) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.sendChatMessage("Test chat message: " + System.currentTimeMillis());
          }
        }
      }
    }
  }