optionally use guarded alloc for tiles compositor, also replace allocation functions...
[blender.git] / source / gameengine / GameLogic / SCA_IInputDevice.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_IInputDevice.cpp
29  *  \ingroup gamelogic
30  */
31
32
33 #include <assert.h>
34 #include "SCA_IInputDevice.h"
35
36 SCA_IInputDevice::SCA_IInputDevice()
37         :
38         m_currentTable(0)
39 {
40         ClearStatusTable(0);
41         ClearStatusTable(1);
42 }
43
44
45
46 SCA_IInputDevice::~SCA_IInputDevice()
47 {
48 }       
49
50 void SCA_IInputDevice::HookEscape()
51 {
52         assert(false && "This device does not support hooking escape.");
53 }
54
55 void SCA_IInputDevice::ClearStatusTable(int tableid)
56 {
57         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
58                 m_eventStatusTables[tableid][i]=SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS,0);
59 }
60
61
62
63 const SCA_InputEvent& SCA_IInputDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
64 {
65 //      cerr << "SCA_IInputDevice::GetEventValue" << endl;
66         return m_eventStatusTables[m_currentTable][inputcode];
67 }
68
69
70
71 int SCA_IInputDevice::GetNumActiveEvents()
72 {
73         int num = 0;
74
75         //      cerr << "SCA_IInputDevice::GetNumActiveEvents" << endl;
76
77         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
78         {
79                 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
80                 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
81                         || (event.m_status == SCA_InputEvent::KX_ACTIVE))
82                         num++;
83         }
84
85         return num;
86 }
87
88
89
90 int SCA_IInputDevice::GetNumJustEvents()
91 {
92         int num = 0;
93
94         //      cerr << "SCA_IInputDevice::GetNumJustEvents" << endl;
95
96         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
97         {
98                 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
99                 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
100                         || (event.m_status == SCA_InputEvent::KX_JUSTRELEASED))
101                         num++;
102         }
103
104         return num;
105 }
106
107
108
109 void SCA_IInputDevice::NextFrame()
110 {
111         m_currentTable = 1 - m_currentTable;
112
113         //      cerr << "SCA_IInputDevice::NextFrame " << GetNumActiveEvents() << endl;
114         
115         for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
116         {
117                 switch (m_eventStatusTables[1 - m_currentTable][i].m_status)
118                 {
119                 case SCA_InputEvent::KX_NO_INPUTSTATUS:
120                         m_eventStatusTables[m_currentTable][i]
121                                 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
122                         break;
123                 case SCA_InputEvent::KX_JUSTACTIVATED:
124                         m_eventStatusTables[m_currentTable][i]
125                                 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
126                         break;
127                 case SCA_InputEvent::KX_ACTIVE:
128                         m_eventStatusTables[m_currentTable][i]
129                                 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
130                         break;
131                 case SCA_InputEvent::KX_JUSTRELEASED:
132                         m_eventStatusTables[m_currentTable][i]
133                                 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
134                         break;
135                 default:
136                         ; /* error */
137                 }       
138         }
139 }