Exemplo n.º 1
0
        void UpdateAllSystems()
        {
            if (m_systemSortDirty)
            {
                SortSystems();
            }

            // Update all unmanaged and managed systems together, in the correct sort order.
            // The master update list contains indices for both managed and unmanaged systems.
            // Negative values indicate an index in the unmanaged system list.
            // Positive values indicate an index in the managed system list.
            for (int i = 0; i < m_MasterUpdateList.Length; ++i)
            {
                try
                {
                    var index = m_MasterUpdateList[i];

                    if (!index.IsManaged)
                    {
                        // Update unmanaged (burstable) code.
                        SystemState *sys = World.ResolveSystemState(m_UnmanagedSystemsToUpdate[index.Index]);
                        if (sys != null)
                        {
                            if (SystemBase.UnmanagedUpdate(sys, out var details))
                            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                                var metaIndex       = sys->m_UnmanagedMetaIndex;
                                var systemDebugName = SystemBaseRegistry.GetDebugName(metaIndex);
                                var errorString     = details.FormatToString(systemDebugName);
                                Debug.LogError(errorString);
#endif
                            }
                        }
                    }
                    else
                    {
                        // Update managed code.
                        var sys = m_systemsToUpdate[index.Index];
                        sys.Update();
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
#if UNITY_DOTSPLAYER
                    // When in a DOTS Runtime build, throw this upstream -- continuing after silently eating an exception
                    // is not what you'll want, except maybe once we have LiveLink.  If you're looking at this code
                    // because your LiveLink dots runtime build is exiting when you don't want it to, feel free
                    // to remove this block, or guard it with something to indicate the player is not for live link.
                    throw;
#endif
                }

                if (World.QuitUpdate)
                {
                    break;
                }
            }
        }
        private void FreeSlot(ushort handle, SystemState *statePtr)
        {
            var systemPtr = statePtr->m_SystemPtr;

            // If the system ptr is not null, this is an unmanaged system and we need to actually destroy it.
            if (systemPtr != null)
            {
                try
                {
                    SystemBaseRegistry.CallOnStopRunning(statePtr);
                    SystemBaseRegistry.CallOnDestroy(statePtr);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }
            statePtr->Dispose();
            _stateMemory.Free(handle);
        }