Debian Codegraph @

linux/lnxapp.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/linux/lnxapp.cpp $
21 * $Revision: 1.3 $
22 * $Date: 2004/02/25 00:04:06 $
23 * $Author: ryan $
24 *
25 * Linux application routines
26 *
27 * $Log: lnxapp.cpp,v $
28 * Revision 1.3 2004/02/25 00:04:06 ryan
29 * Removed loki_utils dependency and ported to MacOS X (runs, but incomplete).
30 *
31 * Revision 1.2 2000/04/28 20:18:27 icculus
32 * Replaced X stuff with SDL stuff.
33 *
34 * Revision 1.1.1.1 2000/04/18 00:00:39 icculus
35 * initial checkin
36 *
37 *
38 * 25 10/19/99 8:35p Jeff
39 * added a couple functions for Window OpenGL
40 *
41 * 24 10/17/99 3:55p Jeff
42 *
43 * 23 10/15/99 12:14p Jeff
44 * dyna load pthread library
45 *
46 * 22 9/24/99 8:26p Jeff
47 * better cleanup (including restoring the mouse) in case of a crash or
48 * error exit
49 *
50 * 21 9/09/99 4:35p Jeff
51 * dynamically load the Outrage Xlib extension library (for DGA). Init
52 * DGA if needed for Mouse control
53 *
54 * 20 9/07/99 4:37p Jeff
55 *
56 * 19 9/06/99 9:22p Jeff
57 * set initial window position to 0,0
58 *
59 * 18 9/05/99 9:44p Jeff
60 * handle window option flag
61 *
62 * 17 7/15/99 11:37a Jeff
63 * turn on/off autorepeat
64 *
65 * 16 7/14/99 9:09p Jeff
66 * added comment header
67 *
68 * $NoKeywords: $
69 */
70
71 #include <cstdlib>
72 #include <cctype>
73 #if defined(POSIXcxx . . $ `<built-in>:477:9`!)
74 #include <sys/time.h>
75 #include <termios.h>
76 #else
77 #include "winsock.h"
78 #endif
79
80 #include "application.h"cxx . . $ `<file>/lib/application.h`/
81 #include "lnxapp.h"cxx . . $ `<file>/linux/lnxapp.h`/
82
83 #ifdef buttons // termios.h defines buttons, but SDL's headers use that symbol.
84 #undef buttons
85 #endif
86
87 #if defined(POSIXcxx . . $ `<built-in>:477:9`!)
88 static struct termios Linux_initial_terminal_settingscxx . . $ Linux_initial_terminal_settings.;
89 #endif
90
91 bool oeLnxApplicationcxx . . $ oeLnxApplication#::os_initializedcxx . . $ oeLnxApplication#os_initialized. = false;
92 bool oeLnxApplicationcxx . . $ oeLnxApplication#::first_timecxx . . $ oeLnxApplication#first_time. = true;
93
94 bool con_Createcxx . . $ con_Create(83c267b20bac841a).(int flags);
95 void con_Destroycxx . . $ con_Destroy(49f6e7a06ebc5aa8).();
96 void con_Defercxx . . $ con_Defer(49f6e7a06ebc5aa8).();
97
98 void Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(int millis) {
99 struct timeval tv{};
100 tv.tv_sec = 0;
101 tv.tv_usec = millis * 1000;
102 select(0, nullptr, nullptr, nullptr, &tv);
103 }
104
105 char *struprcxx . . $ strupr(7a9722d75b371431).(char *string) {
106 while (string && *string) {
107 *string = toupper(*string);
108 string++;
109 }
110 return string;
111 }
112
113 static uint32_tcxx . . $ uint32_t# LinuxAppFlagscxx . . $ LinuxAppFlags. = 0;
114 // static Display *LinuxAppDisplay=NULL;
115 static bool LinuxAppSetAtExitcxx . . $ LinuxAppSetAtExit. = false;
116 static bool LinuxAppDontCallShutdowncxx . . $ LinuxAppDontCallShutdown. = false;
117
118 void LnxAppShutdowncxx . . $ LnxAppShutdown(49f6e7a06ebc5aa8).() {
119 if (LinuxAppDontCallShutdowncxx . . $ LinuxAppDontCallShutdown.)
120 return;
121 LinuxAppDontCallShutdowncxx . . $ LinuxAppDontCallShutdown. = true;
122 if (LinuxAppFlagscxx . . $ LinuxAppFlags. & OEAPP_CONSOLEcxx . . $ OEAPP_CONSOLE.) {
123 con_Destroycxx . . $ con_Destroy(49f6e7a06ebc5aa8).();
124 #if defined(POSIXcxx . . $ `<built-in>:477:9`!)
125 tcsetattr(0, TCSANOWcxx . . $ `<external>/7740429199341890421/termios-tcflow.h:24:9`!, &Linux_initial_terminal_settingscxx . . $ Linux_initial_terminal_settings.);
126 #endif
127 }
128 }
129
130 // Creates the application object
131 oeLnxApplicationcxx . . $ oeLnxApplication#::oeLnxApplicationcxx . . $ oeLnxApplication#oeLnxApplication(cb2f890c2fdad230).(unsigned flags) {
132 m_Flagscxx . . $ oeLnxApplication#m_Flags. = flags;
133 m_AppActivecxx . . $ oeApplication#m_AppActive. = true;
134
135 if (flags & OEAPP_CONSOLEcxx . . $ OEAPP_CONSOLE.) {
136 #if defined(POSIXcxx . . $ `<built-in>:477:9`!)
137 tcgetattr(0, &Linux_initial_terminal_settingscxx . . $ Linux_initial_terminal_settings.);
138 #endif
139 con_Createcxx . . $ con_Create(83c267b20bac841a).(m_Flagscxx . . $ oeLnxApplication#m_Flags.);
140 }
141
142 LinuxAppFlagscxx . . $ LinuxAppFlags. = m_Flagscxx . . $ oeLnxApplication#m_Flags.;
143
144 if (!LinuxAppSetAtExitcxx . . $ LinuxAppSetAtExit.) {
145 LinuxAppSetAtExitcxx . . $ LinuxAppSetAtExit. = true;
146 atexit(LnxAppShutdowncxx . . $ LnxAppShutdown(49f6e7a06ebc5aa8).);
147 }
148 }
149
150 // Create object with a premade info
151 oeLnxApplicationcxx . . $ oeLnxApplication#::oeLnxApplicationcxx . . $ oeLnxApplication#oeLnxApplication(7c10a581adce9eb2).(tLnxAppInfocxx . . $ tLnxAppInfo# *appinfo) {
152 #if defined(POSIXcxx . . $ `<built-in>:477:9`!)
153 tcgetattr(0, &Linux_initial_terminal_settingscxx . . $ Linux_initial_terminal_settings.);
154 #endif
155 m_Flagscxx . . $ oeLnxApplication#m_Flags. = appinfo->flagscxx . . $ tLnxAppInfo#flags.;
156 m_Xcxx . . $ oeLnxApplication#m_X. = appinfo->wnd_xcxx . . $ tLnxAppInfo#wnd_x.;
157 m_Ycxx . . $ oeLnxApplication#m_Y. = appinfo->wnd_ycxx . . $ tLnxAppInfo#wnd_y.;
158 m_Wcxx . . $ oeLnxApplication#m_W. = appinfo->wnd_wcxx . . $ tLnxAppInfo#wnd_w.;
159 m_Hcxx . . $ oeLnxApplication#m_H. = appinfo->wnd_hcxx . . $ tLnxAppInfo#wnd_h.;
160 m_AppActivecxx . . $ oeApplication#m_AppActive. = true;
161
162 if (m_Flagscxx . . $ oeLnxApplication#m_Flags. & OEAPP_CONSOLEcxx . . $ OEAPP_CONSOLE.) {
163 con_Createcxx . . $ con_Create(83c267b20bac841a).(m_Flagscxx . . $ oeLnxApplication#m_Flags.);
164 }
165
166 LinuxAppFlagscxx . . $ LinuxAppFlags. = m_Flagscxx . . $ oeLnxApplication#m_Flags.;
167
168 if (!LinuxAppSetAtExitcxx . . $ LinuxAppSetAtExit.) {
169 LinuxAppSetAtExitcxx . . $ LinuxAppSetAtExit. = true;
170 atexit(LnxAppShutdowncxx . . $ LnxAppShutdown(49f6e7a06ebc5aa8).);
171 }
172 }
173
174 // Destructor
175 oeLnxApplicationcxx . . $ oeLnxApplication#::~cxx . . $ oeLnxApplication#`~oeLnxApplication`(ced63f7c635d850d).oeLnxApplicationcxx . . $ oeLnxApplication#() { LnxAppShutdowncxx . . $ LnxAppShutdown(49f6e7a06ebc5aa8).(); }
176
177 // initializes the object
178 void oeLnxApplicationcxx . . $ oeLnxApplication#::initcxx . . $ oeLnxApplication#init(49f6e7a06ebc5aa8).() {
179 if (m_WasCreatedcxx . . $ oeLnxApplication#m_WasCreated.) {
180 // Create graphics window and prepare for graphics!
181 }
182 }
183
184 // Function to retrieve information from object through a platform defined structure.
185 void oeLnxApplicationcxx . . $ oeLnxApplication#::get_infocxx . . $ oeLnxApplication#get_info(5d22bdacc48458e8).(void *info) {
186 tLnxAppInfocxx . . $ tLnxAppInfo# *appinfo = (tLnxAppInfocxx . . $ tLnxAppInfo# *)info;
187 appinfo->flagscxx . . $ tLnxAppInfo#flags. = m_Flagscxx . . $ oeLnxApplication#m_Flags.;
188 appinfo->wnd_xcxx . . $ tLnxAppInfo#wnd_x. = m_Xcxx . . $ oeLnxApplication#m_X.;
189 appinfo->wnd_ycxx . . $ tLnxAppInfo#wnd_y. = m_Ycxx . . $ oeLnxApplication#m_Y.;
190 appinfo->wnd_wcxx . . $ tLnxAppInfo#wnd_w. = m_Wcxx . . $ oeLnxApplication#m_W.;
191 appinfo->wnd_hcxx . . $ tLnxAppInfo#wnd_h. = m_Hcxx . . $ oeLnxApplication#m_H.;
192 }
193
194 // defer returns some flags. essentially this function defers program control to OS.
195 unsigned oeLnxApplicationcxx . . $ oeLnxApplication#::defercxx . . $ oeLnxApplication#defer(db52760e79bf9054).() {
196 bool res = 0;
197
198 if (m_DeferFunccxx . . $ oeLnxApplication#m_DeferFunc.) {
199 res = 1;
200 (*m_DeferFunccxx . . $ oeLnxApplication#m_DeferFunc.)(true);
201 }
202
203 con_Defercxx . . $ con_Defer(49f6e7a06ebc5aa8).();
204
205 return res;
206 }
207
208 // set a function to run when deferring to OS.
209 void oeLnxApplicationcxx . . $ oeLnxApplication#::set_defer_handlercxx . . $ oeLnxApplication#set_defer_handler(ea22beb3ee77eebe).(void (*func)(bool)) { m_DeferFunccxx . . $ oeLnxApplication#m_DeferFunc. = func; }
210
211 // delays app for a certain amount of time
212 void oeLnxApplicationcxx . . $ oeLnxApplication#::delaycxx . . $ oeLnxApplication#delay(9364e6e7bff7660).(float secs) {
213 int msecs = (int)(secs * 1000.0f);
214 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(msecs);
215 }
216
217 // Function to get the flags
218 int oeLnxApplicationcxx . . $ oeLnxApplication#::flagscxx . . $ oeLnxApplication#flags(455f465bc33b4cdf).() const { return m_Flagscxx . . $ oeLnxApplication#m_Flags.; }
219
220 // Sizes the displayable region of the app (the window)
221 void oeLnxApplicationcxx . . $ oeLnxApplication#::set_sizeposcxx . . $ oeLnxApplication#set_sizepos(748afa4755bc9595).(int x, int y, int w, int h) {
222 m_Xcxx . . $ oeLnxApplication#m_X. = x;
223 m_Ycxx . . $ oeLnxApplication#m_Y. = y;
224 m_Wcxx . . $ oeLnxApplication#m_W. = w;
225 m_Hcxx . . $ oeLnxApplication#m_H. = h;
226 }
227
228 const char *oeLnxApplicationcxx . . $ oeLnxApplication#::get_window_namecxx . . $ oeLnxApplication#get_window_name(33a1f659e94feb42).(void) { return "Descent 3"; }
229
230 void oeLnxApplicationcxx . . $ oeLnxApplication#::clear_windowcxx . . $ oeLnxApplication#clear_window(49f6e7a06ebc5aa8).(void) {
231 }
232
233 // initializes OS components.
234 void oeLnxApplicationcxx . . $ oeLnxApplication#::os_initcxx . . $ oeLnxApplication#os_init(49f6e7a06ebc5aa8).() {
235 /* We only need to do this once */
236 if (!os_initializedcxx . . $ oeLnxApplication#os_initialized.) {
237 os_initializedcxx . . $ oeLnxApplication#os_initialized. = true;
238 }
239 }