示例#1
0
        private void Reconcile(ClientControllablePlayer clientControllablePlayer, ClientGameSnapshot gameSnapshot)
        {
            ClientControllable clientControllable      = clientControllablePlayer.clientControllable;
            Vector2            incorrectClientPosition = clientControllable.stateSnapshots[gameSnapshot.yourLastProcessedInputId].position;
            Vector2            correctServerPosition   = gameSnapshot.playersInfo[clientControllablePlayer.basePlayer.information.id].position;

            Physics2D.simulationMode = SimulationMode2D.Script;

            // Teleport to server location
            clientControllablePlayer.basePlayer.movable.Teleport(correctServerPosition);
            Physics2D.Simulate(Time.fixedDeltaTime);
            clientControllable.UpdateSnapshotStatePosition(gameSnapshot.yourLastProcessedInputId, clientControllablePlayer.transform.position);

            // Apply not yet processed by server inputs
            for (int inputId = gameSnapshot.yourLastProcessedInputId + 1; inputId <= clientControllable.stateSnapshots.Keys.Max(); inputId++)
            {
                clientControllablePlayer.basePlayer.movable.MoveByPlayerInput(clientControllable.stateSnapshots[inputId].input);
                Physics2D.Simulate(Time.fixedDeltaTime);
                clientControllable.UpdateSnapshotStatePosition(inputId, clientControllablePlayer.transform.position);
            }

            Physics2D.simulationMode = SimulationMode2D.FixedUpdate;

            Logger.LogEvent(LoggerSection.ServerReconciliation, $"Reconciled position with the server position. SnapshotId: {gameSnapshot.id}. YourLastProcessedInputId: {gameSnapshot.yourLastProcessedInputId}. Server position: {correctServerPosition}. Client position: {incorrectClientPosition}.");
        }
示例#2
0
    public static void Save(ClientControllable obj)
    {
        WWWForm w = new WWWForm();
        w.AddField("guid", obj.guid);
        w.AddField("posx", ((int)obj.bounds.x));
        w.AddField("posy", ((int)obj.bounds.y));
        w.AddField("sid", SystemInfo.deviceUniqueIdentifier);
        WWW w2 = new WWW(OmniNetwork.url_save, w);

        if(!instance.saves.Contains(w2))
        {
            instance.saves.Add(w2);
        }
    }
示例#3
0
    public InputEvent(int tick, ClientControllable owner, int mask, params Vector2[] args)
        : base(tick)
    {
        this.mask = mask;
        type = NetworkSendType.ClientUnreliable;
        this.owner = owner;

        if (args.Length > 0)
        {
            clickPos = args[0];
        }

        //        if(Network.isClient)
        //         OmniNetwork.getView().RPC("RemoteInput", RPCMode.Server, Network.player, mask, tick,clickPos);
    }
示例#4
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.F3))
     {
         ClientControllable[] objs = new ClientControllable[connectedClients.Values.Count];
         connectedClients.Values.CopyTo(objs, 0);
         for (int i = 0; i < connectedClients.Values.Count; i++)
         {
             Vector3 pos = cam.ScreenToWorldPoint(Input.mousePosition);
             objs[i].bounds.x = pos.x;
             objs[i].bounds.y = pos.y;
         }
     }
 }
示例#5
0
 public static void AddClient(ClientControllable obj, NetworkPlayer player)
 {
     instance.connectedClients.Add(player, obj);
 }
示例#6
0
 public void setOwner(OmniObject owner)
 {
     if (owner is ClientControllable)
     {
         controlOwner = (ClientControllable)owner;
         inventoryManager.setOwner(controlOwner);
         controlOwner.lerpSpeed = OmniWorld.timeStep;
     }
     this.owner = owner;
     cam.owner = owner;
 }