private void UpdateWarningState(List <VoosActor> actorsToControl) { messagePanelLazy = messagePanelLazy ?? GameObject.FindObjectOfType <PersistentMessagePanel>(); if (messagePanelLazy == null) { return; } // If we haven't been assigned a player number yet, don't warn. if (GetMyPlayerNumber() <= 0) { return; } // Whenever we go into edit mode, we reset to "not warned state" to warn the user again if they // go into play mode. if (userMain.InEditMode()) { warnState = WarnState.NO_WARNING; messagePanelLazy.Hide(); return; } switch (warnState) { case WarnState.NO_WARNING: if (actorsToControl.Count != 1) { warnState = WarnState.COUNTING_DOWN; countdownToWarn = DELAY_BEFORE_WARNING; } break; case WarnState.COUNTING_DOWN: if (actorsToControl.Count == 1) { warnState = WarnState.NO_WARNING; } if (engine.GetIsRunning() && 0 > (countdownToWarn -= Time.unscaledDeltaTime)) { warnState = WarnState.SHOWING_WARNING; ShowControlsWarning(actorsToControl); } break; case WarnState.SHOWING_WARNING: if (actorsToControl.Count == 1) { warnState = WarnState.NO_WARNING; messagePanelLazy.Hide(); } break; default: throw new System.Exception("Invalid warn state " + warnState); } }
public IEnumerator Setup() { TestUtil.TestScene scene = new TestUtil.TestScene("main"); yield return(scene.LoadAndWait()); behaviorSystem = scene.FindRootComponent <BehaviorSystem>("ScriptingSystems"); voosEngine = scene.FindRootComponent <VoosEngine>("ScriptingSystems"); // Wait for loading done.. while (true) { if (voosEngine.GetIsRunning()) { yield break; } yield return(null); } }
bool GetIsPaused() { return(!voosEngine.GetIsRunning()); }
IEnumerator BenchmarkRoutine() { float loadToStart = Time.realtimeSinceStartup - SceneLoadStartTime; UnityEngine.Profiling.Profiler.enabled = false; SaveLoadController.SuppressLegacyWarning = true; // Let the framerate run free.. QualitySettings.vSyncCount = 0; Application.targetFrameRate = -1; // Hitches.. autosaves.SetPaused(true); CheckGlobals(); while (!voosEngine.GetIsRunning()) { yield return(null); } float loadToVoos = Time.realtimeSinceStartup - SceneLoadStartTime; // Make sure we want for all terrain chunks too.. while (!terrain.IsSettledForPerfMeasurement()) { yield return(new WaitForSecondsRealtime(0.5f)); } float loadToTerrain = Time.realtimeSinceStartup - SceneLoadStartTime; // Let it settle down a bit.. yield return(new WaitForSecondsRealtime(2f)); CheckGlobals(); // Now collect some frame times. const int numSamples = 200; long[] sampleTicks = new long[numSamples]; float[] voosUpdateSampleMillis = new float[numSamples]; SD.Stopwatch watch = new SD.Stopwatch(); // Don't run until we start our first frame. watch.Stop(); int currSample = 0; voosEngine.onVoosUpdateTiming += millis => { if (watch.IsRunning) { voosUpdateSampleMillis[currSample] = millis; } }; while (true) { CheckGlobals(); yield return(new WaitForEndOfFrame()); if (watch.IsRunning) { // Just finished recording a sample! watch.Stop(); sampleTicks[currSample] = watch.ElapsedTicks; currSample++; if (currSample >= numSamples) { // All done! break; } } // Start next sample. watch.Restart(); } // Sanity check voos. foreach (float voosMs in voosUpdateSampleMillis) { Debug.Assert(voosMs > 0); } float averageMs = TicksToMillis(sampleTicks.Sum()) / numSamples; float averageVoosMs = voosUpdateSampleMillis.Sum() / numSamples; // Update state file and kick off the next one.. BenchmarkState state = CurrState; Array.Sort(sampleTicks); var res = new BenchmarkState.SceneResult { voosFile = BenchmarkVoosFiles[CurrSceneIndex], avgFrameMs = averageMs, avgVoosUpdateMs = averageVoosMs, percentile90 = TicksToMillis(sampleTicks.AtFractionalPosition(0.90f)), percentile95 = TicksToMillis(sampleTicks.AtFractionalPosition(0.95f)), percentile99 = TicksToMillis(sampleTicks.AtFractionalPosition(0.99f)), loadToStart = loadToStart, loadToTerrain = loadToTerrain, loadToVoos = loadToVoos, actorBytes = networking.GetVoosInitBytes().Length, terrainBytes = terrain.SerializeTerrainV2().Length }; state.results = state.results ?? new BenchmarkState.SceneResult[0]; state.results = state.results.ExpensiveWith(res); CurrSceneIndex++; Util.Log($"OK finished benchmark for scene {res.voosFile}. avgFrameMs={res.avgFrameMs} avgVoosUpdateMs={res.avgVoosUpdateMs}"); CheckGlobals(); if (CurrSceneIndex >= BenchmarkVoosFiles.Length) { string outDir = Path.Combine((Application.isEditor ? "editor-" : "release-") + "benchmark-results", System.Net.Dns.GetHostName()); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } // We're done! Save to file. string outPath = Path.Combine(outDir, System.DateTime.Now.ToString("yyyyMMddTHHmm") + ".json"); File.WriteAllText(outPath, JsonUtility.ToJson(CurrState, true)); CurrState = null; FindObjectOfType <GameBuilderSceneController>().LoadSplashScreen(); } else { GameBuilderSceneController scenes = FindObjectOfType <GameBuilderSceneController>(); SceneLoadStartTime = Time.realtimeSinceStartup; scenes.RestartAndLoad(System.IO.Path.Combine(Application.streamingAssetsPath, "ExampleGames", "Internal", BenchmarkVoosFiles[CurrSceneIndex])); } }
void Update() { if (IsMultiplayerHost()) { UpdateBuildPermissionsForNewUsers(); } CheckResetByHotkey(); CheckPauseByHotkey(); AudioListener.volume = Application.isFocused ? 1 : 0; bool playingAndPaused = !editMode && !voosEngine.GetIsRunning(); if (pauseFeedbackObjectPlaying.activeSelf != playingAndPaused) { pauseFeedbackObjectPlaying.SetActive(playingAndPaused); } bool editingAndPaused = editMode && !voosEngine.GetIsRunning(); if (pauseFeedbackObjectEditing.activeSelf != editingAndPaused) { pauseFeedbackObjectEditing.SetActive(editingAndPaused); } ToggleReticles(!CursorActive()); recoveryModeText.SetActive(GameBuilderApplication.IsRecoveryMode); if (!KeyLock()) { if (inputControl.GetButtonDown("View")) { NextCameraView(); } if (!GameBuilderApplication.IsStandaloneExport) { if (inputControl.GetButtonDown("Save")) { SaveFromShortcut(); } if (inputControl.GetButtonDown("Console")) { ToggleConsole(); } UndoCheck(); } } if (inputControl.GetButtonDown("ToggleBuildPlay") && (!KeyLock() || Input.GetKey(KeyCode.LeftControl)) && !IsHeaderMenuActive() && CanEdit()) { SetEditMode(!editMode); } if (editMode && !CanEdit()) { SetEditMode(false); } if (Input.GetButtonDown("Cancel")) { OnMenuButtonDown(); } if (CursorActive() != IsCursorVisible()) { Cursor.lockState = CursorActive() ? CursorLockMode.None : CursorLockMode.Locked; Cursor.visible = Cursor.lockState == CursorLockMode.Locked ? false : true; } //update mouse position if (CursorActive() && !CursorOverUI()) { Vector2 pos = Input.mousePosition; pos.x = Mathf.Clamp01(pos.x / Screen.width); pos.y = Mathf.Clamp01(pos.y / Screen.height); mousePos = pos; } // Check if we are in the right camera mode for the current player actor. UpdateCameraActor(); // HACK: to avoid jarring camera changes, if there is no player actor and we're in play mode, then set // the UserBody to be where the last play mode avatar position was. Otherwise it would just sit there // at Vector3.zero, and the camera would warp all the way there, then all the way back, and that's ugly. if (GetPlayerActor() == null && !InEditMode() // Fix NPE on scene switch && userBody != null && userBody.transform != null) { userBody.transform.position = playMain.GetAvatarPosition(); } UpdateUserBodyTint(); UpdateIsPlayingAsRobot(); }