示例#1
0
 public EventCallback <ClipboardEventArgs> OnCut(Value128 id)
 {
     return(EventCallback.Factory.Create <ClipboardEventArgs>(this, args =>
     {
         OnEvent(id, HtmlEvents.Clipboard.OnCut, null);
     }));
 }
		public void ConvertStringCustomVsNativeLoadTest()
		{
			// Initialize Data
			var testSamples = new Value128[loadTestsIterationsCount];

			for (var index = 0; index < loadTestsIterationsCount; index++)
			{
				testSamples[index] = (Value128) Guid.NewGuid();
			}

			// Encode
			var customIntermediateResults = new String[loadTestsIterationsCount];

			var nativeIntermediateResults = new String[loadTestsIterationsCount];

			var testResults1 = LoadTest.ExecuteCompare
				(
					"Value128Converter.TryToBase64String",
					index =>
					{
						var inputValue = testSamples[(Int32) index];

						customIntermediateResults[index] = Value128Converter.TryToBase64String(inputValue, Base64Encoding.Mime).Result;
					},
					"Convert.ToBase64String",
					index =>
					{
						var inputValue = testSamples[(Int32) index];

						nativeIntermediateResults[index] = Convert.ToBase64String((Byte[]) inputValue);
					},
					loadTestsIterationsCount
				);

			Trace.TraceInformation(testResults1.ToString());

			// Decode
			var customActualResults = new Value128[loadTestsIterationsCount];

			var decodedGuids = new Value128[loadTestsIterationsCount];

			var testResults2 = LoadTest.ExecuteCompare
				(
					"Value128Converter.TryFromBase64String",
					index =>
					{
						var inputValue = customIntermediateResults[index];

						customActualResults[index] = Value128Converter.TryFromBase64String(inputValue, 0, Base64Encoding.Mime).Result;
					},
					"Convert.FromBase64String",
					index =>
					{
						var inputValue = nativeIntermediateResults[index];

						decodedGuids[index] = Value128Converter.TryFromByteArray(Convert.FromBase64String(inputValue), 0).Result;
					}, loadTestsIterationsCount);

			Trace.TraceInformation(testResults2.ToString());
		}
示例#3
0
 public EventCallback <DragEventArgs> OnScroll(Value128 id)
 {
     return(EventCallback.Factory.Create <DragEventArgs>(this, args =>
     {
         OnEvent(id, HtmlEvents.Drag.OnScroll, null);
     }));
 }
示例#4
0
 public EventCallback <MouseEventArgs> OnWheel(Value128 id)
 {
     return(EventCallback.Factory.Create <MouseEventArgs>(this, args =>
     {
         OnEvent(id, HtmlEvents.Mouse.OnWheel, null);
     }));
 }
示例#5
0
        private void OnEvent(Value128 id, string eventType, object data)
        {
            var instructionCount = Ui.InstructionCount;

            Trace.TraceInformation($"Event: {eventType} on element {id}");
            Ui.AddEvent(eventType, id, data);
            Begin();
            Ui.Invoke(Handler);

            if (Ui.InstructionCount != instructionCount)
            {
                Trace.TraceInformation("Pending update");
            }
        }
示例#6
0
文件: Loop.cs 项目: zcxxv1213/Pixel3D
 public static Loop TryLoadFromFile(string filename, ref Value128 definitionHash)
 {
     try
     {
         using (var fileStream = File.OpenRead(filename))
         {
             return(TryLoadFromStream(fileStream, filename, ref definitionHash));
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Loop \"" + Path.GetFileNameWithoutExtension(filename) + "\": Failed to open file (" + e.Message + ")");
         return(null);
     }
 }
