]> icculus.org git repositories - taylor/freespace2.git/blob - src/osapi/os_unix.cpp
added copyright header
[taylor/freespace2.git] / src / osapi / os_unix.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/OsApi/OsApi.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Low level Windows code
16  *
17  * $Log$
18  * Revision 1.8  2002/06/09 04:41:25  relnev
19  * added copyright header
20  *
21  * Revision 1.7  2002/06/05 04:03:32  relnev
22  * finished cfilesystem.
23  *
24  * removed some old code.
25  *
26  * fixed mouse save off-by-one.
27  *
28  * sound cleanups.
29  *
30  * Revision 1.6  2002/05/31 03:34:02  theoddone33
31  * Fix Keyboard
32  * Add titlebar
33  *
34  * Revision 1.5  2002/05/30 23:46:29  theoddone33
35  * some minor key changes (not necessarily fixes)
36  *
37  * Revision 1.4  2002/05/30 16:50:24  theoddone33
38  * Keyboard partially fixed
39  *
40  * Revision 1.3  2002/05/29 06:25:13  theoddone33
41  * Keyboard input, mouse tracking now work
42  *
43  * Revision 1.2  2002/05/07 03:16:48  theoddone33
44  * The Great Newline Fix
45  *
46  * Revision 1.1.1.1  2002/05/03 03:28:10  root
47  * Initial import.
48  * 
49  * 
50  * 7     6/30/99 5:53p Dave
51  * Put in new anti-camper code.
52  * 
53  * 6     6/03/99 6:37p Dave
54  * More TNT fun. Made perspective bitmaps more flexible.
55  * 
56  * 5     6/02/99 6:18p Dave
57  * Fixed TNT lockup problems! Wheeeee!
58  * 
59  * 4     12/18/98 1:13a Dave
60  * Rough 1024x768 support for Direct3D. Proper detection and usage through
61  * the launcher.
62  * 
63  * 3     10/09/98 2:57p Dave
64  * Starting splitting up OS stuff.
65  * 
66  * 2     10/08/98 2:38p Dave
67  * Cleanup up OsAPI code significantly. Removed old functions, centralized
68  * registry functions.
69  * 
70  * 118   7/10/98 5:04p Dave
71  * Fix connection speed bug on standalone server.
72  * 
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.
77  * 
78  * 116   5/18/98 9:22p John
79  * Took out the annoying tab check.
80  * 
81  * 115   5/18/98 11:17a John
82  * Fixed some bugs with software window and output window.
83  * 
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.
88  * 
89  * 113   5/15/98 4:49p John
90  * 
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.
94  * 
95  * 111   5/14/98 5:42p John
96  * Revamped the whole window position/mouse code for the graphics windows.
97  * 
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.
101  *
102  * $NoKeywords: $
103  */
104
105 #include "pstypes.h"
106 #include "osapi.h"
107 #include "key.h"
108 #include "palman.h"
109 #include "mouse.h"
110 #include "outwnd.h"
111 #include "2d.h"
112 #include "cfile.h"
113 #include "sound.h"
114 #include "freespaceresource.h"
115 #include "managepilot.h"
116 #include "joy.h"
117 #include "joy_ff.h"
118 #include "gamesequence.h"
119 #include "freespace.h"
120 #include "osregistry.h"
121 #include "cmdline.h"
122
123 // ----------------------------------------------------------------------------------------------------
124 // OSAPI DEFINES/VARS
125 //
126
127 // os-wide globals
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;
134
135 static CRITICAL_SECTION Os_lock;
136
137 int Os_debugger_running = 0;
138
139 // ----------------------------------------------------------------------------------------------------
140 // OSAPI FORWARD DECLARATIONS
141 //
142
143 #ifdef THREADED
144         // thread handler for the main message thread
145         DWORD win32_process(DWORD lparam);
146 #else
147         DWORD win32_process1(DWORD lparam);
148         DWORD win32_process1(DWORD lparam);
149 #endif
150
151 // Fills in the Os_debugger_running with non-zero if debugger detected.
152 void os_check_debugger();
153
154 // called at shutdown. Makes sure all thread processing terminates.
155 void os_deinit();
156
157
158 // ----------------------------------------------------------------------------------------------------
159 // OSAPI FUNCTIONS
160 //
161
162 // initialization/shutdown functions -----------------------------------------------
163
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 )
167 {
168         STUB_FUNCTION;
169
170         Os_inited = 1;
171
172         // check to see if we're running under msdev
173         os_check_debugger();
174
175         atexit(os_deinit);
176 }
177
178 // set the main window title
179 void os_set_title( char * title )
180 {
181         STUB_FUNCTION;
182 }
183
184 // call at program end
185 void os_cleanup()
186 {
187         STUB_FUNCTION;
188         
189         #ifndef NDEBUG
190                 outwnd_close();
191         #endif
192 }
193
194
195 // window management -----------------------------------------------------------------
196
197 static int app_active = 1;
198 // Returns 1 if app is not the foreground app.
199 int os_foreground()
200 {
201         return app_active;
202 }
203
204 // Returns the handle to the main window
205 uint os_get_window()
206 {
207         STUB_FUNCTION;
208         return 0;
209 }
210
211
212 // process management -----------------------------------------------------------------
213
214 // Sleeps for n milliseconds or until app becomes active.
215 void os_sleep(int ms)
216 {
217         usleep(ms*1000);
218 }
219
220 // Used to stop message processing
221 void os_suspend()
222 {
223         ENTER_CRITICAL_SECTION(&Os_lock);       
224 }
225
226 // resume message processing
227 void os_resume()
228 {
229         LEAVE_CRITICAL_SECTION(&Os_lock);       
230 }
231
232
233 // ----------------------------------------------------------------------------------------------------
234 // OSAPI FORWARD DECLARATIONS
235 //
236
237 // Fills in the Os_debugger_running with non-zero if debugger detected.
238 void os_check_debugger()
239 {
240 }
241
242 // called at shutdown. Makes sure all thread processing terminates.
243 void os_deinit()
244 {
245 }
246
247 extern int SDLtoFS2[SDLK_LAST];
248 void os_poll()
249 {
250         SDL_Event e;
251
252         while (SDL_PollEvent (&e)) {
253                 switch (e.type) {
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);
261                                 break;
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);
269                                 break;
270                         case SDL_KEYDOWN:
271                                 if (SDLtoFS2[e.key.keysym.sym])
272                                 key_mark (SDLtoFS2[e.key.keysym.sym], 1, 0);
273                                 break;
274                         case SDL_KEYUP:
275                                 if (SDLtoFS2[e.key.keysym.sym])
276                                 key_mark (SDLtoFS2[e.key.keysym.sym], 0, 0);
277                                 break;
278                         default:
279                                 break;
280                 }
281         }
282 }
283
284 void debug_int3()
285 {
286         STUB_FUNCTION;
287 }
288