Beispiel #1
0
        internal void AddFrame()
        {
            if (Framekeys.Count == maxPoints)
            {
                FrameData.Remove(Framekeys.Dequeue());
            }

            FrameData.Add((float)NetworkTime.time, new TrackedPointData()
            {
                position = transform.position,
                rotation = transform.rotation
            });
            Framekeys.Enqueue((float)NetworkTime.time);
        }
Beispiel #2
0
        internal void AddFrame()
        {
            if (Framekeys.Count == maxPoints)
            {
                FrameData.Remove(Framekeys.Dequeue());
            }

            FrameData.Add(NetworkingManager.singleton.NetworkTime, new TrackedPointData()
            {
                position = transform.position,
                rotation = transform.rotation
            });
            Framekeys.Enqueue(NetworkingManager.singleton.NetworkTime);
        }
        public void RemoveValues(Predicate <T> falseCondition)
        {
            List <Tuple <DateTime, T> > tuplesList =
                new List <Tuple <DateTime, T> >(Enumerable.Zip(lDateTimeStamps.ToList(), dataSeria.ToList(),
                                                               (dt, dat) => new Tuple <DateTime, T>(dt, dat)));

            List <Tuple <DateTime, T> > filteredTuplesList = tuplesList.FindAll(tpl => !falseCondition(tpl.Item2));


            dataSeria = new FixedQueue <T>(dataSeria.Count);
            dataSeria.Enqueue(filteredTuplesList.ConvertAll <T>(tpl => tpl.Item2));
            lDateTimeStamps = new FixedQueue <DateTime>(lDateTimeStamps.Count);
            lDateTimeStamps.Enqueue(filteredTuplesList.ConvertAll <DateTime>(tpl => tpl.Item1));
        }
Beispiel #4
0
        internal void AddFrame()
        {
            if (m_Framekeys.Count == m_MaxPoints)
            {
                m_FrameData.Remove(m_Framekeys.Dequeue());
            }

            m_FrameData.Add(NetworkManager.Singleton.NetworkTime, new TrackedPoint()
            {
                position = transform.position,
                rotation = transform.rotation
            });
            m_Framekeys.Enqueue(NetworkManager.Singleton.NetworkTime);
        }
        public unsafe void Enqueue_Item_Success()
        {
            var expected = new TestStruct()
            {
                X = 3, Y = 1
            };

            FixedQueue <TestStruct> sut = stackalloc TestStruct[1];

            Assert.AreEqual(1, sut.Capacity);
            Assert.AreEqual(0, sut.Count);

            Assert.True(sut.Enqueue(expected));
            Assert.AreEqual(1, sut.Count);
        }
Beispiel #6
0
        private void LogCallback(ApplicationLogHandler.LogInfo log)
        {
            if (log == null)
            {
                return;
            }

            var item = new LogEntry()
            {
                type       = log.Type,
                message    = log.Condition,
                stackTrace = log.StackTrace,
            };

            reportQueue.Enqueue(item);
        }
