Пример #1
0
  /**
   * handle timeouts etc
   *
   * @param maximumDurationInNS - the maximum amount of time to spend generating selections for
   *     clients. 0 = don't generate any.
   */
  public void tick(long maximumDurationInNS) {
    for (MultipartOneAtATimeReceiver receiver : playerMOATreceivers.values()) {
      receiver.onTick();
    }
    for (MultipartOneAtATimeSender sender : playerMOATsenders.values()) {
      sender.onTick();
    }

    if (maximumDurationInNS == 0) return;

    boolean foundSuitable = false;
    CommandQueueEntry currentCommand;
    do {
      currentCommand = commandQueue.peekFirst();
      if (currentCommand == null) return;
      if (currentCommand.entityPlayerMP.get() == null) {
        commandQueue.removeFirst();
      } else {
        foundSuitable = true;
      }
    } while (!foundSuitable);
    EntityPlayerMP entityPlayerMP = currentCommand.entityPlayerMP.get();
    World playerWorld = entityPlayerMP.getEntityWorld();
    Packet250ServerSelectionGeneration commandPacket = currentCommand.commandPacket;

    if (!currentCommand.hasStarted) {
      BlockVoxelMultiSelector blockVoxelMultiSelector = new BlockVoxelMultiSelector();
      playerBlockVoxelMultiSelectors.put(entityPlayerMP, blockVoxelMultiSelector);
      playerCommandStatus.put(entityPlayerMP, CommandStatus.EXECUTING);
      currentCommand.blockVoxelMultiSelector = blockVoxelMultiSelector;
      switch (commandPacket.getCommand()) {
        case ALL_IN_BOX:
          {
            blockVoxelMultiSelector.selectAllInBoxStart(
                playerWorld, commandPacket.getCorner1(), commandPacket.getCorner2());
            break;
          }
        case UNBOUND_FILL:
          {
            blockVoxelMultiSelector.selectUnboundFillStart(
                playerWorld, commandPacket.getFillAlgorithmSettings());
            break;
          }
        case BOUND_FILL:
          {
            blockVoxelMultiSelector.selectBoundFillStart(
                playerWorld,
                commandPacket.getFillAlgorithmSettings(),
                commandPacket.getCorner1(),
                commandPacket.getCorner2());
            break;
          }
        default:
          {
            ErrorLog.defaultLog()
                .severe("Invalid command in ServerVoxelSelections: " + commandPacket.getCommand());
            break;
          }
      }
      currentCommand.hasStarted = true;
    } else {
      BlockVoxelMultiSelector blockVoxelMultiSelector = currentCommand.blockVoxelMultiSelector;
      float progress =
          blockVoxelMultiSelector.continueSelectionGeneration(playerWorld, maximumDurationInNS);
      if (progress < 0) { // finished
        BlockPos origin = blockVoxelMultiSelector.getWorldOrigin();
        VoxelSelectionWithOrigin newSelection =
            new VoxelSelectionWithOrigin(
                origin.getX(),
                origin.getY(),
                origin.getZ(),
                blockVoxelMultiSelector.getSelection());
        //        System.out.println("New selection origin: ["  + newSelection.getWxOrigin()
        //                                   + ", " + newSelection.getWyOrigin()
        //                                   + ", " + newSelection.getWzOrigin()+"]");

        playerSelections.put(entityPlayerMP, newSelection);
        playerBlockVoxelMultiSelectors.remove(entityPlayerMP);
        playerCommandStatus.put(entityPlayerMP, CommandStatus.COMPLETED);

        MultipartOneAtATimeSender sender = playerMOATsenders.get(entityPlayerMP);
        if (sender != null) {
          SelectionPacket selectionPacket =
              SelectionPacket.createSenderPacket(blockVoxelMultiSelector, Side.SERVER);
          SenderLinkage newLinkage =
              new SenderLinkage(entityPlayerMP, selectionPacket.getUniqueID());
          playerSenderLinkages.put(entityPlayerMP, newLinkage);
          //          System.out.println("send new Multipart Selection from server to client, ID = "
          // + selectionPacket.getUniqueID()); // todo remove
          sender.sendMultipartPacket(newLinkage, selectionPacket);
        }
        assert (commandQueue.peekFirst() == currentCommand);
        commandQueue.removeFirst();
      }
    }
  }
