private IEnumerator SucceedGetGeometryBufferRequest(string modelPath, GeometryBuffer buffer) { // Check to see if any other requests were waiting on this model LinkedList <LoadCubeRequest> dependentRequests; while (!Monitor.TryEnter(_dependentCubes)) { yield return(null); } if (_dependentCubes.TryGetValue(modelPath, out dependentRequests)) { _dependentCubes.Remove(modelPath); } Monitor.Exit(_dependentCubes); // If any were send them to their next stage if (dependentRequests != null) { foreach (var request in dependentRequests) { request.GeometryBuffer = buffer; MoveRequestForward(request); } } }
private void Build(GeometryBuffer buffer, MaterialData materialData, int x, int y, int z, int lod, Action <GameObject> registerCreatedObjects) { if (CacheFill) { return; } var cubeName = new StringBuilder("cube_L"); cubeName.Append(lod); cubeName.Append(':'); cubeName.Append(x); cubeName.Append('_'); cubeName.Append(y); cubeName.Append('_'); cubeName.Append(z); var newCube = ObjectPooler.Current.GetPooledObject(BaseModelCube); newCube.name = cubeName.ToString(); buffer.PopulateMeshes(newCube, materialData.Material); // Put object in scene, claim from pool newCube.SetActive(true); if (registerCreatedObjects != null) { registerCreatedObjects(newCube); } }
private void Build(GeometryBuffer buffer, MaterialData materialData, int x, int y, int z, int lod, GameObject obj) { if (CacheFill) { return; } var cubeName = new StringBuilder("cube_L"); cubeName.Append(lod); cubeName.Append(':'); cubeName.Append(x); cubeName.Append('_'); cubeName.Append(y); cubeName.Append('_'); cubeName.Append(z); obj.name = cubeName.ToString(); buffer.PopulateMeshes(obj, materialData.Material); obj.SetActive(true); }
private IEnumerator GetModelForRequest(LoadCubeRequest loadRequest) { //var modelPath = loadRequest.Query.GetModelPath(loadRequest.LodIndex, loadRequest.X, loadRequest.Y, loadRequest.Z); var modelPath = pyriteQuery.GetModelPath(loadRequest.LodIndex, loadRequest.X, loadRequest.Y, loadRequest.Z); while (!Monitor.TryEnter(_eboCache)) { yield return(null); } // If the geometry data is being loaded or this is the first request to load it add the request the dependency list if (!_eboCache.ContainsKey(modelPath) || _eboCache[modelPath] == null) { yield return(StartCoroutine(AddDependentRequest(loadRequest, modelPath))); if (!_eboCache.ContainsKey(modelPath)) { // Model data was not present in cache nor has any request started constructing it //EboCacheMisses++; _eboCache[modelPath] = null; if (UseWwwForEbo) { var cachePath = CacheWebRequest.GetCacheFilePath(modelPath); WWW modelWww; if (CacheWebRequest.IsItemInCache(cachePath)) { //FileCacheHits++; modelWww = new WWW("file:///" + cachePath); yield return(modelWww); } else { //FileCacheMisses++; modelWww = new WWW(modelPath); yield return(modelWww); CacheWebRequest.AddToCache(cachePath, modelWww.bytes); } GeometryBuffer buffer = new GeometryBuffer(_geometryBufferAltitudeTransform, true) { Buffer = modelWww.bytes }; buffer.Process(); _eboCache[modelPath] = buffer; yield return(StartCoroutine(SucceedGetGeometryBufferRequest(modelPath, buffer))); } else { CacheWebRequest.GetBytes(modelPath, modelResponse => { lock (_eboCache) { if (modelResponse.Status == CacheWebRequest.CacheWebResponseStatus.Error) { Debug.LogError("Error getting model [" + modelPath + "] " + modelResponse.ErrorMessage); FailGetGeometryBufferRequest(loadRequest, modelPath); } else if (modelResponse.Status == CacheWebRequest.CacheWebResponseStatus.Cancelled) { _eboCache.Remove(modelPath); } else { if (modelResponse.IsCacheHit) { //FileCacheHits++; } else { //FileCacheMisses++; } GeometryBuffer buffer = new GeometryBuffer(_geometryBufferAltitudeTransform, true) { Buffer = modelResponse.Content }; buffer.Process(); _eboCache[modelPath] = buffer; SucceedGetGeometryBufferRequest(modelPath, buffer).Wait(); } } }, DependentRequestsExistBlocking); } } } else // The model data was in the cache { // Model was constructed move request to next step //EboCacheHits++; loadRequest.GeometryBuffer = _eboCache[modelPath]; MoveRequestForward(loadRequest); } Monitor.Exit(_eboCache); }