2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/OsApi/OsApi.cpp $
15 * Low level Windows code
18 * Revision 1.9 2002/06/16 23:59:31 relnev
19 * untested joystick code
21 * Revision 1.8 2002/06/09 04:41:25 relnev
22 * added copyright header
24 * Revision 1.7 2002/06/05 04:03:32 relnev
25 * finished cfilesystem.
27 * removed some old code.
29 * fixed mouse save off-by-one.
33 * Revision 1.6 2002/05/31 03:34:02 theoddone33
37 * Revision 1.5 2002/05/30 23:46:29 theoddone33
38 * some minor key changes (not necessarily fixes)
40 * Revision 1.4 2002/05/30 16:50:24 theoddone33
41 * Keyboard partially fixed
43 * Revision 1.3 2002/05/29 06:25:13 theoddone33
44 * Keyboard input, mouse tracking now work
46 * Revision 1.2 2002/05/07 03:16:48 theoddone33
47 * The Great Newline Fix
49 * Revision 1.1.1.1 2002/05/03 03:28:10 root
53 * 7 6/30/99 5:53p Dave
54 * Put in new anti-camper code.
56 * 6 6/03/99 6:37p Dave
57 * More TNT fun. Made perspective bitmaps more flexible.
59 * 5 6/02/99 6:18p Dave
60 * Fixed TNT lockup problems! Wheeeee!
62 * 4 12/18/98 1:13a Dave
63 * Rough 1024x768 support for Direct3D. Proper detection and usage through
66 * 3 10/09/98 2:57p Dave
67 * Starting splitting up OS stuff.
69 * 2 10/08/98 2:38p Dave
70 * Cleanup up OsAPI code significantly. Removed old functions, centralized
73 * 118 7/10/98 5:04p Dave
74 * Fix connection speed bug on standalone server.
76 * 117 5/24/98 2:28p Hoffoss
77 * Because we never really care about if the left or the right shift or
78 * alt key was used, but rather than either shift or alt was used, made
79 * both map to the left one. Solves some problems, causes none.
81 * 116 5/18/98 9:22p John
82 * Took out the annoying tab check.
84 * 115 5/18/98 11:17a John
85 * Fixed some bugs with software window and output window.
87 * 114 5/16/98 2:20p John
88 * Changed the os_suspend and resume to use a critical section to prevent
89 * threads from executing rather than just suspending the thread. Had to
90 * make sure gr_close was called before os_close.
92 * 113 5/15/98 4:49p John
94 * 112 5/15/98 3:36p John
95 * Fixed bug with new graphics window code and standalone server. Made
96 * hwndApp not be a global anymore.
98 * 111 5/14/98 5:42p John
99 * Revamped the whole window position/mouse code for the graphics windows.
101 * 110 5/04/98 11:08p Hoffoss
102 * Expanded on Force Feedback code, and moved it all into Joy_ff.cpp.
103 * Updated references everywhere to it.
117 #include "freespaceresource.h"
118 #include "managepilot.h"
121 #include "gamesequence.h"
122 #include "freespace.h"
123 #include "osregistry.h"
126 // ----------------------------------------------------------------------------------------------------
127 // OSAPI DEFINES/VARS
131 static int fAppActive = 0;
132 static int main_window_inited = 0;
133 static char szWinTitle[128];
134 static char szWinClass[128];
135 static int WinX, WinY, WinW, WinH;
136 static int Os_inited = 0;
138 static CRITICAL_SECTION Os_lock;
140 int Os_debugger_running = 0;
142 // ----------------------------------------------------------------------------------------------------
143 // OSAPI FORWARD DECLARATIONS
147 // thread handler for the main message thread
148 DWORD win32_process(DWORD lparam);
150 DWORD win32_process1(DWORD lparam);
151 DWORD win32_process1(DWORD lparam);
154 // Fills in the Os_debugger_running with non-zero if debugger detected.
155 void os_check_debugger();
157 // called at shutdown. Makes sure all thread processing terminates.
161 // ----------------------------------------------------------------------------------------------------
165 // initialization/shutdown functions -----------------------------------------------
167 // If app_name is NULL or ommited, then TITLE is used
168 // for the app name, which is where registry keys are stored.
169 void os_init(char * wclass, char * title, char *app_name, char *version_string )
175 // check to see if we're running under msdev
181 // set the main window title
182 void os_set_title( char * title )
187 // call at program end
198 // window management -----------------------------------------------------------------
200 static int app_active = 1;
201 // Returns 1 if app is not the foreground app.
207 // Returns the handle to the main window
215 // process management -----------------------------------------------------------------
217 // Sleeps for n milliseconds or until app becomes active.
218 void os_sleep(int ms)
223 // Used to stop message processing
226 ENTER_CRITICAL_SECTION(&Os_lock);
229 // resume message processing
232 LEAVE_CRITICAL_SECTION(&Os_lock);
236 // ----------------------------------------------------------------------------------------------------
237 // OSAPI FORWARD DECLARATIONS
240 // Fills in the Os_debugger_running with non-zero if debugger detected.
241 void os_check_debugger()
245 // called at shutdown. Makes sure all thread processing terminates.
250 extern int SDLtoFS2[SDLK_LAST];
255 while (SDL_PollEvent (&e)) {
257 case SDL_MOUSEBUTTONDOWN:
258 if (e.button.button == SDL_BUTTON_LEFT)
259 mouse_mark_button (MOUSE_LEFT_BUTTON,1);
260 else if (e.button.button == SDL_BUTTON_RIGHT)
261 mouse_mark_button (MOUSE_RIGHT_BUTTON,1);
262 else if (e.button.button == SDL_BUTTON_MIDDLE)
263 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 1);
265 case SDL_MOUSEBUTTONUP:
266 if (e.button.button == SDL_BUTTON_LEFT)
267 mouse_mark_button (MOUSE_LEFT_BUTTON,0);
268 else if (e.button.button == SDL_BUTTON_RIGHT)
269 mouse_mark_button (MOUSE_RIGHT_BUTTON,0);
270 else if (e.button.button == SDL_BUTTON_MIDDLE)
271 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 0);
274 if (SDLtoFS2[e.key.keysym.sym])
275 key_mark (SDLtoFS2[e.key.keysym.sym], 1, 0);
278 if (SDLtoFS2[e.key.keysym.sym])
279 key_mark (SDLtoFS2[e.key.keysym.sym], 0, 0);
287 extern int joy_pollrate;
288 extern void joy_process(int time_delta);
290 static Uint32 lasttic = 0;
291 Uint32 curtic = SDL_GetTicks();
292 Uint32 delta = curtic - lasttic;
294 while (delta >= joy_pollrate) {
297 lasttic += joy_pollrate;
299 delta = curtic - lasttic;