Beispiel #7
0
        public void Add(LogData log)
        {
            var controllerName = log.ControllerName;

            if (string.IsNullOrEmpty(controllerName))
            {
                return;
            }

            logs.Enqueue(log);

            if (onLogUpdate != null)
            {
                onLogUpdate.OnNext(Unit.Default);
            }
        }
        public unsafe void Wrapping_Success()
        {
            FixedQueue <TestStruct> sut = stackalloc TestStruct[1];

            for (var i = 0; i < 20; i++)
            {
                var expected = new TestStruct()
                {
                    X = i, Y = i
                };
                sut.Enqueue(expected);

                ref var actual = ref sut.Dequeue();

                Assert.AreEqual(expected.X, actual.X);
                Assert.AreEqual(expected.Y, actual.Y);
            }
        public unsafe void Peek_Item_Success()
        {
            var expected = new TestStruct()
            {
                X = 3, Y = 1
            };

            FixedQueue <TestStruct> sut = stackalloc TestStruct[1];

            sut.Enqueue(expected);

            var testStruct = sut.Peek();

            Assert.AreEqual(1, sut.Count);

            Assert.AreEqual(3, testStruct.X);
            Assert.AreEqual(1, testStruct.Y);
        }
Beispiel #10
0
        /// <summary>
        /// Tries to save the value to the history.
        /// Only succeeds if this value was cached before.
        /// </summary>
        /// <param name="value"></param>
        public void SaveValue(T value)
        {
            //The value must be the last value te be cached.
            if (!Comparisons <T> .AreEqual(value, _lastValue))
            {
                throw new InvalidOperationException(" Value added to history was not registered to the pattern matchers.");
            }

            //Add the value.
            _historyValues.Enqueue(_lastValue);
            HistoryMatches.Enqueue(_lastValueMatch);

            //Update match counter.
            if (_lastValueMatch)
            {
                Matches++;
            }
        }
        public void Start(WebRequest webRequest)
        {
            var url = webRequest.HostUrl.Replace(serverUrl, string.Empty);

            var info = new WebRequestInfo()
            {
                url         = url,
                requestType = GetRequestType(webRequest),
                status      = WebRequestInfo.RequestStatus.Connection,
            };

            webRequestInfos.Add(webRequest, info);

            requestInfoHistory.Enqueue(info);

            if (onUpdateInfo != null)
            {
                onUpdateInfo.OnNext(Unit.Default);
            }
        }
        public void RemoveDuplicatedTimeStamps()
        {
            List <DateTime> lDateTimeStampsLoc      = lDateTimeStamps.ToList();
            List <DateTime> lDateTimeStampsFiltered = new List <DateTime>(lDateTimeStamps.ToList().Distinct <DateTime>());
            List <T>        dataSeriaLoc            = dataSeria.ToList();

            List <T> dataSeriaFiltered = new List <T>();
            int      idx = 0;

            foreach (DateTime dtStamp in lDateTimeStampsFiltered)
            {
                idx = lDateTimeStampsLoc.FindIndex(idx, datetimeValue => datetimeValue == dtStamp);
                dataSeriaFiltered.Add(dataSeriaLoc[idx]);
            }

            lDateTimeStamps = new FixedQueue <DateTime>(lDateTimeStamps.Count);
            lDateTimeStamps.Enqueue(lDateTimeStampsFiltered);
            dataSeria = new FixedQueue <T>(dataSeria.Count);
            dataSeria.Enqueue(dataSeriaFiltered);
        }
Beispiel #13
0
        internal static void StartTick(TickType type)
        {
            if (!isRunning)
            {
                return;
            }
            if (Ticks.Count == tickHistory)
            {
                Ticks.Dequeue();
            }

            ProfilerTick tick = new ProfilerTick()
            {
                Type    = type,
                Frame   = Time.frameCount,
                EventId = EventIdCounter
            };

            EventIdCounter++;
            Ticks.Enqueue(tick);
            CurrentTick = tick;
        }
Beispiel #14
0
        //----- property -----

        //----- method -----

        private void ApplyDummyAsset()
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (Image.sprite != null && Image.sprite.name != DummyAssetName)
            {
                return;
            }

            if (string.IsNullOrEmpty(assetGuid))
            {
                return;
            }

            if (string.IsNullOrEmpty(spriteId))
            {
                return;
            }

            var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);

            if (string.IsNullOrEmpty(assetPath))
            {
                return;
            }

            if (spriteAssetCache == null)
            {
                spriteAssetCache = new FixedQueue <AssetCacheInfo>(250);
            }

            Sprite spriteAsset = null;

            var cacheAssetInfo = spriteAssetCache.FirstOrDefault(x => x.assetGuid == assetGuid && x.spriteId == spriteId);

            if (cacheAssetInfo == null)
            {
                spriteAsset = AssetDatabase.LoadAllAssetsAtPath(assetPath)
                              .OfType <Sprite>()
                              .FirstOrDefault(x => x.GetSpriteID().ToString() == spriteId);

                if (spriteAsset != null)
                {
                    cacheAssetInfo = new AssetCacheInfo()
                    {
                        assetGuid   = assetGuid,
                        spriteId    = spriteId,
                        spriteAsset = spriteAsset,
                    };

                    spriteAssetCache.Enqueue(cacheAssetInfo);
                }
            }
            else
            {
                spriteAsset = cacheAssetInfo.spriteAsset;

                spriteAssetCache.Remove(cacheAssetInfo);

                spriteAssetCache.Enqueue(cacheAssetInfo);
            }

            if (spriteAsset == null)
            {
                return;
            }

            DeleteCreatedAsset();

            var texture       = spriteAsset.texture;
            var rect          = spriteAsset.rect;
            var pivot         = spriteAsset.pivot;
            var pixelsPerUnit = spriteAsset.pixelsPerUnit;
            var border        = spriteAsset.border;

            var sprite = Sprite.Create(texture, rect, pivot, pixelsPerUnit, 0, SpriteMeshType.FullRect, border);

            sprite.name = DummyAssetName;

            sprite.hideFlags = HideFlags.DontSaveInEditor;

            Image.sprite = sprite;
        }
