示例#1
0
 internal void DestroyLogic(Logic logic, UpdateLoop updateLoop)
 {
     if (updateLoop != null)
     {
         updateLoop.Pop(logic);
     }
 }
示例#2
0
        /// <summary>
        /// Adds a custom update loop.
        /// </summary>
        /// <param name="updateLoop">The custom update loop implementation.</param>
        /// <param name="parentLoop">Which Unity update loop should this be run under?</param>
        /// <param name="priority">A priority that decides whether this update loop runs before or after other custom update loops.</param>
        public static void AddCustomUpdateLoop(ICustomUpdateLoop updateLoop, UpdateLoop parentLoop = UpdateLoop.Update, int priority = 0)
        {
            if (_idToUpdateLoop == null)
            {
                _idToUpdateLoop      = new Dictionary <int, ICustomUpdateLoop>(4);
                _idToUnityUpdateLoop = new Dictionary <int, UpdateLoop>(4);
                _customUpdateLoops   = new Dictionary <int, PrioritizedList <ICustomUpdateLoop> >(3);
            }

            PrioritizedList <ICustomUpdateLoop> customLoops;

            if (!_customUpdateLoops.TryGetValue((int)parentLoop, out customLoops))
            {
                _customUpdateLoops[(int)parentLoop] = customLoops = new PrioritizedList <ICustomUpdateLoop>(4);
            }

            var id = updateLoop.Event.Id;

            if (_idToUpdateLoop.ContainsKey(id))
            {
                Debug.LogErrorFormat("An update loop with ID '{0}' is already registered.", id);
                return;
            }

            _idToUpdateLoop[id]      = updateLoop;
            _idToUnityUpdateLoop[id] = parentLoop;
            customLoops.Add(updateLoop, priority);
        }
示例#3
0
        /// <summary>
        /// Stops all coroutines that are running in the specified update loop.
        /// </summary>
        public static void StopAll(UpdateLoop updateLoop)
        {
            var coroutines = GetList(updateLoop);
            var isInUpdate = _current != null && _current.Value.UpdateLoop == updateLoop;

            var current = coroutines.First;

            while (current != null)
            {
                var next    = current.Next;
                var routine = current.Value;

                Stop(routine);

                if (!isInUpdate)
                {
                    IdToCoroutine.Remove(routine.Id);
                    PoolHelper <BetterCoroutine> .Despawn(routine);

                    coroutines.Remove(current);
                }

                current = next;
            }
        }
