Ejemplo n.º 1
0
        internal void processThreadsUnityUpdate(Action <TreeDictionary <long, NifLoadJob>, DateTime> processRunningList, Func <ObjectPosition, GameObject> process)
        {
            /** Create an end time, if we pass that end time we should abort immediately */
            // 33ms = 30fps
            DateTime fend = DateTime.Now.AddMilliseconds(15);

            TryWithLock(camPlaneLock, () => camPlanes = GeometryUtility.CalculateFrustumPlanes(cam));
            if (DateTime.Now > fend)
            {
                return;
            }
            processLoadingQueue(fend);
            if (DateTime.Now > fend)
            {
                return;
            }
            TryWithLock(objectRunningList, () =>
            {
                objectRunningListSampler.Begin();
                processRunningList(objectRunningList, fend);
                oListCountEstimate = objectRunningList.Count;
                objectRunningListSampler.End();
            });
            if (DateTime.Now > fend)
            {
                return;
            }
            TryWithLock(terrainRunningList, () =>
            {
                terrainRunningListSampler.Begin();
                processRunningList(terrainRunningList, fend);
                tListCountEstimate = terrainRunningList.Count;
                terrainRunningListSampler.End();
            });

            if (DateTime.Now > fend)
            {
                return;
            }
            TryWithLock(objectPositions, () =>
            {
                while (objectPositions.Count() > 0 && fend > DateTime.Now)
                {
                    ObjectPosition p = objectPositions[0];
                    objectPositions.RemoveAt(0);

                    GameObject go = process(p);
                }
            });
        }
Ejemplo n.º 2
0
        void processCDRQueue()
        {
            int tileX = Mathf.FloorToInt(telaraWorldCamPos.x / 256.0f);
            int tileY = Mathf.FloorToInt(telaraWorldCamPos.z / 256.0f);

            cdrJobQueue = cdrJobQueue.OrderBy(x => Vector2.Distance(new Vector2(tileX, tileY), new Vector2(x.Key, x.Value))).ToList();
            while (runningTerrainThreads < MAX_TERRAIN_THREADS && cdrJobQueue.Count() > 0)
            {
                KeyValuePair <int, int> job = cdrJobQueue[0];
                cdrJobQueue.RemoveAt(0);
                int tx = job.Key;
                int ty = job.Value;
                runningTerrainThreads++;
                //Debug.Log("Starting thread for CDR job[" + tx + "," + ty + "]");

                System.Threading.Thread m_Thread = new System.Threading.Thread(() =>
                {
                    try
                    {
                        SCG.List <ObjectPosition> objs = new SCG.List <ObjectPosition>();
                        CDRParse.doWorldTile(AssetDatabaseInst.DB, DBInst.inst, GameWorld.worldName, tx * 256, ty * 256, (p) =>
                        {
                            objs.Add(p);
                        });
                        lock (objectPositions)
                        {
                            objectPositions.AddRange(objs);
                        }
                    }
                    finally
                    {
                        runningTerrainThreads--;
                    }
                });
                m_Thread.Priority = (System.Threading.ThreadPriority)ProgramSettings.get("MAP_LOAD_THREAD_PRIORITY", (int)System.Threading.ThreadPriority.Normal);
                m_Thread.Start();
            }
        }