Ejemplo n.º 1
0
        // full interface.
        // ask = AllStars/UnpopulatedStars/PopulatedStars = only v1/c1 is returned..
        // ask = SplitPopulatedStars = vertices1 is populated, 2 is unpopulated stars

        public static void GetSystemVector <V>(int gridid, ref V[] vertices1, ref uint[] colours1,
                                               ref V[] vertices2, ref uint[] colours2,
                                               int percentage, Func <int, int, int, V> tovect,
                                               SystemAskType ask = SystemAskType.SplitPopulatedStars)
        {
            using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem(mode: SQLLiteExtensions.SQLExtConnection.AccessMode.Reader))
            {
                GetSystemVector <V>(gridid, ref vertices1, ref colours1, ref vertices2, ref colours2, percentage, tovect, cn, ask);
            }
        }
Ejemplo n.º 2
0
        // full interface.
        // ask = AllStars/UnpopulatedStars/PopulatedStars = only v1/c1 is returned..
        // ask = SplitPopulatedStars = vertices1 is populated, 2 is unpopulated stars

        public static void GetSystemVector <V>(int gridid, ref V[] vertices1, ref uint[] colours1,
                                               ref V[] vertices2, ref uint[] colours2,
                                               int percentage, Func <int, int, int, V> tovect,
                                               SystemAskType ask = SystemAskType.SplitPopulatedStars)
        {
            V[]    cpvertices1 = vertices1;
            uint[] cpcolours1  = colours1;
            V[]    cpvertices2 = vertices2;
            uint[] cpcolours2  = colours2;

            SystemsDatabase.Instance.ExecuteWithDatabase(db =>
            {
                GetSystemVector <V>(gridid, ref cpvertices1, ref cpcolours1, ref cpvertices2, ref cpcolours2, percentage, tovect, db.Connection, ask);
            }, warnthreshold: 5000);

            vertices1 = cpvertices1;
            colours1  = cpcolours1;
            vertices2 = cpvertices2;
            colours2  = cpcolours2;
        }
