Esempio n. 1
0
        public void SendInputFrameDeltas(SWBytes inputFrameDeltas, int count, byte inputSize)
        {
            for (int i = 0; i < count; i++)
            {
                int playerFrameNumber    = inputFrameDeltas.PopInt();
                int predictedFrameNumber = inputFrameDeltas.PopInt();

                byte length = inputFrameDeltas.PopByte();

                if (playerFrameNumber == _lastReceivedPlayerFrameNumber + 1)
                {
                    int correctPredictedFrameNumber = 0;

                    if (predictedFrameNumber != 0)
                    {
                        correctPredictedFrameNumber = _lastPredictedFrameNumber + 1;
                        _predictedFrameNumber       = predictedFrameNumber;
                        _correctFrameNumber         = correctPredictedFrameNumber;
                        SWConsole.Info($"MOCK: SendInputFrameDeltas playerFrameNumber={playerFrameNumber} correctPredictedFrameNumber={correctPredictedFrameNumber} _predictedFrameNumber={_predictedFrameNumber}");
                    }

                    InputFrameDelta delta = new InputFrameDelta();
                    delta.frameNumber = playerFrameNumber;
                    inputFrameDeltas.PopByteBuffer(delta.bytes, 0, length);
                    _receivedInputFrameDeltas.Enqueue(delta);
                    _lastReceivedPlayerFrameNumber = playerFrameNumber;
                    _lastPredictedFrameNumber      = correctPredictedFrameNumber;
                }
                else
                {
                    SWConsole.Info($"MOCK: SendInputFrameDeltas SKIP playerFrameNumber={playerFrameNumber}");
                    inputFrameDeltas.SkipRead(length);
                }
            }
        }
Esempio n. 2
0
        //should include startFrame, include endframe
        public void HandleInputFramesInBackground(SWBytes initialInputFramesData, int startFrameNumber, int endFrameNumber)
        {
            lock (FRAME_SYNC_LOCK)
            {
                if (_game.gameState == FrameSyncGameState.Stopped)
                {
                    return;
                }
                SWConsole.Info($"HandleInputFramesInBackground startFrameNumber={startFrameNumber} endFrameNumber={endFrameNumber}");
                _startFrameNumber = startFrameNumber;
                _endFrameNumber   = endFrameNumber;
                _initialInputFrameDeltas.Clear();
                _initialInputFramesData = initialInputFramesData;
                for (int i = startFrameNumber; i < endFrameNumber; i++)
                {
                    InputFrameDelta delta  = new InputFrameDelta();
                    byte            length = initialInputFramesData.PopByte();
                    initialInputFramesData.PopByteBuffer(delta.bytes, 0, length);
                    _initialInputFrameDeltas.Add(delta);
                }

                int expected = endFrameNumber - startFrameNumber;
                int got      = _initialInputFrameDeltas.Count;
                //reset read index, we will save the data to disk later
                _initialInputFramesData.SetReadIndex(0);
                if (expected != got)
                {
                    SWConsole.Error($"HandleInputFramesInBackground got={got} expected={expected}");
                }
            }
        }
        void Awake()
        {
            if (instance)
            {
                Destroy(this);
            }

            DontDestroyOnLoad(gameObject);
            instance = this;
            SWConsole.Info("SWClientBehaviour awake");
        }
Esempio n. 4
0
        void RunningOnline()
        {
            SWConsole.Info($"Engine: ================RunningOnline {_currentInputFrameNumber + 1}=================");

            if (CanSimulateInputFrame(_currentInputFrameNumber + 1))
            {
                SimulateInputFrame(_currentInputFrameNumber + 1);
                ExportSimulationResult();
            }

            SWConsole.Info("Engine: ================end=================");
        }
Esempio n. 5
0
        void SaveInput(SWBytes data, int start, int end)
        {
            SWConsole.Info($"SaveItems start={start}, end={end}");

            if (end > _lastEndIndex)
            {
                _lastEndIndex = end;
            }

            return;

            string partialName            = _game.replayFileName + start.ToString("D6") + end.ToString("D6");
            SaveReplayoperation operation = new SaveReplayoperation(data.Data(), partialName);

            operationQueue.AddOperation(operation);
        }
Esempio n. 6
0
        public static void RandromTest()
        {
            Dictionary <UInt32, int> dict         = new Dictionary <uint, int>();
            SortedList <UInt32, int> distribution = new SortedList <UInt32, int>();

            _internal_seed(1);
            int  count     = 1000;
            uint groupSize = 5;

            for (int i = 0; i < count; i++)
            {
                UInt32 result = Next(100);
                SWConsole.Info($"PRandom = {result}");
                if (dict.ContainsKey(result))
                {
                    dict[result]++;
                }
                else
                {
                    dict[result] = 1;
                }

                UInt32 group = result / groupSize;

                if (distribution.ContainsKey(group))
                {
                    distribution[group]++;
                }
                else
                {
                    distribution[group] = 1;
                }
            }

            foreach (var pair in distribution)
            {
                SWConsole.Info($"{pair.Key} = {pair.Value}");
            }
        }
Esempio n. 7
0
 internal void OnUnityApplicationQuit()
 {
     Disconnect();
     SWConsole.Info($"{_debugName} Application ending after " + Time.time + " seconds");
 }
Esempio n. 8
0
 public override void Start()
 {
     SWConsole.Info("StaticFrameSyncBehaviourManager: started");
     instanceCount++;
 }
Esempio n. 9
0
 public static void Register(StaticFrameSyncBehaviour staticFrameSyncBehaviour)
 {
     SWConsole.Info($"StaticFrameSyncBehaviourManager: register {staticFrameSyncBehaviour.name}");
     _behaviours.Add(staticFrameSyncBehaviour.FrameSyncBehaviourID, staticFrameSyncBehaviour);
 }
Esempio n. 10
0
 public override void Stop()
 {
     _behaviours.Clear();
     SWConsole.Info("StaticFrameSyncBehaviourManager: stopped");
     instanceCount--;
 }
Esempio n. 11
0
 public override void Stop()
 {
     SWConsole.Info("DynamicFrameSyncBehaviourManager: stopped");
     DynamicFrameSyncBehaviourSpawner.OnGameObjectCreated   -= _behaviourSpawner_OnGameObjectCreated;
     DynamicFrameSyncBehaviourSpawner.OnGameObjectDestroyed -= _behaviourSpawner_OnGameObjectDestroyed;
 }
Esempio n. 12
0
        //


        //

        public override void Start()
        {
            SWConsole.Info("DynamicFrameSyncBehaviourManager: started");
        }