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