Quantcast
Channel: Questions in topic: "webgl"
Viewing all articles
Browse latest Browse all 2390

Multi threading to Main thread

$
0
0
I follow Sebastian Legue's procedural terrain generation tutorials and it work. and I'm try to use it for webgl and for that it don't work. I think it's because of Multi Threading. so can you tell me how to edit for only main thread? using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Threading; public class ThreadedDataRequester : MonoBehaviour { static ThreadedDataRequester instance; Queue dataQueue = new Queue(); void Awake() { instance = FindObjectOfType (); } public static void RequestData(Func generateData, Action callback) { ThreadStart threadStart = delegate { instance.DataThread (generateData, callback); }; new Thread (threadStart).Start (); } void DataThread(Func generateData, Action callback) { object data = generateData (); lock (dataQueue) { dataQueue.Enqueue (new ThreadInfo (callback, data)); } } void Update() { if (dataQueue.Count > 0) { for (int i = 0; i < dataQueue.Count; i++) { ThreadInfo threadInfo = dataQueue.Dequeue (); threadInfo.callback (threadInfo.parameter); } } } struct ThreadInfo { public readonly Action callback; public readonly object parameter; public ThreadInfo (Action callback, object parameter) { this.callback = callback; this.parameter = parameter; } } } this is his code

Viewing all articles
Browse latest Browse all 2390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>