]> icculus.org git repositories - taylor/freespace2.git/blob - src/osapi/os_unix.cpp
Fix Keyboard
[taylor/freespace2.git] / src / osapi / os_unix.cpp
1 /*
2  * $Logfile: /Freespace2/code/OsApi/OsApi.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Low level Windows code
8  *
9  * $Log$
10  * Revision 1.6  2002/05/31 03:34:02  theoddone33
11  * Fix Keyboard
12  * Add titlebar
13  *
14  * Revision 1.5  2002/05/30 23:46:29  theoddone33
15  * some minor key changes (not necessarily fixes)
16  *
17  * Revision 1.4  2002/05/30 16:50:24  theoddone33
18  * Keyboard partially fixed
19  *
20  * Revision 1.3  2002/05/29 06:25:13  theoddone33
21  * Keyboard input, mouse tracking now work
22  *
23  * Revision 1.2  2002/05/07 03:16:48  theoddone33
24  * The Great Newline Fix
25  *
26  * Revision 1.1.1.1  2002/05/03 03:28:10  root
27  * Initial import.
28  * 
29  * 
30  * 7     6/30/99 5:53p Dave
31  * Put in new anti-camper code.
32  * 
33  * 6     6/03/99 6:37p Dave
34  * More TNT fun. Made perspective bitmaps more flexible.
35  * 
36  * 5     6/02/99 6:18p Dave
37  * Fixed TNT lockup problems! Wheeeee!
38  * 
39  * 4     12/18/98 1:13a Dave
40  * Rough 1024x768 support for Direct3D. Proper detection and usage through
41  * the launcher.
42  * 
43  * 3     10/09/98 2:57p Dave
44  * Starting splitting up OS stuff.
45  * 
46  * 2     10/08/98 2:38p Dave
47  * Cleanup up OsAPI code significantly. Removed old functions, centralized
48  * registry functions.
49  * 
50  * 118   7/10/98 5:04p Dave
51  * Fix connection speed bug on standalone server.
52  * 
53  * 117   5/24/98 2:28p Hoffoss
54  * Because we never really care about if the left or the right shift or
55  * alt key was used, but rather than either shift or alt was used, made
56  * both map to the left one.  Solves some problems, causes none.
57  * 
58  * 116   5/18/98 9:22p John
59  * Took out the annoying tab check.
60  * 
61  * 115   5/18/98 11:17a John
62  * Fixed some bugs with software window and output window.
63  * 
64  * 114   5/16/98 2:20p John
65  * Changed the os_suspend and resume to use a critical section to prevent
66  * threads from executing rather than just suspending the thread.  Had to
67  * make sure gr_close was called before os_close.
68  * 
69  * 113   5/15/98 4:49p John
70  * 
71  * 112   5/15/98 3:36p John
72  * Fixed bug with new graphics window code and standalone server.  Made
73  * hwndApp not be a global anymore.
74  * 
75  * 111   5/14/98 5:42p John
76  * Revamped the whole window position/mouse code for the graphics windows.
77  * 
78  * 110   5/04/98 11:08p Hoffoss
79  * Expanded on Force Feedback code, and moved it all into Joy_ff.cpp.
80  * Updated references everywhere to it.
81  *
82  * $NoKeywords: $
83  */
84
85 #include "pstypes.h"
86 #include "osapi.h"
87 #include "key.h"
88 #include "palman.h"
89 #include "mouse.h"
90 #include "outwnd.h"
91 #include "2d.h"
92 #include "cfile.h"
93 #include "sound.h"
94 #include "freespaceresource.h"
95 #include "managepilot.h"
96 #include "joy.h"
97 #include "joy_ff.h"
98 #include "gamesequence.h"
99 #include "freespace.h"
100 #include "osregistry.h"
101 #include "cmdline.h"
102
103 // ----------------------------------------------------------------------------------------------------
104 // OSAPI DEFINES/VARS
105 //
106
107 // os-wide globals
108 static int                      fAppActive = 0;
109 static int                      main_window_inited = 0;
110 static char                     szWinTitle[128];
111 static char                     szWinClass[128];
112 static int                      WinX, WinY, WinW, WinH;
113 static int                      Os_inited = 0;
114
115 static CRITICAL_SECTION Os_lock;
116
117 int Os_debugger_running = 0;
118
119 // ----------------------------------------------------------------------------------------------------
120 // OSAPI FORWARD DECLARATIONS
121 //
122
123 #ifdef THREADED
124         // thread handler for the main message thread
125         DWORD win32_process(DWORD lparam);
126 #else
127         DWORD win32_process1(DWORD lparam);
128         DWORD win32_process1(DWORD lparam);
129 #endif
130
131 // Fills in the Os_debugger_running with non-zero if debugger detected.
132 void os_check_debugger();
133
134 // called at shutdown. Makes sure all thread processing terminates.
135 void os_deinit();
136
137
138 // ----------------------------------------------------------------------------------------------------
139 // OSAPI FUNCTIONS
140 //
141
142 // initialization/shutdown functions -----------------------------------------------
143
144 // If app_name is NULL or ommited, then TITLE is used
145 // for the app name, which is where registry keys are stored.
146 void os_init(char * wclass, char * title, char *app_name, char *version_string )
147 {
148         STUB_FUNCTION;
149
150         Os_inited = 1;
151
152         // check to see if we're running under msdev
153         os_check_debugger();
154
155         atexit(os_deinit);
156 }
157
158 // set the main window title
159 void os_set_title( char * title )
160 {
161         STUB_FUNCTION;
162 }
163
164 // call at program end
165 void os_cleanup()
166 {
167         STUB_FUNCTION;
168         
169         #ifndef NDEBUG
170                 outwnd_close();
171         #endif
172 }
173
174
175 // window management -----------------------------------------------------------------
176
177 static int app_active = 1;
178 // Returns 1 if app is not the foreground app.
179 int os_foreground()
180 {
181         return app_active;
182 }
183
184 // Returns the handle to the main window
185 uint os_get_window()
186 {
187         STUB_FUNCTION;
188         return 0;
189 }
190
191
192 // process management -----------------------------------------------------------------
193
194 // Sleeps for n milliseconds or until app becomes active.
195 void os_sleep(int ms)
196 {
197         usleep(ms*1000);
198 }
199
200 // Used to stop message processing
201 void os_suspend()
202 {
203         ENTER_CRITICAL_SECTION(&Os_lock);       
204 }
205
206 // resume message processing
207 void os_resume()
208 {
209         LEAVE_CRITICAL_SECTION(&Os_lock);       
210 }
211
212
213 // ----------------------------------------------------------------------------------------------------
214 // OSAPI FORWARD DECLARATIONS
215 //
216
217 // Fills in the Os_debugger_running with non-zero if debugger detected.
218 void os_check_debugger()
219 {
220 }
221
222 // called at shutdown. Makes sure all thread processing terminates.
223 void os_deinit()
224 {
225 }
226
227 extern int SDLtoFS2[SDLK_LAST];
228 void os_poll()
229 {
230         SDL_Event e;
231
232         while (SDL_PollEvent (&e)) {
233                 switch (e.type) {
234                         case SDL_MOUSEBUTTONDOWN:
235                                 if (e.button.button == SDL_BUTTON_LEFT)
236                                         mouse_mark_button (MOUSE_LEFT_BUTTON,1);
237                                 else if (e.button.button == SDL_BUTTON_RIGHT)
238                                         mouse_mark_button (MOUSE_RIGHT_BUTTON,1);
239                                 else if (e.button.button == SDL_BUTTON_MIDDLE)
240                                         mouse_mark_button (MOUSE_MIDDLE_BUTTON, 1);
241                                 break;
242                         case SDL_MOUSEBUTTONUP:
243                                 if (e.button.button == SDL_BUTTON_LEFT)
244                                         mouse_mark_button (MOUSE_LEFT_BUTTON,0);
245                                 else if (e.button.button == SDL_BUTTON_RIGHT)
246                                         mouse_mark_button (MOUSE_RIGHT_BUTTON,0);
247                                 else if (e.button.button == SDL_BUTTON_MIDDLE)
248                                         mouse_mark_button (MOUSE_MIDDLE_BUTTON, 0);
249                                 break;
250                         case SDL_KEYDOWN:
251                                 if (SDLtoFS2[e.key.keysym.sym])
252                                 key_mark (SDLtoFS2[e.key.keysym.sym], 1, 0);
253                                 break;
254                         case SDL_KEYUP:
255                                 if (SDLtoFS2[e.key.keysym.sym])
256                                 key_mark (SDLtoFS2[e.key.keysym.sym], 0, 0);
257                                 break;
258                         default:
259                                 break;
260                 }
261         }
262 }
263
264 void debug_int3()
265 {
266 }
267