Beispiel #1
0
 protected override void Removed(SystemRegistry registry)
 {
     if (Parent != null)
     {
         bool result = Parent._children.Remove(this);
         Debug.Assert(result);
     }
 }
Beispiel #2
0
        internal void InternalRemoved(SystemRegistry registry)
        {
            if (_enabledInHierarchy)
            {
                OnDisabled();
            }

            Removed(registry);
        }
Beispiel #3
0
 public Game()
 {
     _timeSystem = new TimeControlSystem();
     SystemRegistry.Register(_timeSystem);
     SystemRegistry.Register(new GameObjectQuerySystem(_gameObjects));
     GameObject.InternalConstructed      += OnGameObjectConstructed;
     GameObject.InternalDestroyRequested += OnGameObjectDestroyRequested;
     GameObject.InternalDestroyCommitted += OnGameObjectDestroyCommitted;
 }
Beispiel #4
0
        public void NewSceneLoaded()
        {
            var systemEnumerator = SystemRegistry.GetSystemsEnumerator();

            while (systemEnumerator.MoveNext())
            {
                var kvp = systemEnumerator.Current;
                kvp.Value.OnNewSceneLoaded();
            }

            ResetDeltaTime();
        }
Beispiel #5
0
        private void RunMainLoopCore()
        {
            _running = true;

            _sw = Stopwatch.StartNew();
            while (_running)
            {
                double desiredFrameTime  = 1000.0 / DesiredFramerate;
                long   currentFrameTicks = _sw.ElapsedTicks;
                double deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0 / Stopwatch.Frequency);

                while (LimitFrameRate && deltaMilliseconds < desiredFrameTime)
                {
                    Thread.Sleep(0);
                    currentFrameTicks = _sw.ElapsedTicks;
                    deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0 / Stopwatch.Frequency);
                }

                _previousFrameTicks = currentFrameTicks;

                FlushDeletedObjects();

                var systemEnumerator = SystemRegistry.GetSystemsEnumerator();
                while (systemEnumerator.MoveNext())
                {
                    var        kvp          = systemEnumerator.Current;
                    GameSystem system       = kvp.Value;
                    float      deltaSeconds = (float)deltaMilliseconds / 1000.0f;
                    system.Update(deltaSeconds * _timeSystem.TimeScale);
                }

                RunEndOfFrameActions();
            }

            var cleanupEnumerator = SystemRegistry.GetSystemsEnumerator();

            while (cleanupEnumerator.MoveNext())
            {
                var        kvp    = cleanupEnumerator.Current;
                GameSystem system = kvp.Value;
                if (system is IDisposable)
                {
                    ((IDisposable)system).Dispose();
                }
            }
        }
Beispiel #6
0
 protected override void Attached(SystemRegistry registry)
 {
 }
Beispiel #7
0
 internal void SetRegistry(SystemRegistry systemRegistry)
 {
     _registry = systemRegistry;
 }
Beispiel #8
0
 protected abstract void Removed(SystemRegistry registry);
Beispiel #9
0
 protected abstract void Attached(SystemRegistry registry);
Beispiel #10
0
 internal void InternalAttached(SystemRegistry registry)
 {
     Attached(registry);
     HierarchyEnabledStateChanged();
 }
Beispiel #11
0
 internal void AttachToGameObject(GameObject go, SystemRegistry registry)
 {
     _attachedGO = go;
     _transform  = _attachedGO.Transform;
     InternalAttached(registry);
 }