SuperTuxKart
wiimote_manager.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2012-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef WIIMOTE_MANAGER_HPP
20 #define WIIMOTE_MANAGER_HPP
21 
22 #ifdef ENABLE_WIIUSE
23 
24 #include "input/wiimote.hpp"
25 #include "states_screens/dialogs/message_dialog.hpp"
26 #include "utils/cpp2011.hpp"
27 
28 #include <thread>
29 
30 #include "IEventReceiver.h"
31 
32 #define MAX_WIIMOTES 4
33 
34 struct wiimote_t;
35 class GamepadConfig;
36 class GamePadDevice;
37 class WiimoteManager;
38 
39 extern WiimoteManager* wiimote_manager;
40 
41 
45 class WiimoteManager
46 {
47 private:
49  std::vector<Wiimote*> m_wiimotes;
50 
52  wiimote_t** m_all_wiimote_handles;
53 
54  // While the wiimote code can technically work without threading,
55  // its too slow (high latency), but it is useful for debugging.
56 #define WIIMOTE_THREADING
57 #ifdef WIIMOTE_THREADING
59  std::thread m_thread;
60 
62  bool m_shut;
63 #endif
64 
66  static bool m_enabled;
67 
69  void threadFunc();
70  void setWiimoteBindings(GamepadConfig* gamepad_config);
71 
72 public:
73  WiimoteManager();
74  ~WiimoteManager();
75 
77  static void enable() { m_enabled = true; }
78 
80  static bool isEnabled() { return m_enabled; }
81 
82  void launchDetection(int timeout);
83  void update();
84  void cleanup();
85 
86  void enableAccelerometer(bool state);
87 
92  class WiimoteDialogListener : public MessageDialog::IConfirmDialogListener
93  {
94  public:
95  virtual void onConfirm() OVERRIDE;
96  }; // class WiimoteDialoListener
97 
101  int askUserToConnectWiimotes();
102  // ------------------------------------------------------------------------
104  unsigned int getNumberOfWiimotes() const {
105  return (unsigned int)m_wiimotes.size();
106  } // getNumberOfWiimotes
107 
108 }; // class WiimoteManager
109 
110 
111 #endif
112 
113 #endif // WIIMOTE_MANAGER_HPP
specialisation of Inputdevice for gamepad type devices
Definition: gamepad_device.hpp:33
specialisation of DeviceConfig for gamepad type devices
Definition: gamepad_config.hpp:43
Listener interface to get notified of whether the user chose to confirm or cancel.
Definition: message_dialog.hpp:39
void update(float dt)
Updates all widgets that need to be updated.
Definition: engine.cpp:872