Debian Codegraph @

ddio/ddio.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/ddio_common/ddio.cpp $
21 * $Revision: 18 $
22 * $Date: 10/21/99 9:27p $
23 * $Author: Jeff $
24 *
25 * Common DDIO Initialization
26 *
27 * $Log: /DescentIII/Main/ddio_common/ddio.cpp $
28 *
29 * 18 10/21/99 9:27p Jeff
30 * B.A. Macintosh code merge
31 *
32 * 17 8/11/99 3:09p Samir
33 * win32 as well calls ddioInternalJoyFrame.
34 *
35 * 16 7/28/99 5:18p Kevin
36 * Mac merge fixes
37 *
38 * 15 7/28/99 3:33p Kevin
39 * Mac!
40 *
41 * 14 4/22/99 1:56a Jeff
42 * pass in ddio_init_info to keyboard handlers
43 *
44 * 13 4/09/99 12:02p Samir
45 * joystick changes (Win32 DirectInput support)
46 *
47 * 12 2/21/99 6:38p Samir
48 * mouse and key input better. buffered mouse.
49 *
50 * 11 1/25/99 6:47p Samir
51 * allow slow keyboard
52 *
53 * 10 10/20/98 12:58a Jeff
54 * added a way to force a lo-resolution timer
55 *
56 * 9 10/16/98 1:03p Samir
57 * fixed timer issue when closing ddio, should not close timer.
58 *
59 * 8 6/30/98 4:20p Samir
60 * added ddio_Close as standalone. ddio_Init will no longer close
61 * itself.
62 *
63 * 7 6/29/98 6:46p Samir
64 * MouseInit no longer takes in required number of mouse buttons.
65 *
66 * 6 12/09/97 2:08p Samir
67 * Non preemptive keyboard as of now?
68 *
69 * 5 10/23/97 2:58p Samir
70 * Took out extranneous messages.
71 *
72 * 4 10/17/97 5:18p Samir
73 * ddio_Init now does mouse opening and closing, where it should be.
74 *
75 * 3 10/17/97 5:03p Samir
76 * Default to preemptive keyboard handler (not under NT).
77 *
78 * 2 10/16/97 2:28p Samir
79 * move keyboard init into ddio_init and added preemptive select for
80 * keyboard.
81 *
82 * 2 5/12/97 1:21p Samir
83 * Commented out timer hook function calls.
84 *
85 * 1 5/08/97 1:54p Samir
86 * Created skeletal initialization functions.
87 *
88 * $NoKeywords: $
89 */
90 #include "ddio.h"
91 #include "joystick.h"
92 #include "pserror.h"
93 #include <stdlib.h>
94 static bool DDIO_initialized = false;
95 // ----------------------------------------------------------------------------
96 // Common initialization
97 // ----------------------------------------------------------------------------
98 // Initializes DDIO system
99 bool ddio_Init(ddio_init_info *init_info) {
100 static bool first_time = true;
101 bool res;
102 ASSERT(!DDIO_initialized);
103 if (first_time) {
104 atexit(ddio_Close);
105 }
106 mprintf(0, "DDIO system initializing...\n");
107 res = ddio_InternalInit(init_info);
108 if (res) {
109 if (first_time) { // initialize once and only once.
110 timer_Init();
111 }
112 if (!ddio_KeyInit(init_info))
113 Error("Failed to initialize keyboard system.");
114 ddio_MouseInit();
115 }
116 first_time = false;
117 DDIO_initialized = true;
118 joy_Init(init_info->joy_emulation);
119 return res;
120 }
121 void ddio_Close() {
122 if (DDIO_initialized) {
123 joy_Close();
124 ddio_MouseClose();
125 ddio_KeyClose();
126 ddio_InternalClose();
127 mprintf(0, "DDIO system closed.\n");
128 DDIO_initialized = false;
129 }
130 }
131 void ddio_Suspend() {
132 ddio_InternalKeySuspend();
133 ddio_InternalMouseSuspend();
134 }
135 void ddio_Resume() {
136 ddio_InternalKeyResume();
137 ddio_InternalMouseResume();
138 }
139 // handles buffered input from devices once per frame.
140 void ddio_Frame() {
141 ddio_InternalKeyFrame();
142 ddio_InternalMouseFrame();
143 ddio_InternalJoyFrame();
144 }