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