doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
posix_input.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #include "../../idlib/precompiled.h"
29 #include "posix_public.h"
30 
31 typedef struct poll_keyboard_event_s
32 {
33  int key;
34  bool state;
36 
37 typedef struct poll_mouse_event_s
38 {
39  int action;
40  int value;
42 
43 #define MAX_POLL_EVENTS 50
44 #define POLL_EVENTS_HEADROOM 2 // some situations require to add several events
45 static poll_keyboard_event_t poll_events_keyboard[MAX_POLL_EVENTS + POLL_EVENTS_HEADROOM];
46 static int poll_keyboard_event_count;
47 static poll_mouse_event_t poll_events_mouse[MAX_POLL_EVENTS + POLL_EVENTS_HEADROOM];
48 static int poll_mouse_event_count;
49 
50 /*
51 ==========
52 Posix_AddKeyboardPollEvent
53 ==========
54 */
55 bool Posix_AddKeyboardPollEvent(int key, bool state) {
56  if (poll_keyboard_event_count >= MAX_POLL_EVENTS + POLL_EVENTS_HEADROOM)
57  common->FatalError( "poll_keyboard_event_count exceeded MAX_POLL_EVENT + POLL_EVENTS_HEADROOM\n");
58  poll_events_keyboard[poll_keyboard_event_count].key = key;
59  poll_events_keyboard[poll_keyboard_event_count++].state = state;
60  if (poll_keyboard_event_count >= MAX_POLL_EVENTS) {
61  common->DPrintf("WARNING: reached MAX_POLL_EVENT poll_keyboard_event_count\n");
62  return false;
63  }
64  return true;
65 }
66 
67 /*
68 ==========
69 Posix_AddMousePollEvent
70 ==========
71 */
72 bool Posix_AddMousePollEvent(int action, int value) {
73  if (poll_mouse_event_count >= MAX_POLL_EVENTS + POLL_EVENTS_HEADROOM)
74  common->FatalError( "poll_mouse_event_count exceeded MAX_POLL_EVENT + POLL_EVENTS_HEADROOM\n");
75  poll_events_mouse[poll_mouse_event_count].action = action;
76  poll_events_mouse[poll_mouse_event_count++].value = value;
77  if (poll_mouse_event_count >= MAX_POLL_EVENTS) {
78  common->DPrintf("WARNING: reached MAX_POLL_EVENT poll_mouse_event_count\n");
79  return false;
80  }
81  return true;
82 }
83 
84 /*
85 ===========================================================================
86 polled from GetDirectUsercmd
87 async input polling is obsolete
88 we have a single entry point for both mouse and keyboard
89 the mouse/keyboard seperation is API legacy
90 ===========================================================================
91 */
92 
94  return poll_keyboard_event_count;
95 }
96 
97 int Sys_ReturnKeyboardInputEvent( const int n, int &key, bool &state ) {
98  if ( n >= poll_keyboard_event_count ) {
99  return 0;
100  }
101  key = poll_events_keyboard[n].key;
102  state = poll_events_keyboard[n].state;
103  return 1;
104 }
105 
107  //isn't this were it's supposed to be, was missing some key strokes with it set below
108  poll_keyboard_event_count = 0;
109  }
110 
112 #if 0 //moved to the Sys_End functions
113  poll_keyboard_event_count = 0;
114  poll_mouse_event_count = 0;
115 #endif
116 
117  // that's OS specific, implemented in osx/ and linux/
118  Posix_PollInput( );
119 
120  return poll_mouse_event_count;
121 }
122 
123 int Sys_ReturnMouseInputEvent( const int n, int &action, int &value )
124 {
125  if ( n>=poll_mouse_event_count ) {
126  return 0;
127  }
128  action = poll_events_mouse[ n ].action;
129  value = poll_events_mouse[ n ].value;
130  return 1;
131 }
132 
134  // moved out of the Sys_PollMouseInputEvents
135  poll_mouse_event_count = 0;
136 }
GLsizei const GLfloat * value
Definition: glext.h:3614
bool Posix_AddKeyboardPollEvent(int key, bool state)
Definition: posix_input.cpp:55
#define POLL_EVENTS_HEADROOM
Definition: posix_input.cpp:44
int Sys_PollMouseInputEvents(void)
GLenum GLsizei n
Definition: glext.h:3705
bool Posix_AddMousePollEvent(int action, int value)
Definition: posix_input.cpp:72
int Sys_ReturnKeyboardInputEvent(const int n, int &key, bool &state)
Definition: posix_input.cpp:97
void Posix_PollInput()
Definition: input.cpp:337
struct poll_mouse_event_s poll_mouse_event_t
idCommon * common
Definition: Common.cpp:206
int Sys_PollKeyboardInputEvents(void)
Definition: posix_input.cpp:93
virtual void virtual void FatalError(const char *fmt,...) id_attribute((format(printf
struct poll_keyboard_event_s poll_keyboard_event_t
void Sys_EndMouseInputEvents(void)
#define MAX_POLL_EVENTS
Definition: posix_input.cpp:43
int Sys_ReturnMouseInputEvent(const int n, int &action, int &value)
virtual void DPrintf(const char *fmt,...) id_attribute((format(printf
void Sys_EndKeyboardInputEvents(void)