예제 #1
0
            public static DirectionNumber operator ++(DirectionNumber left)
            {
                DirectionNumber result         = left;
                bool            updigit        = false;
                int             currDigitIndex = 0;

                while (true)
                {
                    result.Value[currDigitIndex].NumValue++;
                    if (result.Value[currDigitIndex].NumValue < 10)
                    {
                        break;
                    }
                    result.Value[currDigitIndex].NumValue = result.Value[currDigitIndex].NumValue % 10;
                    currDigitIndex++;
                    if (currDigitIndex >= result.Value.Count)
                    {
                        result.Value.Add(new DirectionDigit()
                        {
                            NumValue = 1, Direction = Direction.Any
                        });
                        break;
                    }
                }
                for (int i = currDigitIndex; i >= 0; i--)
                {
                    result.SetDirection(i);
                }
                return(result);
            }
예제 #2
0
        static void Main(string[] args)
        {
            int             totalCount = 99;
            DirectionNumber num        = new DirectionNumber(99);
            int             bCount     = 0;
            float           percent    = 0.0f;

            while (100 * bCount < 99 * totalCount)
            {
                totalCount++;
                num++;
                if (num.Value[0].Direction == Direction.Bouncy)
                {
                    bCount++;
                }
            }

            Console.WriteLine("Result is {0}", num.ToString());
        }
예제 #3
0
        public NavEdge(LevelDeserializeContext context)
        {
            if (context.Version < 19)
            {
                // NOTE: Legacy bits were: North, South, East, West, Jump, Drop, Climb
                int       oldTypeValue     = context.br.ReadByte();
                const int oldDirectionBits = 1 | 2 | 4 | 8;
                switch (oldTypeValue & oldDirectionBits)
                {
                case 1: direction = DirectionNumber.North; break;

                case 2: direction = DirectionNumber.South; break;

                case 4: direction = DirectionNumber.East;  break;

                case 8: direction = DirectionNumber.West;  break;

                default:
                    direction = 0;     // <- garbage, but easy to re-generate
                    Debug.Assert(false, "Nonsense direction value, need to regenerate level file");
                    break;
                }

                type = (EdgeType)(oldTypeValue & ~oldDirectionBits);
            }
            else
            {
                direction = (DirectionNumber)context.br.ReadByte();
                type      = (EdgeType)context.br.ReadByte();
            }

            nextSector    = context.br.ReadByte();
            region.startX = context.br.ReadInt32();
            region.startZ = context.br.ReadInt32();
            region.endX   = context.br.ReadInt32();
            region.endZ   = context.br.ReadInt32();
        }
예제 #4
0
        public static Point ToMovement(this DirectionNumber d)
        {
            switch (d)
            {
            case DirectionNumber.East: return(new Point(1, 0));

            case DirectionNumber.NorthEast: return(new Point(1, 1));

            case DirectionNumber.North: return(new Point(0, 1));

            case DirectionNumber.NorthWest: return(new Point(-1, 1));

            case DirectionNumber.West: return(new Point(-1, 0));

            case DirectionNumber.SouthWest: return(new Point(-1, -1));

            case DirectionNumber.South: return(new Point(0, -1));

            case DirectionNumber.SouthEast: return(new Point(1, -1));

            default:
                return(Point.Zero);
            }
        }
예제 #5
0
 public static bool IsValid(this DirectionNumber v)
 {
     Debug.Assert((int)DirectionNumber.Count == 8); // <- this is assumed.
     return(((int)v & 7) == (int)v);
 }
예제 #6
0
 public static DirectionFlags ToFlag(this DirectionNumber v)
 {
     return((DirectionFlags)(1u << (int)v));
 }
예제 #7
0
 public static DirectionNumber Rotate(this DirectionNumber v, int steps)
 {
     return((DirectionNumber)(((int)v + steps) & 7));
 }
예제 #8
0
 public static DirectionNumber Rotate180(this DirectionNumber v)
 {
     return((DirectionNumber)(((int)v + 4) & 7));
 }
예제 #9
0
 public static DirectionNumber RotateClockwise(this DirectionNumber v)
 {
     return((DirectionNumber)(((int)v - 1) & 7));
 }
예제 #10
0
        public static DirectionNumber GetNextDirectionToProjection(int x, int z, DirectionNumber previous, NavRegionProjection projection)
        {
            // This incredible switch construct is so that we can jump directly to the previous value, saving us a lot of code in the general case
            // And, in particular, allowing us to avoid shuffling our large arguments between stacks, as the dopey JIT won't inline the large comparisons used here

            // The use of non-short-circuiting is a speculative optimisation against expected cost of branch mis-prediction (NOTE: inspected JIT but haven't profiled yet -AR)
            // This slightly expands our output code size (~5 icache lines total), but perhaps not a big deal due to the switch behaviour in the typical case.

            switch (previous)
            {
            default:
                previous = 0;     // Reset
                goto case DirectionNumber.East;

            case DirectionNumber.East:
            {
                if ((x < projection.x.min & projection.z.min <= z & z <= projection.z.max) | (x < projection.negative.min & x < projection.positive.min))
                {
                    return(DirectionNumber.East);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.West;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.West:
            {
                if ((x > projection.x.max & projection.z.min <= z & z <= projection.z.max) | (x > projection.negative.max & x > projection.positive.max))
                {
                    return(DirectionNumber.West);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.North;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.North:
            {
                if ((z < projection.z.min & projection.x.min <= x & x <= projection.x.max) | (x <projection.negative.min& x> projection.positive.max))
                {
                    return(DirectionNumber.North);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.South;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.South:
            {
                if ((z > projection.z.max & projection.x.min <= x & x <= projection.x.max) | (x > projection.negative.max & x < projection.positive.min))
                {
                    return(DirectionNumber.South);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.NorthEast;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.NorthEast:
            {
                if ((x <= projection.x.max & z <= projection.z.max & projection.positive.min <= x & x <= projection.positive.max)
                    | (x < projection.x.min & z < projection.z.min))
                {
                    return(DirectionNumber.NorthEast);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.NorthWest;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.NorthWest:
            {
                if ((x >= projection.x.min & z <= projection.z.max & projection.negative.min <= x & x <= projection.negative.max)
                    | (x > projection.x.max & z < projection.z.min))
                {
                    return(DirectionNumber.NorthWest);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.SouthEast;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.SouthEast:
            {
                if ((x <= projection.x.max & z >= projection.z.min & projection.negative.min <= x & x <= projection.negative.max)
                    | (x <projection.x.min& z> projection.z.max))
                {
                    return(DirectionNumber.SouthEast);
                }
            }
                if (previous == 0)
                {
                    goto case DirectionNumber.SouthWest;
                }
                else
                {
                    goto default;
                }

            case DirectionNumber.SouthWest:
            {
                if ((x >= projection.x.min & z >= projection.z.min & projection.positive.min <= x & x <= projection.positive.max)
                    | (x > projection.x.max & z > projection.z.max))
                {
                    return(DirectionNumber.SouthWest);
                }
            }
                if (previous == 0)
                {
                    return(0);    // Nowhere to go :(
                }
                else
                {
                    goto default;
                }
            }
        }