void MasterClientInit()
    {
        SaveGameToLoad saveGameToLoad = FindObjectOfType <SaveGameToLoad>();
        string         bundleId       = GameBuilderApplication.CurrentGameOptions.bundleIdToLoad;

        if (saveGameToLoad)
        {
            Debug.Log("Loading saved game!");
            saveLoad.Load(saveGameToLoad.saved, saveGameToLoad.voosFilePath);
            GameObject.Destroy(saveGameToLoad.gameObject);
        }
        else if (!bundleId.IsNullOrEmpty())
        {
            Debug.Log($"Loading game bundle {bundleId}");
            string voosPath = gameBundleLibrary.GetBundle(bundleId).GetVoosPath();
            saveLoad.Load(SaveLoadController.ReadSaveGame(voosPath), voosPath);
#if !USE_STEAMWORKS
            workshop.Load(gameBundleLibrary.GetBundle(bundleId).GetAssetsPath());
#endif
            lastLoadedBundleId = bundleId;
        }
        else
        {
            SaveLoadController.SaveGame save = SaveLoadController.ReadSaveGame(GameBuilderSceneController.GetMinimalScenePath(mode == Mode.Online));
            saveLoad.Load(save);
        }

        using (Util.Profile("SpawnLocalobjects"))
            SpawnLocalObjects();
        StartCoroutine(LoadingSequence());
    }
Example #2
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]));
    }
Example #3
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]));
        }
    }