1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1997, 2005 - 3D Realms Entertainment
4
5 This file is part of Shadow Warrior version 1.2
6
7 Shadow Warrior is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 Original Source: 1997 - Frank Maddin and Jim Norwood
23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24 */
25 //-------------------------------------------------------------------------
26 #include "build.h"
27 #include "baselayer.h"
28 #include "osd.h"
29
30 #include "settings.h"
31 #include "mytypes.h"
32 #include "scriplib.h"
33 #include "gamedefs.h"
34 #include "keyboard.h"
35 #include "function.h"
36 #include "control.h"
37 #include "fx_man.h"
38 #include "sounds.h"
39 #include "config.h"
40 #include "common.h"
41 #include "common_game.h"
42
43 // we load this in to get default button and key assignments
44 // as well as setting up function mappings
45
46 #include "_functio.h"
47 #include "_config.h"
48
49 #include "renderlayer.h"
50
51 #if defined RENDERTYPESDL && defined SDL_TARGET && SDL_TARGET > 1
52 # include "sdl_inc.h"
53 #endif
54
55 extern void ReadGameSetup(int32_t scripthandle);
56 extern void WriteGameSetup(int32_t scripthandle);
57
58 ud_setup_t ud_setup{};
59 int g_noSetup;
60
61 //
62 // Comm variables
63 //
64
65 char CommPlayerName[32];
66 int32_t NumberPlayers,CommPort,PortSpeed,IrqNumber,UartAddress;
67
68 //
69 // Sound variables
70 //
71 int32_t FXToggle = 1;
72 int32_t MusicToggle = 1;
73 int32_t FXDevice = 0;
74 int32_t MusicDevice = ASS_AutoDetect;
75 int32_t NumVoices = 32;
76 int32_t NumChannels = 2;
77 int32_t NumBits = 16;
78 int32_t MixRate = 44100;
79
80 uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2];
81 int32_t MouseButtons[MAXMOUSEBUTTONS];
82 int32_t MouseButtonsClicked[MAXMOUSEBUTTONS];
83 int32_t MouseDigitalAxes[MAXMOUSEAXES][2];
84 int32_t MouseAnalogAxes[MAXMOUSEAXES];
85 int32_t MouseAnalogScale[MAXMOUSEAXES];
86 int32_t JoystickButtons[MAXJOYBUTTONS];
87 int32_t JoystickButtonsClicked[MAXJOYBUTTONS];
88 int32_t JoystickDigitalAxes[MAXJOYAXES][2];
89 int32_t JoystickAnalogAxes[MAXJOYAXES];
90 int32_t JoystickAnalogScale[MAXJOYAXES];
91 int32_t JoystickAnalogDead[MAXJOYAXES];
92 int32_t JoystickAnalogSaturate[MAXJOYAXES];
93
94 //
95 // Screen variables
96 //
97
98 extern char WangBangMacro[10][64];
99 char RTSName[MAXRTSNAMELENGTH];
100 static int32_t scripthandle = -1;
101
102
103
104 /*
105 ===================
106 =
107 = CONFIG_FunctionNameToNum
108 =
109 ===================
110 */
111
CONFIG_FunctionNameToNum(const char * func)112 int32_t CONFIG_FunctionNameToNum(const char *func)
113 {
114 int32_t i;
115
116 if (!func) return -1;
117 for (i=0; i<NUMGAMEFUNCTIONS; i++)
118 {
119 if (!Bstrcasecmp(func,gamefunctions[i]))
120 {
121 return i;
122 }
123 }
124 return -1;
125 }
126
127 /*
128 ===================
129 =
130 = CONFIG_FunctionNumToName
131 =
132 ===================
133 */
134
CONFIG_FunctionNumToName(int32_t func)135 const char *CONFIG_FunctionNumToName(int32_t func)
136 {
137 if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
138 {
139 return NULL;
140 }
141 else
142 {
143 return gamefunctions[func];
144 }
145 }
146
147 /*
148 ===================
149 =
150 = CONFIG_AnalogNameToNum
151 =
152 ===================
153 */
CONFIG_AnalogNameToNum(const char * func)154 int32_t CONFIG_AnalogNameToNum(const char *func)
155 {
156 if (!Bstrcasecmp(func,"analog_turning"))
157 {
158 return analog_turning;
159 }
160 if (!Bstrcasecmp(func,"analog_strafing"))
161 {
162 return analog_strafing;
163 }
164 if (!Bstrcasecmp(func,"analog_moving"))
165 {
166 return analog_moving;
167 }
168 if (!Bstrcasecmp(func,"analog_lookingupanddown"))
169 {
170 return analog_lookingupanddown;
171 }
172 return -1;
173 }
174
CONFIG_AnalogNumToName(int32_t func)175 const char *CONFIG_AnalogNumToName(int32_t func)
176 {
177 switch (func)
178 {
179 case analog_turning:
180 return "analog_turning";
181 case analog_strafing:
182 return "analog_strafing";
183 case analog_moving:
184 return "analog_moving";
185 case analog_lookingupanddown:
186 return "analog_lookingupanddown";
187 default: break;
188 }
189
190 return NULL;
191 }
192
193 /*
194 ===================
195 =
196 = CONFIG_SetDefaults
197 =
198 ===================
199 */
200
CONFIG_SetDefaults(void)201 void CONFIG_SetDefaults(void)
202 {
203 // JBF 20031211
204 int32_t i;
205
206 ud_setup.ScreenMode = 1;
207
208 #if defined RENDERTYPESDL && SDL_MAJOR_VERSION > 1
209 uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO);
210 if (inited == 0)
211 SDL_Init(SDL_INIT_VIDEO);
212 else if (!(inited & SDL_INIT_VIDEO))
213 SDL_InitSubSystem(SDL_INIT_VIDEO);
214
215 SDL_DisplayMode dm;
216 if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
217 {
218 ud_setup.ScreenWidth = dm.w;
219 ud_setup.ScreenHeight = dm.h;
220 }
221 else
222 #endif
223 {
224 ud_setup.ScreenWidth = 1024;
225 ud_setup.ScreenHeight = 768;
226 }
227
228 ud_setup.ScreenBPP = 32;
229 FXToggle = 1;
230 MusicToggle = 1;
231 FXDevice = 0;
232 MusicDevice = ASS_AutoDetect;
233 NumVoices = 32;
234 NumChannels = 2;
235 NumBits = 16;
236 MixRate = 44100;
237 memcpy(&gs, &gs_defaults, sizeof(gs));
238
239 Bstrcpy(RTSName, DEFAULTRTSFILE);
240 Bstrcpy(CommPlayerName, DEFAULTPLAYERNAME);
241
242 Bstrcpy(WangBangMacro[0], MACRO1);
243 Bstrcpy(WangBangMacro[1], MACRO2);
244 Bstrcpy(WangBangMacro[2], MACRO3);
245 Bstrcpy(WangBangMacro[3], MACRO4);
246 Bstrcpy(WangBangMacro[4], MACRO5);
247 Bstrcpy(WangBangMacro[5], MACRO6);
248 Bstrcpy(WangBangMacro[6], MACRO7);
249 Bstrcpy(WangBangMacro[7], MACRO8);
250 Bstrcpy(WangBangMacro[8], MACRO9);
251 Bstrcpy(WangBangMacro[9], MACRO10);
252
253 SetDefaultKeyDefinitions(1);
254 SetMouseDefaults(1);
255
256 gs.MouseAimingOn = TRUE;
257 gs.AutoRun = TRUE;
258
259 memset(MouseDigitalAxes, -1, sizeof(MouseDigitalAxes));
260 for (i=0; i<MAXMOUSEAXES; i++)
261 {
262 MouseAnalogScale[i] = 65536;
263
264 MouseDigitalAxes[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
265 MouseDigitalAxes[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
266
267 MouseAnalogAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
268 }
269 gs.MouseSpeed = DEFAULTMOUSESENSITIVITY*8192; // fix magic scale factor
270 CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
271
272 #if 0
273 // joystick defaults are pointless
274
275 memset(JoystickButtons, -1, sizeof(JoystickButtons));
276 memset(JoystickButtonsClicked, -1, sizeof(JoystickButtonsClicked));
277 for (i=0; i < (int32_t)(sizeof(joystickdefaults)/sizeof(char *)); i++)
278 {
279 JoystickButtons[i] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
280 JoystickButtonsClicked[i] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
281 }
282
283 memset(JoystickDigitalAxes, -1, sizeof(JoystickDigitalAxes));
284 for (i=0; i < MAXJOYAXES; i++)
285 {
286 JoystickAnalogScale[i] = 65536;
287 JoystickAnalogDead[i] = 1024;
288 JoystickAnalogSaturate[i] = 32767-1024;
289
290 JoystickDigitalAxes[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
291 JoystickDigitalAxes[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
292
293 JoystickAnalogAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
294 }
295 #endif
296 }
297
298
SetDefaultKeyDefinitions(int style)299 void SetDefaultKeyDefinitions(int style)
300 {
301 int numkeydefaults;
302 const char **keydefaultset;
303 int i, f, k1, k2;
304
305 if (style)
306 {
307 numkeydefaults = sizeof(keydefaults_modern) / sizeof(char *) / 3;
308 keydefaultset = keydefaults_modern;
309 }
310 else
311 {
312 numkeydefaults = sizeof(keydefaults) / sizeof(char *) / 3;
313 keydefaultset = keydefaults;
314 }
315
316 memset(KeyboardKeys, 0xff, sizeof(KeyboardKeys));
317 for (i=0; i < numkeydefaults; i++)
318 {
319 f = CONFIG_FunctionNameToNum(keydefaultset[3*i+0]);
320 if (f == -1) continue;
321 k1 = KB_StringToScanCode(keydefaultset[3*i+1]);
322 k2 = KB_StringToScanCode(keydefaultset[3*i+2]);
323 CONTROL_MapKey(i, k1, k2);
324
325 KeyboardKeys[f][0] = k1;
326 KeyboardKeys[f][1] = k2;
327 }
328 }
329
SetMouseDefaults(int style)330 void SetMouseDefaults(int style)
331 {
332 int nummousedefaults;
333 const char **mousedefaultset, **mouseclickeddefaultset;
334 int i;
335
336 if (style)
337 {
338 nummousedefaults = sizeof(mousedefaults_modern) / sizeof(char *);
339 mousedefaultset = mousedefaults_modern;
340 mouseclickeddefaultset = mouseclickeddefaults_modern;
341 }
342 else
343 {
344 nummousedefaults = sizeof(mousedefaults) / sizeof(char *);
345 mousedefaultset = mousedefaults;
346 mouseclickeddefaultset = mouseclickeddefaults;
347 }
348
349 memset(MouseButtons, -1, sizeof(MouseButtons));
350 memset(MouseButtonsClicked, -1, sizeof(MouseButtonsClicked));
351 for (i=0; i < nummousedefaults; i++)
352 {
353 MouseButtons[i] = CONFIG_FunctionNameToNum(mousedefaultset[i]);
354 CONTROL_MapButton(MouseButtons[i], i, FALSE, controldevice_mouse);
355
356 if (i<4) continue;
357
358 MouseButtonsClicked[i] = CONFIG_FunctionNameToNum(mouseclickeddefaultset[i]);
359 CONTROL_MapButton(MouseButtonsClicked[i], i, TRUE, controldevice_mouse);
360 }
361 }
362
363 /*
364 ===================
365 =
366 = CONFIG_ReadKeys
367 =
368 ===================
369 */
370
CONFIG_ReadKeys(int32_t scripthandle)371 void CONFIG_ReadKeys(int32_t scripthandle)
372 {
373 int32_t i;
374 int32_t numkeyentries;
375 int32_t function;
376 char keyname1[80];
377 char keyname2[80];
378 kb_scancode key1,key2;
379
380 if (scripthandle < 0) return;
381
382 numkeyentries = SCRIPT_NumberEntries(scripthandle,"KeyDefinitions");
383
384 for (i=0; i<numkeyentries; i++)
385 {
386 function = CONFIG_FunctionNameToNum(SCRIPT_Entry(scripthandle,"KeyDefinitions", i));
387 if (function != -1)
388 {
389 memset(keyname1,0,sizeof(keyname1));
390 memset(keyname2,0,sizeof(keyname2));
391 SCRIPT_GetDoubleString
392 (
393 scripthandle,
394 "KeyDefinitions",
395 SCRIPT_Entry(scripthandle, "KeyDefinitions", i),
396 keyname1,
397 keyname2
398 );
399 key1 = 0xff;
400 key2 = 0xff;
401 if (keyname1[0])
402 {
403 key1 = (uint8_t) KB_StringToScanCode(keyname1);
404 }
405 if (keyname2[0])
406 {
407 key2 = (uint8_t) KB_StringToScanCode(keyname2);
408 }
409 KeyboardKeys[function][0] = key1;
410 KeyboardKeys[function][1] = key2;
411 }
412 }
413
414 for (i=0; i<NUMGAMEFUNCTIONS; i++)
415 {
416 if (i == gamefunc_Show_Console)
417 OSD_CaptureKey(KeyboardKeys[i][0]);
418 else
419 CONTROL_MapKey(i, KeyboardKeys[i][0], KeyboardKeys[i][1]);
420 }
421 }
422
423 /*
424 ===================
425 =
426 = CONFIG_SetupMouse
427 =
428 ===================
429 */
430
CONFIG_SetupMouse(void)431 void CONFIG_SetupMouse(void)
432 {
433 int32_t i;
434 char str[80];
435 char temp[80];
436 int32_t function, scale;
437
438 if (scripthandle < 0) return;
439
440 for (i=0; i<MAXMOUSEBUTTONS; i++)
441 {
442 Bsprintf(str,"MouseButton%d",i); temp[0] = 0;
443 if (!SCRIPT_GetString(scripthandle,"Controls", str,temp))
444 MouseButtons[i] = CONFIG_FunctionNameToNum(temp);
445
446 Bsprintf(str,"MouseButtonClicked%d",i); temp[0] = 0;
447 if (!SCRIPT_GetString(scripthandle,"Controls", str,temp))
448 MouseButtonsClicked[i] = CONFIG_FunctionNameToNum(temp);
449 }
450
451 // map over the axes
452 for (i=0; i<MAXMOUSEAXES; i++)
453 {
454 Bsprintf(str,"MouseAnalogAxes%d",i); temp[0] = 0;
455 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp))
456 MouseAnalogAxes[i] = CONFIG_AnalogNameToNum(temp);
457
458 Bsprintf(str,"MouseDigitalAxes%d_0",i); temp[0] = 0;
459 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp))
460 MouseDigitalAxes[i][0] = CONFIG_FunctionNameToNum(temp);
461
462 Bsprintf(str,"MouseDigitalAxes%d_1",i); temp[0] = 0;
463 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp))
464 MouseDigitalAxes[i][1] = CONFIG_FunctionNameToNum(temp);
465
466 Bsprintf(str,"MouseAnalogScale%d",i);
467 scale = MouseAnalogScale[i];
468 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
469 MouseAnalogScale[i] = scale;
470 }
471
472 // 0 to 65536
473 SCRIPT_GetNumber(scripthandle, "Controls","MouseSensitivity",&function);
474 gs.MouseSpeed = function;
475
476 for (i=0; i<MAXMOUSEBUTTONS; i++)
477 {
478 CONTROL_MapButton(MouseButtons[i], i, FALSE, controldevice_mouse);
479 CONTROL_MapButton(MouseButtonsClicked[i], i, TRUE, controldevice_mouse);
480 }
481 for (i=0; i<MAXMOUSEAXES; i++)
482 {
483 CONTROL_MapAnalogAxis(i, MouseAnalogAxes[i], controldevice_mouse);
484 CONTROL_MapDigitalAxis(i, MouseDigitalAxes[i][0], 0,controldevice_mouse);
485 CONTROL_MapDigitalAxis(i, MouseDigitalAxes[i][1], 1,controldevice_mouse);
486 CONTROL_SetAnalogAxisScale(i, MouseAnalogScale[i], controldevice_mouse);
487 }
488
489 CONTROL_MouseSensitivity = float(gs.MouseSpeed) * (1.f/8192.f); // fix magic scale factor
490 }
491
492 /*
493 ===================
494 =
495 = CONFIG_SetupJoystick
496 =
497 ===================
498 */
499
CONFIG_SetupJoystick(void)500 void CONFIG_SetupJoystick(void)
501 {
502 int32_t i;
503 char str[80];
504 char temp[80];
505 int32_t scale;
506
507 if (scripthandle < 0) return;
508
509 for (i=0; i<MAXJOYBUTTONS; i++)
510 {
511 Bsprintf(str,"JoystickButton%d",i); temp[0] = 0;
512 if (!SCRIPT_GetString(scripthandle,"Controls", str,temp))
513 JoystickButtons[i] = CONFIG_FunctionNameToNum(temp);
514
515 Bsprintf(str,"JoystickButtonClicked%d",i); temp[0] = 0;
516 if (!SCRIPT_GetString(scripthandle,"Controls", str,temp))
517 JoystickButtonsClicked[i] = CONFIG_FunctionNameToNum(temp);
518 }
519
520 // map over the axes
521 for (i=0; i<MAXJOYAXES; i++)
522 {
523 Bsprintf(str,"JoystickAnalogAxes%d",i); temp[0] = 0;
524 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp))
525 JoystickAnalogAxes[i] = CONFIG_AnalogNameToNum(temp);
526
527 Bsprintf(str,"JoystickDigitalAxes%d_0",i); temp[0] = 0;
528 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp))
529 JoystickDigitalAxes[i][0] = CONFIG_FunctionNameToNum(temp);
530
531 Bsprintf(str,"JoystickDigitalAxes%d_1",i); temp[0] = 0;
532 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp))
533 JoystickDigitalAxes[i][1] = CONFIG_FunctionNameToNum(temp);
534
535 Bsprintf(str,"JoystickAnalogScale%d",i);
536 scale = JoystickAnalogScale[i];
537 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
538 JoystickAnalogScale[i] = scale;
539
540 Bsprintf(str,"JoystickAnalogDead%d",i);
541 scale = JoystickAnalogDead[i];
542 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
543 JoystickAnalogDead[i] = scale;
544
545 Bsprintf(str,"JoystickAnalogSaturate%d",i);
546 scale = JoystickAnalogSaturate[i];
547 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
548 JoystickAnalogSaturate[i] = scale;
549 }
550
551 for (i=0; i<MAXJOYBUTTONS; i++)
552 {
553 CONTROL_MapButton(JoystickButtons[i], i, FALSE, controldevice_joystick);
554 CONTROL_MapButton(JoystickButtonsClicked[i], i, TRUE, controldevice_joystick);
555 }
556 for (i=0; i<MAXJOYAXES; i++)
557 {
558 CONTROL_MapAnalogAxis(i, JoystickAnalogAxes[i], controldevice_joystick);
559 CONTROL_MapDigitalAxis(i, JoystickDigitalAxes[i][0], 0, controldevice_joystick);
560 CONTROL_MapDigitalAxis(i, JoystickDigitalAxes[i][1], 1, controldevice_joystick);
561 CONTROL_SetAnalogAxisScale(i, JoystickAnalogScale[i], controldevice_joystick);
562 //CONTROL_SetJoyAxisDead(i, JoystickAnalogDead[i]);
563 //CONTROL_SetJoyAxisSaturate(i, JoystickAnalogSaturate[i]);
564 joySetDeadZone(i, JoystickAnalogDead[i], JoystickAnalogSaturate[i]); // [JM] !CHECKME!
565 }
566 }
567
568 /*
569 ===================
570 =
571 = CONFIG_ReadSetup
572 =
573 ===================
574 */
575
CONFIG_ReadSetup(void)576 int32_t CONFIG_ReadSetup(void)
577 {
578 int32_t dummy;
579 extern char PlayerNameArg[32];
580
581 char waveformtrackname[MAXWAVEFORMTRACKLENGTH] = {0};
582
583 CONTROL_ClearAssignments();
584 CONFIG_SetDefaults();
585
586 if (buildvfs_exists(setupfilename))
587 scripthandle = SCRIPT_Load(setupfilename);
588
589 if (scripthandle < 0) return -1;
590
591 SCRIPT_GetNumber(scripthandle, "Screen Setup", "ScreenMode",&ud_setup.ScreenMode);
592 SCRIPT_GetNumber(scripthandle, "Screen Setup", "ScreenWidth",&ud_setup.ScreenWidth);
593 SCRIPT_GetNumber(scripthandle, "Screen Setup", "ScreenHeight",&ud_setup.ScreenHeight);
594 SCRIPT_GetNumber(scripthandle, "Screen Setup", "ScreenBPP", &ud_setup.ScreenBPP);
595 if (ud_setup.ScreenBPP < 8) ud_setup.ScreenBPP = 8;
596
597 SCRIPT_GetNumber(scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
598
599 SCRIPT_GetNumber(scripthandle, "Screen Setup", "GLTextureMode", &gltexfiltermode);
600 SCRIPT_GetNumber(scripthandle, "Screen Setup", "GLAnisotropy", &glanisotropy);
601 SCRIPT_GetNumber(scripthandle, "Screen Setup", "GLUseTextureCompr", &glusetexcompr);
602
603 SCRIPT_GetNumber(scripthandle, "Sound Setup", "FXToggle",&FXToggle);
604 SCRIPT_GetNumber(scripthandle, "Sound Setup", "MusicToggle",&MusicToggle);
605 SCRIPT_GetNumber(scripthandle, "Sound Setup", "FXDevice",&FXDevice);
606 SCRIPT_GetNumber(scripthandle, "Sound Setup", "MusicDevice",&MusicDevice);
607 SCRIPT_GetNumber(scripthandle, "Sound Setup", "FXVolume",&dummy);
608 gs.SoundVolume = dummy;
609 SCRIPT_GetNumber(scripthandle, "Sound Setup", "MusicVolume",&dummy);
610 gs.MusicVolume = dummy;
611
612 SCRIPT_GetNumber(scripthandle, "Sound Setup", "NumVoices",&NumVoices);
613 SCRIPT_GetNumber(scripthandle, "Sound Setup", "NumChannels",&NumChannels);
614 SCRIPT_GetNumber(scripthandle, "Sound Setup", "NumBits",&NumBits);
615 SCRIPT_GetNumber(scripthandle, "Sound Setup", "MixRate",&MixRate);
616 SCRIPT_GetNumber(scripthandle, "Sound Setup", "ReverseStereo",&dummy);
617 gs.FlipStereo = dummy;
618 if (gs.FlipStereo) gs.FlipStereo = 1;
619
620 SCRIPT_GetString(scripthandle, "Sound Setup", "WaveformTrackName", waveformtrackname);
621 if (waveformtrackname[0] != '\0')
622 memcpy(gs.WaveformTrackName, waveformtrackname, MAXWAVEFORMTRACKLENGTH);
623
624 SCRIPT_GetNumber(scripthandle, "Setup", "ForceSetup",&ud_setup.ForceSetup);
625
626 if (g_grpNamePtr == NULL && g_addonNum == -1)
627 {
628 SCRIPT_GetStringPtr(scripthandle, "Setup", "SelectedGRP", &g_grpNamePtr);
629 if (g_grpNamePtr && !strlen(g_grpNamePtr))
630 g_grpNamePtr = dup_filename(G_DefaultGrpFile());
631 }
632
633 SCRIPT_GetNumber(scripthandle, "Controls","UseMouse",&ud_setup.UseMouse);
634 SCRIPT_GetNumber(scripthandle, "Controls","UseJoystick",&ud_setup.UseJoystick);
635 SCRIPT_GetString(scripthandle, "Comm Setup", "RTSName",RTSName);
636
637 SCRIPT_GetString(scripthandle, "Comm Setup","PlayerName",CommPlayerName);
638
639 ReadGameSetup(scripthandle);
640
641 CONFIG_ReadKeys(scripthandle);
642
643 //CONFIG_SetupMouse(scripthandle);
644 //CONFIG_SetupJoystick(scripthandle);
645
646 if (PlayerNameArg[0] != '\0')
647 {
648 strcpy(CommPlayerName, PlayerNameArg);
649 }
650 return 0;
651 }
652
CONFIG_WriteCvars()653 static void CONFIG_WriteCvars()
654 {
655 static const char filename[] = "voidsw_cvars.cfg";
656
657 buildvfs_FILE fp = buildvfs_fopen_write(filename);
658
659 if (!fp)
660 {
661 OSD_Printf("Error writing %s: %s\n", filename, strerror(errno));
662 return;
663 }
664
665 buildvfs_fputstr(fp, "// this file is automatically generated by ");
666 buildvfs_fputstrptr(fp, AppProperName);
667 buildvfs_fputstr(fp, "\n");
668
669 OSD_WriteAliases(fp);
670 OSD_WriteCvars(fp);
671
672 buildvfs_fclose(fp);
673
674 OSD_Printf("Wrote %s\n", filename);
675 }
676
677 /*
678 ===================
679 =
680 = CONFIG_WriteSetup
681 =
682 ===================
683 */
684
CONFIG_WriteSetup(void)685 void CONFIG_WriteSetup(void)
686 {
687 int32_t dummy;
688 char buf[80];
689
690 if (scripthandle < 0)
691 scripthandle = SCRIPT_Init(setupfilename);
692
693 SCRIPT_PutNumber(scripthandle, "Screen Setup", "ScreenWidth", ud_setup.ScreenWidth,FALSE,FALSE);
694 SCRIPT_PutNumber(scripthandle, "Screen Setup", "ScreenHeight",ud_setup.ScreenHeight,FALSE,FALSE);
695 SCRIPT_PutNumber(scripthandle, "Screen Setup", "ScreenMode",ud_setup.ScreenMode,FALSE,FALSE);
696 SCRIPT_PutNumber(scripthandle, "Screen Setup", "ScreenBPP",ud_setup.ScreenBPP,FALSE,FALSE);
697 SCRIPT_PutNumber(scripthandle, "Screen Setup", "MaxRefreshFreq",maxrefreshfreq,FALSE,FALSE);
698 SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLTextureMode",gltexfiltermode,FALSE,FALSE);
699 SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLAnisotropy",glanisotropy,FALSE,FALSE);
700 SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLUseTextureCompr",glusetexcompr,FALSE,FALSE);
701
702 SCRIPT_PutNumber(scripthandle, "Sound Setup", "FXToggle", FXToggle, FALSE, FALSE);
703 SCRIPT_PutNumber(scripthandle, "Sound Setup", "MusicToggle", MusicToggle, FALSE, FALSE);
704 SCRIPT_PutNumber(scripthandle, "Sound Setup", "FXDevice", FXDevice, FALSE, FALSE);
705 SCRIPT_PutNumber(scripthandle, "Sound Setup", "MusicDevice", MusicDevice, FALSE, FALSE);
706 SCRIPT_PutNumber(scripthandle, "Sound Setup", "NumVoices", NumVoices, FALSE, FALSE);
707 SCRIPT_PutNumber(scripthandle, "Sound Setup", "NumChannels", NumChannels, FALSE, FALSE);
708 SCRIPT_PutNumber(scripthandle, "Sound Setup", "NumBits", NumBits, FALSE, FALSE);
709 SCRIPT_PutNumber(scripthandle, "Sound Setup", "MixRate", MixRate, FALSE, FALSE);
710 SCRIPT_PutNumber(scripthandle, "Sound Setup", "FXVolume",gs.SoundVolume,FALSE,FALSE);
711 SCRIPT_PutNumber(scripthandle, "Sound Setup", "MusicVolume",gs.MusicVolume,FALSE,FALSE);
712 dummy = gs.FlipStereo;
713 SCRIPT_PutNumber(scripthandle, "Sound Setup", "ReverseStereo",dummy,FALSE,FALSE);
714 SCRIPT_PutString(scripthandle, "Sound Setup", "WaveformTrackName", gs.WaveformTrackName);
715
716 SCRIPT_PutNumber(scripthandle, "Setup", "ForceSetup",ud_setup.ForceSetup,FALSE,FALSE);
717
718 if (g_grpNamePtr && g_addonNum == -1)
719 SCRIPT_PutString(scripthandle, "Setup", "SelectedGRP", g_grpNamePtr);
720
721 SCRIPT_PutNumber(scripthandle, "Controls","UseMouse",ud_setup.UseMouse,FALSE,FALSE);
722 SCRIPT_PutNumber(scripthandle, "Controls","UseJoystick",ud_setup.UseJoystick,FALSE,FALSE);
723 SCRIPT_PutNumber(scripthandle, "Controls","MouseSensitivity",gs.MouseSpeed,FALSE,FALSE);
724
725 WriteGameSetup(scripthandle);
726
727 for (dummy=0; dummy<NUMGAMEFUNCTIONS; dummy++)
728 {
729 SCRIPT_PutDoubleString(scripthandle, "KeyDefinitions", CONFIG_FunctionNumToName(dummy),
730 KB_ScanCodeToString(KeyboardKeys[dummy][0]), KB_ScanCodeToString(KeyboardKeys[dummy][1]));
731 }
732
733 for (dummy=0; dummy<MAXMOUSEBUTTONS; dummy++)
734 {
735 Bsprintf(buf,"MouseButton%d",dummy);
736 SCRIPT_PutString(scripthandle,"Controls", buf, CONFIG_FunctionNumToName(MouseButtons[dummy]));
737
738 if (dummy >= (MAXMOUSEBUTTONS-2)) continue; // scroll wheel
739
740 Bsprintf(buf,"MouseButtonClicked%d",dummy);
741 SCRIPT_PutString(scripthandle,"Controls", buf, CONFIG_FunctionNumToName(MouseButtonsClicked[dummy]));
742 }
743
744 for (dummy=0; dummy<MAXMOUSEAXES; dummy++)
745 {
746 Bsprintf(buf,"MouseAnalogAxes%d",dummy);
747 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_AnalogNumToName(MouseAnalogAxes[dummy]));
748
749 Bsprintf(buf,"MouseDigitalAxes%d_0",dummy);
750 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(MouseDigitalAxes[dummy][0]));
751
752 Bsprintf(buf,"MouseDigitalAxes%d_1",dummy);
753 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(MouseDigitalAxes[dummy][1]));
754
755 Bsprintf(buf,"MouseAnalogScale%d",dummy);
756 SCRIPT_PutNumber(scripthandle, "Controls", buf, MouseAnalogScale[dummy], FALSE, FALSE);
757 }
758
759 for (dummy=0; dummy<MAXJOYBUTTONS; dummy++)
760 {
761 Bsprintf(buf,"JoystickButton%d",dummy);
762 SCRIPT_PutString(scripthandle,"Controls", buf, CONFIG_FunctionNumToName(JoystickButtons[dummy]));
763
764 Bsprintf(buf,"JoystickButtonClicked%d",dummy);
765 SCRIPT_PutString(scripthandle,"Controls", buf, CONFIG_FunctionNumToName(JoystickButtonsClicked[dummy]));
766 }
767
768 for (dummy=0; dummy<MAXJOYAXES; dummy++)
769 {
770 Bsprintf(buf,"JoystickAnalogAxes%d",dummy);
771 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_AnalogNumToName(JoystickAnalogAxes[dummy]));
772
773 Bsprintf(buf,"JoystickDigitalAxes%d_0",dummy);
774 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(JoystickDigitalAxes[dummy][0]));
775
776 Bsprintf(buf,"JoystickDigitalAxes%d_1",dummy);
777 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(JoystickDigitalAxes[dummy][1]));
778
779 Bsprintf(buf,"JoystickAnalogScale%d",dummy);
780 SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogScale[dummy], FALSE, FALSE);
781
782 Bsprintf(buf,"JoystickAnalogDead%d",dummy);
783 SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogDead[dummy], FALSE, FALSE);
784
785 Bsprintf(buf,"JoystickAnalogSaturate%d",dummy);
786 SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogSaturate[dummy], FALSE, FALSE);
787 }
788
789 SCRIPT_Save(scripthandle, setupfilename);
790 SCRIPT_Free(scripthandle);
791
792 CONFIG_WriteCvars();
793 }
794
795