Esempio n. 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Id;
         hashCode = (hashCode * 397) ^ NullableId.GetHashCode();
         hashCode = (hashCode * 397) ^ Byte.GetHashCode();
         hashCode = (hashCode * 397) ^ Short.GetHashCode();
         hashCode = (hashCode * 397) ^ Int;
         hashCode = (hashCode * 397) ^ Long.GetHashCode();
         hashCode = (hashCode * 397) ^ UShort.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)UInt;
         hashCode = (hashCode * 397) ^ ULong.GetHashCode();
         hashCode = (hashCode * 397) ^ Float.GetHashCode();
         hashCode = (hashCode * 397) ^ Double.GetHashCode();
         hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
         hashCode = (hashCode * 397) ^ (String != null ? String.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ DateTime.GetHashCode();
         hashCode = (hashCode * 397) ^ TimeSpan.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeOffset.GetHashCode();
         hashCode = (hashCode * 397) ^ Guid.GetHashCode();
         hashCode = (hashCode * 397) ^ Bool.GetHashCode();
         hashCode = (hashCode * 397) ^ Char.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableDateTime.GetHashCode();
         hashCode = (hashCode * 397) ^ NullableTimeSpan.GetHashCode();
         hashCode = (hashCode * 397) ^ (ByteArray != null ? ByteArray.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (CharArray != null ? CharArray.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StringArray != null ? StringArray.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (IntArray != null ? IntArray.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (LongArray != null ? LongArray.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StringList != null ? StringList.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StringMap != null ? StringMap.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (IntStringMap != null ? IntStringMap.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SubType != null ? SubType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SubTypes != null ? SubTypes.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (CustomText != null ? CustomText.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (MaxText != null ? MaxText.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ CustomDecimal.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Sbyte.GetHashCode();
         hashCode = (hashCode * 397) ^ StringField.GetHashCode();
         hashCode = (hashCode * 397) ^ Short.GetHashCode();
         hashCode = (hashCode * 397) ^ Int;
         hashCode = (hashCode * 397) ^ Long.GetHashCode();
         hashCode = (hashCode * 397) ^ Byte.GetHashCode();
         hashCode = (hashCode * 397) ^ UShort.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)UInt;
         hashCode = (hashCode * 397) ^ ULong.GetHashCode();
         hashCode = (hashCode * 397) ^ Char.GetHashCode();
         hashCode = (hashCode * 397) ^ Float.GetHashCode();
         hashCode = (hashCode * 397) ^ Double.GetHashCode();
         hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
         hashCode = (hashCode * 397) ^ Boolean.GetHashCode();
         return(hashCode);
     }
 }
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Bool.GetHashCode();
         hashCode = (hashCode * 397) ^ Byte.GetHashCode();
         hashCode = (hashCode * 397) ^ Character.GetHashCode();
         hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
         hashCode = (hashCode * 397) ^ Double.GetHashCode();
         hashCode = (hashCode * 397) ^ Float.GetHashCode();
         hashCode = (hashCode * 397) ^ Int;
         hashCode = (hashCode * 397) ^ Long.GetHashCode();
         hashCode = (hashCode * 397) ^ SByte.GetHashCode();
         hashCode = (hashCode * 397) ^ Short.GetHashCode();
         hashCode = (hashCode * 397) ^ (String != null ? String.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)UInt;
         hashCode = (hashCode * 397) ^ UShort.GetHashCode();
         hashCode = (hashCode * 397) ^ ULong.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Byte.GetHashCode();
         hashCode = (hashCode * 397) ^ SByte.GetHashCode();
         hashCode = (hashCode * 397) ^ Short.GetHashCode();
         hashCode = (hashCode * 397) ^ UShort.GetHashCode();
         hashCode = (hashCode * 397) ^ Int;
         hashCode = (hashCode * 397) ^ (int)UInt;
         hashCode = (hashCode * 397) ^ Long.GetHashCode();
         hashCode = (hashCode * 397) ^ ULong.GetHashCode();
         hashCode = (hashCode * 397) ^ Float.GetHashCode();
         hashCode = (hashCode * 397) ^ Double.GetHashCode();
         hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
         hashCode = (hashCode * 397) ^ Guid.GetHashCode();
         hashCode = (hashCode * 397) ^ String.GetHashCode();
         hashCode = (hashCode * 397) ^ Key.GetHashCode();
         return(hashCode);
     }
 }
 public static ULong BigSquare(ULong value, out ULong highResult)
 {
     unchecked {
         if (ULong_Misc.Size > UIntPtr_Misc.Size)
         {
             // 2013Oct04
             var fl = (UInt)value;
             var fh = (UInt)(value >> UInt_Misc.BitSizeAsIntUnchecked);
             var ll = (ULong)fl * fl;
             var lh = (ULong)fl * fh;
             var hl = lh;
             var hh = (ULong)fh * fh;
             lh += (UInt)(ll >> UInt_Misc.BitSizeAsIntUnchecked);
             lh += hl;
             if (lh < hl)
             {
                 hh += (ULong)1u << UInt_Misc.BitSizeAsIntUnchecked;
             }
             highResult = hh + (UInt)(lh >> UInt_Misc.BitSizeAsIntUnchecked);
             return(((ULong)(UInt)lh << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)(ll));
         }
         {
             // 2013Oct04
             var fl = (ULong)(UInt)value;
             var fh = (ULong)(UInt)(value >> UInt_Misc.BitSizeAsIntUnchecked);
             var ll = fl * fl;
             var lh = fl * fh;
             var hl = lh;
             var hh = fh * fh;
             lh += ll >> UInt_Misc.BitSizeAsIntUnchecked;
             lh += hl;
             if (lh < hl)
             {
                 hh += (ULong)1u << UInt_Misc.BitSizeAsIntUnchecked;
             }
             highResult = hh + (lh >> UInt_Misc.BitSizeAsIntUnchecked);
             return((lh << UInt_Misc.BitSizeAsIntUnchecked) + (UInt)(ll));
         }
     }
 }
        private static ulong?DoHash(Object o, ULong hash, Dictionary <string, ulong> savedHashes, bool hashingType = false)
        {
            if (o != null)
            {
                unchecked {
                    ulong obj = 0;
                    if (o is String || o is double || o is float || o is decimal)
                    {
                        var s = o.ToString();
                        if (savedHashes.ContainsKey(s))
                        {
                            obj = savedHashes[s];
                        }
                        else
                        {
                            foreach (var c in s)
                            {
                                obj += c;
                            }
                            savedHashes[s] = obj;
                        }
                    }
                    else
                    {
                        obj = Convert.ToUInt64(CastToUnsigned(o));
                    }

                    hash.Value = (hash.Value * 397) ^ obj;

                    if (!hashingType)
                    {
                        DoHash(o.GetType().ToString(), hash, savedHashes, true);
                    }

                    return(hash.Value);
                }
            }
            return(0);
        }
 public static ULong BigMul(ULong first_lo, ULong first_hi, ULong second_lo, ULong second_hi, out ULong result_lo_hi, out ULong result_hi_lo, out ULong result_hi_hi)
 {
     unchecked {
         var fl  = first_lo;
         var fh  = first_hi;
         var sl  = second_lo;
         var sh  = second_hi;
         var lll = BigMul(fl, sl, out ULong llh);
         var hhl = BigMul(fh, sh, out ULong hhh);
         var fm  = unchecked (fh + fl);
         var sm  = unchecked (sh + sl);
         var tl  = AddUnchecked(hhl, hhh, lll, llh, out ULong th);
         var mml = BigMul(fm, sm, out ULong mmh);
         if (fm < fl)
         {
             mml = AddUnchecked(mml, mmh, 0, sm, out mmh);
         }
         if (sm < sl)
         {
             mml = AddUnchecked(mml, mmh, 0, fm, out mmh);
         }
         mml = SubtractUnchecked(mml, mmh, tl, th, out mmh);
         llh = unchecked (llh + mml);
         hhl = AddUnchecked(hhl, hhh, mmh, 0, out hhh);
         var m = unchecked (fm + sm);
         var n = (m >> 1) | (m < sm ? ((ULong)1) << (64 - 1) : 0);
         if (n < mmh)
         {
             unchecked {
                 --hhh;
             }
         }
         result_hi_hi = hhh;
         result_hi_lo = hhl;
         result_lo_hi = llh;
         return(lll);
     }
 }
 // ~ 192 Cyc (special input set test6)
 public static ULong Remainder(ULong lowDividend, Long highDividend, ULong lowDivisor, Long highDivisor, out Long highResult)
 {
     unchecked {
         Long s = highDividend, t = highDivisor;
         if (0 > highDivisor)
         {
             lowDivisor = MathEx.NegateUnchecked(lowDivisor, highDivisor, out highDivisor);
         }
         if (0 > highDividend)
         {
             lowDividend = MathEx.NegateUnchecked(lowDividend, highDividend, out highDividend);
         }
         ULong lowResult;
         ULong r;
         lowResult = Remainder(lowDividend, (ULong)highDividend, lowDivisor, (ULong)highDivisor, out r);
         if (0 > s)
         {
             lowResult = MathEx.NegateUnchecked(lowResult, r, out r);
         }
         highResult = (Long)r;
         return(lowResult);
     }
 }
        private static void InternalCopy(Object originalObject, ULong hash, Dictionary <string, ulong> savedHashes, HashSet <object> visited)
        {
            if (originalObject == null)
            {
                return;
            }
            var typeToReflect = originalObject.GetType();

            if (IsPrimitive(typeToReflect))
            {
                DoHash(originalObject, hash, savedHashes);
                return;
            }

            if (visited.Contains(originalObject) || typeof(Delegate).IsAssignableFrom(typeToReflect))
            {
                return;
            }

            if (typeToReflect.IsArray)
            {
                var arrayType = typeToReflect.GetElementType();
                if (!IsPrimitive(arrayType))
                {
                    Array clonedArray = (Array)originalObject;
                    clonedArray.ForEach((array, indices) => InternalCopy(clonedArray.GetValue(indices), hash, savedHashes, visited));
                }
            }

            visited.Add(originalObject);
            CopyFields(originalObject, hash, savedHashes, visited, typeToReflect);
            RecursiveCopyBaseTypePrivateFields(originalObject, hash, savedHashes, visited, typeToReflect);

            //DoHash(cloneObject, hash);
            //return;
        }
Esempio n. 10
0
        private static bool FullCompare(RvBase var1, RvBase var2)
        {
            int retv = DBHelper.CompareName(var1, var2);

            if (retv != 0)
            {
                return(false);
            }

            FileType v1 = var1.FileType;
            FileType v2 = var2.FileType;

            retv = Math.Sign(v1.CompareTo(v2));
            if (retv != 0)
            {
                return(false);
            }

            // filetypes are now know to be the same

            // Dir's and Zip's are not deep scanned so matching here is done
            if ((v1 == FileType.Dir) || (v1 == FileType.Zip))
            {
                return(true);
            }

            RvFile f1 = (RvFile)var1;
            RvFile f2 = (RvFile)var2;

            if (f1.Size != null && f2.Size != null)
            {
                retv = ULong.iCompare(f1.Size, f2.Size);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (f1.CRC != null && f2.CRC != null)
            {
                retv = ArrByte.iCompare(f1.CRC, f2.CRC);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (f1.SHA1 != null && f2.SHA1 != null)
            {
                retv = ArrByte.iCompare(f1.SHA1, f2.SHA1);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (f1.MD5 != null && f2.MD5 != null)
            {
                retv = ArrByte.iCompare(f1.MD5, f2.MD5);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (f1.SHA1CHD != null && f2.SHA1CHD != null)
            {
                retv = ArrByte.iCompare(f1.SHA1CHD, f2.SHA1CHD);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (f1.MD5CHD != null && f2.MD5CHD != null)
            {
                retv = ArrByte.iCompare(f1.MD5CHD, f2.MD5CHD);
                if (retv != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 11
0
        private static bool FullCompare(RvBase dbFile, RvBase testFile, bool secondPass, string fullDir = "", eScanLevel sLevel = eScanLevel.Level3)
        {
            Debug.WriteLine("Comparing Dat File " + dbFile.TreeFullName);
            Debug.WriteLine("Comparing File     " + testFile.TreeFullName);

            int retv = DBHelper.CompareName(dbFile, testFile);

            if (retv != 0)
            {
                return(false);
            }

            FileType dbfileType = dbFile.FileType;
            FileType dbtestFile = testFile.FileType;

            retv = Math.Sign(dbfileType.CompareTo(dbtestFile));
            if (retv != 0)
            {
                return(false);
            }

            // filetypes are now know to be the same

            // Dir's and Zip's are not deep scanned so matching here is done
            if ((dbfileType == FileType.Dir) || (dbfileType == FileType.Zip))
            {
                return(true);
            }

            RvFile dbFileF   = (RvFile)dbFile;
            RvFile testFileF = (RvFile)testFile;


            if (dbFileF.Size != null && testFileF.Size != null)
            {
                retv = ULong.iCompare(dbFileF.Size, testFileF.Size);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFileF.CRC != null && testFileF.CRC != null)
            {
                retv = ArrByte.iCompare(dbFileF.CRC, testFileF.CRC);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFileF.SHA1 != null && testFileF.SHA1 != null)
            {
                retv = ArrByte.iCompare(dbFileF.SHA1, testFileF.SHA1);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFileF.MD5 != null && testFileF.MD5 != null)
            {
                retv = ArrByte.iCompare(dbFileF.MD5, testFileF.MD5);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFileF.SHA1CHD != null && testFileF.SHA1CHD != null)
            {
                retv = ArrByte.iCompare(dbFileF.SHA1CHD, testFileF.SHA1CHD);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFileF.MD5CHD != null && testFileF.MD5CHD != null)
            {
                retv = ArrByte.iCompare(dbFileF.MD5CHD, testFileF.MD5CHD);
                if (retv != 0)
                {
                    return(false);
                }
            }

            // beyond here we only test files
            if (dbtestFile != FileType.File)
            {
                return(true);
            }

            // if scanning at level 3 then we have already deep checked the file so all is OK.
            if (sLevel == eScanLevel.Level3)
            {
                return(true);
            }

            // if we got this far then everything we have so far has matched, but that may not be enough.
            // now we see if we need to get any more info and try again.


            // if the file stamps do not match or the file in the DB we are comparing with has not been deep scanned
            // and the file we are scanning has not already been deep scanned, then we need to do a deep scan, and check the deep scan values

            // files are always deep scanned, so the test for IsDeepScanned(dbFileF) is probably not really needed here.

            if ((dbFileF.TimeStamp != testFileF.TimeStamp || !IsDeepScanned(dbFileF)) && !IsDeepScanned(testFileF))
            {
                if (!secondPass)
                {
                    return(false);
                }

                DeepScanFile(fullDir, testFileF);
                if (dbFileF.CRC != null && testFileF.CRC != null)
                {
                    retv = ArrByte.iCompare(dbFileF.CRC, testFileF.CRC);
                    if (retv != 0)
                    {
                        return(false);
                    }
                }

                if (dbFileF.SHA1 != null && testFileF.SHA1 != null)
                {
                    retv = ArrByte.iCompare(dbFileF.SHA1, testFileF.SHA1);
                    if (retv != 0)
                    {
                        return(false);
                    }
                }

                if (dbFileF.MD5 != null && testFileF.MD5 != null)
                {
                    retv = ArrByte.iCompare(dbFileF.MD5, testFileF.MD5);
                    if (retv != 0)
                    {
                        return(false);
                    }
                }
            }

            // CHDman test, if we are only scanning at level 1 then don't do CHDman test so we are done.
            if (sLevel == eScanLevel.Level1)
            {
                return(true);
            }

            if ((dbFileF.TimeStamp != testFileF.TimeStamp || (!IschdmanScanned(dbFileF)) && !IschdmanScanned(testFileF)))
            {
                ChdManCheck(fullDir, testFileF);
            }
            return(true);
        }
 public static ULong BigSquare(ULong value_lo, ULong value_hi, out ULong result_lo_hi, out ULong result_hi_lo, out ULong result_hi_hi)
 {
     unchecked {
         {
             // 2017Nov18
             var fl  = value_lo;
             var fh  = value_hi;
             var lll = BigMul(fl, fl, out ULong llh);
             var lhl = BigMul(fl, fh, out ULong lhh);
             var hll = lhl;
             var hlh = lhh;
             var hhl = BigMul(fh, fh, out ULong hhh);
             lhl = AddUnchecked(lhl, lhh, llh, 0, out lhh);
             lhl = AddUnchecked(lhl, lhh, hll, hlh, out lhh);
             if (LessThan(lhl, lhh, hll, hlh))
             {
                 unchecked {
                     ++hhh;
                 }
             }
             result_hi_lo = AddUnchecked(hhl, hhh, lhh, 0, out result_hi_hi);
             result_lo_hi = lhl;
             return(lll);
         }
     }
 }
 // [outdated] 91.3 Cyc (special input set test6)
 public static ULong Divide(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong highResult)
 {
     return(DivideUnchecked(lowDividend, highDividend, lowDivisor, highDivisor, out highResult));
 }
Esempio n. 14
0
            public int Compare(RvFile x, RvFile y)
            {
                int retVal = 0;

                switch ((eRomGrid)_colIndex)
                {
                case eRomGrid.Got:       // then by name
                    retVal = x.GotStatus - y.GotStatus;
                    if (retVal != 0)
                    {
                        break;
                    }
                    retVal = x.RepStatus - y.RepStatus;
                    if (retVal != 0)
                    {
                        break;
                    }
                    retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal);
                    break;

                case eRomGrid.Rom:
                    retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal);
                    break;

                case eRomGrid.Merge:
                    retVal = string.Compare(x.Merge ?? "", y.Merge ?? "", StringComparison.Ordinal);
                    break;

                case eRomGrid.Size:
                    retVal = ULong.iCompareNull(x.Size, y.Size);
                    break;

                case eRomGrid.CRC32:
                    retVal = ArrByte.ICompare(x.CRC, y.CRC);
                    break;

                case eRomGrid.SHA1:
                    retVal = ArrByte.ICompare(x.SHA1, y.SHA1);
                    break;

                case eRomGrid.MD5:
                    retVal = ArrByte.ICompare(x.MD5, y.MD5);
                    break;

                case eRomGrid.AltSize:
                    retVal = ULong.iCompareNull(x.AltSize, y.AltSize);
                    break;

                case eRomGrid.AltCRC32:
                    retVal = ArrByte.ICompare(x.AltCRC, y.AltCRC);
                    break;

                case eRomGrid.AltSHA1:
                    retVal = ArrByte.ICompare(x.AltSHA1, y.AltSHA1);
                    break;

                case eRomGrid.AltMD5:
                    retVal = ArrByte.ICompare(x.AltMD5, y.AltMD5);
                    break;

                case eRomGrid.Status:
                    retVal = string.Compare(x.Status ?? "", y.Status ?? "", StringComparison.Ordinal);
                    break;
                }

                if (_sortDir == SortOrder.Descending)
                {
                    retVal = -retVal;
                }

                if (retVal == 0 && _colIndex != 1)
                {
                    retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal);
                }

                return(retVal);
            }
Esempio n. 15
0
		internal void Process_StillEvents( KeyboardDevice keyboard )
		{
			if( !GameEnv.Game_Run )
				return;

			if( keyboard[Key.I] && !keydown.Contains( Key.I ) )
			{
				keydown.Add( Key.I );
				if( GameEnv.GameWindow_Storage.Is_Shown() ) { GameEnv.GameWindow_Storage.Hide(); }
				//else if( GameEnv.GameWindow_Programmable.Is_Shown() ) { GameEnv.GameWindow_Programmable.Hide(); }
				//else if( GameEnv.GameWindow_UserTextureTransformer.Is_Shown() ) { GameEnv.GameWindow_UserTextureTransformer.Hide(); }
				//else if( GameEnv.GameWindow_Sequencer.Is_Shown() ) { GameEnv.GameWindow_Sequencer.Hide(); }
				else
				{
					GameEnv.GameWindow_Inventory.SetGameEnv( GameEnv );
					if( GameEnv.GameWindow_Inventory.Is_Shown() ) GameEnv.GameWindow_Inventory.Hide();
					else GameEnv.GameWindow_Inventory.Show();
				}
			}
			else
				keydown.Remove( Key.I );

#if asdsadf
			Actor Actor;
			ZSettings_Hardware* Settings_Hardware;

			Settings_Hardware = GameEnv.Settings_Hardware;
			Actor = GameEnv.GetActiveActor();

			// Process actor Still event

			if( Actor ) if( !Actor.Action_StillEvents( Mouse_Matrix, Keyboard_Matrix ) ) return;

			// Process default still events

			if( Actor )
			{

				if( Keyboard_Matrix[SDLK_LSHIFT] || Keyboard_Matrix[SDLK_CAPSLOCK] ) { Actor.Flag_ActivateAntiFall = true; }
				else { Actor.Flag_ActivateAntiFall = false; }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_MoveLeft] ) { Actor.Action_GoLeftStraff(); }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_MoveRight] ) { Actor.Action_GoRightStraff(); }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_MoveForward] ) { Actor.Action_GoForward(); }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_MoveBackward] ) { Actor.Action_GoBackward(); }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_MoveUp] && ( COMPILEOPTION_DEBUGFACILITY || GameEnv.Settings_Hardware.Experimental_LearningMode ) ) { Actor.Action_GoUp(); }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_MoveDown] && ( COMPILEOPTION_DEBUGFACILITY || GameEnv.Settings_Hardware.Experimental_LearningMode ) ) { Actor.Action_GoDown(); }
				if( Keyboard_Matrix[Settings_Hardware.Setting_Key_Jump] ) { Actor.Action_Jump(); }
				if( Keyboard_Matrix[SDLK_e] ) { Actor.Action_GetInOutOfVehicle(); }
				//if ( Keyboard_Matrix[SDLK_a] )                                     { Actor.Action_GoUp(GameEnv.Time_GameLoop  * 1.5); }
				if( Keyboard_Matrix[SDLK_h] && COMPILEOPTION_DEBUGFACILITY ) { Actor.Action_GoFastForward( 500.0 ); }
				if( Keyboard_Matrix[SDLK_DELETE] && !COMPILEOPTION_DEBUGFACILITY ) { Actor.LifePoints = 0.0; }
				if( Keyboard_Matrix[SDLK_KP0] && ( COMPILEOPTION_DEBUGFACILITY || GameEnv.Settings_Hardware.Experimental_LearningMode ) ) { Actor.Action_SetActorMode( 0 ); }
				if( Keyboard_Matrix[SDLK_KP1] && COMPILEOPTION_DEBUGFACILITY ) { Actor.Action_SetActorMode( 1 ); }
				if( Keyboard_Matrix[SDLK_KP2] && COMPILEOPTION_DEBUGFACILITY ) { Actor.Action_SetActorMode( 2 ); }
				if( Keyboard_Matrix[SDLK_KP3] && ( COMPILEOPTION_DEBUGFACILITY || GameEnv.Settings_Hardware.Experimental_LearningMode ) ) { Actor.Action_SetActorMode( 3 ); }
				if( Keyboard_Matrix[SDLK_KP4] && COMPILEOPTION_DEBUGFACILITY ) { Actor.Action_SetActorMode( 4 ); }
				if( Keyboard_Matrix[SDLK_KP5] && COMPILEOPTION_DEBUGFACILITY )
				{
					if( !Keyboard_Matrix[SDLK_LSHIFT] )
					{
						ZVector3d Position; Position = 0.0; Position.y = 2048000 * 1.0; Actor.SetPosition( Position );

						Actor.ViewDirection.RotateAbsolute( 0, 360.0 - 90.0, 0 );
					}
					else
					{
						ZVector3d Position; Position = 0.0;
						Actor.SetPosition( Position );
						Actor.ViewDirection.RotateAbsolute( 0, 0, 0 );
					}
				}

				if( Keyboard_Matrix[SDLK_KP8] && COMPILEOPTION_DEBUGFACILITY ) { ZVector3d Position; Position = 0.0; Position.y = 6000.0 * GlobalSettings.VoxelBlockSize; Actor.SetPosition( Position ); }
				if( Keyboard_Matrix[SDLK_KP7] && COMPILEOPTION_DEBUGFACILITY )
				{
					//GameEnv.Sound.PlaySound(1);
					GameEnv.Sound.Start_PlaySound( 1, false, true, 0.125, 0 );
					Keyboard_Matrix[SDLK_KP7] = 0;
					printf( "x,y,z : %lf,%lf,%lf\n", Actor.ViewDirection.origin().x, Actor.ViewDirection.origin().y, Actor.ViewDirection.origin().z );

					{
						UShort VoxelType;
						ULong* Table, x, y, z, i, SectorCount, VoxelCount, NonVoidCount;

						Table = new ULong[65536];
						for( i = 0; i < 65536; i++ ) Table[i] = 0;


						ZVoxelSector* Sector;
						Sector = GameEnv.World.SectorList;

						SectorCount = 0;
						VoxelCount = 0;
						NonVoidCount = 0;
						while( Sector )
						{
							for( z = 0; z < ZVOXELBLOCSIZE_Z; z++ )
								for( x = 0; x < ZVOXELBLOCSIZE_X; x++ )
									for( y = 0; y < ZVOXELBLOCSIZE_Y; y++ )
									{
										VoxelType = Sector.GetCube( x, y, z );
										if( VoxelType != 0 ) { Table[VoxelType]++; NonVoidCount++; }
										VoxelCount++;
									}
							SectorCount++;
							Sector = Sector.GlobalList_Next;
						}

						printf( "--------------------------------Stats-------------------------------\n" );
						printf( "Scanned sectors : %d\n", SectorCount );
						printf( "Voxels per sector : %d\n", ZVOXELBLOCSIZE_X * ZVOXELBLOCSIZE_Y * ZVOXELBLOCSIZE_Z );
						printf( "Total Voxel Count : %d\n", VoxelCount );
						printf( "Non empty : %d\n", NonVoidCount );
						double PercentOfVoxel;
						PercentOfVoxel = 100.0 / ( (double)NonVoidCount );

						double Time_ToFindAFilon;
						for( i = 0; i < 65536; i++ )
						{
							if( Table[i] > 0 )
							{
								Time_ToFindAFilon = ( (double)NonVoidCount ) / ( (double)Table[i] ) / 3.0 * 1.25 / 60.0;
								printf( "[%d]=%d : %s (%lf %%) TMoy :%lf Min \n", i, Table[i], GameEnv.VoxelTypeManager.VoxelTable[i].VoxelTypeName.String, ( (double)Table[i] ) * PercentOfVoxel, Time_ToFindAFilon );
							}
						}

						delete[] Table;

						ZWorld_Stat Stat;
						Stat.SetWorld( GameEnv.World );
						// Stat.Get_Stat_DistanceToMineForVoxelType(74);

					}

				}



				if( Keyboard_Matrix[SDLK_j] && COMPILEOPTION_DEBUGFACILITY && false )
				{
					Keyboard_Matrix[SDLK_j] = 0;

					Actor Actor;
					ZInventory* Inventory;
					ULong c = 0;

					Actor = GameEnv.GetActiveActor();
					if( Actor != 0 )
					{
						Inventory = Actor.Inventory;
						if( Inventory != 0 )
						{
							Inventory.SetSlot( c++, 1, 4096 );  // 01
							Inventory.SetSlot( c++, 2, 4096 );  // 02
							Inventory.SetSlot( c++, 3, 4096 );  // 03
							Inventory.SetSlot( c++, 4, 4096 );  // 04
							Inventory.SetSlot( c++, 5, 4096 );  // 05
							Inventory.SetSlot( c++, 6, 4096 );  // 06
							Inventory.SetSlot( c++, 7, 4096 );  // 07
							Inventory.SetSlot( c++, 8, 4096 );  // 08
							Inventory.SetSlot( c++, 9, 4096 );  // 09
							Inventory.SetSlot( c++, 10, 4096 ); // 10
							Inventory.SetSlot( c++, 11, 4096 ); // 11
							Inventory.SetSlot( c++, 12, 4096 ); // 12
																 //Inventory.SetSlot(c++,13,4096);
							Inventory.SetSlot( c++, 14, 4096 ); // 13
																 // Inventory.SetSlot(c++,15,4096);
							Inventory.SetSlot( c++, 16, 4096 ); // 14
							Inventory.SetSlot( c++, 17, 4096 ); // 15
							Inventory.SetSlot( c++, 18, 4096 ); // 16
							Inventory.SetSlot( c++, 19, 4096 ); // 17
							Inventory.SetSlot( c++, 38, 4096 ); // 18
							Inventory.SetSlot( c++, 39, 4096 ); // 19
							Inventory.SetSlot( c++, 20, 4096 ); // 20
							Inventory.SetSlot( c++, 21, 4096 ); // 21
							Inventory.SetSlot( c++, 22, 4096 ); // 22
							Inventory.SetSlot( c++, 80, 4096 ); // 23
							Inventory.SetSlot( c++, 81, 4096 ); // 24
							Inventory.SetSlot( c++, 82, 4096 ); // 25
																 // Inventory.SetSlot(c++,23,4096);
																 // Inventory.SetSlot(c++,24,4096);
																 // Inventory.SetSlot(c++,25,4096);
							Inventory.SetSlot( c++, 26, 4096 ); // 26
							Inventory.SetSlot( c++, 27, 4096 ); // 27
							Inventory.SetSlot( c++, 28, 4096 ); // 28
																 // Inventory.SetSlot(c++,29,4096);
							Inventory.SetSlot( c++, 30, 4096 ); // 29
							Inventory.SetSlot( c++, 31, 4096 ); // 30
							Inventory.SetSlot( c++, 32, 4096 ); // 31
							Inventory.SetSlot( c++, 33, 4096 ); // 32
							Inventory.SetSlot( c++, 34, 4096 ); // 33
							Inventory.SetSlot( c++, 35, 4096 ); // 34
							Inventory.SetSlot( c++, 36, 4096 ); // 35
							Inventory.SetSlot( c++, 37, 4096 ); // 36

							Inventory.SetSlot( c++, 46, 4096 );   // 01
							Inventory.SetSlot( c++, 47, 4096 );   // 02
							Inventory.SetSlot( c++, 53, 4096 );   // 04
																   //Inventory.SetSlot(c++,42,4096);

							Inventory.SetSlot( c++, 44, 4096 ); // 40
																 //Inventory.SetSlot(c++,45,4096);


							c = 40;
							Inventory.SetSlot( c++, 77, 1 );
							Inventory.SetSlot( c++, 75, 1 );
							Inventory.SetSlot( c++, 42, 1 );
							Inventory.SetSlot( c++, 76, 1 );
							Inventory.SetSlot( c++, 78, 1 );
							Inventory.SetSlot( c++, 79, 1 );
							c = 0;
							Inventory.SetSlot( c++, 236, 100 );
							Inventory.SetSlot( c++, 237, 100 );
							Inventory.SetSlot( c++, 238, 100 );
							Inventory.SetSlot( c++, 239, 100 );
							Inventory.SetSlot( c++, 240, 100 );
							Inventory.SetSlot( c++, 241, 100 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );


						}

					}
				}

				if( Keyboard_Matrix[SDLK_k] && COMPILEOPTION_DEBUGFACILITY && false )
				{
					Keyboard_Matrix[SDLK_k] = 0;

					Actor Actor;
					ZInventory* Inventory;
					ULong c = 0;

					Actor = GameEnv.GetActiveActor();
					if( Actor != 0 )
					{
						Inventory = Actor.Inventory;
						if( Inventory != 0 )
						{
							Inventory.SetSlot( c++, 40, 4096 ); // 37

							Inventory.SetSlot( c++, 41, 4096 ); // 38
							Inventory.SetSlot( c++, 43, 4096 ); // 39

							//Inventory.SetSlot(c++,48,4096);
							// Inventory.SetSlot(c++,50,4096);
							// Inventory.SetSlot(c++,51,4096);
							Inventory.SetSlot( c++, 52, 4096 );   // 03

							Inventory.SetSlot( c++, 54, 4096 );   // 05
							Inventory.SetSlot( c++, 55, 4096 );   // 06
																   //Inventory.SetSlot(c++,56,4096);
																   //Inventory.SetSlot(c++,57,4096);
																   //Inventory.SetSlot(c++,58,4096);
																   //Inventory.SetSlot(c++,59,4096);
							Inventory.SetSlot( c++, 60, 4096 );   // 07
							Inventory.SetSlot( c++, 61, 4096 );   // 08
							Inventory.SetSlot( c++, 62, 4096 );   // 09
							Inventory.SetSlot( c++, 63, 4096 );   // 10
							Inventory.SetSlot( c++, 64, 4096 );   // 11
																   //Inventory.SetSlot(c++,65,4096);
							Inventory.SetSlot( c++, 66, 4096 );   // 12
							Inventory.SetSlot( c++, 67, 4096 );   // 13
							Inventory.SetSlot( c++, 68, 4096 );   // 14
							Inventory.SetSlot( c++, 69, 4096 );   // 15
							Inventory.SetSlot( c++, 70, 4096 );   // 16
																   // Inventory.SetSlot(c++,71,4096);
							Inventory.SetSlot( c++, 72, 4096 );   // 17
																   //Inventory.SetSlot(c++,73,4096);
							Inventory.SetSlot( c++, 74, 4096 );   // 18
																   // Inventory.SetSlot(c++,75,4096);
																   // Inventory.SetSlot(c++,76,4096);
																   // Inventory.SetSlot(c++,77,4096);
																   // Inventory.SetSlot(c++,78,4096);
																   // Inventory.SetSlot(c++,79,4096);

							Inventory.SetSlot( c++, 83, 4096 );   // 19

							// Inventory.SetSlot(c++,86,4096);
							Inventory.SetSlot( c++, 109, 4096 );
							Inventory.SetSlot( c++, 110, 4096 );
							Inventory.SetSlot( c++, 111, 4096 );
							Inventory.SetSlot( c++, 112, 4096 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							c = 40;
							Inventory.SetSlot( c++, 77, 1 );
							Inventory.SetSlot( c++, 75, 1 );
							Inventory.SetSlot( c++, 42, 1 );
							Inventory.SetSlot( c++, 76, 1 );
							Inventory.SetSlot( c++, 78, 1 );
							Inventory.SetSlot( c++, 79, 1 );
							c = 50;
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.SetSlot( c++, 0, 0 );

						}

					}
				}

				if( Keyboard_Matrix[SDLK_l] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_l] = 0;

					Actor Actor;
					ZInventory* Inventory;
					ULong c = 0;

					Actor = GameEnv.GetActiveActor();
					if( Actor != 0 )
					{
						Inventory = Actor.Inventory;
						if( Inventory != 0 )
						{
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 99, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 100, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 101, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 102, 4096 );
							// Inventory.SetSlot(c++,89,4096);
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 90, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 52, 4096 );
							// Inventory.SetSlot(c++,91,4096);
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 87, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 92, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 85, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 88, 4096 );
							Inventory.FindFreeSlot( c );
							// Inventory.SetSlot(c++,93,4096);
							Inventory.SetSlot( c++, 94, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 95, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 84, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 97, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 98, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 49, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 96, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 108, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 107, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 0, 0 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 103, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 104, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 105, 4096 );
							Inventory.FindFreeSlot( c );
							Inventory.SetSlot( c++, 106, 4096 );
							/*
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							*/
							c = 40;
							Inventory.SetSlot( c++, 77, 1 );
							Inventory.SetSlot( c++, 75, 1 );
							Inventory.SetSlot( c++, 42, 1 );
							Inventory.SetSlot( c++, 76, 1 );
							Inventory.SetSlot( c++, 78, 1 );
							Inventory.SetSlot( c++, 79, 1 );
							c = 50;
							/*
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							Inventory.SetSlot(c++,0,0);
							*/
						}

					}
				}

				//if ( Keyboard_Matrix[SDLK_w] )                                       { Actor.Action_GoDown(GameEnv.Time_GameLoop  * 1.5); }
				if( Keyboard_Matrix[SDLK_g] && COMPILEOPTION_DEBUGFACILITY ) { Actor.Velocity.y = 10000.0; }
				if( Keyboard_Matrix[SDLK_KP_PLUS] && COMPILEOPTION_DEBUGFACILITY )
				{
					if( Keyboard_Matrix[SDLK_LSHIFT] ) { for( ULong i = 0; i < 10; i++ ) Actor.Action_NextBuildingMaterial(); }
					else Actor.Action_NextBuildingMaterial();
					Keyboard_Matrix[SDLK_KP_PLUS] = 0;
				}
				if( Keyboard_Matrix[SDLK_KP_MINUS] && COMPILEOPTION_DEBUGFACILITY )
				{
					if( Keyboard_Matrix[SDLK_LSHIFT] ) { for( ULong i = 0; i < 10; i++ ) Actor.Action_PrevBuildingMaterial(); }
					Actor.Action_PrevBuildingMaterial();
					Keyboard_Matrix[SDLK_KP_MINUS] = 0;
				}
				if( Keyboard_Matrix[SDLK_t] && COMPILEOPTION_DEBUGFACILITY ) { ZInventory::Entry* Entry = Actor.Inventory.GetSlotRef( Actor.Inventory.GetActualItemSlotNum() ); Entry.VoxelType = Actor.BuildingMaterial; Entry.Quantity = 8192 * 1; }
				if( Keyboard_Matrix[SDLK_F1] ) { GameEnv.Mouse_relative = false; SDL_WM_GrabInput( SDL_GRAB_OFF ); SDL_ShowCursor( SDL_ENABLE ); }
				if( Keyboard_Matrix[SDLK_F2] ) { GameEnv.Mouse_relative = true; SDL_WM_GrabInput( SDL_GRAB_ON ); SDL_ShowCursor( SDL_DISABLE ); }
				if( Keyboard_Matrix[SDLK_F3] && COMPILEOPTION_DEBUGFACILITY ) { SDL_WM_GrabInput( SDL_GRAB_OFF ); SDL_ShowCursor( SDL_DISABLE ); }
				if( Keyboard_Matrix[SDLK_F5] ) { GameEnv.World.Save(); }
				if( Keyboard_Matrix[SDLK_F4] )
				{
					ZString Infos;
					Long x, y, z;

					x = GameEnv.GetActiveActor().PointedVoxel.PointedVoxel.x;
					y = GameEnv.GetActiveActor().PointedVoxel.PointedVoxel.y;
					z = GameEnv.GetActiveActor().PointedVoxel.PointedVoxel.z;

					GameEnv.PointList.AddPosition( x, y, z );
					printf( "-----------------Highlighted Voxel Analysis-------------\n" );
					printf( "Voxel Location : %d,%d,%d\n", x, y, z );
					printf( "VoxelType : %d\n", GameEnv.World.GetVoxel( x, y, z ) );
					VoxelLocation Loc;
					if( GameEnv.World.GetVoxelLocation( &Loc, x, y, z ) )
					{
						printf( "Voxel Name : %s\n", GameEnv.VoxelTypeManager.VoxelTable[Loc.Sector.Data.Data[Loc.Offset]].VoxelTypeName.String );
						GameEnv.VoxelTypeManager.VoxelTable[Loc.Sector.Data.Data[Loc.Offset]].GetBlockInformations( &Loc, Infos );
						printf( "Sector Location : %d,%d,%d\n", Loc.Sector.Pos_x, Loc.Sector.Pos_y, Loc.Sector.Pos_z );
						printf( "Zone Coords : %d,%d\n", ( ( ( Loc.Sector.Pos_x ) >> 4 ) + 32 + 1 ), ( ( ( Loc.Sector.Pos_z ) >> 4 ) + 32 + 1 ) );
						printf( "%s\n", Infos.String );
					}

					Keyboard_Matrix[SDLK_F4] = 0;
				}


				if( Keyboard_Matrix[SDLK_F6] )
				{
					Keyboard_Matrix[SDLK_F6] = 0;
					GameEnv.Basic_Renderer.BvProp_DisplayCrossHair = !GameEnv.Basic_Renderer.BvProp_DisplayCrossHair;
					GameEnv.Basic_Renderer.BvProp_DisplayVoxelSelector = GameEnv.Basic_Renderer.BvProp_DisplayCrossHair;

					/* GameEnv.World.Purge(89); */
				}
				if( Keyboard_Matrix[SDLK_F9] && COMPILEOPTION_DEBUGFACILITY ) { /* GameEnv.World.Load();*/ }
				if( Keyboard_Matrix[SDLK_F7] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_F7] = 0;

					GameEnv.World.Purge( 85 );


					if( 0 ) // Test code bloc
					{
						GameEnv.VoxelTypeManager.DumpInfos();
						ZVoxelSector* Sector;
						bool AllSectorsAreHere;
						Long x, y, z;

						AllSectorsAreHere = true;
						for( x = -5; x <= 5; x++ )
							for( y = 0; y <= 2; y++ )
								for( z = -5; z <= 5; z++ )
								{
									if( 0 == GameEnv.World.FindSector( x, y, z ) ) { AllSectorsAreHere = false; printf( "Missing:%lx,%lx,%lx\n", (UNum)x, (UNum)y, (UNum)z ); GameEnv.World.RequestSector( x, y, z, 4 ); }
								}

						if( AllSectorsAreHere )
						{
							ZVoxelGfx_Tree TreeMaker;
							printf( "Entering tree creation\n" );
							/*
							ZVoxelSector * NewSector;
							NewSector=new ZVoxelSector(128,128,128);
							NewSector.SetVoxelTypeManager(GameEnv.World.VoxelTypeManager);
							ZRect3L Rect;
							ZRect1d Thickness;
							Thickness.Start = 1.0; Thickness.End = 1.0;
							for (Long i=0;i<128;i+=4) { Rect.sx = i; Rect.sy=2; Rect.sz=3; Rect.ex=i; Rect.ey=2; Rect.ez=125; NewSector.Draw_safe_VoxelLine(&Rect,&Thickness, 1); }

							ZVector3L Sp,Dp,Sz;
							Sp.x = 0; Sp.y = 0; Sp.z = 0;
							Dp.x = 0; Dp.y = 0; Dp.z = 0;
							Sz.x = 16; Sz.y = 64; Sz.z = 16;

							Sector.Draw_safe_3DBlit(NewSector, &Dp, &Sp, &Sz );

					*/
							for( x = -5; x <= 5; x++ )
								for( y = 0; y <= 2; y++ )
									for( z = -5; z <= 5; z++ )
									{
										Sector = GameEnv.World.FindSector( x, y, z );
										ZVector3d Coords;
										// Sector.Draw_safe_Tree_Type_3(&Coords );
										Coords.x = ( 40 ) - ( Sector.Pos_x * 16 ); Coords.y = -Sector.Pos_y * 64; Coords.z = ( 40 ) - ( Sector.Pos_z * 16 );
										Sector.Fill( 0 ); TreeMaker.DrawTree( Sector, &Coords );
										TreeMaker.Seed++;
										Coords.x = ( 110 ) - ( Sector.Pos_x * 16 ); Coords.y = -Sector.Pos_y * 64; Coords.z = ( 80 ) - ( Sector.Pos_z * 16 );
										TreeMaker.DrawTree( Sector, &Coords );
										TreeMaker.Seed++;
										Coords.x = ( 0 ) - ( Sector.Pos_x * 16 ); Coords.y = -Sector.Pos_y * 64; Coords.z = ( 0 ) - ( Sector.Pos_z * 16 );
										TreeMaker.DrawTree( Sector, &Coords );
										TreeMaker.Seed -= 2;
									}

							for( x = -5; x <= 5; x++ )
								for( y = 0; y <= 2; y++ )
									for( z = -5; z <= 5; z++ )
									{
										//GameEnv.World.SectorUpdateFaceCulling(x,y,z,false);
										Sector = GameEnv.World.FindSector( x, y, z );
										for( int r = 0; r < 6; r++ )
											Sector.Flag_Render_Dirty[r] = true;
										Sector.Flag_Void_Regular = true;
										Sector.Flag_Void_Transparent = true;
									}
							TreeMaker.Seed++;
						}
					}
				}
				if( Keyboard_Matrix[SDLK_F8] )
				{
					Actor Actor;
					ZVector3L Position;
					ZVector3L Sector;
					ZVector3L Zone;

					Actor = GameEnv.GetActiveActor();

					Position.x = (Long)( Actor.ViewDirection.origin().x / GlobalSettings.VoxelBlockSize );
					Position.y = (Long)( Actor.ViewDirection.origin().y / GlobalSettings.VoxelBlockSize );
					Position.z = (Long)( Actor.ViewDirection.origin().z / GlobalSettings.VoxelBlockSize );
					Sector.x = Position.x >> 4; Sector.y = Position.y >> 6; Sector.z = Position.z >> 4;
					Zone.x = Position.x >> GlobalSettings.VoxelBlockSizeBits; Zone.y = 0; Zone.z = Position.z >> GlobalSettings.VoxelBlockSizeBits;

					printf( "Pos (%ld,%ld,%ld) Sector (%ld,%ld,%ld) Zone (%ld,%ld,%ld)\n", (UNum)Position.x, (UNum)Position.y, (UNum)Position.z, (UNum)Sector.x, (UNum)Sector.y, (UNum)Sector.z, (UNum)Zone.x, (UNum)Zone.y, (UNum)Zone.z );
				}
				if( Keyboard_Matrix[SDLK_ESCAPE] ) { SDL_WM_GrabInput( SDL_GRAB_OFF ); SDL_ShowCursor( SDL_ENABLE ); GameEnv.Game_Run = false; }

				if( Keyboard_Matrix[SDLK_F11] )
				{
					printf( "Sectors in Memory:%lu ", (UNum)GameEnv.World.Info_GetSectorsInMemory() ); //World.Info_PrintHashStats();
																										 // Needs GL_NVX_gpu_memory_info extension
					GLint Availlable_VRam = 0;
					glGetIntegerv(/*GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX*/ 0x9049, &Availlable_VRam );
					GLint Total_Memory = 0;
					glGetIntegerv(/*GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX*/ 0x9048, &Total_Memory );
					printf( "GPU MEMORY (Ko) Free/Total/Used: %d/%d/%d\n", Availlable_VRam, Total_Memory, Total_Memory - Availlable_VRam );
					Keyboard_Matrix[SDLK_F11] = 0;
				}




				if( Keyboard_Matrix[SDLK_F12] )
				{
					Keyboard_Matrix[SDLK_F12] = 0;

					if( GameEnv.GameWindow_DisplayInfos.Is_Shown() ) { GameEnv.GameWindow_DisplayInfos.Hide(); }
					else { GameEnv.GameWindow_DisplayInfos.Show(); }
				}

				if( Keyboard_Matrix[SDLK_o] && 0 )
				{
					Keyboard_Matrix[SDLK_o] = 0;
					GameEnv.VoxelTypeBar.SetGameEnv( GameEnv );
					if( GameEnv.VoxelTypeBar.Is_Shown() ) GameEnv.VoxelTypeBar.Hide();
					else GameEnv.VoxelTypeBar.Show();
				}

				if( Keyboard_Matrix[SDLK_y] && 0 )
				{
					Keyboard_Matrix[SDLK_y] = 0;

					//GameEnv.GameWindow_Advertising.SetCompletion(50.0f);
					GameEnv.GameWindow_Advertising.Advertise( "Test 1", ZGameWindow_Advertising::VISIBILITY_HIGH, 0, 5000.0, 2000.0 );
					GameEnv.GameWindow_Advertising.Advertise( "C'est un texte completement loufoque pour tester le jeu et la largeur d'ecran excessive, je raconte ma vie, mais je n'aime pas les lorem ipsum", ZGameWindow_Advertising::VISIBILITY_HIGH, 0, 5000.0, 2000.0 );
					GameEnv.GameWindow_Advertising.Advertise( "Ceci est un affichage de test MEDIUM", ZGameWindow_Advertising::VISIBILITY_MEDIUM, 0, 5000.0, 2000.0 );
					GameEnv.GameWindow_Advertising.Advertise( "Ceci est un affichage de test MEDLOW", ZGameWindow_Advertising::VISIBILITY_MEDLOW, 0, 5000.0, 2000.0 );
					GameEnv.GameWindow_Advertising.Advertise( "Ceci est un affichage de test LOW", ZGameWindow_Advertising::VISIBILITY_LOW, 0, 5000.0, 2000.0 );
					GameEnv.GameWindow_Advertising.Advertise( "Ceci est un affichage de test VERYLOW", ZGameWindow_Advertising::VISIBILITY_VERYLOW, 0, 5000.0, 2000.0 );


					GameEnv.GameWindow_Advertising.Advertise( "Ceci est un affichage de test VISIBILITY_VERYHARDTOREAD", ZGameWindow_Advertising::VISIBILITY_VERYHARDTOREAD, 0, 5000.0, 2000.0 );


					// if (GameEnv.GameWindow_Advertising.Is_Shown()) GameEnv.GameWindow_Advertising.Hide();
					// else                                   GameEnv.GameWindow_Advertising.Show();
				}

				if( Keyboard_Matrix[SDLK_END] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_END] = 0;
					GameEnv.Enable_MVI = false;
				}
				if( Keyboard_Matrix[SDLK_HOME] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_HOME] = 0;
					GameEnv.Enable_MVI = true;
				}

				if( Keyboard_Matrix[SDLK_PAGEDOWN] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_PAGEDOWN] = 0;
					GameEnv.Enable_NewSectorRendering = false;
				}
				if( Keyboard_Matrix[SDLK_PAGEUP] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_PAGEUP] = 0;
					GameEnv.Enable_NewSectorRendering = true;
				}

				if( Keyboard_Matrix[SDLK_DELETE] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_DELETE] = 0;
					GameEnv.Enable_LoadNewSector = false;
				}
				if( Keyboard_Matrix[SDLK_INSERT] && COMPILEOPTION_DEBUGFACILITY )
				{
					Keyboard_Matrix[SDLK_INSERT] = 0;
					GameEnv.Enable_LoadNewSector = true;
				}




				// Paste Clipboard
				if( !Keyboard_Matrix[SDLK_LSHIFT] )
				{
					if( Keyboard_Matrix[SDLK_KP_MULTIPLY] && COMPILEOPTION_DEBUGFACILITY )
					{
						Keyboard_Matrix[SDLK_KP_MULTIPLY] = 0;

						if( GameEnv.PointList.GetPositionCount() >= 1 )
						{
							ZVoxelSector Sector;
							ZVector3L Position;

							Position = *GameEnv.PointList.GetPosition( 1 );
							Position.y++;
							Sector.SetNotStandardSize();
							Sector.SetVoxelTypeManager( &GameEnv.VoxelTypeManager );
							if( Sector.Load( 0, "Clipboard.dat" ) )
							{
								GameEnv.World.BlitZoneCopy( &Sector, &Position, Keyboard_Matrix[SDLK_LSHIFT] ? true : false );
							}
						}
					}
				}
				else
				{
					// Test routine for sector blit functions.

					if( Keyboard_Matrix[SDLK_KP_MULTIPLY] && COMPILEOPTION_DEBUGFACILITY )
					{
						Keyboard_Matrix[SDLK_KP_MULTIPLY] = 0;

						if( GameEnv.PointList.GetPositionCount() >= 1 )
						{
							ZVector3L Position, Offset;
							VoxelLocation Loc;

							ZVoxelSector Sector;
							Position = *GameEnv.PointList.GetPosition( 1 );
							Sector.SetNotStandardSize();
							Sector.SetVoxelTypeManager( &GameEnv.VoxelTypeManager );
							Sector.Load( 0, "Clipboard.dat" );
							Offset.x = Sector.Handle_x; Offset.y = Sector.Handle_y; Offset.z = Sector.Handle_z;

							//Offset = 0;

							GameEnv.World.GetVoxelLocation( &Loc, Position.x, Position.y, Position.z );
							Offset.x = ( Position.x & 0xF ) - Offset.x;
							Offset.y = ( Position.y & 0x3F ) - Offset.y;
							Offset.z = ( Position.z & 0xF ) - Offset.z;

							Loc.Sector.BlitSector( &Sector, &Offset );

							//GameEnv.World.SectorUpdateFaceCulling(Loc.Sector.Pos_x, Loc.Sector.Pos_y, Loc.Sector.Pos_z , false);

							for( int r = 0; r < 6; r++ )
								Loc.Sector.Flag_Render_Dirty[r] = true;
							Loc.Sector.Flag_IsDebug = true;

						}

					}
				}

				// Copy clipboard

				// Start Point, End Point, Handle Point

				if( Keyboard_Matrix[SDLK_KP_DIVIDE] && COMPILEOPTION_DEBUGFACILITY )
				{


					Keyboard_Matrix[SDLK_KP_DIVIDE] = 0;

					if( GameEnv.PointList.GetPositionCount() >= 3 )
					{
						ZVector3L Start, End, Offset;
						Long tmp;

						Start = *GameEnv.PointList.GetPosition( 3 );
						End = *GameEnv.PointList.GetPosition( 2 );
						Offset = *GameEnv.PointList.GetPosition( 1 );

						if( Start.x > End.x ) { tmp = Start.x; Start.x = End.x; End.x = tmp; }
						if( Start.y > End.y ) { tmp = Start.y; Start.y = End.y; End.y = tmp; }
						if( Start.z > End.z ) { tmp = Start.z; Start.z = End.z; End.z = tmp; }

						Start.x += 1; Start.z += 1;
						End.x -= 1; End.z -= 1;
						Offset -= Start;

						ZVoxelSector* Sector;
						Sector = GameEnv.World.GetZoneCopy( &Start, &End );
						Sector.SetHandle( Offset.x, Offset.y, Offset.z );
						Sector.SetVoxelTypeManager( &GameEnv.VoxelTypeManager );

						printf( "Enregistrement de la zone (%d,%d,%d) à (%d,%d,%d) taille : (%d,%d,%d) Offset : (%d,%d,%d)\n",
								Start.x, Start.y, Start.z, End.x, End.y, End.z,
								Sector.Size_x, Sector.Size_y, Sector.Size_z,
								Sector.Handle_x, Sector.Handle_y, Sector.Handle_z );

						Sector.Save( 0, "Clipboard.dat" );
						if( Sector != null ) Sector = null;
					}







					// DSector = new ZVoxelSector();
					/*
						  DSector = GameEnv.World.FindSector(0,0,0);
						  DSector.Fill(22);
						  GameEnv.World.SectorUpdateFaceCulling(0,0,0, false);
						  DSector.Flag_Render_Dirty = true;
						  DSector.Flag_Void_Regular = true;
						  DSector.Flag_Void_Transparent = true;

						  DSector = GameEnv.World.FindSector(1,0,0);
						  DSector.Fill(21);
						  GameEnv.World.SectorUpdateFaceCulling(1,0,0, false);
						  DSector.Flag_Render_Dirty = true;
						  DSector.Flag_Void_Regular = true;
						  DSector.Flag_Void_Transparent = true;

						  Offset = 0;
						  DSector.SetVoxelTypeManager(&GameEnv.VoxelTypeManager);
						  DSector.BlitSector(Sector, &Offset);

						  GameEnv.World.SectorUpdateFaceCulling(0,0,0, false);
						  DSector.Flag_Render_Dirty = true;
						  DSector.Flag_Void_Regular = true;
						  DSector.Flag_Void_Transparent = true;
					*/



					/*
					DSector.Flag_Render_Dirty = true;
					DSector.Flag_NeedFullCulling = true;
					DSector.Flag_Void_Regular = false;
					DSector.Flag_Void_Transparent = false;
					*/
				}

			}
