Assets/Deps/emotitron/Network/NST/NSTCompressVector.cs
/// <summary>
/// Attempts to guess the most likely upperbits state by seeing if each axis of the new position would be
/// closer to the old one if the upper bit is incremented by one, two, three etc. Stops trying when it fails to get a better result than the last increment.
/// </summary>
/// <param name="oldcpos">Last best position test against.</param>
/// <returns>Returns a corrected CompressPos</returns>
Attempts to guess the most likely upperbits state by seeing if each axis of the new position would be
closer to the old one if the upper bit is incremented by one, two, three etc. Stops trying when it fails to get a better result than the last increment.
Attempts to guess the most likely upperbits state by seeing if each axis of the new position would be closer to the old one if the upper bit is incremented by one two three etc . Stops trying when it fails to get a better result than the last increment .
public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos)
		{
			CompressedElement oldUppers = oldcpos.ZeroLowerBits();
			CompressedElement newLowers = newcpos.ZeroUpperBits();
			CompressedElement bestGuess = oldUppers + newLowers;
			for (int i = 0; i < 3; i++)
			{
				uint increment = ((uint)1 << AxisRanges(i).lowerBits);
				int multiplier = 1;
				long lastguessdist = System.Math.Abs((long)bestGuess[i] - oldcpos[i]);
				bool lookup = true;
				bool lookdn = true;
				while (multiplier < 10)
				{
					if (lookup)
					{
						uint guessup = bestGuess[i] + increment;
						long updist = guessup - oldcpos[i];
						if (updist < lastguessdist)
						{
							bestGuess[i] = guessup;
							lastguessdist = updist;
							lookdn = false;
							continue;
						}
					}  
					if (lookdn)
					{
						uint guessdn = (uint)((long)bestGuess[i] - increment);
						long dndist = (long)oldcpos[i] - guessdn;
						if (dndist < lastguessdist)
						{
							bestGuess[i] = guessdn;
							lastguessdist = dndist;
							lookup = false;
							continue;
						}
					}
					break;
				}
			}
			return bestGuess;
		}
public static CompressedElement GuessUpperBits ( this CompressedElement newcpos , CompressedElement oldcpos ) { CompressedElement oldUppers = oldcpos . ZeroLowerBits ( ) ; CompressedElement newLowers = newcpos . ZeroUpperBits ( ) ; CompressedElement bestGuess = oldUppers + newLowers ; for ( int i = 0 ; i < 3 ; i ++ ) { uint increment = ( ( uint ) 1 << AxisRanges ( i ) . lowerBits ) ; int multiplier = 1 ; long lastguessdist = System . Math . Abs ( ( long ) bestGuess [ i ] - oldcpos [ i ] ) ; bool lookup = true ; bool lookdn = true ; while ( multiplier < 10 ) { if ( lookup ) { uint guessup = bestGuess [ i ] + increment ; long updist = guessup - oldcpos [ i ] ; if ( updist < lastguessdist ) { bestGuess [ i ] = guessup ; lastguessdist = updist ; lookdn = false ; continue ; } } if ( lookdn ) { uint guessdn = ( uint ) ( ( long ) bestGuess [ i ] - increment ) ; long dndist = ( long ) oldcpos [ i ] - guessdn ; if ( dndist < lastguessdist ) { bestGuess [ i ] = guessdn ; lastguessdist = dndist ; lookup = false ; continue ; } } break ; } } return bestGuess ; }
Attempts to guess the most likely upperbits state by seeing if each axis of the new position would be
closer to the old one if the upper bit is incremented by one, two, three etc.
Attempts to guess the most likely upperbits state by seeing if each axis of the new position would be closer to the old one if the upper bit is incremented by one two three etc .
// value that will increase or decrease the upperbits by one // start by just applying the old uppers to the new lowers. This is the distance to beat. //uint lastguess = oldUppers[i] | newLowers[i]; // No improvements found, we are done looking. //multiplier++; //Debug.Log("increment " + ((uint)(increment * multiplier)).PrintBitMask(lowerBitcount[i])); //Debug.Log("oldpositn " + oldcpos[i].PrintBitMask(lowerBitcount[i])); //Debug.Log("lastguess " + lastguess.PrintBitMask(lowerBitcount[i])); //Debug.Log(" -  -  -  -"); //bestGuess[i] = lastguess;
Returns a corrected CompressPos
Returns a corrected CompressPos
CompressedElement
this
oldcpos
CompressedElement
Last best position test against.
Last best position test against .