Beispiel #15
0
 /// <inheritdoc />
 public void RegisterValue(T value)
 {
     _history.Enqueue(value);
 }
Beispiel #16
0
 void Start()
 {
     Framekeys = new FixedQueue <float>(maxPoints);
     Framekeys.Enqueue(0);
     LagCompensationManager.simulationObjects.Add(this);
 }
Beispiel #17
0
        private void ViewAccountListener(View listener)
        {
            ButtonView view = listener as ButtonView;

            void ShowAccountData(string name, decimal balance, Account.AccountType type)
            {
                // Build dialog view manually
                var show = new DialogView(
                    new ViewData("DialogView")

                    // Layout parameters
                    .SetAttribute("padding_left", 2)
                    .SetAttribute("padding_right", 2)
                    .SetAttribute("padding_top", 1)
                    .SetAttribute("padding_bottom", 1)
                    .SetAttribute("border", (int)ConsoleColor.DarkGreen)

                    // Option buttons
                    .AddNested(new ViewData("Options").AddNestedSimple("Option", GetIntlString("GENERIC_dismiss")).AddNestedSimple("Option", GetIntlString("SE_account_delete")))

                    // Message
                    .AddNestedSimple("Text",
                                     GetIntlString("SE_info")
                                     .Replace("$0", name)
                                     .Replace("$1", GetIntlString(type == Account.AccountType.Savings ? "SE_acc_saving" : "SE_acc_checking"))
                                     .Replace("$2", balance.ToTruncatedString())),

                    // No translation (it's already handled)
                    LangManager.NO_LANG);

                show.RegisterSelectListener((_, s, l) =>
                {
                    if (s == 0)
                    {
                        Hide(show);
                    }
                    else
                    {
                        var ynDialog  = GetView <DialogView>("yn");
                        ynDialog.Text = GetIntlString("SE_account_delete_warn");
                        ynDialog.RegisterSelectListener((v, i, str) =>
                        {
                            var stall  = GetView <TextView>("stall");
                            stall.Text = GetIntlString("SE_account_delete_stall");
                            Show(stall);
                            if (i == 1)
                            {
                                Promise p   = Promise.AwaitPromise(interactor.CloseAccount(name));
                                p.Subscribe = deleteAwait =>
                                {
                                    if (bool.Parse(deleteAwait.Value))
                                    {
                                        accountChange = true;
                                        controller.Popup(GetIntlString("SE_account_delete_success"), 1500, ConsoleColor.Green, () => {
                                            bool closed = false;
                                            controller.CloseIf(predV => closed = !closed && predV is ListView);
                                            Hide(show);
                                        });
                                    }
                                    else
                                    {
                                        controller.Popup(GetIntlString("SE_account_delete_fail"), 2000, ConsoleColor.Red);
                                    }
                                    Hide(stall);
                                };
                            }
                        });
                        Show(ynDialog);
                    }
                });
                Show(show);
            }

            // TODO: Show account info
            var account = AccountLookup(view.Text);

            if (account == null)
            {
                // TODO: Get account data from server + cache data
                Show("data_fetch");
                Promise info_promise = Promise.AwaitPromise(interactor.AccountInfo(view.Text));
                info_promise.Subscribe = evt =>
                {
                    Hide("data_fetch");
                    if (evt.Value.StartsWith("ERROR") || !Account.TryParse(evt.Value, out var act))
                    {
                        controller.Popup(GetIntlString("GENERIC_error"), 3000, ConsoleColor.Red);
                    }
                    else
                    {
                        // Cache result (don't cache savings accounts because their value updates pretty frequently)
                        if (act.type != Account.AccountType.Savings)
                        {
                            accountDataCache.Enqueue(new Tuple <string, Account>(view.Text, act));
                        }
                        ShowAccountData(view.Text, act.balance, act.type);
                    }
                };
            }
            else
            {
                ShowAccountData(account.Item1, account.Item2.balance, account.Item2.type);
            }
        }
