Пример #1
0
        public void ReceiveMessage()
        {
            // The entire test harness is already in scope, so we are breaking that scope
            // so we can test if the playerconnection can allow message handlers to make temp allocs
            TempMemoryScope.ExitScope();

            InitSpoofConnection();

            PlayerConnection.instance.Register(spoofMessage.ToGuid(), (MessageEventArgs test) =>
            {
                // We want to ensure we can still use the temp allocator in our registered handler
                var tempAllocatedContainer = new NativeList <int>(Allocator.Temp);
                tempAllocatedContainer.Add(1); // Perform an operation that will validate the safetyhandle
                tempAllocatedContainer.Dispose();
            });

            DotsRuntime.UpdatePreFrame();
            SendSpoofMessage();
            Baselib_Timer_WaitForAtLeast(100);
            DotsRuntime.UpdatePostFrame(true); // Internally calls TransmistAndReceive();

            // Note we don't validate we received the spoofed message.
            // We do this to avoid ci issues that might occur if our message doesn't
            // get picked up over the socket in time. I feel comfortable enough that this test
            // will still validate it's purpose and not frequently fail silently on the farm
            // We don't loop until we receive the message as we explicitly want UpdatePostFrame()
            // to be the code that receives and handles the messages and we currently don't separate
            // the logic for Transmitting and Receiving messages.

            ShutdownSpoofConnection();

            TempMemoryScope.EnterScope(); // restore temp memscope
        }
Пример #2
0
        [PreserveBody] // Workaround for case 1276535
        public bool Update(double timestampInSeconds)
        {
            var shouldContinue = true;

            if (m_BootPhase == BootPhase.Running)
            {
                switch (m_RunState)
                {
                case RunState.Resuming:
                    m_RunState = RunState.Running;

                    m_StartTimeInSeconds           = timestampInSeconds - m_ElapsedTimeInSeconds;
                    m_PreviousElapsedTimeInSeconds = m_ElapsedTimeInSeconds;
                    goto case RunState.Running;

                case RunState.Running:
                    ComputeTime(timestampInSeconds);
                    *m_TimeData = new TimeData(
                        elapsedTime: m_ElapsedTimeInSeconds,
                        deltaTime: (float)m_DeltaTimeInSeconds);

                    DotsRuntime.UpdatePreFrame();

                    m_World.Update();
                    shouldContinue = !m_World.QuitUpdate;

                    DotsRuntime.UpdatePostFrame(shouldContinue);
                    break;
                }
            }
            else
            {
                TempMemoryScope.EnterScope();
                if (m_BootPhase == BootPhase.Booting)
                {
                    UpdateBooting();
                }
                else if (m_BootPhase == BootPhase.LoadingConfig)
                {
                    shouldContinue = UpdateLoading();

                    if (m_BootPhase == BootPhase.Running)
                    {
                        // Loaded - set up dots runtime with config info
                        var config = m_EntityManager.GetComponentData <CoreConfig>(m_ConfigEntity);

#if ENABLE_PLAYERCONNECTION
                        Connection.InitializeMulticast(config.editorGuid32, "DOTS_Runtime_Game");
#endif

#if ENABLE_PROFILER
                        ProfilerStats.Stats.debugStats.m_UnityVersionMajor              = config.editorVersionMajor;
                        ProfilerStats.Stats.debugStats.m_UnityVersionMinor              = config.editorVersionMinor;
                        ProfilerStats.Stats.debugStats.m_UnityVersionRevision           = config.editorVersionRevision;
                        ProfilerStats.Stats.debugStats.m_UnityVersionReleaseType        = config.editorVersionReleaseType;
                        ProfilerStats.Stats.debugStats.m_UnityVersionIncrementalVersion = config.editorVersionInc;
#endif
                        // Hook instance time into each world if the required system exists
                        foreach (var world in World.All)
                        {
                            var timeSystem = world.GetExistingSystem <UpdateWorldTimeSystem>();
                            if (timeSystem == null)
                            {
                                continue;
                            }
                            timeSystem.SetInstanceTime(m_TimeData);
                        }
                    }
                }
                else
                {
                    throw new Exception($"Invalid BootPhase specified: {(int)m_BootPhase}");
                }
                TempMemoryScope.ExitScope();
            }

            return(shouldContinue);
        }