예제 #1
0
        public EntityListWrapper(GameController gameController, CoreSettings settings, MultiThreadManager multiThreadManager)
        {
            _instance       = this;
            _gameController = gameController;
            _settings       = settings;
            _gameController.Area.OnAreaChange += AreaChanged;
            _parallelUpdateDictionary          = new Coroutine(CollectEntities(), null, "Collect Entities")
            {
                SyncModWork = true
            };

            _settings.EntitiesUpdate.OnValueChanged += (sender, i) => { UpdateCondition(1000 / i); };
            UpdateCondition(1000 / _settings.EntitiesUpdate);

            PlayerUpdate       += (sender, entity) => Entity.Player = entity;
            ValidEntitiesByType = NewValidEntitiesByType();
        }
예제 #2
0
 public DebugWindow(Graphics graphics, CoreSettings coreSettings)
 {
     this._graphics     = graphics;
     this._coreSettings = coreSettings;
     graphics.InitImage("menu-background.png");
 }
예제 #3
0
        public GameController(Memory memory, SoundController soundController, SettingsContainer settings,
                              MultiThreadManager multiThreadManager)
        {
            _settings          = settings.CoreSettings;
            Memory             = memory;
            SoundController    = soundController;
            Settings           = settings;
            MultiThreadManager = multiThreadManager;

            try
            {
                Cache             = new Cache();
                Game              = new TheGame(memory, Cache);
                Area              = new AreaController(Game);
                Window            = new GameWindow(memory.Process);
                Files             = Game.Files;
                EntityListWrapper = new EntityListWrapper(this, _settings, multiThreadManager);
            }
            catch (Exception e)
            {
                DebugWindow.LogError(e.ToString());
            }

            PluginBridge = new PluginBridge();

            IsForeGroundCache = WinApi.IsForegroundWindow(Window.Process.MainWindowHandle);
            var values = Enum.GetValues(typeof(IconPriority));

            LeftPanel  = new PluginPanel(GetLeftCornerMap());
            UnderPanel = new PluginPanel(GetUnderCornerMap());

            var debParseFile = new DebugInformation("Parse files", false);

            debClearCache = new DebugInformation("Clear cache", false);

            // Core.DebugInformations.Add(debParseFile);

            /*Area.OnAreaChange += controller =>
             * {
             *
             *  debParseFile.TickAction(() =>
             *  {
             *      Files.LoadFiles();
             *  });
             * };*/

            debDeltaTime = Core.DebugInformations.FirstOrDefault(x => x.Name == "Delta Time");

            NativeMethods.LogError = _settings.LogReadMemoryError;

            _settings.LogReadMemoryError.OnValueChanged +=
                (obj, b) => NativeMethods.LogError       = _settings.LogReadMemoryError;

            LeftCornerMap  = new TimeCache <Vector2>(GetLeftCornerMap, 500);
            UnderCornerMap = new TimeCache <Vector2>(GetUnderCornerMap, 500);

            eIsForegroundChanged += b =>
            {
                if (b)
                {
                    Core.MainRunner.ResumeCoroutines(Core.MainRunner.Coroutines);
                    Core.ParallelRunner.ResumeCoroutines(Core.ParallelRunner.Coroutines);
                }
                else
                {
                    Core.MainRunner.PauseCoroutines(Core.MainRunner.Coroutines);
                    Core.ParallelRunner.PauseCoroutines(Core.ParallelRunner.Coroutines);
                }

                // DebugWindow.LogMsg($"Foreground: {b}");
            };

            _settings.RefreshArea.OnPressed += () => { Area.ForceRefreshArea(_settings.AreaChangeMultiThread); };
            Area.RefreshState();
            EntityListWrapper.StartWork();
            Initialized = true;
        }
