public void Update() { if (Input.GetKeyDown(KeyCode.Space)) { LoadingThread.AddCommand(() => { Debug.Log(values[0]); }); } }
//TODO //Use some clever resources loading system public IEnumerator Generate() { if (state == State.Unloaded) { state = State.Loading; while (loading) { yield return(null); } loading = true; clusterBuffer = new NativeArray <ClusterMeshData>(length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); pointsBuffer = new NativeArray <Point>(length * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); indicesBuffer = new NativeArray <int>(length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); ResourceRequest clusterRequest = Resources.LoadAsync <TextAsset>("MapInfos/" + fileName); ResourceRequest pointsRequest = Resources.LoadAsync <TextAsset>("MapPoints/" + fileName); yield return(clusterRequest); yield return(pointsRequest); pointBytesArray = ((TextAsset)pointsRequest.asset).bytes; clusterBytesArray = ((TextAsset)clusterRequest.asset).bytes; Resources.UnloadAsset(pointsRequest.asset); Resources.UnloadAsset(clusterRequest.asset); pointerContainer.AddCapacityTo(pointerContainer.Length + indicesBuffer.Length); LoadingThread.AddCommand(generateAsyncFunc); } }
public void Dispose() { current = null; isRunning = false; resetEvent.Set(); thread.Join(); resetEvent.Dispose(); }
public LoadingThread() { current = this; isRunning = true; resetEvent = new AutoResetEvent(false); thread = new Thread(Run); thread.Start(); }
private void OnDestroy() { current = null; isRunning = false; resetEvent.Set(); thread.Join(); resetEvent.Dispose(); }
public IEnumerator Generate() { if (state == State.Unloaded) { state = State.Loading; while (loading) { yield return(null); } loading = true; LoadingThread.AddCommand(generateAsyncFunc, this); } }
/* * private void Update() * { * if(state == State.Loaded) * { * SceneController.MoveScene(propertyCount, (float3)transform.position - originPos, loader.clusterCount); * originPos = transform.position; * } * } */ public static IEnumerator Separate(SceneStreaming parent, List <SceneStreaming> children) { while (loading) { yield return(null); } loading = true; if (children.Count > 0) { var scene = children[0]; if (scene.state == State.Unloaded) { scene.waiting = true; scene.state = State.Loading; LoadingThread.AddCommand(generateAsyncFunc, scene); } for (int i = 1; i < children.Count; ++i) { var lastScene = children[i - 1]; while (lastScene.state == State.Loading) { yield return(null); } scene = children[i]; if (scene.state == State.Unloaded) { scene = children[i]; scene.waiting = true; scene.state = State.Loading; LoadingThread.AddCommand(generateAsyncFunc, scene); } } scene = children[children.Count - 1]; while (scene.state == State.Loading) { yield return(null); } SceneController.baseBuffer.clusterCount = SceneController.baseBuffer.prepareClusterCount; } if (parent) { var deleteScene = parent; if (deleteScene.state == State.Loaded) { deleteScene.DeleteSyncGPU(); deleteScene.DeleteDisposeMemory(); } } loading = false; }
public void Init() { if (current != null) { Debug.LogError("Loading Thread should be singleton!"); return; } current = this; isRunning = true; resetEvent = new AutoResetEvent(false); thread = new Thread(Run); thread.Start(); commandQueue = new LoadingCommandQueue(); }
public IEnumerator Delete() { if (state == State.Loaded) { state = State.Loading; while (loading) { yield return(null); } loading = true; results = new NativeArray <Vector2Int>(indicesBuffer.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); resultLength = 0; LoadingThread.AddCommand(deleteAsyncFunc, this); } }
private void Awake() { if (current != null) { Debug.LogError("GPU RP Scene should be singleton!"); Destroy(this); return; } current = this; SceneController.Awake(resources, resolution, texArrayCapacity, lightmapAtlasSize, lightmapCapacity, propertyCapacity, mapResources); loadingThread = new LoadingThread(); int length = 0; Count(transformParents, ref length); transformArray = new TransformAccessArray(length, 32); SetBuffer(transformParents, transformArray); }
public bool LoadVolume(int index) { if (isLoading) { return(false); } if (index < 0 || index >= resources.allVolume.Count) { return(false); } isLoading = true; IrradianceResources.Volume data = resources.allVolume[index]; currentIrr = new LoadedIrradiance { resolution = data.resolution, position = data.position, localToWorld = data.localToWorld, renderTextureIndex = loadedIrradiance.Length }; targetPath = data.path; currentTexture = new CoeffTexture(data.resolution); len = (int)(data.resolution.x * data.resolution.y * data.resolution.z * 9); if (coeff != null && coeff.count < len) { coeff.Dispose(); coeff = new ComputeBuffer(len, 12); } if (coeff == null) { coeff = new ComputeBuffer(len, 12); } LoadingThread.AddCommand((obj) => { var controller = (IrradianceVolumeController)obj; controller.LoadVolumeAsync(); }, this); return(true); }