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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>di_game_device.cpp</h1><a href="di__game__device_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2000-2002 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026
00027 <font class="preprocessor">#include "<a class="code" href="stdmisc_8h.html">stdmisc.h</a>"</font>
00028 <font class="preprocessor">#include "<a class="code" href="di__game__device_8h.html">misc/di_game_device.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="game__device__events_8h.html">nel/misc/game_device_events.h</a>"</font>
00030 <font class="preprocessor">#include <stddef.h></font>
00031 <font class="preprocessor">#include <memory></font>
00032 <font class="preprocessor">#include <algorithm></font>
00033
00034 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00035 <font class="preprocessor"></font>
00036 <font class="keyword">namespace </font>NLMISC
00037 {
00038
00039 <font class="comment">//============================================================================</font>
00040 CDIGameDevice::CDIGameDevice() : _Device(NULL)
00041 {
00042 ::memset(&_CurrentState, 0, <font class="keyword">sizeof</font>(_CurrentState));
00043 }
00044
00045 <font class="comment">//============================================================================</font>
00046 CDIGameDevice::~CDIGameDevice()
00047 {
00048 <font class="keywordflow">if</font> (_Device)
00049 {
00050 _Device->Unacquire();
00051 _Device->Release();
00052 }
00053 }
00054
00055 <font class="comment">//============================================================================</font>
00056 CDIGameDevice *CDIGameDevice::createGameDevice(IDirectInput8 *di8,
00057 HWND hwnd,
00058 CDIEventEmitter *diEventEmitter,
00059 <font class="keyword">const</font> CGameDeviceDesc &desc,
00060 REFGUID rguid) <font class="keywordflow">throw</font>(EDirectInput)
00061 {
00062 <a class="code" href="debug_8h.html#a6">nlassert</a>(diEventEmitter);
00063 <a class="code" href="debug_8h.html#a6">nlassert</a>(di8);
00064 std::auto_ptr<CDIGameDevice> dev(<font class="keyword">new</font> CDIGameDevice);
00065 <font class="comment">//</font>
00066
00067 HRESULT <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = di8->CreateDevice(rguid, &dev->_Device, NULL);
00068 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK) <font class="keywordflow">throw</font> EDirectInputGameDeviceNotCreated();
00069
00070 <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = dev->_Device->SetDataFormat(pJoyDataFormat);
00071 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> == DI_OK);
00072 <font class="comment">//</font>
00073 <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = dev->_Device->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
00074 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK) <font class="keywordflow">throw</font> EDirectInputCooperativeLevelFailed();
00075 <font class="comment">// </font>
00076 <font class="comment">// </font>
00077 dev->_Desc = desc;
00078 dev->_EventEmitter = diEventEmitter;
00079 dev->querryControls();
00080 <font class="keywordflow">return</font> dev.release();
00081 }
00082
00083 <font class="comment">//============================================================================</font>
00084 <font class="keywordtype">void</font> CDIGameDevice::begin(CEventServer *server)
00085 {
00086 <a class="code" href="debug_8h.html#a6">nlassert</a>(_Device);
00087 HRESULT <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a>;
00088 <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = _Device->Poll();
00089 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> == DIERR_INPUTLOST || <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> == DIERR_NOTACQUIRED)
00090 {
00091 <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = _Device->Acquire();
00092 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK) <font class="keywordflow">return</font>;
00093 <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = _Device->Poll();
00094 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK) <font class="keywordflow">return</font>;
00095 }
00096
00097 CDIJoyState newState;
00098 <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = _Device->GetDeviceState(<font class="keyword">sizeof</font>(CDIJoyState), &newState);
00099 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK) <font class="keywordflow">return</font>;
00100
00101 <a class="code" href="types__nl_8h.html#a14">uint</a> k;
00103 <font class="comment">// Axis //</font>
00105 <font class="comment"> for (k = 0; k < MaxNumAxis; ++k)</font>
00106 {
00107 CAxis &axis = _Axis[k];
00108 <font class="keywordflow">if</font> (axis.Present)
00109 {
00110
00111 <font class="keywordflow">if</font> (((LONG *) &newState)[k] != ((LONG *) &_CurrentState)[k]) <font class="comment">// state changed ?</font>
00112 {
00113 <font class="comment">// update position</font>
00114 axis.Value = 2.f * (((LONG *) &newState)[k] - axis.Min) / (float) (axis.Max - axis.Min) - 1.f;
00115 <font class="comment">// create event</font>
00116 CGDAxisMoved *event = <font class="keyword">new</font> CGDAxisMoved((IGameDevice::TAxis) k, axis.Value, <font class="keyword">this</font>, _EventEmitter);
00117 <font class="comment">// update state</font>
00118 ((LONG *) &_CurrentState)[k] = ((LONG *) &newState)[k];
00119 <font class="comment">//</font>
00120 server->postEvent(event);
00121 <font class="comment">//</font>
00122 }
00123 }
00124 }
00125
00126
00128 <font class="comment">// Buttons //</font>
00130 <font class="comment"> for (k = 0; k < _Buttons.size(); ++k)</font>
00131 {
00132 CButton &bt = _Buttons[k];
00133 <font class="keywordflow">if</font> ((newState.rgbButtons[k] & 0x80) != (_CurrentState.rgbButtons[k] & 0x80))
00134 {
00135 <font class="keywordtype">bool</font> pushed = (newState.rgbButtons[k] & 0x80) != 0;
00136 <font class="comment">// update the state of the button</font>
00137 bt.Pushed = pushed;
00138 CGDButton *event;
00139 <font class="keywordflow">if</font> (pushed) event = <font class="keyword">new</font> CGDButtonDown(k, <font class="keyword">this</font>, _EventEmitter);
00140 <font class="keywordflow">else</font> event = <font class="keyword">new</font> CGDButtonUp(k, <font class="keyword">this</font>, _EventEmitter);
00141 <font class="comment">// update state </font>
00142 _CurrentState.rgbButtons[k] = newState.rgbButtons[k];
00143 server->postEvent(event);
00144 }
00145 }
00146
00148 <font class="comment">// Sliders //</font>
00150 <font class="comment"> for (k = 0; k < _Sliders.size(); ++k)</font>
00151 {
00152 CSlider &sl = _Sliders[k];
00153 <font class="keywordflow">if</font> (newState.rglSlider[k] != _CurrentState.rglSlider[k]) <font class="comment">// state changed ?</font>
00154 {
00155 <font class="comment">// update position</font>
00156 sl.Pos = ( newState.rglSlider[k] - sl.Min) / (float) (sl.Max - sl.Min);
00157 <font class="comment">// create event</font>
00158 CGDSliderMoved *event = <font class="keyword">new</font> CGDSliderMoved(sl.Pos, k, <font class="keyword">this</font>, _EventEmitter);
00159 <font class="comment">// update state</font>
00160 _CurrentState.rglSlider[k] = newState.rglSlider[k];
00161 <font class="comment">//</font>
00162 server->postEvent(event);
00163 }
00164 }
00165
00167 <font class="comment">// POVs //</font>
00169 <font class="comment"> for (k = 0; k < _POVs.size(); ++k)</font>
00170 {
00171 CPOV &pov = _POVs[k];
00172 <font class="keywordflow">if</font> (newState.rgdwPOV[k] != _CurrentState.rgdwPOV[k]) <font class="comment">// state changed ?</font>
00173 {
00174 DWORD value = newState.rgdwPOV[k];
00175
00176 pov.Centered = (LOWORD(value) == 0xFFFF);
00177 <font class="keywordflow">if</font> (!pov.Centered)
00178 {
00179 <font class="comment">// update position</font>
00180 pov.Angle = value / 100.f;
00181 }
00182 <font class="comment">// create event</font>
00183 CGDPOVChanged *event = <font class="keyword">new</font> CGDPOVChanged(pov.Centered, pov.Angle, k, <font class="keyword">this</font>, _EventEmitter);
00184 <font class="comment">// update state</font>
00185 _CurrentState.rgdwPOV[k] = newState.rgdwPOV[k];
00186 <font class="comment">//</font>
00187 server->postEvent(event);
00188 }
00189 }
00190
00191 }
00192
00193 <font class="comment">//============================================================================</font>
00194 <font class="keywordtype">void</font> CDIGameDevice::poll(CInputDeviceServer *dev)
00195 {
00196 <font class="comment">// buffered datas not supported</font>
00197 }
00198
00199 <font class="comment">//============================================================================</font>
00200 <font class="keywordtype">void</font> CDIGameDevice::submit(IInputDeviceEvent *deviceEvent, CEventServer *server)
00201 {
00202 <font class="comment">// should never be called, buffered datas not supported</font>
00203 <a class="code" href="debug_8h.html#a6">nlassert</a>(0);
00204 }
00205
00206
00207 <font class="comment">//============================================================================</font>
00211 <font class="comment"></font><font class="keyword">static</font> <font class="keywordtype">void</font> BuildCtrlName(LPCDIDEVICEOBJECTINSTANCE lpddoi,
00212 std::string &destName,
00213 <font class="keyword">const</font> <font class="keywordtype">char</font> *defaultName)
00214 {
00215 <font class="keywordflow">if</font> (lpddoi->dwSize >= offsetof(DIDEVICEOBJECTINSTANCE, tszName) + <font class="keyword">sizeof</font>(TCHAR[MAX_PATH]))
00216 {
00217 destName = (::strcmp(<font class="stringliteral">"N/A"</font>, lpddoi->tszName) == 0) ? defaultName
00218 : lpddoi->tszName;
00219 }
00220 <font class="keywordflow">else</font>
00221 {
00222 destName = defaultName;
00223 }
00224 }
00225
00226 <font class="comment">//============================================================================</font>
00227 <font class="comment">// A callback to enumerate the controls of a device</font>
00228 <font class="keyword">static</font> BOOL CALLBACK DIEnumDeviceObjectsCallback
00229 (
00230 LPCDIDEVICEOBJECTINSTANCE lpddoi,
00231 LPVOID pvRef
00232 )
00233 {
00234
00235 CDIGameDevice *gd = (CDIGameDevice *) pvRef;
00236 <font class="keywordflow">return</font> gd->processEnumObject(lpddoi);
00237 }
00238
00239
00240
00241 <font class="comment">//=======================================================================</font>
00242 <font class="comment">// get range for an axis</font>
00243 <font class="keyword">static</font> HRESULT GetDIAxisRange(LPDIRECTINPUTDEVICE8 device, <a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a256">offset</a>, DWORD <a class="code" href="driver__opengl__extension__def_8h.html#a251">type</a>, <a class="code" href="types__nl_8h.html#a13">sint</a> &<a class="code" href="bit__set_8cpp.html#a0">min</a>, <a class="code" href="types__nl_8h.html#a13">sint</a> &max)
00244 {
00245 DIPROPRANGE diprg;
00246 diprg.diph.dwSize = <font class="keyword">sizeof</font>(DIPROPRANGE);
00247 diprg.diph.dwHeaderSize = <font class="keyword">sizeof</font>(DIPROPHEADER);
00248 diprg.diph.dwHow = DIPH_BYOFFSET;
00249 diprg.diph.dwObj = <a class="code" href="driver__opengl__extension__def_8h.html#a256">offset</a>;
00250
00251 <font class="comment">// Set the range for the axis</font>
00252 HRESULT <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = device->GetProperty(DIPROP_RANGE, &diprg.diph);
00253
00254 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> == DIERR_OBJECTNOTFOUND)
00255 {
00256 <font class="comment">// try from its ID</font>
00257 diprg.diph.dwHow = DIPH_BYID;
00258 diprg.diph.dwObj = <a class="code" href="driver__opengl__extension__def_8h.html#a251">type</a>;
00259
00260 <font class="comment">// Set the range for the axis</font>
00261 HRESULT <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = device->GetProperty(DIPROP_RANGE, &diprg.diph);
00262 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK)
00263 {
00264 <font class="comment">// setup default values ...</font>
00265 <a class="code" href="bit__set_8cpp.html#a0">min</a> = 0;
00266 max = 65535;
00267 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a>;
00268 }
00269 }
00270 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> != DI_OK)
00271 {
00272 <a class="code" href="bit__set_8cpp.html#a0">min</a> = 0;
00273 max = 65535;
00274 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a>;
00275 }
00276
00277
00278 <font class="comment">/* switch (r)</font>
00279 <font class="comment"> {</font>
00280 <font class="comment"> default:</font>
00281 <font class="comment"> nlinfo("ok");</font>
00282 <font class="comment"> break;</font>
00283 <font class="comment"> case DIERR_INVALIDPARAM: </font>
00284 <font class="comment"> nlinfo("invalid param");</font>
00285 <font class="comment"> break;</font>
00286 <font class="comment"> case DIERR_NOTEXCLUSIVEACQUIRED: </font>
00287 <font class="comment"> nlinfo("DIERR_NOTEXCLUSIVEACQUIRED");</font>
00288 <font class="comment"> break;</font>
00289 <font class="comment"> case DIERR_NOTINITIALIZED: </font>
00290 <font class="comment"> nlinfo("DIERR_NOTINITIALIZED");</font>
00291 <font class="comment"> break;</font>
00292 <font class="comment"> case DIERR_OBJECTNOTFOUND: </font>
00293 <font class="comment"> nlinfo("DIERR_OBJECTNOTFOUND");</font>
00294 <font class="comment"> break;</font>
00295 <font class="comment"> case DIERR_UNSUPPORTED: </font>
00296 <font class="comment"> nlinfo("DIERR_UNSUPPORTED");</font>
00297 <font class="comment"> break;</font>
00298 <font class="comment"> }*/</font>
00299
00300
00301 <a class="code" href="bit__set_8cpp.html#a0">min</a> = (sint) diprg.lMin;
00302 max = (sint) diprg.lMax;
00303
00304 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a>;
00305 }
00306
00307 <font class="comment">//============================================================================</font>
00308 BOOL CDIGameDevice::processEnumObject(LPCDIDEVICEOBJECTINSTANCE lpddoi)
00309 {
00310 <font class="comment">// the dwSize field gives us the size of the objects, and the available fields</font>
00311 <font class="comment">// has this object the field guidType and dwOfs ?</font>
00312 <font class="keywordflow">if</font> (lpddoi->dwSize < offsetof(DIDEVICEOBJECTINSTANCE, dwOfs) + <font class="keyword">sizeof</font>(DWORD)) <font class="keywordflow">return</font> DIENUM_CONTINUE;
00313
00314 <a class="code" href="types__nl_8h.html#a14">uint</a> ctrlType = (uint) lpddoi->dwType;
00315
00317 <font class="comment">// axis, we only support absolute ones //</font>
00319 <font class="comment"></font>
00320 <font class="keywordflow">if</font> (lpddoi->guidType == GUID_XAxis && (ctrlType & DIDFT_ABSAXIS) )
00321 {
00322 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Axis[XAxis].Min, _Axis[XAxis].Max);
00323 BuildCtrlName(lpddoi, _Axis[XAxis].Name, <font class="stringliteral">"X Axis"</font>);
00324 _Axis[XAxis].Present = <font class="keyword">true</font>;
00325 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00326 }
00327 <font class="keywordflow">if</font> (lpddoi->guidType == GUID_YAxis && (ctrlType & DIDFT_ABSAXIS))
00328 {
00329 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Axis[YAxis].Min, _Axis[YAxis].Max);
00330 BuildCtrlName(lpddoi, _Axis[YAxis].Name, <font class="stringliteral">"Y Axis"</font>);
00331 _Axis[YAxis].Present = <font class="keyword">true</font>;
00332 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00333 }
00334
00335 <font class="keywordflow">if</font> (lpddoi->guidType == GUID_ZAxis && (ctrlType & DIDFT_ABSAXIS))
00336 {
00337 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Axis[ZAxis].Min, _Axis[ZAxis].Max);
00338 BuildCtrlName(lpddoi, _Axis[ZAxis].Name, <font class="stringliteral">"Z Axis"</font>);
00339 _Axis[ZAxis].Present = <font class="keyword">true</font>;
00340 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00341 }
00342 <font class="keywordflow">if</font> (lpddoi->guidType == GUID_RxAxis && (ctrlType & DIDFT_ABSAXIS))
00343 {
00344 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Axis[RXAxis].Min, _Axis[RXAxis].Max);
00345 BuildCtrlName(lpddoi, _Axis[RXAxis].Name, <font class="stringliteral">"RX Axis"</font>);
00346 _Axis[RXAxis].Present = <font class="keyword">true</font>;
00347 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00348 }
00349 <font class="keywordflow">if</font> (lpddoi->guidType == GUID_RyAxis && (ctrlType & DIDFT_ABSAXIS))
00350 {
00351 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Axis[RYAxis].Min, _Axis[RYAxis].Max);
00352 BuildCtrlName(lpddoi, _Axis[RYAxis].Name, <font class="stringliteral">"RY Axis"</font>);
00353 _Axis[RYAxis].Present = <font class="keyword">true</font>;
00354 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00355 }
00356 <font class="keywordflow">if</font> (lpddoi->guidType == GUID_RzAxis && (ctrlType & DIDFT_ABSAXIS))
00357 {
00358 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Axis[RZAxis].Min, _Axis[RZAxis].Max);
00359 BuildCtrlName(lpddoi, _Axis[RZAxis].Name, <font class="stringliteral">"RZ Axis"</font>);
00360 _Axis[RZAxis].Present = <font class="keyword">true</font>;
00361 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00362 }
00363
00364
00365 <font class="comment">// has this object the field dwType ?</font>
00366 <font class="keywordflow">if</font> (lpddoi->dwSize < offsetof(DIDEVICEOBJECTINSTANCE, dwType) + <font class="keyword">sizeof</font>(DWORD)) <font class="keywordflow">return</font> DIENUM_CONTINUE;
00367
00368
00369 <a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a251">type</a> = lpddoi->dwType;
00371 <font class="comment">// Buttons //</font>
00373 <font class="comment"> if (type & DIDFT_BUTTON)</font>
00374 {
00375 <font class="keywordflow">if</font> (_Buttons.size() < MaxNumButtons)
00376 {
00377 _Buttons.push_back(CButton());
00378 <a class="code" href="types__nl_8h.html#a14">uint</a> buttonIndex = _Buttons.size() - 1;
00379 <font class="keywordtype">char</font> defaultButtonName[32];
00380 <a class="code" href="namespaceNLMISC.html#a203">smprintf</a>(defaultButtonName, 32, <font class="stringliteral">"BUTTON %d"</font>, buttonIndex + 1);
00381 BuildCtrlName(lpddoi, _Buttons[buttonIndex].Name, defaultButtonName);
00382 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00383 }
00384 }
00385
00387 <font class="comment">// Sliders //</font>
00389 <font class="comment"> if (type & DIDFT_ABSAXIS)</font>
00390 {
00391 <font class="keywordflow">if</font> (_Sliders.size() < MaxNumSliders)
00392 {
00393 _Sliders.push_back(CSlider());
00394 <a class="code" href="types__nl_8h.html#a14">uint</a> sliderIndex = _Sliders.size() - 1;
00395 GetDIAxisRange(_Device, lpddoi->dwOfs, lpddoi->dwType, _Sliders[sliderIndex].Min, _Sliders[sliderIndex].Max);
00396 <font class="keywordtype">char</font> defaultSliderName[32];
00397 <a class="code" href="namespaceNLMISC.html#a203">smprintf</a>(defaultSliderName, 32, <font class="stringliteral">"SLIDER %d"</font>, sliderIndex + 1);
00398 BuildCtrlName(lpddoi, _Sliders[sliderIndex].Name, defaultSliderName);
00399 }
00400 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00401 }
00402
00403
00405 <font class="comment">// POVs //</font>
00407 <font class="comment"> if (type & DIDFT_POV)</font>
00408 {
00409 <font class="keywordflow">if</font> (_POVs.size() < MaxNumPOVs)
00410 {
00411 _POVs.push_back(CPOV());
00412 <a class="code" href="types__nl_8h.html#a14">uint</a> povIndex = _POVs.size() - 1;
00413 <font class="keywordtype">char</font> defaultPOVName[16];
00414 <a class="code" href="namespaceNLMISC.html#a203">smprintf</a>(defaultPOVName, 16, <font class="stringliteral">"POV %d"</font>, povIndex + 1);
00415 BuildCtrlName(lpddoi, _POVs[povIndex].Name, defaultPOVName);
00416 }
00417 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00418 }
00419
00420 <font class="keywordflow">return</font> DIENUM_CONTINUE;
00421 }
00422
00423 <font class="comment">//============================================================================</font>
00424 <font class="keywordtype">void</font> CDIGameDevice::querryControls()
00425 {
00426 HRESULT <a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> = _Device->EnumObjects(&DIEnumDeviceObjectsCallback, (LPVOID) <font class="keyword">this</font>, DIDFT_ALL);
00427 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a262">r</a> == DI_OK);
00428 }
00429
00430 <font class="comment">//============================================================================</font>
00431 <font class="keywordtype">bool</font> CDIGameDevice::setBufferSize(<a class="code" href="types__nl_8h.html#a14">uint</a> size)
00432 {
00433 <font class="comment">// uisually not supported by this kind of devices</font>
00434 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00435 }
00436
00437 <font class="comment">//============================================================================</font>
00438 <a class="code" href="types__nl_8h.html#a14">uint</a> CDIGameDevice::getBufferSize()<font class="keyword"> const</font>
00439 <font class="keyword"></font>{
00440 <font class="comment">// uisually not supported by this kind of devices</font>
00441 <font class="keywordflow">return</font> 0;
00442 }
00443
00444 <font class="comment">//============================================================================</font>
00445 <a class="code" href="types__nl_8h.html#a14">uint</a> CDIGameDevice::getNumButtons()<font class="keyword"> const</font>
00446 <font class="keyword"></font>{
00447 <font class="keywordflow">return</font> _Buttons.size();
00448 }
00449
00450 <font class="comment">//============================================================================</font>
00451 <font class="keywordtype">bool</font> CDIGameDevice::hasAxis(TAxis axis)<font class="keyword"> const</font>
00452 <font class="keyword"></font>{
00453 <a class="code" href="debug_8h.html#a6">nlassert</a>(axis < MaxNumAxis);
00454 <font class="keywordflow">return</font> _Axis[axis].Present;
00455 }
00456
00457 <font class="comment">//============================================================================</font>
00458 <a class="code" href="types__nl_8h.html#a14">uint</a> CDIGameDevice::getNumSliders()<font class="keyword"> const</font>
00459 <font class="keyword"></font>{
00460 <font class="keywordflow">return</font> _Sliders.size();
00461 }
00462
00463 <font class="comment">//============================================================================</font>
00464 <a class="code" href="types__nl_8h.html#a14">uint</a> CDIGameDevice::getNumPOV()<font class="keyword"> const </font>
00465 <font class="keyword"></font>{
00466 <font class="keywordflow">return</font> _POVs.size();
00467 }
00468 <font class="comment">//============================================================================</font>
00469 <font class="keyword">const</font> <font class="keywordtype">char</font> *CDIGameDevice::getButtonName(<a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>)<font class="keyword"> const</font>
00470 <font class="keyword"></font>{
00471 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a> < _Buttons.size());
00472 <font class="keywordflow">return</font> _Buttons[<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>].Name.c_str();
00473 }
00474
00475 <font class="comment">//============================================================================</font>
00476 <font class="keyword">const</font> <font class="keywordtype">char</font> *CDIGameDevice::getAxisName(TAxis axis)<font class="keyword"> const</font>
00477 <font class="keyword"></font>{
00478 <a class="code" href="debug_8h.html#a6">nlassert</a>(axis < MaxNumAxis);
00479 <a class="code" href="debug_8h.html#a6">nlassert</a>(hasAxis(axis)); <font class="comment">// ! Not an axis of this device</font>
00480 <font class="keywordflow">return</font> _Axis[axis].Name.c_str();
00481 }
00482
00483 <font class="comment">//============================================================================</font>
00484 <font class="keyword">const</font> <font class="keywordtype">char</font> *CDIGameDevice::getSliderName(<a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>)<font class="keyword"> const</font>
00485 <font class="keyword"></font>{
00486 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a> < _Sliders.size());
00487 <font class="keywordflow">return</font> _Sliders[<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>].Name.c_str();
00488 }
00489
00490 <font class="comment">//============================================================================</font>
00491 <font class="keyword">const</font> <font class="keywordtype">char</font> *CDIGameDevice::getPOVName(<a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>)<font class="keyword"> const</font>
00492 <font class="keyword"></font>{
00493 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a> < _POVs.size());
00494 <font class="keywordflow">return</font> _POVs[<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>].Name.c_str();
00495 }
00496
00497 <font class="comment">//============================================================================</font>
00498 <font class="keywordtype">bool</font> CDIGameDevice::getButtonState(<a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>)<font class="keyword"> const</font>
00499 <font class="keyword"></font>{
00500 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a> < _Buttons.size());
00501 <font class="keywordflow">return</font> _Buttons[<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>].Pushed;
00502 }
00503
00504 <font class="comment">//============================================================================</font>
00505 <font class="keywordtype">float</font> CDIGameDevice::getAxisValue(TAxis axis)<font class="keyword"> const</font>
00506 <font class="keyword"></font>{
00507 <a class="code" href="debug_8h.html#a6">nlassert</a>(axis < MaxNumAxis);
00508 <a class="code" href="debug_8h.html#a6">nlassert</a>(hasAxis(axis)); <font class="comment">// ! Not an axis of this device</font>
00509 <font class="keywordflow">return</font> _Axis[axis].Value;
00510 }
00511
00512 <font class="comment">//============================================================================</font>
00513 <font class="keywordtype">float</font> CDIGameDevice::getSliderPos(<a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>)<font class="keyword"> const</font>
00514 <font class="keyword"></font>{
00515 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a> < _Sliders.size());
00516 <font class="keywordflow">return</font> _Sliders[<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>].Pos;
00517 }
00518
00519 <font class="comment">//============================================================================</font>
00520 <font class="keywordtype">float</font> CDIGameDevice::getPOVAngle(<a class="code" href="types__nl_8h.html#a14">uint</a> <a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>)<font class="keyword"> const</font>
00521 <font class="keyword"></font>{
00522 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a> < _POVs.size());
00523 <font class="keywordflow">return</font> _POVs[<a class="code" href="driver__opengl__extension__def_8h.html#a236">index</a>].Angle;
00524 }
00525
00526
00527
00528 } <font class="comment">// NLMISC</font>
00529
00530
00531 <font class="preprocessor">#endif // NL_OS_WINDOWS</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|