Пример #1
0
 public WorldLoadingThread()
 {
     objectRunningList              = new TreeDictionary <long, NifLoadJob>();
     terrainRunningList             = new TreeDictionary <long, NifLoadJob>();
     objectPositions                = new SCG.List <ObjectPosition>();
     MAX_RUNNING_THREADS            = ProgramSettings.get("MAX_RUNNING_THREADS", 2);
     this.loadingQueueSampler       = CustomSampler.Create("LoadingQueuesampler");
     this.objectRunningListSampler  = CustomSampler.Create("LoadingQueuesampler");
     this.terrainRunningListSampler = CustomSampler.Create("LoadingQueuesampler");
 }
Пример #2
0
 void startJob(NifLoadJob job, TreeDictionary <long, NifLoadJob> runningList, KdTreeNode <float, SCG.List <NifLoadJob> >[] candidates)
 {
     lock (loadingCapsuleQueue)
     {
         loadingCapsuleQueue.Enqueue(job);
     };
     lock (runningList)
     {
         runningList.Add(job.uid, job);
     }
     foreach (KdTreeNode <float, SCG.List <NifLoadJob> > n in candidates)
     {
         n.Value.Remove(job);
     }
     //Debug.Log("Start job:" + job.filename);
     job.Start((System.Threading.ThreadPriority)ProgramSettings.get("OBJECT_LOAD_THREAD_PRIORITY", (int)System.Threading.ThreadPriority.Normal));
 }
Пример #3
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();
            }
        }
Пример #4
0
        private void init()
        {
            overrideDirectory = ProgramSettings.get("ASSETS_OVERRIDE_DIR");
            assetsDirectory   = ProgramSettings.get("ASSETS_DIR");
            if (assetsDirectory == null)
            {
                throw new Exception("Assets directory was null");
            }
            assetsManifest = ProgramSettings.get("ASSETS_MANIFEST");
            if (assetsManifest == null)
            {
                throw new Exception("Assets manifest was null");
            }


            if (overrideDirectory != null)
            {
                Debug.Log("Detected override directory, checking for validity");
                // check the override directory for a manifest
                string manifestName       = Path.GetFileName(assetsManifest);
                string overriddenManifest = overrideDirectory + Path.DirectorySeparatorChar + manifestName;
                Debug.Log("checking for overriden manifest:" + overriddenManifest);
                if (File.Exists(overriddenManifest))
                {
                    assetsManifest = overriddenManifest;
                    Debug.Log("Found overriden manifest");
                }
                else
                {
                    Debug.Log("No valid overide manifest found");
                }
            }

            manifest = new Manifest(assetsManifest);
            db       = AssetProcessor.buildDatabase(manifest, assetsDirectory, overrideDirectory);
        }
Пример #5
0
        private void worldLoad()
        {
            processJobAdds();

            /**
             * Load the world tiles around the camera and their objects
             */
            int tileX = Mathf.FloorToInt(telaraWorldCamPos.x / 256.0f);
            int tileY = Mathf.FloorToInt(telaraWorldCamPos.z / 256.0f);

            int[][] v =
            {
                new int[] { -1,  1 }, new int[] { 0,  1 }, new int[] { 1,  1 },
                new int[] { -1,  0 }, new int[] { 0,  0 }, new int[] { 1,  0 },
                new int[] { -1, -1 }, new int[] { 0, -1 }, new int[] { 1, -1 },
            };
            int range = ProgramSettings.get("TERRAIN_VIS", 10);

            submitCDRJob(tileX, tileY);
            for (int txx = tileX - range; txx <= tileX + range; txx++)
            {
                for (int txy = tileY - range; txy <= tileY + range; txy++)
                {
                    submitCDRJob(txx, txy);
                }
            }
            processCDRQueue();

            if (availThreads() > 0)
            {
                Vector3 camPos = cameraWorldCamPos;
                //getWorldCamPos();
                float[] camPosF = new float[] { camPos.x, camPos.z };

                lock (terraintree)
                {
                    lock (postree)
                    {
                        KdTreeNode <float, SCG.List <NifLoadJob> >[] tercandidates = this.terraintree.RadialSearch(camPosF, Math.Max(256, ProgramSettings.get("TERRAIN_VIS", 10) * 256), 200);
                        KdTreeNode <float, SCG.List <NifLoadJob> >[] candidates    = this.postree.RadialSearch(camPosF, ProgramSettings.get("OBJECT_VISIBLE", 500), 200);
                        SCG.IEnumerable <NifLoadJob> terjobs = tercandidates.SelectMany(e => e.Value);
                        // always have a terrain job running

                        if (terjobs.Count() > 0)
                        {
                            lock (camPlaneLock)
                            {
                                terjobs = terjobs.OrderBy(n => Vector3.Distance(n.parentPos, camPos));
                            }
                            SCG.List <NifLoadJob> jobs = terjobs.ToList();
                            lock (terrainRunningList)
                            {
                                if (terrainRunningList.Count <= 1)
                                {
                                    startJob(jobs[0], terrainRunningList, tercandidates);
                                }
                            }
                        }
                        lock (terrainRunningList)
                        {
                            tListCountEstimate = terrainRunningList.Count;
                        }
                        foreach (KdTreeNode <float, SCG.List <NifLoadJob> > n in tercandidates)
                        {
                            if (n.Value.Count == 0)
                            {
                                terraintree.RemoveAt(n.Point);
                            }
                        }

                        if (availThreads() > 0)
                        {
                            oListCountEstimate = objectRunningList.Count;
                            SCG.IEnumerable <NifLoadJob> otherjobs = candidates.SelectMany(e => e.Value);
                            lock (camPlaneLock)
                            {
                                otherjobs = otherjobs.OrderBy(n => !TestPlanesAABB(camPlanes, n.parentPos)).ThenBy(n => Vector3.Distance(n.parentPos, camPos));
                            }
                            foreach (NifLoadJob job in otherjobs)
                            {
                                if (availThreads() > 0)
                                {
                                    lock (objectRunningList)
                                    {
                                        startJob(job, objectRunningList, candidates);
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            foreach (KdTreeNode <float, SCG.List <NifLoadJob> > n in candidates)
                            {
                                if (n.Value.Count == 0)
                                {
                                    postree.RemoveAt(n.Point);
                                }
                            }
                        }
                    }
                }
            }
        }