Пример #2
0
    public Packet250ServerSelectionGeneration handlePacket(
        Packet250ServerSelectionGeneration packet, MessageContext ctx) {
      final float ERROR_STATUS = -10.0F;
      EntityPlayerMP entityPlayerMP = ctx.getServerHandler().playerEntity;
      int uniqueID = packet.getUniqueID();
      if (!players.containsKey(entityPlayerMP)) {
        ErrorLog.defaultLog()
            .info("ServerVoxelSelections:: Packet received from player not in players");
        Packet250Base message =
            Packet250ServerSelectionGeneration.replyFractionCompleted(uniqueID, ERROR_STATUS);
        sendReplyMessageToClient(message, entityPlayerMP);
        return null;
      }

      Integer lastCommandID = playerLastCommandID.get(entityPlayerMP);
      if (lastCommandID == null) lastCommandID = Integer.MIN_VALUE;
      if (uniqueID < lastCommandID) return null; // discard old commands

      switch (packet.getCommand()) {
        case STATUS_REQUEST:
          {
            if (uniqueID != lastCommandID) return null; // discard old or too-new commands
            CommandStatus commandStatus = playerCommandStatus.get(entityPlayerMP);
            if (commandStatus == null)
              return Packet250ServerSelectionGeneration.replyFractionCompleted(
                  uniqueID, ERROR_STATUS);
            final float JUST_STARTED_VALUE = 0.01F;
            Packet250Base message = null;
            switch (commandStatus) {
              case QUEUED:
                {
                  message =
                      Packet250ServerSelectionGeneration.replyFractionCompleted(
                          uniqueID, JUST_STARTED_VALUE);
                  break;
                }
              case COMPLETED:
                {
                  message =
                      Packet250ServerSelectionGeneration.replyFractionCompleted(uniqueID, 1.0F);
                  break;
                }
              case EXECUTING:
                {
                  BlockVoxelMultiSelector blockVoxelMultiSelector =
                      playerBlockVoxelMultiSelectors.get(entityPlayerMP);
                  if (blockVoxelMultiSelector == null) {
                    message =
                        Packet250ServerSelectionGeneration.replyFractionCompleted(
                            uniqueID, ERROR_STATUS);
                  } else {
                    message =
                        Packet250ServerSelectionGeneration.replyFractionCompleted(
                            uniqueID, blockVoxelMultiSelector.getEstimatedFractionComplete());
                  }
                  break;
                }
              default:
                assert false : "Invalid commandStatus in ServerVoxelSelections:" + commandStatus;
            }
            if (message != null) {
              sendReplyMessageToClient(message, entityPlayerMP);
            }
            return null;
          }
        case ABORT:
          {
            if (uniqueID == lastCommandID) {
              abortCurrentCommand(entityPlayerMP);
            }
            return null;
          }
        case ALL_IN_BOX:
        case UNBOUND_FILL:
        case BOUND_FILL:
          {
            if (uniqueID < lastCommandID) return null; // discard old commands
            if (uniqueID == lastCommandID) {
              CommandStatus commandStatus = playerCommandStatus.get(entityPlayerMP);
              if (commandStatus != CommandStatus.COMPLETED)
                return null; // ignore this command if we're currently processing it
            }

            boolean success = enqueueSelectionCommand(entityPlayerMP, packet);
            if (success) {
              playerLastCommandID.put(entityPlayerMP, uniqueID);
            }
            Packet250Base message =
                Packet250ServerSelectionGeneration.replyFractionCompleted(
                    uniqueID, success ? 0.0F : ERROR_STATUS);
            sendReplyMessageToClient(message, entityPlayerMP);
            return null;
          }
        default:
          {
            ErrorLog.defaultLog()
                .severe("Invalid command received in ServerVoxelSelections:" + packet.getCommand());
            return null;
          }
      }
    }