Ejemplo n.º 3
0
        internal static void GetSystemVector <V>(int gridid, ref V[] vertices1, ref uint[] colours1,
                                                 ref V[] vertices2, ref uint[] colours2,
                                                 int percentage, Func <int, int, int, V> tovect,
                                                 SQLiteConnectionSystem cn,
                                                 SystemAskType ask = SystemAskType.SplitPopulatedStars)
        {
            int numvertices1 = 0;

            vertices1 = vertices2 = null;

            int numvertices2 = 0;

            colours1 = colours2 = null;

            Color[] fixedc = new Color[4];
            fixedc[0] = Color.Red;
            fixedc[1] = Color.Orange;
            fixedc[2] = Color.Yellow;
            fixedc[3] = Color.White;

            //System.Diagnostics.Debug.WriteLine("sysLap : " + BaseUtils.AppTicks.TickCountLap());

            // tried xz comparision but slower than grid select
            using (DbCommand cmd = cn.CreateSelect("Systems s",
                                                   outparas: "s.edsmid,s.x,s.y,s.z" + (ask == SystemAskType.SplitPopulatedStars ? ",e.eddbid" : ""),
                                                   where : "s.sectorid IN (Select id FROM Sectors c WHERE c.gridid = @p1)" +
                                                   (percentage < 100 ? (" AND ((s.edsmid*2333)%100) <" + percentage.ToStringInvariant()) : "") +
                                                   (ask == SystemAskType.PopulatedStars ? " AND e.edsmid NOT NULL " : "") +
                                                   (ask == SystemAskType.UnpopulatedStars ? " AND e.edsmid IS NULL " : ""),
                                                   paras: new Object[] { gridid },
                                                   joinlist: ask != SystemAskType.AllStars ? new string[] { "LEFT OUTER JOIN EDDB e ON e.edsmid = s.edsmid " } : null
                                                   ))
            {
                //System.Diagnostics.Debug.WriteLine( cn.ExplainQueryPlanString(cmd));

                vertices1 = new V[250000];
                colours1  = new uint[250000];

                if (ask == SystemAskType.SplitPopulatedStars)
                {
                    vertices2 = new V[250000];
                    colours2  = new uint[250000];
                }

                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    //System.Diagnostics.Debug.WriteLine("sysLapStart : " + BaseUtils.AppTicks.TickCountLap());

                    Object[] data = new Object[4];

                    while (reader.Read())
                    {
                        long id = reader.GetInt64(0);       // quicker than cast
                        int  x  = reader.GetInt32(1);
                        int  y  = reader.GetInt32(2);
                        int  z  = reader.GetInt32(3);

                        bool addtosecondary = (ask == SystemAskType.SplitPopulatedStars) ? (reader[4] is System.DBNull) : false;

                        Color basec = fixedc[(id) & 3];
                        int   fade  = 100 - (((int)id >> 2) & 7) * 8;
                        byte  red   = (byte)(basec.R * fade / 100);
                        byte  green = (byte)(basec.G * fade / 100);
                        byte  blue  = (byte)(basec.B * fade / 100);

                        if (addtosecondary)
                        {
                            if (numvertices2 == vertices2.Length)
                            {
                                Array.Resize(ref vertices2, vertices2.Length * 2);
                                Array.Resize(ref colours2, colours2.Length * 2);
                            }

                            colours2[numvertices2]    = BitConverter.ToUInt32(new byte[] { red, green, blue, 255 }, 0);
                            vertices2[numvertices2++] = tovect(x, y, z);
                        }
                        else
                        {
                            if (numvertices1 == vertices1.Length)
                            {
                                Array.Resize(ref vertices1, vertices1.Length * 2);
                                Array.Resize(ref colours1, colours1.Length * 2);
                            }

                            colours1[numvertices1]    = BitConverter.ToUInt32(new byte[] { red, green, blue, 255 }, 0);
                            vertices1[numvertices1++] = tovect(x, y, z);
                        }
                    }

                    //      System.Diagnostics.Debug.WriteLine("sysLapEnd : " + BaseUtils.AppTicks.TickCountLap());
                }

                Array.Resize(ref vertices1, numvertices1);
                Array.Resize(ref colours1, numvertices1);

                if (ask == SystemAskType.SplitPopulatedStars)
                {
                    Array.Resize(ref vertices2, numvertices2);
                    Array.Resize(ref colours2, numvertices2);
                }

                if (gridid == GridId.SolGrid && vertices1 != null) // BODGE do here, better once on here than every star for every grid..
                {                                                  // replace when we have a better naming system
                    int solindex = Array.IndexOf(vertices1, tovect(0, 0, 0));
                    if (solindex >= 0)
                    {
                        colours1[solindex] = 0x00ffff;   //yellow
                    }
                }
            }
        }
Ejemplo n.º 4
0
 // all stars/Unpopulated/Poplulated only
 public static void GetSystemVector <V>(int gridid, ref V[] vertices1, ref uint[] colours1, int percentage, Func <int, int, int, V> tovect, SystemAskType ask = SystemAskType.AllStars)
 {
     V[]    v2 = null;
     uint[] c2 = null;
     GetSystemVector <V>(gridid, ref vertices1, ref colours1, ref v2, ref c2, percentage, tovect, ask);
 }