예제 #4
0
        public EntityListWrapper(GameController gameController, CoreSettings settings, MultiThreadManager multiThreadManager)
        {
            _instance           = this;
            this.gameController = gameController;
            _settings           = settings;

            //    EntitiesStack = new MultiThreadProp<Stack<Entity>>();

            entityCache = new Dictionary <uint, Entity>(1000);
            gameController.Area.OnAreaChange += AreaChanged;
            EntitiesVersion = 0;

            updateEntity =
                new Coroutine(RefreshState, new WaitTime(coroutineTimeWait), null, "Update Entity")
            {
                Priority = CoroutinePriority.High, SyncModWork = true
            };

            var collectEntitiesDebug = new DebugInformation("Collect Entities");

            /*parallelUpdateDictionary = new Coroutine(() =>
             * {
             *  if (!EntitiesStack.CanUpdate) return;
             *  collectEntitiesDebug.TickAction(() =>
             *  {
             *      gameController.Game.IngameState.Data.EntityList.CollectEntities(EntitiesStack.Write(), entityCache, multiThreadManager,
             *                                                                      settings.ParseServerEntities,
             *                                                                      settings.MyMultiOrAsParallel,
             *                                                                      settings.CollectEntitiesInParallelWhenMoreThanX,
             *                                                                      gameController.IngameState.Data.EntitiesCount,
             *                                                                      _entitiesVersion);
             *      _entitiesVersion++;
             *  });
             * }, new WaitTime(coroutineTimeWait), null, "EntitiesAsDictionary") {Priority = CoroutinePriority.High};*/
            /*parallelUpdateDictionary = new Coroutine(() =>
             * {
             *  if (!needUpdate) return;
             *  collectEntitiesDebug.TickAction(() =>
             *  {
             *      gameController.Game.IngameState.Data.EntityList.CollectEntities(Simple, keysForDelete, entityCache, multiThreadManager,
             *                                                                      settings.ParseServerEntities,
             *                                                                      settings.MyMultiOrAsParallel,
             *                                                                      settings.CollectEntitiesInParallelWhenMoreThanX,
             *                                                                      gameController.IngameState.Data.EntitiesCount,
             *                                                                      EntitiesVersion);
             *
             *      EntitiesVersion++;
             *      needUpdate = false;
             *  });
             * }, new WaitTime(coroutineTimeWait), null, "EntitiesAsDictionary") {Priority = CoroutinePriority.High};*/

            entityCollectSettingsContainer                                        = new EntityCollectSettingsContainer();
            entityCollectSettingsContainer.Simple                                 = Simple;
            entityCollectSettingsContainer.KeyForDelete                           = keysForDelete;
            entityCollectSettingsContainer.EntityCache                            = entityCache;
            entityCollectSettingsContainer.MultiThreadManager                     = multiThreadManager;
            entityCollectSettingsContainer.ParseServer                            = () => settings.ParseServerEntities;
            entityCollectSettingsContainer.ParseEntitiesInMultiThread             = () => settings.ParseEntitiesInMultiThread;
            entityCollectSettingsContainer.EntitiesCount                          = () => gameController.IngameState.Data.EntitiesCount;
            entityCollectSettingsContainer.EntitiesVersion                        = EntitiesVersion;
            entityCollectSettingsContainer.CollectEntitiesInParallelWhenMoreThanX = settings.CollectEntitiesInParallelWhenMoreThanX;
            entityCollectSettingsContainer.DebugInformation                       = collectEntitiesDebug;

            IEnumerator Test()
            {
                while (true)
                {
                    yield return(gameController.IngameState.Data.EntityList.CollectEntities(entityCollectSettingsContainer));

                    yield return(new WaitTime(1000 / settings.EntitiesUpdate));

                    parallelUpdateDictionary.UpdateTicks((uint)(parallelUpdateDictionary.Ticks + 1));
                }
            }

            parallelUpdateDictionary = new Coroutine(Test(), null, "Collect entites")
            {
                SyncModWork = true
            };
            UpdateCondition(1000 / settings.EntitiesUpdate);

            settings.EntitiesUpdate.OnValueChanged += (sender, i) => { UpdateCondition(1000 / i); };

            var enumValues = typeof(EntityType).GetEnumValues();

            ValidEntitiesByType = new Dictionary <EntityType, List <Entity> >(enumValues.Length);

            // NotValidEntitiesByType = new Dictionary<EntityType, List<Entity>>(enumValues.Length);
            foreach (EntityType enumValue in enumValues)
            {
                ValidEntitiesByType[enumValue] = new List <Entity>(8);
            }

            //   NotValidEntitiesByType[enumValue] = new List<Entity>(8);
            PlayerUpdate += (sender, entity) => Entity.Player = entity;
        }