Exemplo n.º 1
0
    static void OnSyncReceived(MatchCommand currCommand)
    {
        CommandSyncData command = currCommand as CommandSyncData;

        if (command == null)
        {
            return;
        }

        /*StringBuilder sb = new StringBuilder ("sync received at ");
         * sb.Append (Timer.Time);
         * sb.Append (", lag = ");
         * sb.Append (command.Lag);
         * foreach (var change in command.Changes) {
         *      sb.Append ("; (type=");
         *      sb.Append (change.After.GetType ());
         *      sb.Append (", data=");
         *      sb.Append (change.After.ToString ());
         *      sb.Append (")");
         * }
         * Debug.Log (sb.ToString ());*/

        //LogCharPos ("Before sync");
        float commandDelay = (command.Lag + LagController.Lag) * 0.001f;

        TimeMachiene.GoToPast(commandDelay);
        //LogCharPos ("In past");
        foreach (var change in command.Changes)
        {
            SaveBeforeState(change);
        }
        foreach (var change in command.Changes)
        {
            ApplyChange(change);
        }
        //LogCharPos ("after sync in past");
        TimeMachiene.SaveReceivedCommands(command.Changes);
        TimeMachiene.GoForward(commandDelay);
        //LogCharPos ("after sync in curr time");
    }
Exemplo n.º 2
0
    public static void CalcComponentsChange(List <Entity> currEntities)
    {
        List <ComponentChange> changes = new List <ComponentChange>();

        for (int i = 0; i < currEntities.Count; i++)
        {
            int prevInd = FindInd(_prevEntities, currEntities[i].Id);
            if (prevInd == -1)
            {
                // Add all components.
                foreach (var component in currEntities[i].GetComponents())
                {
                    var change = new ComponentChange(currEntities[i].Id, false, null, component);
                    changes.Add(change);
                }
            }
            else
            {
                CalcComponentsChangeInOneEntity(currEntities[i], _prevEntities[prevInd], changes);
            }
        }
        for (int i = 0; i < _prevEntities.Count; i++)
        {
            int currInd = FindInd(currEntities, _prevEntities[i].Id);
            if (currInd != -1)
            {
                continue;
            }
            // Entity deleted, all components removed.
            foreach (var component in _prevEntities[i].GetComponents())
            {
                var change = new ComponentChange(_prevEntities[i].Id, true, component, null);
                changes.Add(change);
            }
        }
        TimeMachiene.SaveCalculatedChanges(changes, Timer.DeltaTime);
    }
Exemplo n.º 3
0
    public void StartMatch(bool multiplayer)
    {
        var systems = new List <EntitySystem>()
        {
            new MovingSystem()
        };

        if (multiplayer)
        {
            systems.Add(new NetworkMatchSystem());
            systems.Add(new NetworkInputSystem());
        }
        else
        {
            systems.Add(new SinglePlayerMatchSystem());
            systems.Add(new InputControlSystem());
        }
        LagController.OnMatchStarted();
        TimeMachiene.OnStartMatch();
        Entities.Init(systems);
        SyncChangesController.OnStartMatch();
        _view.OnStartMatch();
        _isPlaying = true;
    }