//Serialize a set of rectangles(RectList) to SerializedRects
        public static SerializedRects RectsToSerializedRects(RectList rectSet)
        {
            GridConverter.BuildCircuit(rectSet, false);
            var sb = new StringBuilder();

            bool mode2D = false;// RectsAre2D(rectSet);

            //Sort the rectlist into sets of rectlists where rects have same properties
            IEnumerable <List <Rect> > superRects = SuperSortByProperties(rectSet);

            //Iterate through entire set of rectlists
            foreach (List <Rect> rectList in superRects)
            {
                string rectPropertiesSerialized = SerializeRectProperties(rectList[0].Properties, mode2D);
                sb.Append(rectPropertiesSerialized);

                //Iterate through each rect in the set (will all have same properties)
                //Each will inherit properties values when read later from last properties write
                foreach (Rect rect in rectList)
                {
                    string rectSerialized = Transcode64.SerializeRectPointsToString(rect, 1, mode2D);
                    rectSerialized += SerializeCircuitProperties(rectList[0].Properties);
                    sb.Append(rectSerialized);
                }
            }
            //Then return new serialized rect with that string
            return(new SerializedRects(sb.ToString()));
        }
Exemple #2
0
        //Load a glyphics file, precompute rectangles and append them to codeString as speedy cache
        public static void PreSerializeGlyphicsFile(string filename)
        {
            CodeList codes = GlyToCodes(filename);

            foreach (Code t in codes)
            {
                string code = t.codeString;

                if (code.Contains("*"))
                {
                    code = code.Split('*')[0];
                }

                Grid grid = CodeConverter.TokensToGrid(CodeConverter.CodeToTokens(new Code(code)));

                if (grid != null)
                {
                    RectList rectSet         = GridConverter.GridToRects(grid);
                    string   serializedRects = RectConverter.RectsToSerializedRects(rectSet).SerializedData;
                    code         = code + serializedRects;
                    t.codeString = code;
                }
            }
            CodesToGly(filename, codes);
        }
        //Input: Glyphics code
        //Output: Rectangles
        //Side-Effects: May use deserialized cache at end of codeString instead
        public static RectList CodeToRects(Code rasterCode)
        {
            string code = rasterCode.codeString;

            if (code.Contains("" + CharRgba))
            {
                string start = code.Substring(code.IndexOf('*'));
                return(SerializedRectsToRects(new SerializedRects(start)));
            }
            RectList rectSet = GridConverter.GridToRects(RasterApi.TokensToGrid(RasterApi.CodeToTokens(rasterCode)));

            return(rectSet);
        }
Exemple #4
0
        public void FromGrid(Grid inGrid)
        {
            Grid = inGrid;

            int scale;

            if (Grid.SizeX > 128)
            {
                scale = 1;
            }
            else
            {
                //scale = (int)((256) / (float)(Grid.SizeX) * 1.3) & 254;
                scale = (int)((256) / (float)(Grid.SizeX) * 1.8) & 254;
            }
            //scale = 12;

            if ((enableFlags & enables.RenderIsometricThumb) == enables.RenderIsometricThumb)
            {
                GridIsometricThumb = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(Grid, 0, 0, 0, 0, 1, 1, "Render Isometric (Thumbnail) ");
            }
            if ((enableFlags & enables.RenderIsometricRegular) == enables.RenderIsometricRegular)
            {
                GridIsometric = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(Grid, 31, 31, 31, 0, scale, scale, "Render Isometric (Regular) ");
            }
            if ((enableFlags & enables.RenderIsometricLarge) == enables.RenderIsometricLarge)
            {
                GridIsometricLarge = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(Grid, 0, 0, 0, 0, 8, 8, "Render Isometric (Large) ");
            }

            if ((enableFlags & enables.RenderOrthogonal) == enables.RenderOrthogonal)
            {
                GridOrthogonal = RasterLib.RasterApi.Renderer.RenderObliqueCells(Grid);
            }

            if ((enableFlags & enables.DoRects) == enables.DoRects)
            {
                Rects = GridConverter.GridToRects(Grid);
                FromRects(Rects);
            }
        }
Exemple #5
0
 //Circuit
 public static void BuildCircuit(RectList rects, bool verbose)
 {
     GridConverter.BuildCircuit(rects, verbose);
 }
