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