Exemplo n.º 1
0
        public void IterateLogic()
        {
            var now = DateTime.Now;
            var delta = (now - _previousTime).Milliseconds;

            foreach (var newOne in _newLogicEntries)
            {
                var newEntry = new LogicEntry
                    {
                        Enumerator = newOne().GetEnumerator(),
                        SleepTime = 0
                    };
                _logicEntries.Add(newEntry);
            }
            _newLogicEntries.Clear();

            var removals = new List<LogicEntry>();
            foreach (var each in _logicEntries)
            {
                each.SleepTime -= delta;
                if (each.SleepTime >= 0)
                    continue;

                if (!each.Enumerator.MoveNext())
                    removals.Add(each);
                else each.SleepTime = each.Enumerator.Current;
            }

            _logicEntries.RemoveAll(removals.Contains);

            _previousTime = now;
        }
Exemplo n.º 2
0
        public void IterateLogic()
        {
            var now   = DateTime.Now;
            var delta = (now - _previousTime).Milliseconds;

            foreach (var newOne in _newLogicEntries)
            {
                var newEntry = new LogicEntry
                {
                    Enumerator = newOne().GetEnumerator(),
                    SleepTime  = 0
                };
                _logicEntries.Add(newEntry);
            }
            _newLogicEntries.Clear();

            var removals = new List <LogicEntry>();

            foreach (var each in _logicEntries)
            {
                each.SleepTime -= delta;
                if (each.SleepTime >= 0)
                {
                    continue;
                }

                if (!each.Enumerator.MoveNext())
                {
                    removals.Add(each);
                }
                else
                {
                    each.SleepTime = each.Enumerator.Current;
                }
            }

            _logicEntries.RemoveAll(removals.Contains);

            _previousTime = now;
        }
Exemplo n.º 3
0
        /// <summary>
        /// MEngine 객체를 초기화합니다.
        /// </summary>
        /// <param name="logicEntry"> 로직 처리를 담당하는 객체입니다. </param>
        /// <param name="translater"> 패킷을 구별해주는 객체입니다. </param>
        /// <param name="dispatcher"> 로직을 처리해주는 객체입니다. [기본값 : MLogicDispatcher] </param>
        /// <returns></returns>
        public bool Intialize(LogicEntry logicEntry, PacketTranslater translater, LogicDispatcher dispatcher = null)
        {
            if (logicEntry == null)
            {
                throw new NullReferenceException("MEngine Initialize Failed - logicEntry is null.");
            }

            if (dispatcher == null)
            {
                dispatcher = new MLogicDispatcher();
            }

            if (translater == null)
            {
                throw new NullReferenceException("MEngine Initialize Failed - distinctioner is null.");
            }

            if (NetworkEngine == null)
            {
                CreateEngine(true);
            }

            Dispatcher          = dispatcher;
            packetDistinctioner = translater;

            if (Dispatcher.CreateLogicSystem(logicEntry) == false)
            {
                throw new Exceptions.InitializeException("MEngine Initialize Failed - Dispatcher.CreateLogicSystem() Failed");
            }

            if (NetworkEngine.Initialize() == false)
            {
                throw new Exceptions.InitializeException("MEngine Initialize Failed - NetworkEngine.Initialize() Failed");
            }

            return(true);
        }