Exemplo n.º 1
0
        public static LinearUnit Build(double value, LinearMode mode)
        {
            switch (mode)
            {
            case LinearMode.Meter:
                return(new Meter(value));   //, LinearPrefix.Nothing);

            case LinearMode.Mile:
                return(new Mile(value));

            case LinearMode.Yard:
                return(new Yard(value));

            case LinearMode.Foot:
                return(new Foot(value));

            case LinearMode.Inch:
                return(new Inch(value));

            case LinearMode.Rod:
                return(new Rod(value));

            case LinearMode.Chain:
                return(new Chain(value));

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
 private void Start()
 {
     linearMode        = FindObjectOfType <LinearMode>();
     movementDirection = -Vector3.forward;
 }
Exemplo n.º 3
0
        MakeLinear(LinearMode mode = LinearMode.TopToBottom)
        {
            var pixmap = new List <DynamicTable.Entry>();
            var attrs  = new List <DynamicTable.Entry>();

            // take each third of the screen in turn
            for (int third = 0; third < 3; third++)
            {
                int baseAddress = 16384 + (third * 2048);
                // we have eight rows of characters per third
                for (int row = 0; row < 8; row++)
                {
                    // each row begins 32 bytes after the previous row
                    int rowAddress = baseAddress + (row * 32);

                    // we have eight lines of pixels per row
                    for (int line = 0; line < 8; line++)
                    {
                        // each line begins 256 bytes after the previous line
                        var lineAddress = (ushort)(rowAddress + (line * 256));
                        pixmap.Add(new DynamicTable.Entry(lineAddress, 32));
                    }
                }
            }

            // attributes are a lot easier
            attrs.AddRange(from row in Enumerable.Range(0, 24)
                           let rowAddress = 0x5800 + (row * 32)
                                            select new DynamicTable.Entry((ushort)rowAddress, 32)
                           );

            switch (mode)
            {
            case LinearMode.BottomToTop:
                pixmap.Reverse();
                attrs.Reverse();
                goto case LinearMode.TopToBottom; // fall through

            case LinearMode.TopToBottom:
                // for each row, write one lot of attributes and eight lines
                int lineIndex = 0;
                foreach (var row in attrs)
                {
                    yield return(row);

                    for (int i = 0; i < 8; i++)
                    {
                        yield return(pixmap[lineIndex++]);
                    }
                }
                break;

            case LinearMode.Diverge:
                // reverse the top and bottom halves of the screen
                pixmap = (pixmap.Take(pixmap.Count / 2).Reverse()
                          .Concat(pixmap.Skip(pixmap.Count / 2).Reverse())).ToList();
                attrs = (attrs.Take(attrs.Count / 2).Reverse()
                         .Concat(attrs.Skip(attrs.Count / 2).Reverse())).ToList();
                goto case LinearMode.Converge; // fall through

            case LinearMode.Converge:
                // write a pair of rows together: two lots of attributes
                // and lines
                while (attrs.Count > 0)
                {
                    yield return(attrs[0]);

                    yield return(attrs[attrs.Count - 1]);

                    attrs.RemoveAt(attrs.Count - 1);
                    attrs.RemoveAt(0);
                    for (int i = 0; i < 8; i++)
                    {
                        yield return(pixmap[0]);

                        yield return(pixmap[pixmap.Count - 1]);

                        pixmap.RemoveAt(pixmap.Count - 1);
                        pixmap.RemoveAt(0);
                    }
                }
                break;

            case LinearMode.S4:
            case LinearMode.S8:
                // we divide each row into n, depending on the size of the square.
                // We do the zeroth, second etc. chunks top-to-bottom and the first,
                // third etc. chunks bottom-to-top.  When we've done a square, we
                // do the first, third etc. chunks top-to-bottom and the zeroth,
                // second etc. chunks bottom-to-top.  The top-to-bottom and bottom-
                // to-top rows are interleaved, like with a Converge
                byte size = mode == LinearMode.S8 ? (byte)8 : (byte)4;
                List <DynamicTable.Entry>
                ttbPixmap      = new List <DynamicTable.Entry>(),
                    ttbAttrs   = new List <DynamicTable.Entry>(),
                    bttPixmap  = new List <DynamicTable.Entry>(),
                    bttAttrs   = new List <DynamicTable.Entry>(),
                    evenPixmap = ttbPixmap,
                    oddPixmap  = bttPixmap,
                    evenAttrs  = ttbAttrs,
                    oddAttrs   = bttAttrs;
                for (int attrIndex = 0; attrIndex < attrs.Count; attrIndex++)
                {
                    var split = attrs[attrIndex].Split(size).ToArray();
                    for (int splitIndex = 0; splitIndex < split.Length; splitIndex++)
                    {
                        if (splitIndex % 2 == 0)
                        {
                            evenAttrs.Add(split[splitIndex]);
                        }
                        else
                        {
                            oddAttrs.Add(split[splitIndex]);
                        }
                    }

                    // now the corresponding pixmap rows, same deal
                    for (int pixmapIndex = attrIndex * 8, x = 0;
                         x < 8;
                         pixmapIndex++, x++)
                    {
                        split = pixmap[pixmapIndex].Split(size).ToArray();
                        for (int splitIndex = 0; splitIndex < split.Length; splitIndex++)
                        {
                            if (splitIndex % 2 == 0)
                            {
                                evenPixmap.Add(split[splitIndex]);
                            }
                            else
                            {
                                oddPixmap.Add(split[splitIndex]);
                            }
                        }
                    }

                    if ((attrIndex % size) == (size - 1))
                    {
                        // this was the last row of a square
                        var tmp = evenAttrs;
                        evenAttrs  = oddAttrs;
                        oddAttrs   = tmp;
                        tmp        = evenPixmap;
                        evenPixmap = oddPixmap;
                        oddPixmap  = tmp;
                    }
                }

                // bottom-to-top entries have to be done in reverse, natch
                bttAttrs.Reverse();
                bttPixmap.Reverse();

                // now we send them interleaved.  For each attr entry, we send
                // eight pixmap entries, alternating between TTB and BTT
                while (ttbAttrs.Count > 0)
                {
                    // send a row's worth of attrs
                    for (int x = 0; x < 32 / 2 / size; x++)
                    {
                        yield return(ttbAttrs[0]);

                        ttbAttrs.RemoveAt(0);
                        yield return(bttAttrs[0]);

                        bttAttrs.RemoveAt(0);
                    }
                    // now all the corresponding pixmap entries
                    for (int x = 0; x < 32 / 2 / size; x++)
                    {
                        for (int y = 0; y < 8; y++)
                        {
                            yield return(ttbPixmap[0]);

                            ttbPixmap.RemoveAt(0);
                            yield return(bttPixmap[0]);

                            bttPixmap.RemoveAt(0);
                        }
                    }
                }

                break;
            }
        }