Exemple #1
0
        public void FromRects(RectList inRects)
        {
            Rects                   = inRects;
            SerializedRects         = RasterLib.RasterApi.RectsToSerializedRects(Rects);
            SerializedRectsLimit255 = RasterLib.RasterApi.RectsToSerializedRectsLimit255(Rects);

            JSON = SceneToJson.Convert(RasterLib.RasterApi.RectsToScene(Rects));

            if ((enableFlags & enables.DoScene) == enables.DoScene)
            {
                FromSerializedRects(SerializedRects);
            }
        }
Exemple #2
0
        public void FromSerializedRects(SerializedRects inSerializedRects)
        {
            SerializedRects = inSerializedRects;
            Rects           = RasterLib.RasterApi.SerializedRectsToRects(SerializedRects);

            if ((enableFlags & enables.DoQuads) == enables.DoQuads)
            {
                Quads = RasterLib.RasterApi.RectsToQuads(Rects);
            }

            if ((enableFlags & enables.DoTriangles) == enables.DoTriangles)
            {
                FromQuads(Quads);
            }
        }
Exemple #3
0
        public void FromCode(Code inCode)
        {
            code     = inCode;
            codename = RasterLib.RasterApi.CodeToCodename(code);
            try
            {
                Tokens = RasterLib.RasterApi.CodeToTokens(code);
                FromTokens(Tokens);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception " + ex);
            }

            if ((enableFlags & enables.DoRectsMipMap) == enables.DoRectsMipMap)
            {
                Code     codeSmaller = RasterLib.RasterApi.CodeToRescaledCode(inCode, 16, 16, 16);
                Grid     gridSmall   = RasterLib.RasterApi.CodeToGrid(codeSmaller);
                RectList rectsSmall  = RasterLib.RasterApi.GridToRects(gridSmall);
                SerializedRectsMipMap = RasterLib.RasterApi.RectsToSerializedRects(rectsSmall);
            }
        }
Exemple #4
0
 public static RectList SerializedRectsToRects(SerializedRects serializedRects)
 {
     return(RectConverter.SerializedRectsToRects(serializedRects));
 }
        //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);
        }
Exemple #6
0
 public DownSolver(SerializedRects inSerializedRects)
 {
     FromSerializedRects(inSerializedRects);
 }