Exemple #6
0
 //Grid-To
 public static RectList GridToRects(Grid grid)
 {
     return(GridConverter.GridToRects(grid));
 }
        //Deserialized SerializedRects back to set of rectangles(RectList)
        public static RectList SerializedRectsToRects(SerializedRects serializedRects)
        {
            RectList rects     = new RectList();
            char     state     = ' ';
            byte     shapeId   = 0;
            byte     textureId = 0;
            ulong    rgba      = 0;
            byte     groupId   = 0;
            ulong    worldid   = 0;
            string   serial    = serializedRects.SerializedData;
            char     mode      = CharRects3D;


            for (int i = 0; i < serial.Length; i++)
            {
                if (serial[i] == CharRects2D)
                {
                    mode = CharRects2D; state = CharRgba;
                }
                if (serial[i] == CharRgba)
                {
                    mode = CharRects3D; state = CharRgba;
                }
                if (serial[i] == CharGroup)
                {
                    state = CharGroup;
                }
                if (serial[i] == CharLimit255)
                {
                    state = CharLimit255;
                }
                if (serial[i] == CharCircuit)
                {
                    state = CharCircuit;
                }
                if (serial[i] == CharWorld)
                {
                    state = CharWorld;
                }
                switch (state)
                {
                case CharGroup:
                {
                    groupId = Transcode64.From64(serial[++i]);
                    state   = mode;
                    break;
                }

                case CharRgba:    //Reading RGBA palette
                {
                    i++;
                    int r = Transcode64.From64(serial[i++]);
                    int g = Transcode64.From64(serial[i++]);
                    int b = Transcode64.From64(serial[i++]);
                    int a = Transcode64.From64(serial[i++]);

                    rgba      = Transcode64.RecodeRgbatoUlong((byte)r, (byte)g, (byte)b, (byte)a);
                    shapeId   = Transcode64.From64(serial[i++]);
                    textureId = Transcode64.From64(serial[i]);
                    state     = mode;

                    break;
                }

                case CharRects2D:    //Reading emergents
                {
                    Rect rect = new Rect();
                    rect.Pt1[0] = Transcode64.From64(serial[i++]);
                    rect.Pt1[2] = Transcode64.From64(serial[i++]);

                    rect.Pt2[0] = Transcode64.From64(serial[i++]);
                    rect.Pt2[2] = Transcode64.From64(serial[i]);

                    //Convert from inclusve
                    rect.Pt2[0]++;
                    rect.Pt2[2]++;

                    rect.Properties.Rgba      = rgba;
                    rect.Properties.ShapeId   = shapeId;
                    rect.Properties.TextureId = textureId;
                    rect.Properties.GroupId   = groupId;
                    rect.Properties.WorldId   = worldid;
                    rects.AddRect(rect);
                    break;
                }

                case CharRects3D:    //Reading emergents
                {
                    Rect rect = new Rect();
                    rect.Pt1[0] = Transcode64.From64(serial[i++]);
                    rect.Pt1[1] = Transcode64.From64(serial[i++]);
                    rect.Pt1[2] = Transcode64.From64(serial[i++]);

                    rect.Pt2[0] = Transcode64.From64(serial[i++]);
                    rect.Pt2[1] = Transcode64.From64(serial[i++]);
                    rect.Pt2[2] = Transcode64.From64(serial[i]);

                    //Convert from inclusve
                    rect.Pt2[0]++;
                    rect.Pt2[1]++;
                    rect.Pt2[2]++;

                    rect.Properties.Rgba      = rgba;
                    rect.Properties.ShapeId   = shapeId;
                    rect.Properties.TextureId = textureId;
                    rect.Properties.GroupId   = groupId;
                    rect.Properties.WorldId   = worldid;
                    rects.AddRect(rect);
                    break;
                }

                case CharCircuit:
                {
                    i++;
                    byte pid = Transcode64.From64(serial[i++]);      //physics id
                    byte cid = Transcode64.From64(serial[i]);        //circuit id
                    if (rects.GetRect(rects.Count - 1).Properties.CircuitIds == null)
                    {
                        rects.GetRect(rects.Count - 1).Properties.CircuitIds = new List <int>();
                    }

                    rects.GetRect(rects.Count - 1).Properties.PhysicsId = pid;
                    rects.GetRect(rects.Count - 1).Properties.CircuitIds.Add(cid);
                    state = mode;
                    break;
                }

                case CharWorld:    //Reading World ID
                {
                    i++;
                    int v4 = Transcode64.From64(serial[i++]);
                    int v3 = Transcode64.From64(serial[i++]);
                    int v2 = Transcode64.From64(serial[i++]);
                    int v1 = Transcode64.From64(serial[i++]);

                    worldid = (ulong)((v4 << 24) | (v3 << 16) | (v2 << 8) | v1);
                    state   = mode;

                    break;
                }
                }
            }
            GridConverter.BuildCircuit(rects, false);
            return(rects);
        }