#endif

		}
Esempio n. 16
0
            public int Compare(RvFile x, RvFile y)
            {
                int retVal = 0;

                switch (_colIndex)
                {
                case 1:
                    retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal);
                    break;

                case 2:
                    retVal = string.Compare(x.Merge ?? "", y.Merge ?? "", StringComparison.Ordinal);
                    break;

                case 3:
                    retVal = ULong.iCompareNull(x.Size, y.Size);
                    break;

                case 4:
                    retVal = ArrByte.ICompare(x.CRC, y.CRC);
                    break;

                case 5:
                    retVal = ArrByte.ICompare(x.SHA1, y.SHA1);
                    break;

                case 6:
                    retVal = ArrByte.ICompare(x.MD5, y.MD5);
                    break;

                case 7:
                    retVal = ULong.iCompareNull(x.AltSize, y.AltSize);
                    break;

                case 8:
                    retVal = ArrByte.ICompare(x.AltCRC, y.AltCRC);
                    break;

                case 9:
                    retVal = ArrByte.ICompare(x.AltSHA1, y.AltSHA1);
                    break;

                case 10:
                    retVal = ArrByte.ICompare(x.AltMD5, y.AltMD5);
                    break;

                case 11:
                    retVal = string.Compare(x.Status ?? "", y.Status ?? "", StringComparison.Ordinal);
                    break;
                }

                if (_sortDir == SortOrder.Descending)
                {
                    retVal = -retVal;
                }

                if (retVal == 0 && _colIndex != 1)
                {
                    retVal = string.Compare(x.UiDisplayName ?? "", y.UiDisplayName ?? "", StringComparison.Ordinal);
                }

                return(retVal);
            }
 private static void RecursiveCopyBaseTypePrivateFields(object originalObject, ULong hash, Dictionary <string, ulong> savedHashes, HashSet <object> visited, Type typeToReflect)
 {
     if (typeToReflect.BaseType != null)
     {
         RecursiveCopyBaseTypePrivateFields(originalObject, hash, savedHashes, visited, typeToReflect.BaseType);
         CopyFields(originalObject, hash, savedHashes, visited, typeToReflect.BaseType, BindingFlags.Instance | BindingFlags.NonPublic, info => info.IsPrivate);
     }
 }
        // 109 Cyc (special inpot set test6)
        public static ULong Remainder(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong highResult)
        {
            unchecked {
                if (0u != highDivisor)
                {
                    if (0 <= (Long)highDivisor)
                    {
                        ULong lowProduct;
                        ULong highProduct;
                        ULong lowResult;
                        ULong t;
                        {
                            int cc;
#if (NET5_0 || NET6_0 || NET5_0_OR_GREATER)
                            cc = BinaryNumerals.CountLeadingZeros(highDivisor);
                            t  = highDivisor << cc;
#else
                            // CountLeadingZeros
                            // ? using CountLeadingZeros is better or not?
                            cc = 0;
                            t  = highDivisor;
                            for (; 0 <= (Long)t; t <<= 1)
                            {
                                ++cc;
                            }
#endif
                            lowResult = MathEx.BigDivInternal(
                                lowDividend >> (Misc.ULong.BitSize - cc) | (highDividend << cc),
                                highDividend >> (Misc.ULong.BitSize - cc),
                                (lowDivisor >> (Misc.ULong.BitSize - cc)) | t);
                        }
                        t            = lowResult * highDivisor;
                        lowProduct   = MathEx.BigMul(lowResult, lowDivisor, out highProduct);
                        highProduct += t;
                        if (t > highProduct || highProduct > highDividend)
                        {
                            goto L_0001;
                        }
                        if (highDividend > highProduct || lowProduct <= lowDividend)
                        {
                            goto L_0002;
                        }
L_0001:
                        --lowResult;
                        highProduct = ((lowDivisor > lowProduct) ? (highProduct - highDivisor - 1u) : (highProduct - highDivisor));
                        lowProduct -= lowDivisor;
L_0002:
                        highResult = ((lowProduct > lowDividend) ? (highDividend - highProduct - 1u) : (highDividend - highProduct));
                        return(lowDividend - lowProduct);
                    }
                    else
                    {
                        highResult = 0u;
                        if (highDivisor <= highDividend && (highDivisor != highDividend || lowDivisor <= lowDividend))
                        {
                            return(MathEx.SubtractUnchecked(lowDividend, highDividend, lowDivisor, highDivisor, out highResult));
                        }
                        else
                        {
                            highResult = highDividend;
                            return(lowDividend);
                        }
                    }
                }
                else
                {
                    highResult = 0u;
                    return(MathEx.BigRemInternal(lowDividend, highDividend % lowDivisor, lowDivisor));
                }
            }
        }
 public static ULong BigSqrt(ULong lo, ULong hi)
 {
     unchecked {
         if (0u == hi)
         {
             return(Mathematics.Elementary.Math.Sqrt(lo));
         }
         if (hi <= ~(ULong)0 >> 2)
         {
             var   old = (ULong)Math.Sqrt((0.0 + ((ULong)1u << (Misc.ULong.BitSize - 1)) + ((ULong)1u << (Misc.ULong.BitSize - 1))) * hi + lo);
             ULong h;
             var   l = MathEx.BigSquare(old, out h);
             l += lo;
             h += hi;
             if (l < lo)
             {
                 ++h;
             }
             var @new = MathEx.BigDivNoThrow(l, h, old) >> 1;
             l = MathEx.BigSquare(@new, out h);
             if ((h > hi) || ((h == hi) && (l > lo)))
             {
                 return(@new - (ULong)1u);
             }
             else
             {
                 return(@new);
             }
         }
         {
             if (hi == ~(ULong)0)
             {
                 return(~(ULong)0);
             }
             var old = (ULong)(((ULong)1u << (Misc.UInt.BitSize - 1)) * Math.Sqrt(hi));
             var a   = lo;
             lo = (lo >> 2) | (hi << (Misc.ULong.BitSize - 2));
             hi = hi >> 2;
             ULong h;
             var   l = MathEx.BigSquare(old, out h);
             l += lo;
             h += hi;
             if (l < lo)
             {
                 ++h;
             }
             var @new = MathEx.BigDivNoThrow(l, h, old) >> 1;
             l = MathEx.BigSquare(@new, out h);
             if ((h > hi) || ((h == hi) && (l > lo)))
             {
                 --@new;
                 @new <<= 1;
                 hi     = (hi << 2) | (lo >> (Misc.ULong.BitSize - 2));
                 lo     = a;
                 a      = (@new << 1) + 1u;
                 var b = l;
                 l <<= 2;
                 h   = (h << 2) + (ULong)(((l < a) ? -1 : 0) + ((0 > (Long)@new) ? -1 : 0) + ((int)(b >> (Misc.ULong.BitSize - 2))));
                 l  -= a;
             }
             else
             {
                 @new <<= 1;
                 hi     = (hi << 2) | (lo >> (Misc.ULong.BitSize - 2));
                 lo     = a;
                 a      = (@new << 1) + 1u;
                 var b = l;
                 l <<= 2;
                 l  += a;
                 h   = (h << 2) + (((l < a) ? 1u : 0u) + ((0 > (Long)@new) ? 1u : 0u) + ((uint)(b >> (Misc.ULong.BitSize - 2))));
             }
             if ((h > hi) || ((h == hi) && (l > lo)))
             {
             }
             else
             {
                 ++@new;
             }
             return(@new);
         }
     }
 }
        public static ULong BigRemNoThrow(ULong dividend_lo_lo, ULong dividend_lo_hi, ULong dividend_hi_lo, ULong dividend_hi_hi, ULong divisor_lo, ULong divisor_hi, out ULong result_hi)
        {
            unchecked {
                if (0u == dividend_hi_lo && 0u == dividend_hi_hi)
                {
                    return(Remainder(dividend_lo_lo, dividend_lo_hi, divisor_lo, divisor_hi, out result_hi));
                }
                else if (0u == divisor_hi && ULong.MaxValue > divisor_lo)
                {
                    result_hi = 0;
                    return(Remainder(dividend_lo_lo, Remainder(dividend_lo_hi, dividend_hi_lo, divisor_lo), divisor_lo));
                }
                else
                {
                    // 2017Nov01
                    var dividend_lo_lo_ = dividend_lo_lo;
                    var dividend_lo_hi_ = dividend_lo_hi;
                    var dividend_hi_lo_ = dividend_hi_lo;
                    var dividend_hi_hi_ = dividend_hi_hi;
                    var divisor_lo_     = divisor_lo;
                    var divisor_hi_     = divisor_hi;
                    var c = 0;
                    if (0 <= (Long)divisor_hi_)
                    {
                        do
                        {
                            divisor_lo_ = ShiftLeft(divisor_lo_, divisor_hi_, out divisor_hi_);
                            ++c;
                        } while (0 <= (Long)divisor_hi_);
                        dividend_hi_hi_ = ShiftLeft(dividend_hi_lo_, dividend_hi_hi_, c);
                        dividend_hi_lo_ = ShiftLeft(dividend_lo_hi_, dividend_hi_lo_, c);
                        dividend_lo_lo_ = ShiftLeft(dividend_lo_lo_, dividend_lo_hi_, c, out dividend_lo_hi_);
                    }
                    ULong p_lo;
                    ULong p_hi;
                    if (dividend_hi_hi_ < divisor_hi_)
                    {
                        p_lo = BigMul(BigDivRemPartialInternal(dividend_hi_lo_, dividend_hi_hi_, divisor_hi_, out dividend_hi_lo_), divisor_lo_, out p_hi);
                    }
                    else
                    {
                        p_lo  = BigMul(Math.DivRem(dividend_hi_lo_, divisor_hi_, out dividend_hi_lo_), divisor_lo_, out p_hi);
                        p_hi += divisor_lo_;
                    }

                    /*
                     * p_lo = BigMul(DivRem(dividend_hi_lo_, dividend_hi_hi_, divisor_hi_, 0, out dividend_hi_lo_, out var ignored0, out var q_hi), divisor_lo_, out p_hi);
                     * if (1 == q_hi) {
                     *  p_hi += divisor_lo_;
                     * }
                     */
                    if (LessThan(dividend_lo_hi_, dividend_hi_lo_, p_lo, p_hi))
                    {
                        {
                            dividend_lo_hi_ = AddUnchecked(dividend_lo_hi_, dividend_hi_lo_, divisor_lo_, divisor_hi_, out dividend_hi_lo_);
                        }
                        if (GreaterThanOrEqual(dividend_lo_hi_, dividend_hi_lo_, divisor_lo_, divisor_hi_))
                        {
                            if (LessThan(dividend_lo_hi_, dividend_hi_lo_, p_lo, p_hi))
                            {
                                dividend_lo_hi_ = AddUnchecked(dividend_lo_hi_, dividend_hi_lo_, divisor_lo_, divisor_hi_, out dividend_hi_lo_);
                            }
                        }
                    }
                    dividend_lo_hi_ = SubtractUnchecked(dividend_lo_hi_, dividend_hi_lo_, p_lo, p_hi, out dividend_hi_lo_);
                    if (dividend_hi_lo_ < divisor_hi_)
                    {
                        p_lo = BigMul(BigDivRemPartialInternal(dividend_lo_hi_, dividend_hi_lo_, divisor_hi_, out dividend_lo_hi_), divisor_lo_, out p_hi);
                    }
                    else
                    {
                        p_lo  = BigMul(Math.DivRem(dividend_lo_hi_, divisor_hi_, out dividend_lo_hi_), divisor_lo_, out p_hi);
                        p_hi += divisor_lo_;
                    }

                    /*
                     * p_lo = BigMul(DivRem(dividend_lo_hi_, dividend_hi_lo_, divisor_hi_, 0, out dividend_lo_hi_, out var ignored1, out var q_lo), divisor_lo_, out p_hi);
                     * if (1 == q_lo) {
                     *  p_hi += divisor_lo_;
                     * }
                     */
                    if (LessThan(dividend_lo_lo_, dividend_lo_hi_, p_lo, p_hi))
                    {
                        {
                            dividend_lo_lo_ = AddUnchecked(dividend_lo_lo_, dividend_lo_hi_, divisor_lo_, divisor_hi_, out dividend_lo_hi_);
                        }
                        if (GreaterThanOrEqual(dividend_lo_lo_, dividend_lo_hi_, divisor_lo_, divisor_hi_))
                        {
                            if (LessThan(dividend_lo_lo_, dividend_lo_hi_, p_lo, p_hi))
                            {
                                dividend_lo_lo_ = AddUnchecked(dividend_lo_lo_, dividend_lo_hi_, divisor_lo_, divisor_hi_, out dividend_lo_hi_);
                            }
                        }
                    }
                    dividend_lo_lo_ = SubtractUnchecked(dividend_lo_lo_, dividend_lo_hi_, p_lo, p_hi, out dividend_lo_hi_);
                    return(ShiftRightUnsigned(dividend_lo_lo_, dividend_lo_hi_, c, out result_hi));
                }
            }
        }
 public static ULong DivRem(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong lowRemainder, out ULong highRemainder, out ULong highResult)
 {
     return(DivRemUnchecked(lowDividend, highDividend, lowDivisor, highDivisor, out lowRemainder, out highRemainder, out highResult));
 }
 public static ULong Divide(ULong lowDividend, ULong highDividend, ULong divisor, out ULong highResult)
 {
     unchecked {
         ULong t;
         highResult = Math.DivRem(highDividend, divisor, out t);
         return(MathEx.BigDivInternal(lowDividend, t, divisor));
     }
 }
 public static ULong BigRemUnchecked(ULong lowDividend, ULong highDividend, ULong divisor)
 {
     unchecked {
         ULong p;
         if (0u == highDividend)
         {
             return(lowDividend % divisor);
         }
         else if (UInt.MaxValue > divisor)
         {
             highDividend  = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
             highDividend %= divisor;
             highDividend  = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
             return(highDividend % divisor);
         }
         else
         {
             // 2013Dec24
             int c = 0;
             if (0 <= (Long)divisor)
             {
                 do
                 {
                     ++c;
                     divisor <<= 1;
                 } while (0 <= (Long)divisor);
                 highDividend = (highDividend << c) | (lowDividend >> (ULong_Misc.BitSizeAsIntUnchecked - c));
                 lowDividend  = lowDividend << c;
             }
             var dh = (ULong)(UInt)(divisor >> UInt_Misc.BitSizeAsIntUnchecked);
             var dl = (ULong)(UInt)divisor;
             p            = Math.DivRem(highDividend, dh, out highDividend) * dl;
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
             if (highDividend < p)
             {
                 {
                     highDividend += divisor;
                 }
                 if (highDividend >= divisor)
                 {
                     if (highDividend < p)
                     {
                         highDividend += divisor;
                     }
                 }
             }
             highDividend -= p;
             p             = Math.DivRem(highDividend, dh, out highDividend) * dl;
             highDividend  = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
             if (highDividend < p)
             {
                 {
                     highDividend += divisor;
                 }
                 if (highDividend >= divisor)
                 {
                     if (highDividend < p)
                     {
                         highDividend += divisor;
                     }
                 }
             }
             return((highDividend - p) >> c);
         }
     }
 }
 public static ULong BigDivRem(ULong lowDividend, ULong highDividend, ULong divisor, out ULong remainder)
 {
     unchecked {
         ULong p, ql, qh;
         if (0u == highDividend)
         {
             return(Math.DivRem(lowDividend, divisor, out remainder));
         }
         else if (UInt.MaxValue > divisor)
         {
             // 2014Jan08
             if (divisor <= highDividend && 0u != divisor)
             {
                 highDividend = checked (0u - highDividend);
                 throw (System.OverflowException)null;
             }
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
             qh           = Math.DivRem(highDividend, divisor, out highDividend);
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
             ql           = Math.DivRem(highDividend, divisor, out remainder);
             return((qh << UInt_Misc.BitSizeAsIntUnchecked) | ql);
         }
         else
         {
             // 2013Dec24, 2014Jan08
             if (divisor <= highDividend)
             {
                 highDividend = checked (0u - highDividend);
                 throw (System.OverflowException)null;
             }
             int c = 0;
             if (0 <= (Long)divisor)
             {
                 do
                 {
                     ++c;
                     divisor <<= 1;
                 } while (0 <= (Long)divisor);
                 highDividend = (highDividend << c) | (lowDividend >> (ULong_Misc.BitSizeAsIntUnchecked - c));
                 lowDividend  = lowDividend << c;
             }
             var dh = (ULong)(UInt)(divisor >> UInt_Misc.BitSizeAsIntUnchecked);
             var dl = (ULong)(UInt)divisor;
             qh           = Math.DivRem(highDividend, dh, out highDividend);
             p            = qh * dl;
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
             if (highDividend < p)
             {
                 {
                     --qh;
                     highDividend += divisor;
                 }
                 if (highDividend >= divisor)
                 {
                     if (highDividend < p)
                     {
                         --qh;
                         highDividend += divisor;
                     }
                 }
             }
             highDividend -= p;
             ql            = Math.DivRem(highDividend, dh, out highDividend);
             p             = ql * dl;
             highDividend  = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
             if (highDividend < p)
             {
                 {
                     --ql;
                     highDividend += divisor;
                 }
                 if (highDividend >= divisor)
                 {
                     if (highDividend < p)
                     {
                         --ql;
                         highDividend += divisor;
                     }
                 }
             }
             remainder = (highDividend - p) >> c;
             return((qh << UInt_Misc.BitSizeAsIntUnchecked) | ql);
         }
     }
 }
        // primary overload
        public static ULong BigMul_A_Long(ULong first, ULong second, out ULong highResult)
        {
            unchecked {
                if (ULong_Misc.Size > UIntPtr_Misc.Size)
                {
                    // 2013Oct03
                    // 我很滿意。
                    var fl = (UInt)first;
                    var fh = (UInt)(first >> UInt_Misc.BitSizeAsIntUnchecked);
                    var sl = (UInt)second;
                    var sh = (UInt)(second >> UInt_Misc.BitSizeAsIntUnchecked);
                    var ll = (ULong)fl * sl;
                    var lh = (ULong)fl * sh;
                    var hl = (ULong)fh * sl;
                    var hh = (ULong)fh * sh;
                    lh += (UInt)(ll >> UInt_Misc.BitSizeAsIntUnchecked);
                    lh += hl;
                    if (lh < hl)
                    {
                        hh += (ULong)1u << UInt_Misc.BitSizeAsIntUnchecked;
                    }
                    highResult = hh + (UInt)(lh >> UInt_Misc.BitSizeAsIntUnchecked);
                    // Bad for jitter:
                    // return (lh << UInt_Misc.BitSizeAsIntUnchecked) + (UInt)(ll);
                    return(((ULong)(UInt)lh << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)(ll));
                }
                {
                    // 2013Oct03
                    // 我很滿意。
                    // Bad for jitter:
                    // fl = (UInt)first;
                    var fl = (ULong)(UInt)first;
                    // Bad for jitter:
                    // var fh = (ULong)(first >> UInt_Misc.BitSizeAsIntUnchecked);
                    var fh = (ULong)(UInt)(first >> UInt_Misc.BitSizeAsIntUnchecked);
                    var sl = (ULong)(UInt)second;
                    var sh = (ULong)(UInt)(second >> UInt_Misc.BitSizeAsIntUnchecked);
                    // Bad for jitter:
                    // var ll = (ULong)(UInt)fl * (ULong)(UInt)sl;
                    var ll = fl * sl;
                    var lh = fl * sh;
                    var hl = fh * sl;
                    var hh = fh * sh;
                    // Bad for jitter:
                    // lh += (UInt)(ll >> UInt_Misc.BitSizeAsIntUnchecked);
                    lh += ll >> UInt_Misc.BitSizeAsIntUnchecked;
                    lh += hl;
                    if (lh < hl)
                    {
                        hh += (ULong)1u << UInt_Misc.BitSizeAsIntUnchecked;
                    }
                    highResult = hh + (lh >> UInt_Misc.BitSizeAsIntUnchecked);
                    return((lh << UInt_Misc.BitSizeAsIntUnchecked) + (UInt)(ll));
                }
            }

            /* // old version
             * var xh = first >> UInt_Misc.BitSizeAsIntUnchecked;
             * var yh = second >> UInt_Misc.BitSizeAsIntUnchecked;
             * var lo = unchecked((ULong)(UInt)first * (UInt)second);
             * var xl = unchecked((UInt)first * yh);
             * var yl = unchecked(xh * (UInt)second);
             * xl = unchecked(xl + yl);
             * xh = unchecked(xh * yh);
             * yh = unchecked(lo + (xl << UInt_Misc.BitSizeAsIntUnchecked));
             * highResult = unchecked((xh + (UInt)(xl >> UInt_Misc.BitSizeAsIntUnchecked)) + ((lo > yh ? (ULong)1 : 0) + (yl > xl ? (ULong)1 << UInt_Misc.BitSizeAsIntUnchecked : 0)));
             * return yh;
             */
        }
 public static ULong DivRemUnchecked(ULong lowDividend, Long highDividend, ULong lowDivisor, Long highDivisor, out ULong lowRemainder, out Long highRemainder, out Long highResult)
 {
     unchecked {
         Long s = highDividend, t = highDivisor;
         if (0 > highDivisor)
         {
             lowDivisor = MathEx.NegateUnchecked(lowDivisor, highDivisor, out highDivisor);
         }
         if (0 > highDividend)
         {
             lowDividend = MathEx.NegateUnchecked(lowDividend, highDividend, out highDividend);
         }
         ULong lowProduct;
         ULong highProduct;
         ULong lowResult;
         ULong r;
         lowResult = DivRem(lowDividend, (ULong)highDividend, lowDivisor, (ULong)highDivisor, out lowProduct, out highProduct, out r);
         if (0 > (s ^ t))
         {
             lowResult = MathEx.NegateUnchecked(lowResult, r, out r);
         }
         if (0 > s)
         {
             lowProduct = MathEx.NegateUnchecked(lowProduct, highProduct, out highProduct);
         }
         lowRemainder  = lowProduct;
         highRemainder = (Long)highProduct;
         highResult    = (Long)r;
         return(lowResult);
     }
 }
 internal static ULong BigDivInternal(ULong lowDividend, ULong highDividend, ULong divisor)
 {
     // 2014Sep13
     unchecked {
         ULong p, ql, qh;
         if (0u == highDividend)
         {
             return(lowDividend / divisor);
         }
         else if (UInt.MaxValue > divisor)
         {
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
             qh           = Math.DivRem(highDividend, divisor, out highDividend);
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
             ql           = highDividend / divisor;
             return((qh << UInt_Misc.BitSizeAsIntUnchecked) | ql);
         }
         else
         {
             // 2013Dec24
             int c = 0;
             if (0 <= (Long)divisor)
             {
                 do
                 {
                     ++c;
                     divisor <<= 1;
                 } while (0 <= (Long)divisor);
                 highDividend = (highDividend << c) | (lowDividend >> (ULong_Misc.BitSizeAsIntUnchecked - c));
                 lowDividend  = lowDividend << c;
             }
             var dh = (ULong)(UInt)(divisor >> UInt_Misc.BitSizeAsIntUnchecked);
             var dl = (ULong)(UInt)divisor;
             qh           = Math.DivRem(highDividend, dh, out highDividend);
             p            = qh * dl;
             highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
             if (highDividend < p)
             {
                 {
                     --qh;
                     highDividend += divisor;
                 }
                 if (highDividend >= divisor)
                 {
                     if (highDividend < p)
                     {
                         --qh;
                         highDividend += divisor;
                     }
                 }
             }
             highDividend -= p;
             ql            = Math.DivRem(highDividend, dh, out highDividend);
             p             = ql * dl;
             highDividend  = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
             if (highDividend < p)
             {
                 {
                     --ql;
                     highDividend += divisor;
                 }
                 if (highDividend >= divisor)
                 {
                     if (highDividend < p)
                     {
                         --ql;
                         // highDividend += divisor;
                     }
                 }
             }
             // remainder = (highDividend - p) >> c;
             return((qh << UInt_Misc.BitSizeAsIntUnchecked) | ql);
         }
     }
 }
        // 91.3 Cyc (special input set test6)
        public static ULong Divide(ULong lowDividend, ULong highDividend, ULong lowDivisor, ULong highDivisor, out ULong highResult)
        {
            unchecked {
                if (0u != highDivisor)
                {
                    if (0 <= (Long)highDivisor)
                    {
                        ULong lowProduct;
                        ULong highProduct;
                        ULong lowResult;
                        ULong t;
                        {
                            var cc = 0;
                            // CountLeadingZeros
                            // ? using CountLeadingZeros is better or not?
                            t = highDivisor;
                            for (; 0 <= (Long)t; t <<= 1)
                            {
                                ++cc;
                            }
                            lowResult = MathEx.BigDivInternal(
                                lowDividend >> (ULong_Misc.BitSizeAsIntUnchecked - cc) | (highDividend << cc),
                                highDividend >> (ULong_Misc.BitSizeAsIntUnchecked - cc),
                                (lowDivisor >> (ULong_Misc.BitSizeAsIntUnchecked - cc)) | t);
                        }
                        t            = lowResult * highDivisor;
                        lowProduct   = MathEx.BigMul(lowResult, lowDivisor, out highProduct);
                        highProduct += t;
                        if (t > highProduct || highProduct > highDividend)
                        {
                            goto L_0001;
                        }
                        if (highDividend > highProduct || lowProduct <= lowDividend)
                        {
                            goto L_0002;
                        }
L_0001:
                        --lowResult;
                        highProduct = ((lowDivisor > lowProduct) ? (highProduct - highDivisor - 1u) : (highProduct - highDivisor));
                        lowProduct -= lowDivisor;
L_0002:
                        highResult = 0u;
                        return(lowResult);
                    }
                    else
                    {
                        highResult = 0u;
                        if (highDivisor <= highDividend && (highDivisor != highDividend || lowDivisor <= lowDividend))
                        {
                            return(1u);
                        }
                        else
                        {
                            return(0u);
                        }
                    }
                }
                else
                {
                    ULong t;
                    highResult = Math.DivRem(highDividend, lowDivisor, out t);
                    return(MathEx.BigDivInternal(lowDividend, t, lowDivisor));
                }
            }
        }
 internal static ULong BigDivRemPartialInternal(ULong lowDividend, ULong highDividend, ULong divisor, out ULong remainder)
 {
     unchecked {
         var dh = (ULong)(UInt)(divisor >> UInt_Misc.BitSizeAsIntUnchecked);
         var dl = (ULong)(UInt)divisor;
         var qh = Math.DivRem(highDividend, dh, out highDividend);
         var p  = qh * dl;
         highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (lowDividend >> UInt_Misc.BitSizeAsIntUnchecked);
         if (highDividend < p)
         {
             {
                 --qh;
                 highDividend += divisor;
             }
             if (highDividend >= divisor)
             {
                 if (highDividend < p)
                 {
                     --qh;
                     highDividend += divisor;
                 }
             }
         }
         highDividend -= p;
         var ql = Math.DivRem(highDividend, dh, out highDividend);
         p            = ql * dl;
         highDividend = (highDividend << UInt_Misc.BitSizeAsIntUnchecked) | (UInt)lowDividend;
         if (highDividend < p)
         {
             {
                 --ql;
                 highDividend += divisor;
             }
             if (highDividend >= divisor)
             {
                 if (highDividend < p)
                 {
                     --ql;
                     highDividend += divisor;
                 }
             }
         }
         remainder = highDividend - p;
         return((qh << UInt_Misc.BitSizeAsIntUnchecked) | ql);
     }
 }
        // ~327. Cyc
        public static ULong SqrtDouble(ULong radicand)
        {
            unchecked {
                if (0u == radicand)
                {
                    return(0u);
                }

                /*
                 * if (radicand <= ~(ULong)0 >> 2) {
                 *  var old = (ULong)(((ULong)1u << (Misc.UInt.BitSize - 0)) * Math.Sqrt(radicand));
                 *  ULong h;
                 *  var l = MathEx.BigSquare(old, out h);
                 *  h += radicand;
                 *  var @new = MathEx.BigDivUnchecked(l, h, old) >> 1;
                 *  l = MathEx.BigSquare(@new, out h);
                 *  if ((h > radicand) || ((h == radicand) && (l > 0u))) {
                 *      return @new - (ULong)1u;
                 *  } else {
                 *      return @new;
                 *  }
                 * }
                 */
                {
                    if (radicand == ~(ULong)0)
                    {
                        return(~(ULong)0);
                    }
                    var old = (ULong)(((ULong)1u << (Misc.UInt.BitSize - 1)) * Math.Sqrt(radicand));
                    var a   = (ULong)0u;
                    var lo  = radicand << (Misc.ULong.BitSize - 2);
                    radicand = radicand >> 2;
                    ULong h;
                    var   l = MathEx.BigSquare(old, out h);
                    l += lo;
                    h += radicand;
                    if (l < lo)
                    {
                        ++h;
                    }
                    var @new = MathEx.BigDivNoThrow(l, h, old) >> 1;
                    l = MathEx.BigSquare(@new, out h);
                    if ((h > radicand) || ((h == radicand) && (l > lo)))
                    {
                        --@new;
                        @new   <<= 1;
                        radicand = (radicand << 2) | (lo >> (Misc.ULong.BitSize - 2));
                        lo       = a;
                        a        = (@new << 1) + 1u;
                        var b = l;
                        l <<= 2;
                        h   = (h << 2) + (ULong)(((l < a) ? -1 : 0) + ((0 > (Long)@new) ? -1 : 0) + ((int)(b >> (Misc.ULong.BitSize - 2))));
                        l  -= a;
                    }
                    else
                    {
                        @new   <<= 1;
                        radicand = (radicand << 2) | (lo >> (Misc.ULong.BitSize - 2));
                        lo       = a;
                        a        = (@new << 1) + 1u;
                        var b = l;
                        l <<= 2;
                        l  += a;
                        h   = (h << 2) + (((l < a) ? 1u : 0u) + ((0 > (Long)@new) ? 1u : 0u) + ((uint)(b >> (Misc.ULong.BitSize - 2))));
                    }
                    if ((h > radicand) || ((h == radicand) && (l > lo)))
                    {
                    }
                    else
                    {
                        ++@new;
                    }
                    return(@new);
                }
            }
        }
 public static ULong BigMul(ULong first_lo, Long first_hi, ULong second_lo, Long second_hi, out ULong result_lo_hi, out ULong result_hi_lo, out Long result_hi_hi)
 {
     unchecked {
         var fl  = first_lo;
         var fh  = unchecked ((ULong)first_hi);
         var sl  = second_lo;
         var sh  = unchecked ((ULong)second_hi);
         var lll = BigMul(fl, sl, out ULong llh);
         var hhl = BigMul(fh, sh, out ULong hhh);
         var fm  = unchecked (fh + fl);
         var sm  = unchecked (sh + sl);
         var tl  = AddUnchecked(hhl, hhh, lll, llh, out ULong th);
         var mml = BigMul(fm, sm, out ULong mmh);
         var dh  = (ULong)0;
         if (fm < fl)
         {
             unchecked {
                 ++dh;
                 mmh += sm;
             }
         }
         if (sm < sl)
         {
             unchecked {
                 ++dh;
                 mmh += fm;
             }
         }
         mml = SubtractUnchecked(mml, mmh, tl, th, out mmh);
         var dl = unchecked (fm + sm);
         if (dl < fm)
         {
             unchecked {
                 ++dh;
             }
         }
         llh = unchecked (llh + mml);
         if (llh < mml)
         {
             hhl = IncreaseUnchecked(hhl, hhh, out hhh);
         }
         hhl = AddUnchecked(hhl, hhh, mmh, 0, out hhh);
         dl  = ShiftRightUnsigned(dl, dh, out dh);
         dl  = SubtractUnchecked(dl, dh, mmh, 0, out dh);
         hhh = unchecked (hhh + dh);
         if (0 > unchecked ((Long)fh))
         {
             hhl = SubtractUnchecked(hhl, hhh, sl, sh, out hhh);
         }
         if (0 > unchecked ((Long)sh))
         {
             hhl = SubtractUnchecked(hhl, hhh, fl, fh, out hhh);
         }
         result_hi_hi = unchecked ((Long)hhh);
         result_hi_lo = hhl;
         result_lo_hi = llh;
         return(lll);
     }
 }