This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
forked from jedis/jedioutcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmac_input.c
212 lines (176 loc) · 4.75 KB
/
mac_input.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "../client/client.h"
#include "mac_local.h"
#include "InputSprocket.h"
qboolean inputActive;
qboolean inputSuspended;
#define MAX_DEVICES 100
ISpDeviceReference devices[MAX_DEVICES];
ISpElementListReference elementList;
#define MAX_ELEMENTS 512
#define MAX_MOUSE_DEVICES 2
UInt32 numDevices;
UInt32 numElements[MAX_MOUSE_DEVICES];
ISpElementReference elements[MAX_MOUSE_DEVICES][MAX_ELEMENTS];
cvar_t *in_nomouse;
void Input_Init(void);
void Input_GetState( void );
/*
=================
Sys_InitInput
=================
*/
void Sys_InitInput( void ) {
NumVersion ver;
ISpElementInfo info;
int i, j;
OSStatus err;
// no input with dedicated servers
if ( com_dedicated->integer ) {
return;
}
Com_Printf( "------- Input Initialization -------\n" );
in_nomouse = Cvar_Get( "in_nomouse", "0", 0 );
if ( in_nomouse->integer != 0 ) {
Com_Printf( "in_nomouse is set, skipping.\n" );
Com_Printf( "------------------------------------\n" );
return;
}
ver = ISpGetVersion();
Com_Printf( "InputSprocket version: 0x%x\n", ver );
err = ISpStartup();
if ( err ) {
Com_Printf( "ISpStartup failed: %i\n", err );
Com_Printf( "------------------------------------\n" );
return;
}
// disable everything
ISpDevices_Extract( MAX_DEVICES, &numDevices, devices );
Com_Printf("%i total devices\n", numDevices);
if (numDevices > MAX_DEVICES) {
numDevices = MAX_DEVICES;
}
err = ISpDevices_Deactivate(
numDevices,
devices);
// enable mouse
err = ISpDevices_ExtractByClass(
kISpDeviceClass_Mouse,
MAX_DEVICES,
&numDevices,
devices);
Com_Printf("%i mouse devices\n", numDevices);
if (numDevices > MAX_MOUSE_DEVICES) {
numDevices = MAX_MOUSE_DEVICES;
}
err = ISpDevices_Activate( numDevices, devices);
for ( i = 0 ; i < numDevices ; i++ ) {
ISpDevice_GetElementList( devices[i], &elementList );
// ISpGetGlobalElementList( &elementList );
// go through all the elements and asign them Quake key codes
ISpElementList_Extract( elementList, MAX_ELEMENTS, &numElements[i], elements[i] );
Com_Printf("%i elements in list\n", numElements[i] );
for ( j = 0 ; j < numElements[i] ; j++ ) {
ISpElement_GetInfo( elements[i][j], &info );
PStringToCString( (char *)info.theString );
Com_Printf( "%i : %s\n", i, info.theString );
}
}
inputActive = true;
HideCursor();
Com_Printf( "------------------------------------\n" );
}
/*
=================
Sys_ShutdownInput
=================
*/
void Sys_ShutdownInput( void ) {
if ( !inputActive ) {
return;
}
ShowCursor();
ISpShutdown();
inputActive = qfalse;
}
void Sys_SuspendInput( void ) {
if ( inputSuspended ) {
return;
}
inputSuspended = true;
ShowCursor();
ISpSuspend();
}
void Sys_ResumeInput( void ) {
if ( !inputSuspended ) {
return;
}
inputSuspended = false;
HideCursor();
ISpResume();
}
/*
=================
Sys_Input
=================
*/
void Sys_Input( void ) {
ISpElementEvent event;
Boolean wasEvent;
UInt32 state, state2;
int xmove, ymove;
int button;
static int xtotal, ytotal;
int device;
if ( !inputActive ) {
return;
}
// during debugging it is sometimes usefull to be able to kill mouse support
if ( in_nomouse->integer ) {
Com_Printf( "Shutting down input.\n");
Sys_ShutdownInput();
return;
}
// always suspend for dedicated
if ( com_dedicated->integer ) {
Sys_SuspendInput();
return;
}
// temporarily deactivate if not in the game and
if ( cls.keyCatchers || cls.state != CA_ACTIVE ) {
if ( !glConfig.isFullscreen ) {
Sys_SuspendInput();
return;
}
}
Sys_ResumeInput();
// send all button events
for ( device = 0 ; device < numDevices ; device++ ) {
// mouse buttons
for ( button = 2 ; button < numElements[device] ; button++ ) {
while ( 1 ) {
ISpElement_GetNextEvent( elements[device][button], sizeof( event ), &event, &wasEvent );
if ( !wasEvent ) {
break;
}
if ( event.data ) {
Sys_QueEvent( 0, SE_KEY, K_MOUSE1 + button - 2, 1, 0, NULL );
} else {
Sys_QueEvent( 0, SE_KEY, K_MOUSE1 + button - 2, 0, 0, NULL );
}
}
}
// mouse movement
#define MAC_MOUSE_SCALE 163 // why this constant?
// send mouse event
ISpElement_GetSimpleState( elements[device][0], &state );
xmove = (int)state / MAC_MOUSE_SCALE;
ISpElement_GetSimpleState( elements[device][1], &state2 );
ymove = (int)state2 / -MAC_MOUSE_SCALE;
if ( xmove || ymove ) {
xtotal += xmove;
ytotal += ymove;
//Com_Printf("%i %i = %i %i\n", state, state2, xtotal, ytotal );
Sys_QueEvent( 0, SE_MOUSE, xmove, ymove, 0, NULL );
}
}
}