forked from DescentDevelopers/Descent3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
winio.cpp
176 lines (152 loc) · 4.46 KB
/
winio.cpp
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
/*
* $Logfile: /DescentIII/Main/ddio_win/winio.cpp $
* $Revision: 17 $
* $Date: 7/09/01 1:55p $
* $Author: Matt $
*
* <insert description of file here>
*
* $Log: /DescentIII/Main/ddio_win/winio.cpp $
*
* 17 7/09/01 1:55p Matt
* Try opening DX5 for NT so force feedback will work.
*
* 16 4/09/99 12:02p Samir
* joystick changes (Win32 DirectInput support)
*
* 15 1/25/99 11:02a Samir
* revamped mouse and key controls.
*
* 14 11/18/98 5:50p Jeff
* free up force feedback before unloading DI
*
* 13 11/03/98 6:43p Jeff
* new low-level & high level Force Feedback system implemented, handles
* window losing focus, etc.
*
* 12 11/01/98 1:58a Jeff
* converted the vsprintf calls to use the Pvsprintf, which is a safe
* vsprintf, no buffer overflows allowed
*
* 11 10/18/98 6:18p Matt
* Turn the pointer on when shutting down. This fixes a problem where you
* couldn't click Ok on an error message box because the pointer was off
* for our app.
*
* 10 9/18/98 7:38p Jeff
* creation of low-level forcefeedback and beginning of high-level
* forcefeedback
*
* 9 9/15/98 12:25p Jeff
* If we are in NT, then only require DX3, else require DX6 (we may need
* to change this due to NT5)
*
* 8 9/15/98 12:05p Jeff
* initial creation of low-level forcefeedback
*
* 7 6/29/98 6:43p Samir
* Took out GetMsgProc and legacy keyboard variables.
*
* 6 5/08/98 12:54p Samir
* newer unused mouse handler.
*
* 5 3/31/98 12:46p Samir
* keyboard IO system better. uses getmsgproc windows hook.
*
* 4 10/23/97 2:58p Samir
* Took out extranneous messages.
*
* 3 10/16/97 2:29p Samir
* Changed DirectInput Keyboard to FOREGROUND
*
* 2 8/01/97 7:30p Samir
* Better NT keyboard support.
*
* 10 6/11/97 1:07p Samir
* The removal of gameos and replaced with oeApplication, oeDatabase
*
* 9 5/08/97 1:56p Samir
* These functions should only be applicable to windows (no shared code)
*
* 8 3/18/97 11:14a Samir
* Use real error call when DirectInput init fails.
*
* 7 2/28/97 11:03a Samir
* Changes to reflect newer gameos interface.
*
* 6 1/30/97 6:08p Samir
* Reflects changes in gameos.h
*
* 5 1/23/97 2:23p Samir
* Preemptive flag now just affects timer.
*
* $NoKeywords: $
*/
// ----------------------------------------------------------------------------
// Win32 IO System Main Library Interface
// ----------------------------------------------------------------------------
#include "DDAccess.h"
#include <stdlib.h>
#include <stdarg.h>
#include "pserror.h"
#include "pstring.h"
#include "Application.h"
#include "ddio_win.h"
#include "ddio.h"
#include "dinput.h"
#include "forcefeedback.h"
bool DDIO_init = 0;
dinput_data DInputData;
// ----------------------------------------------------------------------------
// Initialization and destruction functions
// ----------------------------------------------------------------------------
bool ddio_InternalInit(ddio_init_info *init_info) {
oeWin32Application *obj = (oeWin32Application *)init_info->obj;
LPDIRECTINPUT lpdi;
HRESULT dires;
ASSERT(!DDIO_init);
// Initialize DirectInput subsystem
mprintf((0, "DI system initializing.\n"));
// Try to open DirectX 5.00
dires = DirectInputCreate((HINSTANCE)obj->m_hInstance, DIRECTINPUT_VERSION, &lpdi, NULL);
// Deal with error opening DX5
if (dires != DI_OK) {
// If running NT, try DirectX 3.0
if (obj->NT()) {
dires = DirectInputCreate((HINSTANCE)obj->m_hInstance, 0x0300, &lpdi, NULL);
if (dires != DI_OK) {
Error("Unable to DirectInput system (Requires at least DirectX 3.0 For NT) [DirectInput:%x]\n", dires);
}
} else { // Not running NT, so error out
// Couldn't open DirectX, so print error
Error("Unable to DirectInput system (Requires at least DirectX 5.0) [DirectInput:%x]\n", dires);
}
}
DInputData.app = obj;
DInputData.lpdi = lpdi;
DInputData.hwnd = (HWND)obj->m_hWnd;
DDIO_init = 1;
return 1;
}
void ddio_InternalClose() {
ASSERT(DDIO_init);
// //Close down forcefeedback
// ddio_ff_DetachForce();
DInputData.lpdi->Release();
DInputData.lpdi = NULL;
DDIO_init = 0;
mprintf((0, "DI system closed.\n"));
}
#ifdef _DEBUG
void ddio_DebugMessage(unsigned err, char *fmt, ...) {
char buf[128];
va_list arglist;
va_start(arglist, fmt);
Pvsprintf(buf, 128, fmt, arglist);
va_end(arglist);
mprintf((0, "DDIO: %s\n", buf));
if (err) {
mprintf((1, "DIERR %x.\n", err));
}
}
#endif