zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Controllers.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
32 #ifndef ZENI_CONTROLLERS_H
33 #define ZENI_CONTROLLERS_H
34 
35 #include <Zeni/Error.h>
36 #include <Zeni/Singleton.h>
37 
38 #include <SDL/SDL.h>
39 
40 #include <vector>
41 
42 namespace Zeni {
43 
44  class ZENI_CORE_DLL Controllers;
45 
46 #ifdef _WINDOWS
47  ZENI_CORE_EXT template class ZENI_CORE_DLL Singleton<Controllers>;
48 #endif
49 
50  class ZENI_CORE_DLL Controllers : public Singleton<Controllers> {
51  friend class Singleton<Controllers>;
52 
53  static Controllers * create();
54 
55 #ifdef _WINDOWS
56 #pragma warning( push )
57 #pragma warning( disable : 4251 )
58 #endif
59  static Uninit g_uninit;
60  static Reinit g_reinit;
61 #ifdef _WINDOWS
62 #pragma warning( pop )
63 #endif
64 
65  Controllers();
66  ~Controllers();
67 
68  // Undefined
69  Controllers(const Controllers &);
70  Controllers & operator=(const Controllers &);
71 
72  public:
73  size_t get_num_controllers() const;
74 
75  Sint32 get_controller_index(const Sint32 &id) const;
76  const char * get_controller_name(const Sint32 &index) const;
77  bool is_controller_connected(const Sint32 &index) const;
78 
79  void reinit();
80  void enable(const bool &enable_);
81 
82  void device_added(const Sint32 &index);
83  void device_removed(const Sint32 &id);
84  void detect_removed();
85 
86  void set_vibration(const size_t &index, const float &left, const float &right);
87  void reset_vibration_all();
88 
89  private:
90  void device_add_all();
91 
92  class Joystick_Info {
93  Joystick_Info(const Joystick_Info &rhs);
94  Joystick_Info & operator=(const Joystick_Info &rhs);
95 
96  public:
97  Joystick_Info();
98  ~Joystick_Info();
99 
100  SDL_Joystick * joystick;
101  Sint32 joystick_id;
102 
103  SDL_GameController * gamecontroller;
104  SDL_Haptic * haptic;
105 
107  int haptic_effect_id;
108  };
109 
110  void init();
111  void uninit();
112 
113 #ifdef _WINDOWS
114 #pragma warning( push )
115 #pragma warning( disable : 4251 )
116 #endif
117  typedef std::vector<Joystick_Info *> Joystick_Array;
118  Joystick_Array m_joysticks;
119 #ifdef _WINDOWS
120 #pragma warning( pop )
121 #endif
122  };
123 
124  ZENI_CORE_DLL Controllers & get_Controllers();
125 
126  struct Controllers_Init_Failure : public Error {
127  Controllers_Init_Failure() : Error("Zeni Controllers Failed to Initialize Correctly") {}
128  };
129 
130 }
131 
132 #endif
Controllers & get_Controllers()
Get access to the singleton.
Definition: Controllers.cpp:59
int32_t Sint32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:141
GLint left
Definition: glew.h:7291
struct _SDL_GameController SDL_GameController
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
The generic template for any haptic effect.
Definition: SDL_haptic.h:787
GLboolean enable
Definition: gl2ext.h:940
GLuint index
Definition: glew.h:1800
The Controllers Singleton.
Definition: Controllers.h:50
The Error Class.
Definition: Error.h:52
GLfloat right
Definition: glew.h:13816