/// <summary> /// This function is run every physics update, and in it we collect any generated mapData and meshData from the other thread and use it's ///data in the map /// </summary> private void FixedUpdate() { //If there is data in the mapData thread queue, get all of it if (mapDataThreadInfoQueue.Count > 0) { //iterate over all the data for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { //get the data MapThreadInfo <MapData> mapThreadInfo = mapDataThreadInfoQueue.Dequeue(); //call the function tht was stored in the thread data with the variable that was computed in the other thread as a parameter, //the supplied callBack Action must only take in one parameter of the correct type for this to work mapThreadInfo.callBack(mapThreadInfo.parameter); } } //Do the exact same again for meshData if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> meshThreadInfo = meshDataThreadInfoQueue.Dequeue(); meshThreadInfo.callBack(meshThreadInfo.parameter); } textureData.updateMeshHeights(terrainMaterial, terrainData.minHeight, terrainData.maxHeight); } //textureData.updateMeshHeights(terrainMaterial, terrainData.minHeight, terrainData.maxHeight); }
private void Update() { if (mapDataThreadInfoQueue.Count > 0) { while (0 < mapDataThreadInfoQueue.Count) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { while (0 < meshDataThreadInfoQueue.Count) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (prefabDataInfoQueue.Count > 0) { while (0 < prefabDataInfoQueue.Count) { MapThreadInfo <PreFabData> threadInfo = prefabDataInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { lock (mapDataThreadInfoQueue) { if (mapDataThreadInfoQueue.Count > 0) { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } } lock (meshDataThreadInfoQueue) { if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } } }
void Update() { if (terrainData.reset || noiseData.reset) { textureData.ApplyToMaterial(terrainMaterial); terrainData.reset = false; noiseData.reset = false; } if (mapDataTheadInfoQueue.Count > 0) { for (int i = 0; i < mapDataTheadInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataTheadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataTheadInfoQueue.Count > 0) { for (int i = 0; i < meshDataTheadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataTheadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { int countMapDataThreadqueue = mapDataThreadQueue.Count; int countMeshDataThreadqueue = meshDataThreadQueue.Count; if (countMapDataThreadqueue > 0) { for (int i = 0; i < countMapDataThreadqueue; i++) { //info next item out of the que MapThreadInfo <MapData> threadInfo = mapDataThreadQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (countMeshDataThreadqueue > 0) { for (int i = 0; i < countMeshDataThreadqueue; i++) { //info next item out of the que MapThreadInfo <MeshData> threadInfo = meshDataThreadQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { if (chunkDataThreadInQueue.Count > 0) { for (int i = 0; i < chunkDataThreadInQueue.Count; i++) { MapThreadInfo <WorldChunkData> threadInfo = chunkDataThreadInQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (chunkComputedThreadInQueue.Count > 0) { for (int i = 0; i < chunkComputedThreadInQueue.Count; i++) { MapComputingThreadInfo <WorldChunkComputed> threadInfo = chunkComputedThreadInQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (chunkMeshThreadInQueue.Count > 0) { for (int i = 0; i < chunkMeshThreadInQueue.Count; i++) { MeshDataThreadInfo <MeshData> threadInfo = chunkMeshThreadInQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void MapDataThread(Vector2 center, Action <MapData> callback) { MapThreadInfo <MapData> mapInfo = new MapThreadInfo <MapData>(callback, GenerateMapData(center)); lock (mapDataThreadInfoQueue) { mapDataThreadInfoQueue.Enqueue(mapInfo); } }
void MeshDataThread(MapData data, int lod, Action <MeshData> callback) { MeshData meshData = MeshGenerator.GenerateTerrainMesh(data.noiseMap, meshHeightMultiplier, meshHeightCurve, lod); MapThreadInfo <MeshData> meshThreadInfo = new MapThreadInfo <MeshData>(callback, meshData); lock (meshDataThreadInfoQueue) { meshDataThreadInfoQueue.Enqueue(meshThreadInfo); } }
/// <summary> /// This function is called in a sperate thread and just generates the meshData using the terrainData object, and then adds the data ///to the queue to be accessed from the main thread /// </summary> /// <param name="mapData">The height map</param> /// <param name="levelOfDetail">The level of detail for the mesh</param> /// <param name="callBack">The function to be called once the mesh is generated</param> private void meshDataThread(MapData mapData, int levelOfDetail, Action <MeshData> callBack) { MeshData meshData = MeshGenerator.generateTerrainMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, levelOfDetail, terrainData.useFlatShading); MapThreadInfo <MeshData> meshThreadInfo = new MapThreadInfo <MeshData>(callBack, meshData); //Prevent multiple threads from accessing it at the same time lock (meshDataThreadInfoQueue) { meshDataThreadInfoQueue.Enqueue(meshThreadInfo); } }
// Update is called once per frame void Update() { if (threadQueue.Count > 0) { for (int i = 0; i < threadQueue.Count; i++) { MapThreadInfo mapThreadInfo = threadQueue.Dequeue(); mapThreadInfo.callback(mapThreadInfo.platforms); } } }
void Update() { while (mapDataThreadInfoQueue.Count > 0) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } while (meshDataThreadInfoQueue.Count > 0) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } }
/// <summary> /// This function is called in a seperate thread so that the game doesn't jam up as we generate lots of mapData objects /// </summary> /// <param name="centre">The centre point of the map</param> /// <param name="callBack">The function to be called once the map data is generated</param> private void mapDataThread(Vector2 centre, Action <MapData> callBack) { //Generate the mapData, all functions called in a thread run in this thread MapData mapData = generateMapData(centre); //Save this data to the MapThreadInfo object, it simply stores the data so that it can cross threads, with the given function and //The mapData as the parameter for that function MapThreadInfo <MapData> mapThreadInfo = new MapThreadInfo <MapData>(callBack, mapData); //lock prevents multiple threads from accessing an object at the same time //Add the mapThreadInfo to the Queue (like a list) of mapThreadInfo, where it can be accessed from the main thread lock (mapDataThreadInfoQueue) { mapDataThreadInfoQueue.Enqueue(mapThreadInfo); } }
private void Update() { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <float[, ]> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } }
private void CheckMeshDataThreadInfoQueue() { if (_meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < _meshDataThreadInfoQueue.Count; i++) { if (_meshDataThreadInfoQueue.Count > 0) { MapThreadInfo <MeshData> threadInfo = _meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } } }
void Update(){ if (mapDataThreadInfoQueue.Count > 0) { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo<MapData> threadInfo = mapDataThreadInfoQueue.Dequeue ();//Dequeue= the next thing in a queue threadInfo.Callback (threadInfo.Parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo<MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue (); threadInfo.Callback (threadInfo.Parameter); } } }
private void Update() { if (MapDataInfoQueue.Count > 0) { for (int i = 0; i < MapDataInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = MapDataInfoQueue.Dequeue(); threadInfo.callback(threadInfo.param); } } if (MeshDataInfoQueue.Count > 0) { for (int i = 0; i < MeshDataInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = MeshDataInfoQueue.Dequeue(); threadInfo.callback(threadInfo.param); } } }
void Update() { if (heightMapThreadInfoQueue.Count > 0) { for (int i = 0; i < heightMapThreadInfoQueue.Count; i++) { MapThreadInfo <HeightMap> threadInfo = heightMapThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { if (mapDataThreadInfoQueue.Count > 0) { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> info = mapDataThreadInfoQueue.Dequeue(); info.action(info.param); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> info = meshDataThreadInfoQueue.Dequeue(); info.action(info.param); } } }
void Update() { if (mapDataInfoQueue.Count > 0) { for (int i = 0; i < mapDataInfoQueue.Count; i++) { MapThreadInfo <MapData> mti = mapDataInfoQueue.Dequeue(); mti.callback(mti.parameter); } } if (meshDataInfoQueue.Count > 0) { for (int i = 0; i < meshDataInfoQueue.Count; i++) { MapThreadInfo <MeshData> mdi = meshDataInfoQueue.Dequeue(); mdi.callback(mdi.parameter); } } }
private void Update() { //Used as an endpoint for all threads, where the data they passed into their thread info queue is sent to the respective caller if (heightMapThreadInfoQueue.Count > 0) { for (int i = 0; i < heightMapThreadInfoQueue.Count; i++) { MapThreadInfo <HeightMap> threadInfo = heightMapThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
private void Update() { if (_mapThreadInfoQueue.Count > 0) { for (int i = 0; i < _mapThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> _threadInfo = _mapThreadInfoQueue.Dequeue(); _threadInfo.callBack(_threadInfo.parameter); } } if (_meshThreadInfoQueue.Count > 0) { for (int i = 0; i < _meshThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> _threadInfo = _meshThreadInfoQueue.Dequeue(); _threadInfo.callBack(_threadInfo.parameter); } } }
void Update() { if (mapDataThreadInfoQueue.Count > 0) { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); // The next thing in the queue threadInfo.callback(threadInfo.parameter); } } /*if (meshDataThreadInfoQueue.Count > 0) * { * for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) * { * MapThreadInfo<MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); * threadInfo.callback(threadInfo.parameter); * } * }*/ }
private void Update() { if (mapDataThradInfoQueue.Count > 0) // wenn sich ein Element in der Warteschlange befindet { for (int i = 0; i < mapDataThradInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThradInfoQueue.Dequeue(); //entfernt das erste element aus der Queue und schreibt dieses in die threadInfo Variable. threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { if (this.mapDataThreadInfoQueue.Count > 0) { for (int c = 0; c < this.mapDataThreadInfoQueue.Count; c++) { MapThreadInfo <MapData> threadInfo = this.mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); // callbacks are a mystifying thing } } if (this.meshDataThreadInfoQueue.Count > 0) { for (int c = 0; c < this.meshDataThreadInfoQueue.Count; c++) { MapThreadInfo <MeshData> threadInfo = this.meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { if (mapDataThreadInfoQueue.Count > 0) // if there are new map data in queue { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { if (mapDataThreadInfoQueueNr.Count > 0) //as long there are threads { for (int i = 0; i < mapDataThreadInfoQueueNr.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueueNr.Dequeue(); //Dequeue: the next thing in the queue threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueueNr.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueueNr.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueueNr.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
public void UpdateCallbacks() { //Go through callbacks if (noiseMapThreadInfoQueue.Count > 0) { for (int i = 0; i < noiseMapThreadInfoQueue.Count; i++) { MapThreadInfo <float[, ]> threadInfo = noiseMapThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (placableMapThreadInfoQueue.Count > 0) { for (int i = 0; i < placableMapThreadInfoQueue.Count; i++) { MapThreadInfo <bool[, ]> threadInfo = placableMapThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
void Update() { if (mapDataThreadInfoQueue.Count > 0) { //If the queue has something in it then loop through the elements for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
// Update is called once per frame void Update() { // Process next MapData in thread Queue if (mapDataThreadInfoQueue.Count > 0) { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } // Process next MeshData in thread Queue if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }
private void Update() { //If there is more than one element within the queue, loop through all elements, proceed to dequeue them, and call callback if (mapDataThreadInfoQueue.Count > 0) { for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) { MapThreadInfo<MapData> threadInfo = mapDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } if (meshDataThreadInfoQueue.Count > 0) { for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) { MapThreadInfo<MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue(); threadInfo.callback(threadInfo.parameter); } } }