public MainWindow() : base(Gtk.WindowType.Toplevel) { mSingleton = this; Build(); this.mController = new SDLController(); this.mController.Closed += delegate { this.Quit(); }; this.mController.PlayerData = new UDPPlayerData(); new Thread(this.ControllerLoop).Start(); this.mUpdaterThread = new Thread(this.UpdaterLoop); this.mUpdaterThread.Start(); this.StatusBar.Push(0, ""); GLib.Timeout.Add(1000, this.FPSLoop); this.mSoapFilter.Name = "OpenVP preset (XML)"; this.mSoapFilter.AddPattern("*.ovp"); this.mBinaryFilter.Name = "OpenVP preset (binary)"; this.mBinaryFilter.AddPattern("*.ovpb"); while (!this.mInitialized) { ; } }
private static void DisposeDevice(GamePadInfo info) { if (info.HapticType > 0) { SDL.Haptic.Close(info.HapticDevice); } SDLController.Close(info.Device); }
internal static void RefreshTranslationTable() { _translationTable.Clear(); foreach (var pair in GamePads) { IntPtr joystick = SDLController.GetJoystick(pair.Value.Device); _translationTable[SDL.Joystick.InstanceID(joystick)] = pair.Key; } }
internal static void RemoveDevice(int instanceId) { foreach (KeyValuePair <int, GamePadInfo> entry in GamePads) { if (SDL.Joystick.InstanceID(SDLController.GetJoystick(entry.Value.Device)) == instanceId) { GamePads.Remove(entry.Key); DisposeDevice(entry.Value); break; } } RefreshTranslationTable(); }
internal static void AddDevice(int deviceId) { IntPtr device = SDLController.Open(deviceId); IntPtr hapticDevice = SDL.Haptic.OpenFromJoystick(SDLController.GetJoystick(device)); int hapticType = 0; var id = 0; while (GamePads.ContainsKey(id)) { id++; } if (hapticDevice != IntPtr.Zero) { try { if (SDL.Haptic.EffectSupported(hapticDevice, ref _hapticLeftRightEffect) == 1) { SDL.Haptic.NewEffect(hapticDevice, ref _hapticLeftRightEffect); hapticType = 1; } else if (SDL.Haptic.RumbleSupported(hapticDevice) == 1) { SDL.Haptic.RumbleInit(hapticDevice); hapticType = 2; } else { SDL.Haptic.Close(hapticDevice); } } catch { SDL.Haptic.Close(hapticDevice); hapticDevice = IntPtr.Zero; SDL.ClearError(); } } GamePads.Add(id, new GamePadInfo(device, hapticDevice, hapticType)); RefreshTranslationTable(); }
/// <summary> /// Loads embedded game controller mappings. /// </summary> internal static void InitDatabase() { var assembly = typeof(GamePad).Assembly; using var stream = assembly.GetManifestResourceStream("gamecontrollerdb.txt"); if (stream == null) { return; } try { using (var reader = new StreamReader(stream)) { string?line; while ((line = reader.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line)) { continue; } if (line.StartsWith("#", StringComparison.Ordinal)) { continue; } switch (SDLController.AddMapping(line)) { case -1: Debug.WriteLine(SDL.GetError()); break; } } } } catch (Exception exc) { Debug.WriteLine("Failed to read game controller mappings: " + exc); } }
public static void Main(string[] args) { UDPPlayerData udp = new UDPPlayerData(); SDLController c = new SDLController(); // LinearPreset preset = new LinearPreset(); // // ClearScreen clear = new ClearScreen(); // clear.ClearColor = new Color(0, 0, 0, 0.3f); // // preset.Effects.Add(clear); // Scope s = new Scope(); // preset.Effects.Add(s); // s.Color = new Color(0, 1, 0); // s.Circular = true; TestTimedPreset preset = new TestTimedPreset(); c.Renderer = preset; c.Initialize(); c.PlayerData = udp; bool run = true; c.Closed += delegate { run = false; }; while (run) { udp.Update(-1); c.RenderFrame(); } c.Destroy(); }