Beispiel #1
0
 void LoadGame(GameBuilderApplication.PlayOptions playOpts)
 {
     if (localVoosFile != null)
     {
         // Two action logs intentional.
     }
     else
     {
         ulong itemId = workshopItem.SteamNative.m_nPublishedFileId.m_PublishedFileId;
         // Two action logs intentional.
     }
     loadingScreen.ShowAndDo(() =>
     {
         if (localVoosFile != null)
         {
             var gameOpts = new GameBuilderApplication.GameOptions {
                 playOptions = playOpts
             };
             loadingScreen.ShowAndDo(() => sceneController.RestartAndLoad(localVoosFile, gameOpts));
         }
         else
         {
             sceneController.LoadWorkshopItem(
                 new LoadableWorkshopItem(workshopItem),
                 playOpts,
                 thumbnailImage.sprite.texture);
         }
     });
 }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F8) && Input.GetKey(KeyCode.LeftControl))
        {
            PerfBenchmark.CommandBenchmark(null);
        }

#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.F9) && Input.GetKey(KeyCode.LeftControl))
        {
            var gameOpts = new GameBuilderApplication.GameOptions
            {
                playOptions = new GameBuilderApplication.PlayOptions
                {
                    isMultiplayer    = true,
                    startAsPublic    = false,
                    startInBuildMode = true
                }
            };
            string path = System.IO.Path.Combine(Application.streamingAssetsPath, "ExampleGames", "Internal", "template-small.voos");
            loadingScreen.ShowAndDo(() => sceneController.RestartAndLoad(path, gameOpts));
        }
#endif

#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.F10) && Input.GetKey(KeyCode.LeftControl))
        {
            sceneController.JoinMultiplayerGameByCode($"1-dev-{System.Net.Dns.GetHostName().ToLowerInvariant()}");
        }
#endif

        if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.N))
        {
            sceneController.RestartAndLoadMinimalScene(new GameBuilderApplication.GameOptions());
        }

        if (Input.GetButtonDown("Cancel"))
        {
            if (creditsObject.activeSelf)
            {
                creditsObject.SetActive(false);
            }
            else if (templateSelectorMenu.IsOpen())
            {
                templateSelectorMenu.Close();
            }
            else
            {
                menuPanelManager.Back();
            }
        }

        AudioListener.volume = Application.isFocused ? 1 : 0;
    }
Beispiel #3
0
    public static void CommandBenchmark(CommandArg[] args)
    {
        string note = "";

        if (args != null && args.Length >= 1)
        {
            note = string.Join(" ", from a in args select a.String);
        }

        var state = new BenchmarkState(note);

        CurrState      = state;
        CurrSceneIndex = 0;
        GameBuilderSceneController scenes = FindObjectOfType <GameBuilderSceneController>();

        SceneLoadStartTime = Time.realtimeSinceStartup;
        scenes.RestartAndLoad(System.IO.Path.Combine(Application.streamingAssetsPath, "ExampleGames", "Internal", BenchmarkVoosFiles[0]));
    }
Beispiel #4
0
    void OnTemplateClicked(BuiltInTemplateInfo template)
    {
        string fullPath = Path.Combine(Application.streamingAssetsPath, "ExampleGames", "Public", template.baseFileName + ".voos");

        if (template.isTutorial)
        {
            loadingScreen.ShowAndDo(() => sceneController.RestartAndLoadTutorial());
        }
        else
        {
            popups.AskHowToPlay(playOpts =>
            {
                var gameOpts = new GameBuilderApplication.GameOptions {
                    playOptions = playOpts
                };
                loadingScreen.ShowAndDo(() => sceneController.RestartAndLoad(fullPath, gameOpts));
            });
        }
    }
Beispiel #5
0
    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]));
        }
    }