Beispiel #1
0
 public void CheckForRenderNeed()
 {
     lock (RenderingNow)
     {
         while (NeedsRendering.Count > 0 && RenderingNow.Count < TheClient.CVars.r_chunksatonce.ValueI)
         {
             Vector3i temp = NeedsRendering.Dequeue();
             Chunk    ch   = GetChunk(temp);
             if (ch != null)
             {
                 ch.MakeVBONow();
                 RenderingNow.Add(temp);
             }
         }
     }
     lock (PreppingNow)
     {
         while (PrepChunks.Count > 0 && PreppingNow.Count < TheClient.CVars.r_chunksatonce.ValueI)
         {
             Action temp = PrepChunks.Dequeue();
             temp.Invoke();
         }
     }
 }
Beispiel #2
0
 public void CheckForRenderNeed()
 {
     lock (RenderingNow)
     {
         int removed = 0;
         if (NeedsRendering.Count > 0)
         {
             NeedsRendering.Sort((a, b) => (a.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition()).CompareTo(
                                     (b.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition())));
             int cap  = TheClient.CVars.r_chunksatonce.ValueI;
             int done = 0;
             while (NeedsRendering.Count > removed && done < cap && RenderingNow.Count < 200)
             {
                 Vector3i temp = NeedsRendering[removed++];
                 try
                 {
                     Chunk ch = GetChunk(temp);
                     if (ch != null)
                     {
                         if (NeedsRendering.Count < 50 || ch.PosMultiplier != 15)
                         {
                             done++;
                         }
                         ch.MakeVBONow();
                         RenderingNow.Add(temp);
                     }
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output("Pre-rendering chunks", ex);
                 }
             }
             if (removed > 0)
             {
                 NeedsRendering.RemoveRange(0, removed);
             }
         }
     }
     lock (PreppingNow)
     {
         if (PrepChunks.Count > 0)
         {
             PrepChunks.Sort((a, b) => (a.Key.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition()).CompareTo(
                                 (b.Key.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition())));
             int removed = 0;
             int done    = 0;
             int help    = 0;
             while (PrepChunks.Count > removed && done < TheClient.CVars.r_chunksatonce.ValueI)
             {
                 Action temp = PrepChunks[removed++].Value;
                 try
                 {
                     help++;
                     if (help > 5 || PrepChunks.Count < 50)
                     {
                         done++;
                         help = 0;
                     }
                     temp.Invoke();
                 }
                 catch (Exception ex)
                 {
                     Utilities.CheckException(ex);
                     SysConsole.Output("Prepping chunks", ex);
                 }
             }
             if (removed > 0)
             {
                 PrepChunks.RemoveRange(0, removed);
             }
         }
     }
 }
Beispiel #3
0
        public void CheckForRenderNeed()
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();
            lock (RenderingNow)
            {
                foreach (Vector3i veccer in CalcingLights.OrderBy((vec) => (vec.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition())))
                {
                    if (LightingNow.Count() < TheClient.CVars.r_chunksatonce.ValueI)
                    {
                        CalcingLights.Remove(veccer);
                        Chunk ch = GetChunk(veccer);
                        if (ch == null)
                        {
                            continue;
                        }
                        LightingNow.Add(veccer);
                        Chunk above = null;
                        for (int i = 1; i < 5 && above == null; i++) // TODO: 5 -> View height limit
                        {
                            above = GetChunk(ch.WorldPosition + new Vector3i(0, 0, i));
                        }
                        if (above == null || !above.LOADING)
                        {
                            TheClient.Schedule.StartAsyncTask(() =>
                            {
                                try
                                {
                                    LightForChunks(ch, above);
                                }
                                catch (Exception ex)
                                {
                                    Utilities.CheckException(ex);
                                    SysConsole.Output("Handling chunk lights", ex);
                                }
                                TheClient.Schedule.ScheduleSyncTask(() =>
                                {
                                    LightingNow.Remove(ch.WorldPosition);
                                });
                            }, true);
                        }
                    }
                }
                crn_ctr += Delta;
                bool renderNews = false;
                if (crn_ctr > 0.5)
                {
                    renderNews = true;
                    crn_ctr    = 0;
                }
                int removed = 0;
                if (NeedsRendering.Count > 0)
                {
                    NeedsRendering.Sort((a, b) => (a.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition()).CompareTo(
                                            (b.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition())));
                    int             cap       = TheClient.CVars.r_chunksatonce.ValueI;
                    int             done      = 0;
                    List <Chunk>    compers   = new List <Chunk>();
                    List <Vector3i> removes   = new List <Vector3i>();
                    int             forgotten = 0;
                    while (NeedsRendering.Count > removed && done < cap && RenderingNow.Count < 200)
                    {
                        Vector3i temp = NeedsRendering[removed++];
                        try
                        {
                            Chunk ch = GetChunk(temp);
                            if (ch != null && (!ch.IsNew || renderNews))
                            {
                                if (!ch.LightCalced)
                                {
                                    CalcingLights.Add(ch.WorldPosition);
                                }
                                else
                                {
                                    if (NeedsRendering.Count < 50 || ch.PosMultiplier != 15)
                                    {
                                        done++;
                                    }
                                    RenderingNow.Add(temp);
                                    ch.MakeVBONow(false);
                                    compers.Add(ch);
                                    removes.Add(temp);
                                }
                            }
                            else if (ch == null)
                            {
                                removes.Add(temp);
                            }
                            else
                            {
                                forgotten++;
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.CheckException(ex);
                            SysConsole.Output("Pre-rendering chunks", ex);
                        }
                    }
                    if (TheClient.CVars.r_compute.ValueB)
                    {
                        TheClient.VoxelComputer.Calc(compers.ToArray());
                    }
                    if (removed > 0)
                    {
                        foreach (Vector3i vec in removes)
                        {
                            NeedsRendering.Remove(vec);
                        }
                    }
                    if (forgotten >= cap)
                    {
                        crn_ctr += 1.0;
                    }
                }
            }
            lock (PreppingNow)
            {
                if (PrepChunks.Count > 0)
                {
                    PrepChunks.Sort((a, b) => (a.Key.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition()).CompareTo(
                                        (b.Key.ToLocation() * Chunk.CHUNK_SIZE).DistanceSquared(TheClient.Player.GetPosition())));
                    int removed = 0;
                    int done    = 0;
                    int help    = 0;
                    while (PrepChunks.Count > removed && done < TheClient.CVars.r_chunksatonce.ValueI)
                    {
                        Action temp = PrepChunks[removed++].Value;
                        try
                        {
                            help++;
                            if (help > 5 || PrepChunks.Count < 50)
                            {
                                done++;
                                help = 0;
                            }
                            temp.Invoke();
                        }
                        catch (Exception ex)
                        {
                            Utilities.CheckException(ex);
                            SysConsole.Output("Prepping chunks", ex);
                        }
                    }
                    if (removed > 0)
                    {
                        PrepChunks.RemoveRange(0, removed);
                    }
                }
            }
            timer.Stop();
            CrunchTime = (double)timer.ElapsedMilliseconds / 1000f;
            if (CrunchTime > CrunchSpikeTime)
            {
                CrunchSpikeTime = CrunchTime;
            }
            timer.Reset();
        }