Пример #1
0
        private void LoadScene()
        {
            this.scene = this.newHostSceneRequest.Scene;

            using (var sync = new ScopedSynchronizationContext(true))
            {
                this.scene.HostInitialise(this);
                sync.Join();

                this.scene.SharedInitialise(this, this.client);
                sync.Join();

                this.scene.InternalHostInitialise();
                sync.Join();
            }

            var initState = this.newHostSceneRequest.InitState;

            this.scene.HostInitialised(initState);

            this.scene.SharedInitialised(initState);

            this.metrics.TickMetricCounters         = this.scene.TickMetricCounters;
            this.metrics.ParallelTickMetricCounters = this.scene.ParallelTickMetricCounters;

            this.newHostSceneRequest = default;
            this.state = HostState.WaitingOnClients;
        }
Пример #2
0
 public override void LoadScene(HostScene scene, object initState = null)
 {
     this.newHostSceneRequest = new NewHostSceneRequest()
     {
         Scene     = scene,
         InitState = initState
     };
     Thread.MemoryBarrier();
     this.state = HostState.LoadingScene;
 }
Пример #3
0
 public abstract void LoadScene(HostScene scene, object initState);
Пример #4
0
        private void Run()
        {
            var hostThread = Thread.CurrentThread;

            hostThread.Name    = $"{this.Application.Name} Host Thread";
            Threads.HostThread = hostThread;
            this.tickCounter.Start();

            var runner = this as IRunner <object, object>;

            while (true)
            {
                var state = this.state;

                switch (state)
                {
                case HostState.RunningScene:
                    var tickDuration = runner.Run(null, null);
                    this.Metrics.TickLag = 1d * (tickDuration.TotalMilliseconds / this.tickTime.TotalMilliseconds);
                    continue;

                case HostState.LoadingScene:
                    runner.StopRun();
                    this.LoadScene();
                    continue;

                case HostState.UnloadingScene:
                    runner.StopRun();

                    using (var sync = new ScopedSynchronizationContext(true))
                    {
                        this.scene.HostDispose(this);
                        sync.Join();

                        this.scene.SharedDispose(this, this.client);
                        sync.Join();
                    }

                    this.scene.SharedDisposed();

                    this.dispatcher.ClearChannels();
                    this.scene = null;
                    this.state = HostState.Constructed;
                    continue;

                case HostState.WaitingOnClients:

                    if (this.client.State == ClientState.WaitingOnHost)
                    {
                        this.tick  = 0;
                        this.state = HostState.RunningScene;
                        runner.BeginRun();
                    }
                    else
                    {
                        Thread.Yield();
                    }
                    continue;

                case HostState.Constructed:
                    Thread.Yield();
                    continue;

                case HostState.BeginShutdown:
                    runner.StopRun();
                    this.Dispose();
                    return;

                case HostState.Shutdown:
                    return;
                }
            }
        }
Пример #5
0
 public override void LoadScene(HostScene scene, object initState)
 {
 }