Exemplo n.º 1
0
        // in a thread, look up the sector
        private void FillSectorThread(Object seco)
        {
            Sector d = (Sector)seco;

            //System.Diagnostics.Debug.WriteLine($"Galaxy: Thread start for {d.pos}");

            // note d.text/d.positions may be much longer than d.systems

            if (d.searchsize > 0)           // if not a clear..
            {
                if (ShowDistance)
                {
                    Vector4 pos = new Vector4(d.pos.X + d.searchsize / 2, d.pos.Y + d.searchsize / 2, d.pos.Z + d.searchsize / 2, 0);       // from centre of box

                    d.systems = SystemsDB.GetSystemList(d.pos.X, d.pos.Y, d.pos.Z, d.searchsize, ref d.text, ref d.positions,
                                                        (x, y, z) => { return(new Vector4((float)x / SystemClass.XYZScalar, (float)y / SystemClass.XYZScalar, (float)z / SystemClass.XYZScalar, 0)); },
                                                        (v, s) => { var dist = (pos - v).Length; return(s + $" @ {dist:0.#}ly"); });
                }
                else
                {
                    d.systems = SystemsDB.GetSystemList(d.pos.X, d.pos.Y, d.pos.Z, d.searchsize, ref d.text, ref d.positions,
                                                        (x, y, z) => { return(new Vector4((float)x / SystemClass.XYZScalar, (float)y / SystemClass.XYZScalar, (float)z / SystemClass.XYZScalar, 0)); },
                                                        null);
                }

                if (d.systems > 0)      // may get nothing, so don't do this if so
                {
                    // note only draw d.systems
                    using (StringFormat fmt = new StringFormat())
                    {
                        fmt.Alignment = StringAlignment.Center;

                        d.bitmaps = GLOFC.Utils.BitMapHelpers.DrawTextIntoFixedSizeBitmaps(slset.LabelSize, d.text, Font, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit,
                                                                                           ForeText, BackText, 0.5f, textformat: fmt, length: d.systems);
                    }

                    d.textpos = GLPLVertexShaderMatrixTriStripTexture.CreateMatrices(d.positions, LabelOffset, //offset
                                                                                     LabelSize,                //size
                                                                                     new Vector3(0, 0, 0),     // rot (unused due to below)
                                                                                     true, false,              // rotate, no elevation
                                                                                     length: d.systems         // limit length
                                                                                     );
                }
            }

            generatedsectors.Enqueue(d);       // d has been filled
            //System.Diagnostics.Debug.WriteLine($"{Environment.TickCount % 100000} {d.pos} {tno} {d.systems} end");

            Interlocked.Add(ref subthreadsrunning, -1);
        }