Пример #1
0
        internal static void ProcessAI(Object obj)
        {
            // Get the game speed
            int loopPause = (int)obj;

            if (loopPause == 0)
            {
                loopPause = 500;
            }
            Events.World.TimedEventManager.Initialize();
            Events.World.TimedEventManager.LoadBasicEvents(Core.GetTickCount());
            // The variables used in the loop
            TickCount tickCount           = null;
            TickCount lastSpawn           = Core.GetTickCount();
            TickCount lastConnectionCheck = Core.GetTickCount();

            Debug.InfiniteLoopDetector loopDetector = new Debug.InfiniteLoopDetector("AIProcessor");
            mapGC = new MapGC();
            System.Threading.Thread mapGCThread = new Thread(mapGC.Cleanup);
            // Start the map garbage collection thread
            mapGCThread.Start();

            Events.World.MapGCTimedEvent mapGCTimedEvent = new Events.World.MapGCTimedEvent("MapGC", mapGC);
            mapGCTimedEvent.SetInterval(Core.GetTickCount(), 1 * 60 * 1000);
            Events.World.TimedEventManager.TimedEvents.Add(mapGCTimedEvent);

            do
            {
                try {
                    if (tickCount != null)
                    {
                        int timePassed = Core.GetTickCount().Tick - tickCount.Tick;

                        if (timePassed < loopPause)
                        {
                            loopDetector.IncrementLoopCount();
                        }
                    }

                    tickCount = Core.GetTickCount();

                    // Copy all active map references to a local list to prevent modification during processing
                    IMap[] activeMaps = MapManager.ToArray();
                    // Now that we have a list of all active maps, lets process the AI on each one
                    //Parallel.ForEach(activeMaps, map =>
                    //{
                    foreach (IMap map in activeMaps)
                    {
                        MapAIProcessingTask aiProcessingTask = new MapAIProcessingTask(map);
                        aiProcessingTask.ProcessAIThreadPoolCallback(null);
                        //ThreadPool.QueueUserWorkItem(new WaitCallback(aiProcessingTask.ProcessAIThreadPoolCallback));
                    }
                    //}
                    //);

                    Events.World.TimedEventManager.Process(tickCount);

                    // Pauses the loop for the time specified
                    System.Threading.Thread.Sleep(loopPause);
                } catch (Exception ex) {
                    Server.Exceptions.ErrorLogger.WriteToErrorLog(ex, "AIProcessor");
                }
            } while (true);
        }
Пример #2
0
        internal static void ProcessAI(Object obj)
        {
            // Get the game speed
            int loopPause = (int)obj;
            if (loopPause == 0) {
                loopPause = 500;
            }
            Events.World.TimedEventManager.Initialize();
            Events.World.TimedEventManager.LoadBasicEvents(Core.GetTickCount());
            // The variables used in the loop
            TickCount tickCount = null;
            TickCount lastSpawn = Core.GetTickCount();
            TickCount lastConnectionCheck = Core.GetTickCount();
            Debug.InfiniteLoopDetector loopDetector = new Debug.InfiniteLoopDetector("AIProcessor");
            mapGC = new MapGC();
            System.Threading.Thread mapGCThread = new Thread(mapGC.Cleanup);
            // Start the map garbage collection thread
            mapGCThread.Start();

            Events.World.MapGCTimedEvent mapGCTimedEvent = new Events.World.MapGCTimedEvent("MapGC", mapGC);
            mapGCTimedEvent.SetInterval(Core.GetTickCount(), 1 * 60 * 1000);
            Events.World.TimedEventManager.TimedEvents.Add(mapGCTimedEvent);

            do {
                try {
                    if (tickCount != null) {
                        int timePassed = Core.GetTickCount().Tick - tickCount.Tick;

                        if (timePassed < loopPause) {
                            loopDetector.IncrementLoopCount();
                        }
                    }

                    tickCount = Core.GetTickCount();

                    // Copy all active map references to a local list to prevent modification during processing
                    IMap[] activeMaps = MapManager.ToArray();
                    // Now that we have a list of all active maps, lets process the AI on each one
                    //Parallel.ForEach(activeMaps, map =>
                    //{
                    foreach (IMap map in activeMaps) {
                        MapAIProcessingTask aiProcessingTask = new MapAIProcessingTask(map);
                        aiProcessingTask.ProcessAIThreadPoolCallback(null);
                        //ThreadPool.QueueUserWorkItem(new WaitCallback(aiProcessingTask.ProcessAIThreadPoolCallback));
                    }
                    //}
                    //);

                    Events.World.TimedEventManager.Process(tickCount);

                    // Pauses the loop for the time specified
                    System.Threading.Thread.Sleep(loopPause);
                } catch (Exception ex) {
                    Server.Exceptions.ErrorLogger.WriteToErrorLog(ex, "AIProcessor");
                }
            } while (true);
        }