Esempio n. 1
0
        /// <summary>NOTE: Will throw an exception if the deserialization isn't clean (eg: bad network). Caller must handle.</summary>
        public void Deserialize(byte[] data)
        {
            var ms = new MemoryStream(data);
            var br = new BinaryReader(ms);

            LoopSystem <TGameState> .deserialize(br, ref gameState, definitionTable);

            if (OnGameStateReplaced != null)
            {
                OnGameStateReplaced.Invoke(gameState);
            }
        }
Esempio n. 2
0
        public bool InjectSnapshot(byte[] snapshot)
        {
            LoopStopAllRecording();
            LoopStopPlaying();

            TGameState loopGameState;

            try
            {
                // NOTE: This will throw if the game state doesn't deserialize cleanly
                //       (No guarantees about whether the deserialized data will explode once it starts simulating, though)
                loopGameState = SafeDeserialize(snapshot, definitionTable);
            }
            catch (Exception e)
            {
                // You probably modified a serializable structure, without a definition change (or something is *seriously* broken)
                Trace.WriteLine(string.Format("Error deserializing snapshot {0}", e));

                if (Debugger.IsAttached)
                {
                    Debugger.Break();                     // Want to know when this happens (caller should have definition-checked)
                }
                return(false);
            }

            if (loopGameState != null)
            {
                gameState = loopGameState;
                if (OnGameStateReplaced != null)
                {
                    OnGameStateReplaced.Invoke(gameState);
                }
                return(true);
            }

            return(false);
        }