BGE: Adding a Python interface for handling joysticks without needing logic bricks...
[blender.git] / source / gameengine / GameLogic / SCA_JoystickManager.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program 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 General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/GameLogic/SCA_JoystickManager.cpp
29  *  \ingroup gamelogic
30  */
31
32 #include "SCA_JoystickSensor.h"
33 #include "SCA_JoystickManager.h"
34 #include "SCA_LogicManager.h"
35 //#include <vector>
36 #include "SCA_ISensor.h"
37
38 //using namespace std;
39
40
41 SCA_JoystickManager::SCA_JoystickManager(class SCA_LogicManager* logicmgr)
42         : SCA_EventManager(logicmgr, JOY_EVENTMGR)
43 {
44         int i;
45         for (i=0; i<JOYINDEX_MAX; i++) {
46                 m_joystick[i] = SCA_Joystick::GetInstance( i );
47         }
48 }
49
50
51 SCA_JoystickManager::~SCA_JoystickManager()
52 {
53         int i;
54         for (i=0; i<JOYINDEX_MAX; i++) {
55                 if (m_joystick[i])
56                         m_joystick[i]->ReleaseInstance();
57         }
58 }
59
60
61 void SCA_JoystickManager::NextFrame(double curtime,double deltatime)
62 {
63         // We should always handle events in case we want to grab them with Python
64 #ifdef WITH_SDL
65         SCA_Joystick::HandleEvents(); /* Handle all SDL Joystick events */
66 #endif
67
68         if (m_sensors.Empty()) {
69                 return;
70         }
71         else {
72                 ;
73                 SG_DList::iterator<SCA_JoystickSensor> it(m_sensors);
74                 for (it.begin();!it.end();++it)
75                 {
76                         SCA_JoystickSensor* joysensor = *it;
77                         if (!joysensor->IsSuspended())
78                         {
79                                 joysensor->Activate(m_logicmgr);
80                         }
81                 }
82         }
83 }
84
85
86 SCA_Joystick *SCA_JoystickManager::GetJoystickDevice( short int joyindex)
87 {
88         /*
89          *Return the instance of SCA_Joystick for use
90          */
91         return m_joystick[joyindex];
92 }