Ejemplo n.º 1
0
        private static void Run()
        {
            m_Now = DateTime.Now;
            m_TotalProfile = new MainProfile(m_Now);
            m_CurrentProfile = new MainProfile(m_Now);

            while ( !m_Closing )
            {
                m_Now = DateTime.Now;

                /* wait until event happens */

                m_Signal.WaitOne();

                ClockProfile(MainProfile.TimerId.Idle);

                /* process mobiles */

                Mobile.ProcessDeltaQueue();

                ClockProfile(MainProfile.TimerId.MobileDelta);

                /* process items */

                Item.ProcessDeltaQueue();

                ClockProfile(MainProfile.TimerId.ItemDelta);

                /* process timers */

                Timer.Slice();

                ClockProfile(MainProfile.TimerId.Timers);

                /* network */

                m_MessagePump.Slice();

                NetState.FlushAll();
                NetState.ProcessDisposedQueue();

                ClockProfile(MainProfile.TimerId.Network);

                if ( Slice != null )
                    Slice();

                /* done with this iteration */
                m_TotalProfile.Next();
                m_CurrentProfile.Next();
            }
        }
Ejemplo n.º 2
0
        public static void Run()
        {
            EventSink.Instance = new EventSink();

            if ( !ScriptCompiler.Compile( Environment.Debug ) )
            {
                Console.WriteLine( "Fatal: Compilation failed. Press any key to exit." );
                Console.ReadLine();
                return;
            }

            ScriptCompiler.VerifyLibraries();

            // This instance is shared among timer scheduler and timer executor,
            // and accessed from both core & timer threads.
            Queue<Timer> timerQueue = new Queue<Timer>();

            // Timer scheduler must be set up before world load, since world load
            // could schedule timers on entity deserialization.
            var timerScheduler = TimerScheduler.Instance = new TimerScheduler( timerQueue );
            m_TimerThread = new TimerThread( timerScheduler );

            TimerExecutor timerExecutor = new TimerExecutor( timerQueue );

            PacketHandlers.Instance = new PacketHandlers();

            try
            {
                ScriptCompiler.Configure();

                TileData.Configure();
            }
            catch ( TargetInvocationException e )
            {
                Console.WriteLine( "Fatal: Configure exception: {0}", e.InnerException );
                return;
            }

            Environment.SaveConfig();

            Region.Load();
            World.Instance.Load();

            try
            {
                ScriptCompiler.Initialize();
            }
            catch ( TargetInvocationException e )
            {
                Logger.Error( "Initialize exception: {0}", e.InnerException );
                return;
            }

            m_TimerThread.Start();

            NetServer netServer = new NetServer( new Listener( Listener.Port ) );
            netServer.Initialize();

            GameServer.Instance = new GameServer( netServer, PacketHandlers.Instance );
            GameServer.Instance.Initialize();

            EventSink.Instance.InvokeServerStarted();

            PacketDispatcher.Initialize();

            m_Now = DateTime.UtcNow;
            m_TotalProfile = new MainProfile( m_Now );
            m_CurrentProfile = new MainProfile( m_Now );

            try
            {
                while ( !m_Closing )
                {
                    m_Now = DateTime.UtcNow;

                    Thread.Sleep( 1 );

                    ClockProfile( MainProfile.TimerId.Idle );

                    Mobile.ProcessDeltaQueue();

                    ClockProfile( MainProfile.TimerId.MobileDelta );

                    Item.ProcessDeltaQueue();

                    ClockProfile( MainProfile.TimerId.ItemDelta );

                    timerExecutor.Slice();

                    ClockProfile( MainProfile.TimerId.Timers );

                    netServer.Slice();

                    ClockProfile( MainProfile.TimerId.Network );

                    // Done with this iteration.
                    m_TotalProfile.Next();
                    m_CurrentProfile.Next();
                }
            }
            catch ( Exception e )
            {
                HandleCrashed( e );
            }

            m_TimerThread.Stop();
        }