2 * $Logfile: /Freespace2/code/OsApi/OsApi.cpp $
7 * Low level Windows code
10 * Revision 1.7 2002/06/05 04:03:32 relnev
11 * finished cfilesystem.
13 * removed some old code.
15 * fixed mouse save off-by-one.
19 * Revision 1.6 2002/05/31 03:34:02 theoddone33
23 * Revision 1.5 2002/05/30 23:46:29 theoddone33
24 * some minor key changes (not necessarily fixes)
26 * Revision 1.4 2002/05/30 16:50:24 theoddone33
27 * Keyboard partially fixed
29 * Revision 1.3 2002/05/29 06:25:13 theoddone33
30 * Keyboard input, mouse tracking now work
32 * Revision 1.2 2002/05/07 03:16:48 theoddone33
33 * The Great Newline Fix
35 * Revision 1.1.1.1 2002/05/03 03:28:10 root
39 * 7 6/30/99 5:53p Dave
40 * Put in new anti-camper code.
42 * 6 6/03/99 6:37p Dave
43 * More TNT fun. Made perspective bitmaps more flexible.
45 * 5 6/02/99 6:18p Dave
46 * Fixed TNT lockup problems! Wheeeee!
48 * 4 12/18/98 1:13a Dave
49 * Rough 1024x768 support for Direct3D. Proper detection and usage through
52 * 3 10/09/98 2:57p Dave
53 * Starting splitting up OS stuff.
55 * 2 10/08/98 2:38p Dave
56 * Cleanup up OsAPI code significantly. Removed old functions, centralized
59 * 118 7/10/98 5:04p Dave
60 * Fix connection speed bug on standalone server.
62 * 117 5/24/98 2:28p Hoffoss
63 * Because we never really care about if the left or the right shift or
64 * alt key was used, but rather than either shift or alt was used, made
65 * both map to the left one. Solves some problems, causes none.
67 * 116 5/18/98 9:22p John
68 * Took out the annoying tab check.
70 * 115 5/18/98 11:17a John
71 * Fixed some bugs with software window and output window.
73 * 114 5/16/98 2:20p John
74 * Changed the os_suspend and resume to use a critical section to prevent
75 * threads from executing rather than just suspending the thread. Had to
76 * make sure gr_close was called before os_close.
78 * 113 5/15/98 4:49p John
80 * 112 5/15/98 3:36p John
81 * Fixed bug with new graphics window code and standalone server. Made
82 * hwndApp not be a global anymore.
84 * 111 5/14/98 5:42p John
85 * Revamped the whole window position/mouse code for the graphics windows.
87 * 110 5/04/98 11:08p Hoffoss
88 * Expanded on Force Feedback code, and moved it all into Joy_ff.cpp.
89 * Updated references everywhere to it.
103 #include "freespaceresource.h"
104 #include "managepilot.h"
107 #include "gamesequence.h"
108 #include "freespace.h"
109 #include "osregistry.h"
112 // ----------------------------------------------------------------------------------------------------
113 // OSAPI DEFINES/VARS
117 static int fAppActive = 0;
118 static int main_window_inited = 0;
119 static char szWinTitle[128];
120 static char szWinClass[128];
121 static int WinX, WinY, WinW, WinH;
122 static int Os_inited = 0;
124 static CRITICAL_SECTION Os_lock;
126 int Os_debugger_running = 0;
128 // ----------------------------------------------------------------------------------------------------
129 // OSAPI FORWARD DECLARATIONS
133 // thread handler for the main message thread
134 DWORD win32_process(DWORD lparam);
136 DWORD win32_process1(DWORD lparam);
137 DWORD win32_process1(DWORD lparam);
140 // Fills in the Os_debugger_running with non-zero if debugger detected.
141 void os_check_debugger();
143 // called at shutdown. Makes sure all thread processing terminates.
147 // ----------------------------------------------------------------------------------------------------
151 // initialization/shutdown functions -----------------------------------------------
153 // If app_name is NULL or ommited, then TITLE is used
154 // for the app name, which is where registry keys are stored.
155 void os_init(char * wclass, char * title, char *app_name, char *version_string )
161 // check to see if we're running under msdev
167 // set the main window title
168 void os_set_title( char * title )
173 // call at program end
184 // window management -----------------------------------------------------------------
186 static int app_active = 1;
187 // Returns 1 if app is not the foreground app.
193 // Returns the handle to the main window
201 // process management -----------------------------------------------------------------
203 // Sleeps for n milliseconds or until app becomes active.
204 void os_sleep(int ms)
209 // Used to stop message processing
212 ENTER_CRITICAL_SECTION(&Os_lock);
215 // resume message processing
218 LEAVE_CRITICAL_SECTION(&Os_lock);
222 // ----------------------------------------------------------------------------------------------------
223 // OSAPI FORWARD DECLARATIONS
226 // Fills in the Os_debugger_running with non-zero if debugger detected.
227 void os_check_debugger()
231 // called at shutdown. Makes sure all thread processing terminates.
236 extern int SDLtoFS2[SDLK_LAST];
241 while (SDL_PollEvent (&e)) {
243 case SDL_MOUSEBUTTONDOWN:
244 if (e.button.button == SDL_BUTTON_LEFT)
245 mouse_mark_button (MOUSE_LEFT_BUTTON,1);
246 else if (e.button.button == SDL_BUTTON_RIGHT)
247 mouse_mark_button (MOUSE_RIGHT_BUTTON,1);
248 else if (e.button.button == SDL_BUTTON_MIDDLE)
249 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 1);
251 case SDL_MOUSEBUTTONUP:
252 if (e.button.button == SDL_BUTTON_LEFT)
253 mouse_mark_button (MOUSE_LEFT_BUTTON,0);
254 else if (e.button.button == SDL_BUTTON_RIGHT)
255 mouse_mark_button (MOUSE_RIGHT_BUTTON,0);
256 else if (e.button.button == SDL_BUTTON_MIDDLE)
257 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 0);
260 if (SDLtoFS2[e.key.keysym.sym])
261 key_mark (SDLtoFS2[e.key.keysym.sym], 1, 0);
264 if (SDLtoFS2[e.key.keysym.sym])
265 key_mark (SDLtoFS2[e.key.keysym.sym], 0, 0);