2 * $Logfile: /Freespace2/code/OsApi/OsApi.cpp $
7 * Low level Windows code
10 * Revision 1.4 2002/05/30 16:50:24 theoddone33
11 * Keyboard partially fixed
13 * Revision 1.3 2002/05/29 06:25:13 theoddone33
14 * Keyboard input, mouse tracking now work
16 * Revision 1.2 2002/05/07 03:16:48 theoddone33
17 * The Great Newline Fix
19 * Revision 1.1.1.1 2002/05/03 03:28:10 root
23 * 7 6/30/99 5:53p Dave
24 * Put in new anti-camper code.
26 * 6 6/03/99 6:37p Dave
27 * More TNT fun. Made perspective bitmaps more flexible.
29 * 5 6/02/99 6:18p Dave
30 * Fixed TNT lockup problems! Wheeeee!
32 * 4 12/18/98 1:13a Dave
33 * Rough 1024x768 support for Direct3D. Proper detection and usage through
36 * 3 10/09/98 2:57p Dave
37 * Starting splitting up OS stuff.
39 * 2 10/08/98 2:38p Dave
40 * Cleanup up OsAPI code significantly. Removed old functions, centralized
43 * 118 7/10/98 5:04p Dave
44 * Fix connection speed bug on standalone server.
46 * 117 5/24/98 2:28p Hoffoss
47 * Because we never really care about if the left or the right shift or
48 * alt key was used, but rather than either shift or alt was used, made
49 * both map to the left one. Solves some problems, causes none.
51 * 116 5/18/98 9:22p John
52 * Took out the annoying tab check.
54 * 115 5/18/98 11:17a John
55 * Fixed some bugs with software window and output window.
57 * 114 5/16/98 2:20p John
58 * Changed the os_suspend and resume to use a critical section to prevent
59 * threads from executing rather than just suspending the thread. Had to
60 * make sure gr_close was called before os_close.
62 * 113 5/15/98 4:49p John
64 * 112 5/15/98 3:36p John
65 * Fixed bug with new graphics window code and standalone server. Made
66 * hwndApp not be a global anymore.
68 * 111 5/14/98 5:42p John
69 * Revamped the whole window position/mouse code for the graphics windows.
71 * 110 5/04/98 11:08p Hoffoss
72 * Expanded on Force Feedback code, and moved it all into Joy_ff.cpp.
73 * Updated references everywhere to it.
87 #include "freespaceresource.h"
88 #include "managepilot.h"
91 #include "gamesequence.h"
92 #include "freespace.h"
93 #include "osregistry.h"
96 // ----------------------------------------------------------------------------------------------------
101 static int fAppActive = 0;
102 static int main_window_inited = 0;
103 static char szWinTitle[128];
104 static char szWinClass[128];
105 static int WinX, WinY, WinW, WinH;
106 static int Os_inited = 0;
108 static CRITICAL_SECTION Os_lock;
110 int Os_debugger_running = 0;
112 // ----------------------------------------------------------------------------------------------------
113 // OSAPI FORWARD DECLARATIONS
117 // thread handler for the main message thread
118 DWORD win32_process(DWORD lparam);
120 DWORD win32_process1(DWORD lparam);
121 DWORD win32_process1(DWORD lparam);
124 // Fills in the Os_debugger_running with non-zero if debugger detected.
125 void os_check_debugger();
127 // called at shutdown. Makes sure all thread processing terminates.
131 // ----------------------------------------------------------------------------------------------------
135 // initialization/shutdown functions -----------------------------------------------
137 // If app_name is NULL or ommited, then TITLE is used
138 // for the app name, which is where registry keys are stored.
139 void os_init(char * wclass, char * title, char *app_name, char *version_string )
145 // check to see if we're running under msdev
151 // set the main window title
152 void os_set_title( char * title )
157 // call at program end
168 // window management -----------------------------------------------------------------
170 // Returns 1 if app is not the foreground app.
177 // Returns the handle to the main window
185 // process management -----------------------------------------------------------------
187 // Sleeps for n milliseconds or until app becomes active.
188 void os_sleep(int ms)
193 // Used to stop message processing
196 ENTER_CRITICAL_SECTION(&Os_lock);
199 // resume message processing
202 LEAVE_CRITICAL_SECTION(&Os_lock);
206 // ----------------------------------------------------------------------------------------------------
207 // OSAPI FORWARD DECLARATIONS
210 // Fills in the Os_debugger_running with non-zero if debugger detected.
211 void os_check_debugger()
215 // called at shutdown. Makes sure all thread processing terminates.
224 while (SDL_PollEvent (&e)) {
226 case SDL_MOUSEBUTTONDOWN:
227 if (e.button.button == SDL_BUTTON_LEFT)
228 mouse_mark_button (MOUSE_LEFT_BUTTON,1);
229 else if (e.button.button == SDL_BUTTON_RIGHT)
230 mouse_mark_button (MOUSE_RIGHT_BUTTON,1);
231 else if (e.button.button == SDL_BUTTON_MIDDLE)
232 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 1);
234 case SDL_MOUSEBUTTONUP:
235 if (e.button.button == SDL_BUTTON_LEFT)
236 mouse_mark_button (MOUSE_LEFT_BUTTON,0);
237 else if (e.button.button == SDL_BUTTON_RIGHT)
238 mouse_mark_button (MOUSE_RIGHT_BUTTON,0);
239 else if (e.button.button == SDL_BUTTON_MIDDLE)
240 mouse_mark_button (MOUSE_MIDDLE_BUTTON, 0);
243 key_mark ((e.key.keysym.mod<<16) | e.key.keysym.sym, 1, 0);
246 key_mark ((e.key.keysym.mod<<16) | e.key.keysym.sym, 0, 0);