Subversion Repositories eduke32

Rev

Rev 8480 | Rev 8591 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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