Ejemplo n.º 5
0
        public static int GetSystemVector(int gridid, ref Vector3[] vertices, ref uint[] colours, 
            SystemAskType ask, int percentage)
        {
            int numvertices = 0;

            vertices = null;
            colours = null;

            Color[] fixedc = new Color[4];
            fixedc[0] = Color.Red;
            fixedc[1] = Color.Orange;
            fixedc[2] = Color.Yellow;
            fixedc[3] = Color.White;

            try
            {
                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    using (DbCommand cmd = cn.CreateCommand("SELECT id,x,y,z,randomid from EdsmSystems where gridid=@gridid"))
                    {
                        cmd.AddParameterWithValue("gridid", gridid);

                        if (ask == SystemAskType.PopulatedStars)
                            cmd.CommandText += " AND (EddbId IS NOT NULL AND EddbId <> 0)";
                        else if (ask == SystemAskType.UnPopulatedStars)
                            cmd.CommandText += " AND (EddbId IS NULL OR EddbId = 0)";

                        if (percentage < 100)
                            cmd.CommandText += " and randomid<" + percentage;

                        //Stopwatch ws = new Stopwatch();  ws.Start();

                        Object[] array = new Object[5];     // to the number of items above queried

                        vertices = new Vector3[250000];
                        colours = new uint[250000];

                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                reader.GetValues(array);

                                long id = (long)array[0];
                                long x = (long)array[1];
                                long y = (long)array[2];
                                long z = (long)array[3];
                                int rand = (int)(long)array[4];

                                if (numvertices == vertices.Length)
                                {
                                    Array.Resize(ref vertices, vertices.Length + 32768);
                                    Array.Resize(ref colours, colours.Length + 32768);
                                }

                                Vector3 pos = new Vector3((float)(x / XYZScalar), (float)(y / XYZScalar), (float)(z / XYZScalar));

                                Color basec = fixedc[rand&3];
                                int fade = 100 - ((rand>>2)&7) * 8;
                                byte red = (byte)(basec.R * fade / 100);
                                byte green = (byte)(basec.G * fade / 100);
                                byte blue = (byte)(basec.B * fade / 100);
                                colours[numvertices] = BitConverter.ToUInt32(new byte[] { red, green, blue, 255 }, 0);
                                vertices[numvertices++] = pos;
                            }
                        }

                        Array.Resize(ref vertices, numvertices);
                        Array.Resize(ref colours, numvertices);

                        //Console.WriteLine("Query {0} grid {1} ret {2} took {3}", cmd.CommandText, gridid, numvertices, ws.ElapsedMilliseconds);

                        if (gridid == 810 && vertices!=null)    // BODGE do here, better once on here than every star for every grid..
                        {                       // replace when we have a better naming system
                            int solindex = Array.IndexOf(vertices, new Vector3(0, 0, 0));

                            if (solindex >= 0)
                                colours[solindex] = 0x00ffff;   //yellow
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }

            return numvertices;
        }
Ejemplo n.º 6
0
        public static int GetSystemVector(int gridid, ref Vector3[] vertices, ref uint[] colours, 
            SystemAskType ask, int percentage)
        {
            int numvertices = 0;

            vertices = null;
            colours = null;

            Color[] fixedc = new Color[4];
            fixedc[0] = Color.Red;
            fixedc[1] = Color.Orange;
            fixedc[2] = Color.Yellow;
            fixedc[3] = Color.White;

            try
            {
                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    using (DbCommand cmd = cn.CreateCommand("SELECT id,x,y,z,randomid from EdsmSystems where gridid=@gridid"))
                    {
                        cmd.AddParameterWithValue("gridid", gridid);

                        if (ask == SystemAskType.PopulatedStars)
                            cmd.CommandText += " AND (EddbId IS NOT NULL AND EddbId <> 0)";
                        else if (ask == SystemAskType.UnPopulatedStars)
                            cmd.CommandText += " AND (EddbId IS NULL OR EddbId = 0)";

                        if (percentage < 100)
                            cmd.CommandText += " and randomid<" + percentage;

                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (System.DBNull.Value != reader["x"])
                                {
                                    if (vertices == null)
                                    {
                                        vertices = new Vector3[1024];
                                        colours = new uint[1024];
                                    }
                                    else if (numvertices == vertices.Length)
                                    {
                                        Array.Resize(ref vertices, vertices.Length + 8192);
                                        Array.Resize(ref colours, colours.Length + 8192);
                                    }

                                    Vector3 pos = new Vector3((float)(double)reader["x"], (float)(double)reader["y"], (float)(double)reader["z"]);

                                    int rand = (int)(long)reader["randomid"];
                                    Color basec = fixedc[rand&3];
                                    int fade = 100 - ((rand>>2)&7) * 8;
                                    byte red = (byte)(basec.R * fade / 100);
                                    byte green = (byte)(basec.G * fade / 100);
                                    byte blue = (byte)(basec.B * fade / 100);
                                    colours[numvertices] = BitConverter.ToUInt32(new byte[] { red, green, blue, 255 }, 0);
                                    vertices[numvertices++] = pos;
                                }
                            }
                        }

                        if (gridid == 810 && vertices!=null)    // BODGE do here, better once on here than every star for every grid..
                        {                       // replace when we have a better naming system
                            int solindex = Array.IndexOf(vertices, new Vector3(0, 0, 0));

                            if (solindex >= 0)
                                colours[solindex] = 0x00ffff;   //yellow
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }

            return numvertices;
        }