c21db794e42102caca78011252580e87c7fa60d3
[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         if (m_sensors.Empty()) {
64                 return;
65         }
66         else {
67                 ;
68 #ifdef WITH_SDL
69                 SCA_Joystick::HandleEvents(); /* Handle all SDL Joystick events */
70 #endif
71                 SG_DList::iterator<SCA_JoystickSensor> it(m_sensors);
72                 for (it.begin();!it.end();++it)
73                 {
74                         SCA_JoystickSensor* joysensor = *it;
75                         if (!joysensor->IsSuspended())
76                         {
77                                 joysensor->Activate(m_logicmgr);
78                         }
79                 }
80         }
81 }
82
83
84 SCA_Joystick *SCA_JoystickManager::GetJoystickDevice( short int joyindex)
85 {
86         /*
87          *Return the instance of SCA_Joystick for use
88          */
89         return m_joystick[joyindex];
90 }