示例#4
0
        protected override void Initialize()
        {
            // graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            // graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            // graphics.IsFullScreen = true;
            //if (!graphics.IsFullScreen)
            //    graphics.ToggleFullScreen();
            graphics.ApplyChanges();
            if (firsLoad)
            {
                mapManager.Initialize();
            }
            playerManager.Initialize();
            enemiesManager.Initialize();
            treasureManager = new TreasureManager(playerManager);
            rainManager     = new RainManager(playerManager.getPlayer(), enemiesManager);
            base.Initialize();

            CurrentGameState = GameState.MainMenu;
            if (firsLoad)
            {
                Task.Factory.StartNew(() =>
                {
                    var gl = new UpdateLoop(rainManager);
                    gl.Loop();
                });
            }

            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
        void IPoolable.OnDespawned()
        {
            var poolableYieldInstruction = Enumerator as IPoolableYieldInstruction;

            if (poolableYieldInstruction != null)
            {
                poolableYieldInstruction.Despawn();
            }

            Id         = -1;
            IsDone     = false;
            UpdateLoop = UpdateLoop.Update;
            Enumerator = null;
            Parent     = null;
            Child      = null;

            WaitTillTime         = float.MinValue;
            WaitTimeIsUnscaled   = false;
            WaitingForEndOfFrame = false;

            LinkedObject        = null;
            LinkedComponent     = null;
            IsLinkedToObject    = false;
            IsLinkedToComponent = false;
        }
示例#6
0
        private static void ProcessCustomLoops(UpdateLoop unityLoop)
        {
            if (_customUpdateLoops == null)
            {
                return;
            }

            PrioritizedList <ICustomUpdateLoop> customLoops;

            if (!_customUpdateLoops.TryGetValue((int)unityLoop, out customLoops))
            {
                return;
            }

            for (var i = 0; i < customLoops.Count; i++)
            {
                var updateLoop = customLoops[i].Item;
                if (updateLoop.IsTimeToRun)
                {
                    DeltaTime         = updateLoop.DeltaTime;
                    UnscaledDeltaTime = updateLoop.UnscaledDeltaTime;
                    updateLoop.Invoke();
                }
            }
        }
示例#7
0
        /// <summary>
        /// Starts a new coroutine.
        /// </summary>
        /// <param name="enumerator"></param>
        /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
        /// <returns>The id of the coroutine.</returns>
        public static int Start(IEnumerator enumerator, UpdateLoop updateLoop = UpdateLoop.Update)
        {
            var coroutine = SpawnCoroutine(enumerator, updateLoop);

            Start(coroutine);

            return(coroutine.Id);
        }
示例#8
0
 public override void Update(double dt)
 {
     UpdateLoop.Update(dt);
     if (KeyboardInputService.IsDown("Quit"))
     {
         Game.Exit();
     }
 }
示例#9
0
 public override void Update(double dt)
 {
     Entities.Update(dt);
     UpdateLoop.Update(dt);
     if (KeyboardInputService.IsDown("Quit") || Entities.List <Ball>().Count == 0)
     {
         Game.Exit();
     }
 }
示例#10
0
        private static BetterCoroutine SpawnCoroutine(IEnumerator enumerator, UpdateLoop updateLoop)
        {
            var coroutine = PoolHelper <BetterCoroutine> .Spawn();

            coroutine.Id         = GetNextId();
            coroutine.Enumerator = enumerator;
            coroutine.UpdateLoop = updateLoop;
            return(coroutine);
        }
示例#11
0
        /// <summary>
        /// Starts a new coroutine and links its lifetime to a gameobject.
        /// The coroutine will be stopped when the linked gameobject is disabled or destroyed.
        /// </summary>
        /// <param name="enumerator"></param>
        /// <param name="linkedObject">Which gameobject to link the coroutine's lifetime with.</param>
        /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
        /// <returns>The id of the coroutine.</returns>
        public static int Start(IEnumerator enumerator, GameObject linkedObject, UpdateLoop updateLoop = UpdateLoop.Update)
        {
            var coroutine = SpawnCoroutine(enumerator, updateLoop);

            coroutine.LinkedObject     = linkedObject;
            coroutine.IsLinkedToObject = true;

            Start(coroutine);

            return(coroutine.Id);
        }
示例#12
0
        public override void Update(double dt)
        {
            Entities.Update(dt);
            UpdateLoop.Update(dt);
            if (KeyboardInputService.IsDown("Quit"))
            {
                Game.Exit();
            }

            DrawableScore.Text = $"Score: {Game.Score}";
        }
示例#13
0
    static void Init()
    {
        if (isInited)
        {
            return;
        }

        isInited = true;

        instance = (UpdateLoop)CoreUpdateManager.RegisterBehaviourQueue <UpdateLoop>("UpdateLoop");
    }
示例#14
0
        private static T CreateNewInstance()
        {
            instance = new T();

            if (instance is IUpdate updateable)
            {
                UpdateLoop.RegisterForUpdate(updateable);
            }

            instance.OnCreated();
            return(instance);
        }
示例#15
0
        private static PooledLinkedList <BetterCoroutine> GetList(UpdateLoop updateLoop)
        {
            switch (updateLoop)
            {
            case UpdateLoop.Update:
                return(CoroutinesUpdate);

            case UpdateLoop.LateUpdate:
                return(CoroutinesLateUpdate);

            case UpdateLoop.FixedUpdate:
                return(CoroutinesFixedUpdate);

            default:
                throw new ArgumentOutOfRangeException("updateLoop", updateLoop, null);
            }
        }
示例#16
0
        private static int GetEventId(UpdateLoop updateLoop)
        {
            switch (updateLoop)
            {
            case UpdateLoop.Update:
                return(ManagedUpdate.EventIds.Update);

            case UpdateLoop.LateUpdate:
                return(ManagedUpdate.EventIds.LateUpdate);

            case UpdateLoop.FixedUpdate:
                return(ManagedUpdate.EventIds.FixedUpdate);

            default:
                throw new ArgumentOutOfRangeException("updateLoop", updateLoop, null);
            }
        }
示例#17
0
        private static float GetTime(UpdateLoop updateLoop, bool unscaled)
        {
            float currentTime;

            if (updateLoop == UpdateLoop.FixedUpdate)
            {
                currentTime = unscaled
                    ? BetterTime.FixedUnscaledTime
                    : BetterTime.FixedTime;
            }
            else
            {
                currentTime = unscaled
                    ? BetterTime.UnscaledTime
                    : BetterTime.Time;
            }

            return(currentTime);
        }
示例#18
0
            internal L CreateLogic <L>(object obj, UpdateLoop updateLoop) where L : Logic, new()
            {
                Logger.Log(LogLevel.Ludacris, $"Creating Logic of type '{typeof(L).FullName}' into {obj.GetType().FullName}");

                var logic = new L()
                {
                    Parent = obj as Entity
                };

                InitializeObject(logic, obj);
                logic.Initialize();

                if (updateLoop != null)
                {
                    updateLoop.Push(logic);
                }

                return(logic);
            }
示例#19
0
 /// <summary>
 /// Stops all coroutines that are running in the specified update loop.
 /// </summary>
 public static void StopAll(UpdateLoop updateLoop)
 {
     StopAll(GetEventId(updateLoop));
 }
示例#20
0
 /// <summary>
 /// Starts a new coroutine and links its lifetime to a component.
 /// The coroutine will be stopped when the linked component is disabled or destroyed.
 /// </summary>
 /// <param name="enumerator"></param>
 /// <param name="linkedComponent">Which component to link the coroutine's lifetime with.</param>
 /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
 /// <returns>The id of the coroutine.</returns>
 public static int Start(IEnumerator enumerator, MonoBehaviour linkedComponent,
                         UpdateLoop updateLoop = UpdateLoop.Update)
 {
     return(Start(enumerator, linkedComponent, GetEventId(updateLoop)));
 }
示例#21
0
 /// <summary>
 /// Starts a new coroutine and links its lifetime to a gameobject.
 /// The coroutine will be stopped when the linked gameobject is disabled or destroyed.
 /// </summary>
 /// <param name="enumerator"></param>
 /// <param name="linkedObject">Which gameobject to link the coroutine's lifetime with.</param>
 /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
 /// <returns>The id of the coroutine.</returns>
 public static int Start(IEnumerator enumerator, GameObject linkedObject,
                         UpdateLoop updateLoop = UpdateLoop.Update)
 {
     return(Start(enumerator, linkedObject, GetEventId(updateLoop)));
 }
示例#22
0
 /// <summary>
 /// Starts a new coroutine.
 /// </summary>
 /// <param name="enumerator"></param>
 /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
 /// <returns>The id of the coroutine.</returns>
 public static int Start(IEnumerator enumerator, UpdateLoop updateLoop = UpdateLoop.Update)
 {
     return(Start(enumerator, GetEventId(updateLoop)));
 }
 /// <summary>
 /// Starts a new coroutine with its lifetime linked to this gameobject.
 /// The coroutine will be stopped when the linked gameobject is disabled or destroyed.
 /// </summary>
 /// <param name="gameObject">The gameobject to link the coroutine to.</param>
 /// <param name="enumerator"></param>
 /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
 /// <returns>The id of the coroutine.</returns>
 public static int StartBetterCoroutineLinked(this GameObject gameObject, IEnumerator enumerator,
                                              UpdateLoop updateLoop = UpdateLoop.Update)
 {
     return(BetterCoroutines.Start(enumerator, gameObject, updateLoop));
 }
示例#24
0
        /// <summary>
        /// Starts a new coroutine and links its lifetime to a component.
        /// The coroutine will be stopped when the linked component is disabled or destroyed.
        /// </summary>
        /// <param name="enumerator"></param>
        /// <param name="linkedComponent">Which component to link the coroutine's lifetime with.</param>
        /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
        /// <returns>The id of the coroutine.</returns>
        public static int Start(IEnumerator enumerator, MonoBehaviour linkedComponent, UpdateLoop updateLoop = UpdateLoop.Update)
        {
            var coroutine = SpawnCoroutine(enumerator, updateLoop);

            coroutine.LinkedComponent     = linkedComponent;
            coroutine.IsLinkedToComponent = true;

            Start(coroutine);

            return(coroutine.Id);
        }
示例#25
0
 void OnDestroy()
 {
     instance = null;
     isInited = false;
 }
 /// <summary>
 /// Starts a new coroutine.
 /// </summary>
 /// <param name="unityObject"></param>
 /// <param name="enumerator"></param>
 /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
 /// <returns>The id of the coroutine.</returns>
 public static int StartBetterCoroutine(this Object unityObject, IEnumerator enumerator,
                                        UpdateLoop updateLoop = UpdateLoop.Update)
 {
     return(BetterCoroutines.Start(enumerator, updateLoop));
 }
示例#27
0
 public void SetUpdateLoop(UpdateLoop updateLoop)
 {
     _updateLoop = updateLoop;
 }
 /// <summary>
 /// Starts a new coroutine with its lifetime linked to this component.
 /// The coroutine will be stopped when the linked component is disabled or destroyed.
 /// </summary>
 /// <param name="monoBehaviour">The component to link the coroutine to.</param>
 /// <param name="enumerator"></param>
 /// <param name="updateLoop">Which update loop should the coroutine be part of?</param>
 /// <returns>The id of the coroutine.</returns>
 public static int StartBetterCoroutineLinked(this MonoBehaviour monoBehaviour, IEnumerator enumerator,
                                              UpdateLoop updateLoop = UpdateLoop.Update)
 {
     return(BetterCoroutines.Start(enumerator, monoBehaviour, updateLoop));
 }