Ejemplo n.º 1
0
        public void Initialize()
        {
            lock (_lock)
            {
                _refereceCount++;

                if (_isRunning)
                {
                    return;
                }

                SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
                SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
                SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
                SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED, "0");
                SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");

                if (SDL_Init(SdlInitFlags) != 0)
                {
                    string errorMessage = $"SDL2 initlaization failed with error \"{SDL_GetError()}\"";

                    Logger.Error?.Print(LogClass.Application, errorMessage);

                    throw new Exception(errorMessage);
                }

                // First ensure that we only enable joystick events (for connected/disconnected).
                SDL_GameControllerEventState(SDL_DISABLE);
                SDL_JoystickEventState(SDL_ENABLE);

                // Disable all joysticks information, we don't need them no need to flood the event queue for that.
                SDL_EventState(SDL_EventType.SDL_JOYAXISMOTION, SDL_DISABLE);
                SDL_EventState(SDL_EventType.SDL_JOYBALLMOTION, SDL_DISABLE);
                SDL_EventState(SDL_EventType.SDL_JOYHATMOTION, SDL_DISABLE);
                SDL_EventState(SDL_EventType.SDL_JOYBUTTONDOWN, SDL_DISABLE);
                SDL_EventState(SDL_EventType.SDL_JOYBUTTONUP, SDL_DISABLE);

                SDL_EventState(SDL_EventType.SDL_CONTROLLERSENSORUPDATE, SDL_DISABLE);

                string gamepadDbPath = Path.Combine(ReleaseInformations.GetBaseApplicationDirectory(), "SDL_GameControllerDB.txt");

                if (File.Exists(gamepadDbPath))
                {
                    SDL_GameControllerAddMappingsFromFile(gamepadDbPath);
                }

                _registeredWindowHandlers = new ConcurrentDictionary <uint, Action <SDL_Event> >();
                _worker    = new Thread(EventWorker);
                _isRunning = true;
                _worker.Start();
            }
        }
Ejemplo n.º 2
0
 private static void ReloadFileLogger(object sender, ReactiveEventArgs <bool> e)
 {
     if (e.NewValue)
     {
         Logger.AddTarget(new AsyncLogTargetWrapper(
                              new FileLogTarget(ReleaseInformations.GetBaseApplicationDirectory(), "file"),
                              1000,
                              AsyncLogTargetOverflowAction.Block
                              ));
     }
     else
     {
         Logger.RemoveTarget("file");
     }
 }
Ejemplo n.º 3
0
        static void Load(Options option)
        {
            IGamepad gamepad;

            if (option.ListInputIds)
            {
                Logger.Info?.Print(LogClass.Application, "Input Ids:");

                foreach (string id in _inputManager.KeyboardDriver.GamepadsIds)
                {
                    gamepad = _inputManager.KeyboardDriver.GetGamepad(id);

                    Logger.Info?.Print(LogClass.Application, $"- {id} (\"{gamepad.Name}\")");

                    gamepad.Dispose();
                }

                foreach (string id in _inputManager.GamepadDriver.GamepadsIds)
                {
                    gamepad = _inputManager.GamepadDriver.GetGamepad(id);

                    Logger.Info?.Print(LogClass.Application, $"- {id} (\"{gamepad.Name}\")");

                    gamepad.Dispose();
                }

                return;
            }

            if (option.InputPath == null)
            {
                Logger.Error?.Print(LogClass.Application, "Please provide a file to load");

                return;
            }

            _inputConfiguration = new List <InputConfig>();
            _enableKeyboard     = (bool)option.EnableKeyboard;
            _enableMouse        = (bool)option.EnableMouse;

            void LoadPlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index)
            {
                InputConfig inputConfig = HandlePlayerConfiguration(inputProfileName, inputId, index);

                if (inputConfig != null)
                {
                    _inputConfiguration.Add(inputConfig);
                }
            }

            LoadPlayerConfiguration(option.InputProfile1Name, option.InputId1, PlayerIndex.Player1);
            LoadPlayerConfiguration(option.InputProfile2Name, option.InputId2, PlayerIndex.Player2);
            LoadPlayerConfiguration(option.InputProfile3Name, option.InputId3, PlayerIndex.Player3);
            LoadPlayerConfiguration(option.InputProfile4Name, option.InputId4, PlayerIndex.Player4);
            LoadPlayerConfiguration(option.InputProfile5Name, option.InputId5, PlayerIndex.Player5);
            LoadPlayerConfiguration(option.InputProfile6Name, option.InputId6, PlayerIndex.Player6);
            LoadPlayerConfiguration(option.InputProfile7Name, option.InputId7, PlayerIndex.Player7);
            LoadPlayerConfiguration(option.InputProfile8Name, option.InputId8, PlayerIndex.Player8);
            LoadPlayerConfiguration(option.InputProfileHandheldName, option.InputIdHandheld, PlayerIndex.Handheld);

            if (_inputConfiguration.Count == 0)
            {
                return;
            }

            // Setup logging level
            Logger.SetEnable(LogLevel.Debug, (bool)option.LoggingEnableDebug);
            Logger.SetEnable(LogLevel.Stub, (bool)option.LoggingEnableStub);
            Logger.SetEnable(LogLevel.Info, (bool)option.LoggingEnableInfo);
            Logger.SetEnable(LogLevel.Warning, (bool)option.LoggingEnableWarning);
            Logger.SetEnable(LogLevel.Error, (bool)option.LoggingEnableError);
            Logger.SetEnable(LogLevel.Trace, (bool)option.LoggingEnableTrace);
            Logger.SetEnable(LogLevel.Guest, (bool)option.LoggingEnableGuest);
            Logger.SetEnable(LogLevel.AccessLog, (bool)option.LoggingEnableFsAccessLog);

            if ((bool)option.EnableFileLog)
            {
                Logger.AddTarget(new AsyncLogTargetWrapper(
                                     new FileLogTarget(ReleaseInformations.GetBaseApplicationDirectory(), "file"),
                                     1000,
                                     AsyncLogTargetOverflowAction.Block
                                     ));
            }

            // Setup graphics configuration
            GraphicsConfig.EnableShaderCache = (bool)option.EnableShaderCache;
            GraphicsConfig.ResScale          = option.ResScale;
            GraphicsConfig.MaxAnisotropy     = option.MaxAnisotropy;
            GraphicsConfig.ShadersDumpPath   = option.GraphicsShadersDumpPath;

            while (true)
            {
                LoadApplication(option);

                if (_userChannelPersistence.PreviousIndex == -1 || !_userChannelPersistence.ShouldRestart)
                {
                    break;
                }

                _userChannelPersistence.ShouldRestart = false;
            }
        }