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.8 2002/06/09 04:41:25 relnev
19 * added copyright header
21 * Revision 1.7 2002/06/05 04:03:32 relnev
22 * finished cfilesystem.
24 * removed some old code.
26 * fixed mouse save off-by-one.
30 * Revision 1.6 2002/05/31 03:34:02 theoddone33
34 * Revision 1.5 2002/05/30 23:46:29 theoddone33
35 * some minor key changes (not necessarily fixes)
37 * Revision 1.4 2002/05/30 16:50:24 theoddone33
38 * Keyboard partially fixed
40 * Revision 1.3 2002/05/29 06:25:13 theoddone33
41 * Keyboard input, mouse tracking now work
43 * Revision 1.2 2002/05/07 03:16:48 theoddone33
44 * The Great Newline Fix
46 * Revision 1.1.1.1 2002/05/03 03:28:10 root
50 * 7 6/30/99 5:53p Dave
51 * Put in new anti-camper code.
53 * 6 6/03/99 6:37p Dave
54 * More TNT fun. Made perspective bitmaps more flexible.
56 * 5 6/02/99 6:18p Dave
57 * Fixed TNT lockup problems! Wheeeee!
59 * 4 12/18/98 1:13a Dave
60 * Rough 1024x768 support for Direct3D. Proper detection and usage through
63 * 3 10/09/98 2:57p Dave
64 * Starting splitting up OS stuff.
66 * 2 10/08/98 2:38p Dave
67 * Cleanup up OsAPI code significantly. Removed old functions, centralized
70 * 118 7/10/98 5:04p Dave
71 * Fix connection speed bug on standalone server.
73 * 117 5/24/98 2:28p Hoffoss
74 * Because we never really care about if the left or the right shift or
75 * alt key was used, but rather than either shift or alt was used, made
76 * both map to the left one. Solves some problems, causes none.
78 * 116 5/18/98 9:22p John
79 * Took out the annoying tab check.
81 * 115 5/18/98 11:17a John
82 * Fixed some bugs with software window and output window.
84 * 114 5/16/98 2:20p John
85 * Changed the os_suspend and resume to use a critical section to prevent
86 * threads from executing rather than just suspending the thread. Had to
87 * make sure gr_close was called before os_close.
89 * 113 5/15/98 4:49p John
91 * 112 5/15/98 3:36p John
92 * Fixed bug with new graphics window code and standalone server. Made
93 * hwndApp not be a global anymore.
95 * 111 5/14/98 5:42p John
96 * Revamped the whole window position/mouse code for the graphics windows.
98 * 110 5/04/98 11:08p Hoffoss
99 * Expanded on Force Feedback code, and moved it all into Joy_ff.cpp.
100 * Updated references everywhere to it.
114 #include "freespaceresource.h"
115 #include "managepilot.h"
118 #include "gamesequence.h"
119 #include "freespace.h"
120 #include "osregistry.h"
123 // ----------------------------------------------------------------------------------------------------
124 // OSAPI DEFINES/VARS
128 static int fAppActive = 0;
129 static int main_window_inited = 0;
130 static char szWinTitle[128];
131 static char szWinClass[128];
132 static int WinX, WinY, WinW, WinH;
133 static int Os_inited = 0;
135 static CRITICAL_SECTION Os_lock;
137 int Os_debugger_running = 0;
139 // ----------------------------------------------------------------------------------------------------
140 // OSAPI FORWARD DECLARATIONS
144 // thread handler for the main message thread
145 DWORD win32_process(DWORD lparam);
147 DWORD win32_process1(DWORD lparam);
148 DWORD win32_process1(DWORD lparam);
151 // Fills in the Os_debugger_running with non-zero if debugger detected.
152 void os_check_debugger();
154 // called at shutdown. Makes sure all thread processing terminates.
158 // ----------------------------------------------------------------------------------------------------
162 // initialization/shutdown functions -----------------------------------------------
164 // If app_name is NULL or ommited, then TITLE is used
165 // for the app name, which is where registry keys are stored.
166 void os_init(char * wclass, char * title, char *app_name, char *version_string )
172 // check to see if we're running under msdev
178 // set the main window title
179 void os_set_title( char * title )
184 // call at program end
195 // window management -----------------------------------------------------------------
197 static int app_active = 1;
198 // Returns 1 if app is not the foreground app.
204 // Returns the handle to the main window
212 // process management -----------------------------------------------------------------
214 // Sleeps for n milliseconds or until app becomes active.
215 void os_sleep(int ms)
220 // Used to stop message processing
223 ENTER_CRITICAL_SECTION(&Os_lock);
226 // resume message processing
229 LEAVE_CRITICAL_SECTION(&Os_lock);
233 // ----------------------------------------------------------------------------------------------------
234 // OSAPI FORWARD DECLARATIONS
237 // Fills in the Os_debugger_running with non-zero if debugger detected.
238 void os_check_debugger()
242 // called at shutdown. Makes sure all thread processing terminates.
247 extern int SDLtoFS2[SDLK_LAST];
252 while (SDL_PollEvent (&e)) {
254 case SDL_MOUSEBUTTONDOWN:
255 if (e.button.button == SDL_BUTTON_LEFT)
256 mouse_mark_button (MOUSE_LEFT_BUTTON,1);
257 else if (e.button.button == SDL_BUTTON_RIGHT)
258 mouse_mark_button (MOUSE_RIGHT_BUTTON,1);
259 else if (e.button.button == SDL_BUTTON_MIDDLE)
260 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 1);
262 case SDL_MOUSEBUTTONUP:
263 if (e.button.button == SDL_BUTTON_LEFT)
264 mouse_mark_button (MOUSE_LEFT_BUTTON,0);
265 else if (e.button.button == SDL_BUTTON_RIGHT)
266 mouse_mark_button (MOUSE_RIGHT_BUTTON,0);
267 else if (e.button.button == SDL_BUTTON_MIDDLE)
268 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 0);
271 if (SDLtoFS2[e.key.keysym.sym])
272 key_mark (SDLtoFS2[e.key.keysym.sym], 1, 0);
275 if (SDLtoFS2[e.key.keysym.sym])
276 key_mark (SDLtoFS2[e.key.keysym.sym], 0, 0);