Beispiel #18
0
        private IEnumerator TransitionCore <TArgument>(TArgument sceneArgument, LoadSceneMode mode, bool isSceneBack, bool registerHistory) where TArgument : ISceneArgument
        {
            if (!sceneArgument.Identifier.HasValue)
            {
                yield break;
            }

            // プリロード停止.
            if (preLoadDisposable != null)
            {
                preLoadDisposable.Dispose();
                preLoadDisposable = null;
            }

            TransitionTarget = sceneArgument.Identifier;

            var prevSceneArgument = currentSceneArgument;

            currentSceneArgument = sceneArgument;

            var diagnostics = new TimeDiagnostics();

            var prev = current;

            // 現在のシーンを履歴に残さない場合は、既に登録済みの現在のシーン(history[要素数 - 1])を外す.
            if (!registerHistory && history.Any())
            {
                history.RemoveAt(history.Count - 1);
            }

            //====== Begin Transition ======

            diagnostics.Begin(TimeDiagnostics.Measure.Total);

            yield return(TransitionStart(currentSceneArgument).ToYieldInstruction());

            if (prev != null)
            {
                //====== Scene Leave ======

                diagnostics.Begin(TimeDiagnostics.Measure.Leave);

                // Leave通知.
                if (onLeave != null)
                {
                    onLeave.OnNext(prevSceneArgument);
                }

                // 現在のシーンの終了処理を実行.
                yield return(prev.Instance.LeaveAsync().ToYieldInstruction());

                // PlayerPrefsを保存.
                PlayerPrefs.Save();

                // Leave終了通知.
                if (onLeaveComplete != null)
                {
                    onLeaveComplete.OnNext(prevSceneArgument);
                }

                prev.Disable();

                diagnostics.Finish(TimeDiagnostics.Measure.Leave);
            }

            //====== Scene Unload ======

            // 不要なシーンをアンロード.
            var unloadScenes = loadedscenes.Values
                               // 遷移先のシーンではない.
                               .Where(x => x.Identifier != TransitionTarget)
                               // SceneBaseクラスが存在しない.
                               .Where(x => UnityUtility.IsNull(x.Instance))
                               // キャッシュ対象でない.
                               .Where(x => cacheScenes.All(y => y != x))
                               // 次のシーンのPreload対象ではない.
                               .Where(x => currentSceneArgument.PreLoadScenes.All(y => y != x.Identifier))
                               .ToArray();

            foreach (var unloadScene in unloadScenes)
            {
                yield return(UnloadScene(unloadScene).ToYieldInstruction());

                if (unloadScene.Identifier.HasValue)
                {
                    loadedscenes.Remove(unloadScene.Identifier.Value);
                }
            }

            //====== Load Next Scene ======

            diagnostics.Begin(TimeDiagnostics.Measure.Load);

            // 次のシーンを読み込み.
            var identifier = sceneArgument.Identifier.Value;

            var sceneInfo = loadedscenes.GetValueOrDefault(identifier);

            if (sceneInfo == null)
            {
                var loadYield = LoadScene(identifier, mode).ToYieldInstruction();

                yield return(loadYield);

                if (!loadYield.HasResult)
                {
                    yield break;
                }

                sceneInfo = loadYield.Result;

                if (sceneArgument.Cache)
                {
                    cacheScenes.Enqueue(sceneInfo);
                }
            }

            var scene = sceneInfo.GetScene();

            if (!scene.HasValue)
            {
                Debug.LogErrorFormat("[ {0} ] : Scene情報の取得に失敗しました.", identifier);

                yield break;
            }

            if (sceneInfo.Instance == null)
            {
                Debug.LogErrorFormat("[ {0} ] : SceneBase継承クラスが存在しません.", scene.Value.path);

                yield break;
            }

            SetSceneActive(scene);

            // 前のシーンからの引数を設定.
            sceneInfo.Instance.SetArgument(sceneArgument);

            // 現在のシーンとして登録.
            current = sceneInfo;

            // 次のシーンを履歴に登録.
            // シーン引数を保存する為遷移時に引数と一緒に履歴登録する為、履歴の最後尾は現在のシーンになる.
            if (current.Instance != null)
            {
                history.Add(currentSceneArgument);
            }

            // シーン読み込み後にAwake、Startが終わるのを待つ為1フレーム後に処理を再開.
            yield return(null);

            diagnostics.Finish(TimeDiagnostics.Measure.Load);

            //====== Scene Prepare ======

            diagnostics.Begin(TimeDiagnostics.Measure.Prepare);

            // Prepar通知.
            if (onPrepare != null)
            {
                onPrepare.OnNext(currentSceneArgument);
            }

            // 次のシーンの準備処理実行.
            if (current.Instance != null)
            {
                yield return(current.Instance.Prepare(isSceneBack).ToYieldInstruction());
            }

            // Prepar終了通知.
            if (onPrepareComplete != null)
            {
                onPrepareComplete.OnNext(currentSceneArgument);
            }

            diagnostics.Finish(TimeDiagnostics.Measure.Prepare);

            //====== Unload PrevScene ======

            // キャッシュ対象でない場合はアンロード.
            if (prevSceneArgument == null || !prevSceneArgument.Cache)
            {
                yield return(UnloadScene(prev).ToYieldInstruction());
            }

            //====== Scene Wait ======

            // メモリ解放.
            yield return(CleanUp().ToYieldInstruction());

            // 外部処理待機.
            yield return(Observable.FromMicroCoroutine(() => TransitionWait()).ToYieldInstruction());

            // シーンを有効化.
            sceneInfo.Enable();

            // シーン遷移完了.
            TransitionTarget = null;

            // シーン遷移終了.
            yield return(TransitionFinish(currentSceneArgument).ToYieldInstruction());

            //====== Scene Enter ======

            // Enter通知.
            if (onEnter != null)
            {
                onEnter.OnNext(currentSceneArgument);
            }

            // 次のシーンの開始処理実行.
            if (current.Instance != null)
            {
                current.Instance.Enter(isSceneBack);
            }

            // Enter終了通知.
            if (onEnterComplete != null)
            {
                onEnterComplete.OnNext(currentSceneArgument);
            }

            //====== Report ======

            diagnostics.Finish(TimeDiagnostics.Measure.Total);

            var prevScene = prev.Identifier;
            var nextScene = current.Identifier;

            var total  = diagnostics.GetTime(TimeDiagnostics.Measure.Total);
            var detail = diagnostics.BuildDetailText();

            UnityConsole.Event(ConsoleEventName, ConsoleEventColor, "{0} → {1} ({2:F2}ms)\n\n{3}", prevScene, nextScene, total, detail);

            //====== PreLoad ======

            preLoadDisposable = PreLoadScene(sceneArgument.PreLoadScenes)
                                .Subscribe(_ => preLoadDisposable = null)
                                .AddTo(Disposable);
        }
