コード例 #1
0
        //Sending newly created Mesh to the GC, making the change visible, this is NOT threadsafe, the chunk must be done one by one.
        //This could lead to "lag" if too many chunks are sending their new mesh to the GC at the same time (during the same frame)
        //Maybe it will be worth to check is a limit of chunk by update must be placed (But this will slow down chunk creation time)
        private void SendMeshesToGC(int maximumUpdateOrderPossible)
        {
            int nbrchunksSend2GC = 0;

            //Process each chunk that are in IsOutsideLightSourcePropagated state, and not currently processed
            foreach (VisualChunk chunk in SortedChunks.Where(x => x.State == ChunkState.MeshesChanged &&
                                                             x.ThreadStatus == ThreadsManager.ThreadStatus.Idle &&
                                                             x.UpdateOrder == maximumUpdateOrderPossible))
            {
                chunk.UpdateOrder = 0;
                chunk.Graphics.SendCubeMeshesToBuffers();
                nbrchunksSend2GC++;
#if PERFTEST
                if (chunk.ChunkID == Utopia.Worlds.Chunks.WorldChunks.perf.cubeChunkID)
                {
                    Utopia.Worlds.Chunks.WorldChunks.perf.AddData("FINISHED");
                    Utopia.Worlds.Chunks.WorldChunks.perf.Actif = false;

                    foreach (var data in Utopia.Worlds.Chunks.WorldChunks.perf.CollectedData)
                    {
                        Console.WriteLine(data);
                    }
                }
                else
                {
                    Utopia.Worlds.Chunks.WorldChunks.perf.AddData("SendMeshesToGC Started  " + chunk.ChunkID);
                }
#endif

                if (nbrchunksSend2GC > VisualWorldParameters.VisibleChunkInWorld.X)
                {
                    break;
                }
            }
        }
コード例 #2
0
        //Will create new chunks based on chunks with state = Empty
        private void CreateNewChunk()
        {
            //Process each chunk that are in Empty state, and not currently processed
            foreach (VisualChunk chunk in SortedChunks.Where(x => (x.State == ChunkState.Empty || x.State == ChunkState.LandscapeCreated) && x.ThreadStatus == ThreadsManager.ThreadStatus.Idle))
            {
                VisualChunk localChunk = chunk;

                //Start chunk creation process in a threaded way !
                localChunk.ThreadStatus = ThreadsManager.ThreadStatus.Locked;           //Lock the thread before entering async process.
#if DEBUG
                localChunk.ThreadLockedBy = "CreateNewChunk";
#endif
                //SmartThread.ThreadPool.QueueWorkItem(ChunkCreationThreadedSteps_Threaded, chunk, WorkItemPriority.Normal);
                S33M3DXEngine.Threading.ThreadsManager.RunAsync(() => ChunkCreationThreadedSteps_Threaded(localChunk));
            }
        }
コード例 #3
0
        //Will take the newly created chunks || the chunk that didn't had the outside light propagate (Border chunk), and propagate the light from the surroundings chunks
        private void PropagateOuterChunkLights()
        {
            //Process each chunk that are in InnerLightsSourcePropagated state, and not being currently processed
            foreach (VisualChunk chunk in SortedChunks.Where(x =>
                                                             (x.State == ChunkState.InnerLightsSourcePropagated || (x.IsOutsideLightSourcePropagated == false && x.IsBorderChunk == false && x.State >= ChunkState.InnerLightsSourcePropagated)) &&
                                                             x.ThreadStatus == ThreadsManager.ThreadStatus.Idle))
            {
                VisualChunk localChunk = chunk;

                //all the surrounding chunks must have had their LightSources Processed at minimum.
                if (localChunk.IsBorderChunk == true || localChunk.SurroundingChunksMinimumState(ChunkState.InnerLightsSourcePropagated))
                {
                    //Check if the surrounding chunk from this chunk are in the correct state = ChunkState.InnerLightsSourcePropagated
                    localChunk.ThreadStatus = ThreadsManager.ThreadStatus.Locked;           //Lock the thread before entering async process.
#if DEBUG
                    localChunk.ThreadLockedBy = "PropagateOuterChunkLights";
#endif
                    S33M3DXEngine.Threading.ThreadsManager.RunAsync(() => ChunkOuterLightPropagation_Threaded(localChunk));
                }
            }
        }
コード例 #4
0
        private void CreateChunkMeshes(int maximumUpdateOrderPossible)
        {
            //Process each chunk that are in IsOutsideLightSourcePropagated state, and not currently processed
            foreach (VisualChunk chunk in SortedChunks.Where(x => x.State == ChunkState.OuterLightSourcesProcessed && x.ThreadStatus == ThreadsManager.ThreadStatus.Idle))
            {
                VisualChunk localChunk = chunk;
                if (maximumUpdateOrderPossible > 0 && localChunk.UpdateOrder == 0)
                {
                    continue;
                }

                //all the surrounding chunks must have had their LightSources Processed at minimum.
                if (localChunk.SurroundingChunksMinimumState(ChunkState.OuterLightSourcesProcessed))
                {
                    localChunk.ThreadStatus = ThreadsManager.ThreadStatus.Locked;
#if DEBUG
                    localChunk.ThreadLockedBy = "CreateChunkMeshes";
#endif
                    S33M3DXEngine.Threading.ThreadsManager.RunAsync(() => CreateChunkMeshes_Threaded(localChunk), localChunk.UpdateOrder > 0 ? ThreadsManager.ThreadTaskPriority.High : ThreadsManager.ThreadTaskPriority.Normal);
                }
            }
        }
コード例 #5
0
ファイル: WorldChunks.cs プロジェクト: ErtyHackward/utopia
 /// <summary>
 /// Enumerates all visible chunks by player (i.e. not frustum culled)
 /// </summary>
 /// <returns></returns>
 public IEnumerable <VisualChunk> VisibleChunks()
 {
     return(SortedChunks.Where(chunk => !chunk.Graphics.IsFrustumCulled));
 }