BGE: bookmark option on controller to make them run before all other controllers.
[blender.git] / source / gameengine / GameLogic / SCA_IInputDevice.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
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 2
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 Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <assert.h>
30 #include "SCA_IInputDevice.h"
31
32 SCA_IInputDevice::SCA_IInputDevice()
33         :
34         m_currentTable(0)
35 {
36         ClearStatusTable(0);
37         ClearStatusTable(1);
38 }
39
40
41
42 SCA_IInputDevice::~SCA_IInputDevice()
43 {
44 }       
45
46 void SCA_IInputDevice::HookEscape()
47 {
48         assert(false && "This device does not support hooking escape.");
49 }
50
51 void SCA_IInputDevice::ClearStatusTable(int tableid)
52 {
53         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
54                 m_eventStatusTables[tableid][i]=SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS,0);
55 }
56
57
58
59 const SCA_InputEvent& SCA_IInputDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
60 {
61   //    cerr << "SCA_IInputDevice::GetEventValue" << endl;
62         return m_eventStatusTables[m_currentTable][inputcode];
63 }
64
65
66
67 int SCA_IInputDevice::GetNumActiveEvents()
68 {
69         int num = 0;
70
71         //      cerr << "SCA_IInputDevice::GetNumActiveEvents" << endl;
72
73         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
74         {
75                 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
76                 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
77                         || (event.m_status == SCA_InputEvent::KX_ACTIVE))
78                         num++;
79         }
80
81         return num;
82 }
83
84
85
86 int SCA_IInputDevice::GetNumJustEvents()
87 {
88         int num = 0;
89
90         //      cerr << "SCA_IInputDevice::GetNumJustEvents" << endl;
91
92         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
93         {
94                 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
95                 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
96                         || (event.m_status == SCA_InputEvent::KX_JUSTRELEASED))
97                         num++;
98         }
99
100         return num;
101 }
102
103
104
105 void SCA_IInputDevice::NextFrame()
106 {
107         m_currentTable = 1 - m_currentTable;
108
109         //      cerr << "SCA_IInputDevice::NextFrame " << GetNumActiveEvents() << endl;
110         
111         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
112         {
113                 switch (m_eventStatusTables[1 - m_currentTable][i].m_status)
114                 {
115                 case SCA_InputEvent::KX_NO_INPUTSTATUS:
116                         m_eventStatusTables[m_currentTable][i]
117                                 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
118                         break;
119                 case SCA_InputEvent::KX_JUSTACTIVATED:
120                         m_eventStatusTables[m_currentTable][i]
121                                 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
122                         break;
123                 case SCA_InputEvent::KX_ACTIVE:
124                         m_eventStatusTables[m_currentTable][i]
125                                 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
126                         break;
127                 case SCA_InputEvent::KX_JUSTRELEASED:
128                         m_eventStatusTables[m_currentTable][i]
129                                 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
130                         break;
131                 default:
132                         ; /* error */
133                 }       
134         }
135 }