Beispiel #19
0
 void Move(InputAction.CallbackContext context)
 {
     lastMoves.Enqueue(new _CallbackContext(context));
 }
Beispiel #20
0
        //----- property -----

        //----- method -----

        private void ApplyDummyAsset()
        {
            if (Application.isPlaying)
            {
                return;
            }

            DeleteCreatedAsset();

            if (RawImage.texture != null && RawImage.texture.name != DummyAssetName)
            {
                return;
            }

            if (string.IsNullOrEmpty(assetGuid))
            {
                return;
            }

            var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);

            if (string.IsNullOrEmpty(assetPath))
            {
                return;
            }

            if (textureAssetCache == null)
            {
                textureAssetCache = new FixedQueue <AssetCacheInfo>(100);
            }

            Texture textureAsset = null;

            var cacheAssetInfo = textureAssetCache.FirstOrDefault(x => x.assetGuid == assetGuid);

            if (cacheAssetInfo == null)
            {
                textureAsset = AssetDatabase.LoadMainAssetAtPath(assetPath) as Texture;

                if (textureAsset != null)
                {
                    cacheAssetInfo = new AssetCacheInfo()
                    {
                        assetGuid    = assetGuid,
                        textureAsset = textureAsset,
                    };

                    textureAssetCache.Enqueue(cacheAssetInfo);
                }
            }
            else
            {
                textureAsset = cacheAssetInfo.textureAsset;

                textureAssetCache.Remove(cacheAssetInfo);

                textureAssetCache.Enqueue(cacheAssetInfo);
            }

            if (textureAsset == null)
            {
                return;
            }

            DeleteCreatedAsset();

            var texture = new Texture2D(textureAsset.width, textureAsset.height, TextureFormat.ARGB32, false);

            texture.name = DummyAssetName;

            texture.hideFlags = HideFlags.DontSaveInEditor;

            Graphics.ConvertTexture(textureAsset, texture);

            // Bug: UnityのバグでこのタイミングでアクティブなRenderTextureを空にしないと下記警告が出る.
            // 「Releasing render texture that is set to be RenderTexture.active!」.
            RenderTexture.active = null;

            RawImage.texture = texture;
        }