Exemplo n.º 1
0
    public void LateUpdate()
    {
        if (nextCheck > Time.time)
        {
            return;
        }
        for (int i = 0; i < downloadingList.Length; i++)
        {
            if (downloadingList[i] == null || downloadingList[i].done)
            {
                if (downloadQueue.Count > 0)
                {
                    downloadingList[i]     = downloadQueue.Dequeue();
                    downloadingList[i].www = new WWW(downloadingList[i].url);
                    pendingRequests++;
                }
            }
            else
            {
                progress[i] = downloadingList[i].www.progress;
                if (downloadingList[i].www.isDone)
                {
                    var www = downloadingList[i].www;
                    if (string.IsNullOrEmpty(www.error) &&
                        !string.IsNullOrEmpty(www.text))
                    {
                        string res = string.Copy(www.text);
                        Debug.Log("Success!: " + www.text + "\n" + www.url);
                        downloadingList[i].onSuccess(res);
                    }
                    else
                    {
                        string err = "NULL RESPONCE";
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            err = string.Copy(www.error);
                        }
                        Debug.Log("Error: " + www.error + "\n" + www.url);
                        downloadingList[i].onFail(err);
                    }
                    www.Dispose();
                    downloadingList[i].www  = null;
                    downloadingList[i].done = true;
                    pendingRequests--;
                }
            }
        }

        InformationMonitor.SetLabel("Pending: ", pendingRequests);

        nextCheck = checkInterval + Time.time;
        if (nextGC < Time.time)
        {
            GC.Collect();
            nextGC = gcInterval + Time.time;
        }
    }
Exemplo n.º 2
0
    void Start()
    {
        Instance = this;

        // FrameRateMonitor = GameObject.Find("FrameRate").GetComponent<Text>();

        OscStatus    = GameObject.Find("OscStatus").GetComponent <RawImage>();
        OscMonitor   = GameObject.Find("OscMonitor").GetComponent <RawImage>();
        MidiStatus   = GameObject.Find("MidiStatus").GetComponent <RawImage>();
        MidiMonitor  = GameObject.Find("MidiMonitor").GetComponent <RawImage>();
        KinectStatus = GameObject.Find("KinectStatus").GetComponent <RawImage>();
        ControlType  = GameObject.Find("ControlType").GetComponent <Text>();

        DummyAirsticks = GameObject.Find("Prototyping").GetComponent <DummyAirsticks>();
    }
Exemplo n.º 3
0
    private IEnumerator CollectAllData(DataType type, DateTime fromDate, DateTime toDate)
    {
        float[] results = currentDatas[type];
        for (var i = 0; i < results.Length; ++i)
        {
            results[i] = -2f;
        }
        float    lon            = 0f;
        float    lat            = 0f;
        DateTime requestDate    = fromDate;
        DateTime endDate        = toDate;
        int      retrievedDatas = 0;

        while (requestDate <= endDate)
        {
            // キャッシュファイルの場所
            var currentDataFilePath =
                type.ToString() + requestDate.ToString("yyyy-MM-dd")
                + "x" + dataScale.ToString() + ".cache";
            if (dataSource == DataSource.SERVER)
            {
                // キャッシュファイルから情報を復元
                if (fileSystem.CopyArrayFromFile(currentDataFilePath, ref results))
                {
                    int loadedCount = 0;
                    foreach (float v in results)
                    {
                        if (v != -2)
                        {
                            ++loadedCount;
//                        print(v);
                        }
                    }
                    print("Loaded " + loadedCount.ToString() + " of " + type.ToString() + " on " +
                          requestDate.ToString("yyyy-MM-dd") + " from cache.");
                }
            }

            // データ保存用のメソッド。コールバックから呼ばれる
            Action <float, float, float> StoreData = (float _lon, float _lat, float val) => {
                pendingHttpRequests--;
                retrievedDatas++;

                int index = Mathf.FloorToInt(_lat * totalLongitudes + _lon);
                results[index] = val;

                if (retrievedDatas % 32 == 0)
                {
                    SaveCache(currentDataFilePath, results);
                }
            };

            print("Retrieving " + type.ToString() + " on " + requestDate.ToString("yyyy-MM-dd"));
            lon = 0f;
            lat = 0f;
            while (lon <= totalLongitudes)
            {
                // 取得を中止しているとき
                if (abortCollection)
                {
                    if (pendingHttpRequests <= 0)
                    {
                        print("Retrieve aborted");
                        SaveCache(currentDataFilePath, results);
                        return(false);
                    }
                    yield return(new WaitForSeconds(3f));

                    continue;
                }

                // すでに初期値以外のデータが入っていた場合
                if (results[Mathf.FloorToInt(lat * totalLongitudes + lon)] != -2f)
                {
                    retrievedDatas++;
                }
                else
                {
                    if (pendingHttpRequests >= MAX_PARALLEL_REQUEST)
                    {
                        yield return(new WaitForSeconds(5f));

                        continue;
                    }

                    // HTTPRequestWrapperにデータの取得を依頼する
                    pendingHttpRequests++;
                    RetrieveData(type, requestDate, lon, lat,
                                 (float data, float longitude, float latitude) => {
                        StoreData(longitude, latitude, data);
                    },
                                 (string responceText, float longitude, float latitude) => {
                        StoreData(longitude, latitude, -1f);
                    });

                    // 取得間隔調整用
                    if (pendingHttpRequests >= 8)
                    {
                        yield return(new WaitForSeconds(2.5f));
                    }
                    else if (pendingHttpRequests > 0)
                    {
                        yield return(new WaitForSeconds(0.2f));
                    }
                }

                // ビューがデータの更新を検知するためのイベント
                if (onDataUpdate != null)
                {
                    onDataUpdate(type, results);
                }

                InformationMonitor.SetLabel("Progress (" + type.ToString() + "): ",
                                            (retrievedDatas * 100 / results.Length).ToString() + "% (" + retrievedDatas.ToString() + "/" +
                                            results.Length.ToString() + ")");

                lat++;
                if (lat >= totalLatitudes)
                {
                    lon++;
                    lat = 0;
                    yield return(null);
                }
            }
            SaveCache(currentDataFilePath, results);
            requestDate = requestDate.AddDays(1);
            yield return(null);
        }
        if (onDataComplete != null)
        {
            onDataComplete(type, results);
        }
    }
Exemplo n.º 4
0
 private void Awake()
 {
     progress = new float[downloadingList.Length];
     InformationMonitor.SetLabel("Pending: ", 0);
 }