BGE: bookmark option on controller to make them run before all other controllers.
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "SCA_JoystickSensor.h"
28 #include "SCA_JoystickManager.h"
29 #include "SCA_LogicManager.h"
30 //#include <vector>
31 #include "SCA_ISensor.h"
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36 //using namespace std;
37
38
39 SCA_JoystickManager::SCA_JoystickManager(class SCA_LogicManager* logicmgr)
40         : SCA_EventManager(JOY_EVENTMGR),
41         m_logicmgr(logicmgr)
42 {
43         int i;
44         for (i=0; i<JOYINDEX_MAX; i++) {
45                 m_joystick[i] = SCA_Joystick::GetInstance( i );
46         }
47 }
48
49
50 SCA_JoystickManager::~SCA_JoystickManager()
51 {
52         int i;
53         for (i=0; i<JOYINDEX_MAX; i++) {
54                 if(m_joystick[i])
55                         m_joystick[i]->ReleaseInstance();
56         }
57 }
58
59
60 void SCA_JoystickManager::NextFrame(double curtime,double deltatime)
61 {
62         if (m_sensors.Empty()) {
63                 return;
64         }
65         else {
66                 ;
67 #ifndef DISABLE_SDL
68                 SCA_Joystick::HandleEvents(); /* Handle all SDL Joystick events */
69 #endif
70                 SG_DList::iterator<SCA_JoystickSensor> it(m_sensors);
71                 for (it.begin();!it.end();++it)
72                 {
73                         SCA_JoystickSensor* joysensor = *it;
74                         if(!joysensor->IsSuspended())
75                         {
76                                 joysensor->Activate(m_logicmgr);
77                         }
78                 }
79         }
80 }
81
82
83 SCA_Joystick *SCA_JoystickManager::GetJoystickDevice( short int joyindex)
84 {
85         /* 
86          *Return the instance of SCA_Joystick for use 
87          */
88         return m_joystick[joyindex];
89 }