示例#7
0
 public static Loop TryLoadFromFile(string filename, ref Value128 definitionHash)
 {
     try
     {
         using (var fileStream = File.OpenRead(filename))
         {
             return(TryLoadFromStream(fileStream, filename, ref definitionHash));
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(string.Format(
                             "Loop \"{0}\": Failed to open file ({1})", Path.GetFileNameWithoutExtension(filename), e.Message));
         return(null);
     }
 }
示例#8
0
文件: Loop.cs 项目: zcxxv1213/Pixel3D
        public static Loop StartRecording(string filename, byte[] saveState, Value128 definitionHash, string comment)
        {
            Loop result = new Loop();

            result.filename       = filename;
            result.definitionHash = definitionHash;
            result.comment        = comment;
            result.saveState      = saveState;
            result.frameCount     = 0;
            result.inputFrames    = new MultiInputState[2 * 60 * 60];

            result.loopWriter = new BinaryWriter(File.Create(filename));
            result.loopWriter.WriteLoopWithComment(saveState, definitionHash, comment);

            return(result);
        }
示例#9
0
        public LoopManager(int slots,
                           Value128 definitionHash,
                           object definitionTable,
                           TGameState gameState,
                           Action <TGameState> onGameStateReplaced,
                           Func <bool> isNetworked)
        {
            loopSlots = new Loop[slots];

            this.definitionHash  = definitionHash;
            this.definitionTable = definitionTable;

            this.gameState      = gameState;
            OnGameStateReplaced = onGameStateReplaced;
            IsNetworked         = isNetworked;

            Trace.WriteLine("Definition Hash = " + definitionHash);
        }
示例#10
0
		public static TryResult<String> TryToBase64String(Value128 data, Base64Encoding base64Encoding)
		{
			if (base64Encoding == null)
			{
				return encodeFailResult;
			}

			Char[] result;

			// Get padding symbol
			var paddingSymbol = base64Encoding.PaddingSymbol;

			if (paddingSymbol.HasValue)
			{
				result = new Char[24];

				result[22] = result[23] = paddingSymbol.Value;
			}
			else
			{
				result = new Char[22];
			}

			var higherHalf = data.HigherHalf;

			var lowerHalf = data.LowerHalf;

			// Get alphabet
			var alphabet = base64Encoding.Alphabet;

			for (Int32 indexH = 0, indexL = 11, shiftH = 58, shiftL = 56; indexH < 10; indexH++, indexL++, shiftH -= 6, shiftL -= 6)
			{
				result[indexH] = alphabet[(Int32) (higherHalf >> shiftH) & 0x3F];

				result[indexL] = alphabet[(Int32) (lowerHalf >> shiftL) & 0x3F];
			}

			result[10] = alphabet[(Int32) (((higherHalf << 2) & 0x3C) | ((lowerHalf >> 62) & 0x03))];

			result[21] = alphabet[(Int32) ((lowerHalf << 4) & 0x30)];

			return TryResult<String>.CreateSuccess(new String(result));
		}
示例#11
0
		public static TryResult<String> TryToBase32String(Value128 data, Base32Encoding base32Encoding)
		{
			if (base32Encoding == null)
			{
				return encodeFailResult;
			}

			Char[] result;

			// Get padding symbol
			var paddingSymbol = base32Encoding.PaddingSymbol;

			if (paddingSymbol.HasValue)
			{
				result = new Char[32];

				// Set padding
				result[26] = result[27] = result[28] = result[29] = result[30] = result[31] = paddingSymbol.Value;
			}
			else
			{
				result = new Char[26];
			}

			var higherHalf = data.HigherHalf;

			var lowerHalf = data.LowerHalf;

			// Get alphabet
			var alphabet = base32Encoding.Alphabet;

			for (Int32 indexH = 0, indexL = 13, shiftH = 59, shiftL = 58; indexH < 12; indexH++, indexL++, shiftH -= 5, shiftL -= 5)
			{
				result[indexH] = alphabet[(Int32) (higherHalf >> shiftH) & 0x1F];

				result[indexL] = alphabet[(Int32) (lowerHalf >> shiftL) & 0x1F];
			}

			result[12] = alphabet[(Int32) (((higherHalf << 1) & 0x1E) | ((lowerHalf >> 63) & 0x01))];

			result[25] = alphabet[(Int32) ((lowerHalf << 2) & 0x1C)];

			return TryResult<String>.CreateSuccess(new String(result));
		}
示例#12
0
		public static TryResult<Value128> TryFromByteArray(Byte[] data, Int32 offset)
		{
			if ((data == null) || (data.Length - offset < 16))
			{
				return convertFailResult;
			}

			// Convert higher half
			var higherHalf = Convert(data, offset);

			// Convert lower half
			var lowerHalf = Convert(data, offset + 8);

			// Initialize result
			var result = new Value128(higherHalf, lowerHalf);

			return TryResult<Value128>.CreateSuccess(result);
		}
示例#13
0
		public static TryResult<Value128> TryFromBase64String(String data, Int32 offset, Base64Encoding base64Encoding)
		{
			// Check input values
			if ((data == null) || (offset > data.Length - base64EncodedSymbolsCount) || (base64Encoding == null))
			{
				return convertFailResult;
			}

			// Get look-up table
			var lookupTable = base64Encoding.LookupTable;

			var lastIndex = offset + 10;

			var symbol10 = (UInt64) lookupTable[data[lastIndex] & 0x7F];

			var symbol21 = (UInt64) lookupTable[data[offset + 21] & 0x7F];

			// Check symbol
			if ((symbol10 | symbol21) == 0xFF)
			{
				return convertFailResult;
			}

			// Calculate higher half
			var higherHalf = symbol10 >> 2;

			// Calculate lower half
			var lowerHalf = symbol10 << 62 | symbol21 >> 4;

			// Decode symbols
			for (Int32 indexH = offset, indexL = offset + 11, shiftH = 58, shiftL = 56; indexH < lastIndex; indexH++, indexL++, shiftH -= 6, shiftL -= 6)
			{
				// Get symbols
				var symbolH = data[indexH] & 0x7F;

				var symbolL = data[indexL] & 0x7F;

				// Get symbols values
				var symbolHValue = (UInt64) lookupTable[symbolH];

				var symbolLValue = (UInt64) lookupTable[symbolL];

				// Check symbol
				if ((symbolHValue | symbolLValue) == 0xFF)
				{
					return convertFailResult;
				}

				higherHalf |= symbolHValue << shiftH;

				lowerHalf |= symbolLValue << shiftL;
			}

			// Initialize a new instance
			var result = new Value128(higherHalf, lowerHalf);

			return TryResult<Value128>.CreateSuccess(result);
		}
示例#14
0
		public static IPAddress ToIPAddress(Value128 value)
		{
			// Get value as byte array
			var address = ToByteArray(value);

			// Initialize a new instance of IPAddress
			return new IPAddress(address);
		}
示例#15
0
		public static Guid ToGuid(Value128 value)
		{
			var higherHalf = value.HigherHalf;

			var lowerHalf = value.LowerHalf;

			return new Guid(new[]
			{
				(Byte) (higherHalf >> 56), (Byte) (higherHalf >> 48), (Byte) (higherHalf >> 40), (Byte) (higherHalf >> 32), (Byte) (higherHalf >> 24), (Byte) (higherHalf >> 16), (Byte) (higherHalf >> 8), (Byte) (higherHalf >> 0), (Byte) (lowerHalf >> 56), (Byte) (lowerHalf >> 48), (Byte) (lowerHalf >> 40), (Byte) (lowerHalf >> 32), (Byte) (lowerHalf >> 24), (Byte) (lowerHalf >> 16), (Byte) (lowerHalf >> 8), (Byte) (lowerHalf >> 0)
			});
		}
示例#16
0
文件: Loop.cs 项目: zcxxv1213/Pixel3D
        public static Loop TryLoadFromStream(Stream stream, string filename, ref Value128 definitionHash)
        {
            Loop result = new Loop();

            result.filename = filename;

            try
            {
                BinaryReader br = new BinaryReader(stream);

                // Read file identifier:
                if (br.ReadByte() != (byte)'l' || br.ReadByte() != (byte)'o' || br.ReadByte() != (byte)'o' || br.ReadByte() != (byte)'p' || br.ReadByte() != (byte)' ')
                {
                    throw new Exception("File missing identifier!");
                }

                // Read comment (typically a git hash):
                List <byte> commentBytes = new List <byte>();
                byte        readByte;
                while ((readByte = br.ReadByte()) != 0) // Wait for null terminator
                {
                    commentBytes.Add(readByte);
                }
                if (commentBytes.Count > 0 && commentBytes[commentBytes.Count - 1] == (byte)' ') // Remove trailing space from comment
                {
                    commentBytes.RemoveAt(commentBytes.Count - 1);
                }
                result.comment = System.Text.Encoding.ASCII.GetString(commentBytes.ToArray());

                result.definitionHash.v1 = br.ReadUInt32();
                result.definitionHash.v2 = br.ReadUInt32();
                result.definitionHash.v3 = br.ReadUInt32();
                result.definitionHash.v4 = br.ReadUInt32();

                if (result.definitionHash == definitionHash) // <- Only bother to load the loop if the definition hash matches
                {
                    int saveStateLength = br.ReadInt32();
                    result.saveState = br.ReadBytes(saveStateLength);

                    long remainingBytes = (int)(br.BaseStream.Length - br.BaseStream.Position);
                    unsafe
                    {
                        if ((ulong)remainingBytes > (ulong)(maxLoopInputCount * sizeof(MultiInputState)))
                        {
                            throw new Exception("File too huge!");         // (or impossible negative size)
                        }
                        if (remainingBytes % sizeof(MultiInputState) != 0) // <- file didn't finish writing out, do we actually care?
                        {
                            throw new Exception("Bad file!");
                        }

                        result.frameCount  = ((int)remainingBytes) / sizeof(MultiInputState);
                        result.inputFrames = new MultiInputState[result.frameCount + 2048];

                        byte[] workingBuffer = new byte[remainingBytes];
                        br.Read(workingBuffer, 0, (int)remainingBytes);

                        fixed(MultiInputState *inputFrames = &(result.inputFrames[0]))
                        {
                            Marshal.Copy(workingBuffer, 0, (IntPtr)inputFrames, (int)remainingBytes);
                        }
                    }
                }

                Debug.WriteLine("Loop \"" + Path.GetFileNameWithoutExtension(filename) + "\": "
                                + (result.saveState == null ? "[INVALID]" : "[OK]")
                                + " comment = \"" + result.comment + "\""
                                + " definitions = \"" + result.definitionHash + "\"");
            }
            catch (Exception e)
            {
                Debug.WriteLine("Loop \"" + Path.GetFileNameWithoutExtension(filename) + "\": Corrupt file! (" + e.Message + ")");
                return(null);
            }

            return(result);
        }
示例#17
0
 public static void WriteLoopWithComment(this BinaryWriter loopWriter, byte[] saveState, Value128 definitionHash, string comment)
 {
     loopWriter.Write((byte)'l');
     loopWriter.Write((byte)'o');
     loopWriter.Write((byte)'o');
     loopWriter.Write((byte)'p');
     loopWriter.Write((byte)' ');
     loopWriter.Write(System.Text.Encoding.ASCII.GetBytes(comment));
     loopWriter.Write((byte)' ');
     loopWriter.Write((byte)0); // <- nul terminated string
     loopWriter.Write(definitionHash.v1);
     loopWriter.Write(definitionHash.v2);
     loopWriter.Write(definitionHash.v3);
     loopWriter.Write(definitionHash.v4);
     loopWriter.Write(saveState.Length);
     loopWriter.Write(saveState);
 }
示例#18
0
		public static Byte[] ToByteArray(Value128 value)
		{
			var result = new Byte[16];

			Convert(value.HigherHalf, 0, result);

			Convert(value.LowerHalf, 8, result);

			return result;
		}