Initial revision
[blender.git] / source / gameengine / GameLogic / SCA_IInputDevice.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL 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. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  */
31
32 #include <iostream.h>
33
34 #include "SCA_IInputDevice.h"
35
36
37
38 SCA_IInputDevice::SCA_IInputDevice()
39         :
40         m_currentTable(0)
41 {
42         ClearStatusTable(0);
43         ClearStatusTable(1);
44 }
45
46
47
48 SCA_IInputDevice::~SCA_IInputDevice()
49 {
50 }       
51
52
53
54 void SCA_IInputDevice::ClearStatusTable(int tableid)
55 {
56         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
57                 m_eventStatusTables[tableid][i]=SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS,0);
58 }
59
60
61
62 const SCA_InputEvent& SCA_IInputDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
63 {
64   //    cerr << "SCA_IInputDevice::GetEventValue" << endl;
65         return m_eventStatusTables[m_currentTable][inputcode];
66 }
67
68
69
70 int SCA_IInputDevice::GetNumActiveEvents()
71 {
72         int num = 0;
73
74         //      cerr << "SCA_IInputDevice::GetNumActiveEvents" << endl;
75
76         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
77         {
78                 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
79                 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
80                         || (event.m_status == SCA_InputEvent::KX_ACTIVE))
81                         num++;
82         }
83
84         return num;
85 }
86
87
88
89 int SCA_IInputDevice::GetNumJustEvents()
90 {
91         int num = 0;
92
93         //      cerr << "SCA_IInputDevice::GetNumJustEvents" << endl;
94
95         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
96         {
97                 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
98                 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
99                         || (event.m_status == SCA_InputEvent::KX_JUSTRELEASED))
100                         num++;
101         }
102
103         return num;
104 }
105
106
107
108 void SCA_IInputDevice::NextFrame()
109 {
110         m_currentTable = 1 - m_currentTable;
111
112         //      cerr << "SCA_IInputDevice::NextFrame " << GetNumActiveEvents() << endl;
113         
114         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
115         {
116                 switch (m_eventStatusTables[1 - m_currentTable][i].m_status)
117                 {
118                 case SCA_InputEvent::KX_NO_INPUTSTATUS:
119                         m_eventStatusTables[m_currentTable][i]
120                                 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
121                         break;
122                 case SCA_InputEvent::KX_JUSTACTIVATED:
123                         m_eventStatusTables[m_currentTable][i]
124                                 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
125                         break;
126                 case SCA_InputEvent::KX_ACTIVE:
127                         m_eventStatusTables[m_currentTable][i]
128                                 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
129                         break;
130                 case SCA_InputEvent::KX_JUSTRELEASED:
131                         m_eventStatusTables[m_currentTable][i]
132                                 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
133                         break;
134                 default:
135                         ; /* error */
136                 }       
137         }
138 }