1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
/*
* PARSEC - Configuration Commands
*
* $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:34 $
*
* Orginally written by:
* Copyright (c) Markus Hadwiger <msh@parsec.org> 1996-1998
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// C library
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// compilation flags/debug support
#include "config.h"
#include "debug.h"
// general definitions
#include "general.h"
#include "objstruc.h"
// global externals
#include "globals.h"
// subsystem headers
#include "aud_defs.h"
#include "vid_defs.h"
// local module header
#include "con_conf.h"
// proprietary module headers
#include "con_arg.h"
#include "con_main.h"
#include "con_std.h"
#include "e_color.h"
#include "net_conn.h"
#include "vid_plug.h"
// generic string paste area
#define PASTE_STR_LEN 255
static char paste_str[ PASTE_STR_LEN + 1 ];
// string constants
static char netsubsys_syntax[] = "syntax: net.subsys [<protocol>]";
// commands to get/set an rgba color value ------------------------------------
//
colcomm_s col_comms[] = {
{ "panelback.i", &PanelBackColor, NULL },
{ "paneltext.i", &PanelTextColor, NULL },
{ "flarebase.i", &FlareBaseColor, NULL },
{ "ambient.i", &LightColorAmbient, NULL },
{ "diffuse.i", &LightColorDiffuse, NULL },
{ "specular.i", &LightColorSpecular, NULL },
{ NULL, NULL, NULL }
};
int num_col_commands = CALC_NUM_ARRAY_ENTRIES( col_comms ) - 1;
PRIVATE
int ExecColorCommand(int cmdid)
{
if ( col_comms[cmdid].func != NULL )
(*col_comms[cmdid].func)();
return TRUE;
}
// check single command for color configuration (rgba) ------------------------
//
INLINE
int CheckColorCommand( int cmdid, char *scan )
{
ASSERT( cmdid >= 0 );
ASSERT( col_comms[ cmdid ].cmd && col_comms[ cmdid ].col );
ASSERT( scan != NULL );
int cmdlen = strlen( col_comms[ cmdid ].cmd );
ASSERT( ( cmdlen > 1 ) && ( cmdlen < 32 ) );
// early exit if wrong prefix
if ( strncmp( scan, col_comms[ cmdid ].cmd, cmdlen - 2 ) != 0 )
return FALSE;
// make copy of command to avoid manipulating BSS string
char cmdstr[ 32 ];
strcpy( cmdstr, col_comms[ cmdid ].cmd );
cmdstr[ cmdlen - 2 ] = '\0';
if ( strcmp( scan, cmdstr ) == 0 ) {
if ( strtok( NULL, " " ) != NULL ) {
// no arguments must be specified!
return FALSE;
}
// color command without field specifier displays (R,G,B,A)
sprintf( paste_str, "%s currently is (rgba):", cmdstr );
CON_AddLine( paste_str );
sprintf( paste_str, "(%03d,%03d,%03d,%03d):",
col_comms[ cmdid ].col->R, col_comms[ cmdid ].col->G,
col_comms[ cmdid ].col->B, col_comms[ cmdid ].col->A );
CON_AddLine( paste_str );
return TRUE;
}
cmdstr[ cmdlen - 2 ] = '.';
int byteconv = col_comms[ cmdid ].col->A;
cmdstr[ cmdlen - 1 ] = 'a';
if ( CheckSetIntArgBounded( "%d", scan, cmdstr, &byteconv, 0, COLRGBA_FULLYOPAQUE, NULL ) ) {
col_comms[ cmdid ].col->A = byteconv;
return ExecColorCommand(cmdid);
}
byteconv = col_comms[ cmdid ].col->R;
cmdstr[ cmdlen - 1 ] = 'r';
if ( CheckSetIntArgBounded( "%d", scan, cmdstr, &byteconv, 0, COLRGBA_FULLBRIGHT, NULL ) ) {
col_comms[ cmdid ].col->R = byteconv;
return ExecColorCommand(cmdid);
}
byteconv = col_comms[ cmdid ].col->G;
cmdstr[ cmdlen - 1 ] = 'g';
if ( CheckSetIntArgBounded( "%d", scan, cmdstr, &byteconv, 0, COLRGBA_FULLBRIGHT, NULL ) ) {
col_comms[ cmdid ].col->G = byteconv;
return ExecColorCommand(cmdid);
}
byteconv = col_comms[ cmdid ].col->B;
cmdstr[ cmdlen - 1 ] = 'b';
if ( CheckSetIntArgBounded( "%d", scan, cmdstr, &byteconv, 0, COLRGBA_FULLBRIGHT, NULL ) ) {
col_comms[ cmdid ].col->B = byteconv;
return ExecColorCommand(cmdid);
}
// luminance=(r,g,b)
byteconv = col_comms[ cmdid ].col->G;
cmdstr[ cmdlen - 1 ] = 'l';
if ( CheckSetIntArgBounded( "%d", scan, cmdstr, &byteconv, 0, COLRGBA_FULLBRIGHT, NULL ) ) {
col_comms[ cmdid ].col->R = byteconv;
col_comms[ cmdid ].col->G = byteconv;
col_comms[ cmdid ].col->B = byteconv;
return ExecColorCommand(cmdid);
}
return FALSE;
}
// check all commands for color configuration (rgba) --------------------------
//
int CheckColorConfig( char *scan )
{
ASSERT( scan != NULL );
// scan list of color commands
for ( int curcmd = 0; col_comms[ curcmd ].cmd; curcmd++ ) {
if ( CheckColorCommand( curcmd, scan ) )
return TRUE;
}
return FALSE;
}
// switch to alternate video configuration ------------------------------------
//
PRIVATE
void SetVideoConfiguration()
{
// display active video subsystem if no parameter supplied
char *vsys;
if ( ( vsys = strtok( NULL, " " ) ) == NULL ) {
// removed
return;
}
// check for more than one parameter
if ( strtok( NULL, " " ) != NULL ) {
CON_AddLine( "specify video subsystem with a single word." );
return;
}
// string must be copied because it will be destroyed
// if a console script is executed on subsystem switch
strcpy( paste_str, vsys );
// try to change to specified video subsystem
if ( VID_PlugInSubsys( vsys ) ) {
strcat( paste_str, " selected as video subsystem." );
CON_AddLine( paste_str );
} else {
strcat( paste_str, " video subsystem not available or invalid." );
CON_AddLine( paste_str );
}
}
// display name of currently active protocol ---------------------------------
//
void DisplayCurrentNetSubsys()
{
// fetch string describing currently active protocol
const char *prot = NET_GetCurrentProtocolName();
// display
sprintf( paste_str, "current networking subsystem: %s", prot);
CON_AddLine( paste_str );
}
// switch to alternate network configuration (protocol/packet api) ------------
//
PRIVATE
void SetNetworkConfiguration()
{
//NOTE:
//CONCOM:
// net_config ::= 'net.subsys' [<protocol>]
// protocol ::= 'peer-to-peer' | 'slot-server' | 'game-server'
//NOTE:
// displays currently active networking subsystem
// if no parameter supplied (protocol/packet-api).
// fetch protocol
const char *prot = strtok( NULL, " " );
if ( prot == NULL ) {
DisplayCurrentNetSubsys();
return;
}
// check for more than one parameter
if ( strtok( NULL, " " ) != NULL ) {
CON_AddLine( netsubsys_syntax );
// return;
}
//FIXME: at startup the init messages are displayed twice due to net.conf in parsecrc.con
// check for idempotent network configuration change
const char* cur_prot = NET_GetCurrentProtocolName();
if ( strncmp( cur_prot, prot, strlen( prot ) ) != 0 ) {
// try to change to specified networking subsystem
if ( NET_SwitchNetSubsys( prot ) ) {
prot = NET_GetCurrentProtocolName();
MSGOUT( "%s selected.", prot );
} else {
if ( prot == NULL )
prot = NET_GetCurrentProtocolName();
MSGOUT( "%s not available or invalid.", prot );
//FIXME: CON_AddLine( netsubsys_syntax );
}
}
}
// set audio configuration (music, sfx ) -------------------------------------
//
PRIVATE
void SetAudioConfiguration()
{
//NOTE:
//CONCOM:
// audio_config ::= 'aud.conf' [conf_spec] [conf_spec]
// conf_spec ::= 'off' | 'music' | 'sfx'
//NOTE:
// displays currently audio configuration
// if no parameter supplied.
if ( SoundDisabled ) {
return;
}
// fetch first option
char *option1 = strtok( NULL, " " );
if ( option1 == NULL ) {
int cursetting = 0x00;
if ( Op_SoundEffects )
cursetting |= 0x01;
if ( Op_Music )
cursetting |= 0x02;
switch ( cursetting ) {
case 0x00:
sprintf( paste_str, "current audio configuration: off" );
break;
case 0x01:
sprintf( paste_str, "current audio configuration: sound effects only" );
break;
case 0x02:
sprintf( paste_str, "current audio configuration: music only" );
break;
case 0x03:
sprintf( paste_str, "current audio configuration: music and sound effects" );
break;
}
CON_AddLine( paste_str );
return;
}
int cursetting = 0x00;
if ( stricmp( option1, "music" ) == 0 ) {
cursetting |= 0x02;
} else if ( stricmp( option1, "sfx" ) == 0 ) {
cursetting |= 0x01;
} else if ( stricmp( option1, "off" ) == 0 ) {
cursetting |= 0x00;
}
// fetch second option
char *option2 = strtok( NULL, " " );
if ( option2 != NULL ) {
if ( stricmp( option2, "music" ) == 0 ) {
cursetting |= 0x02;
} else if ( stricmp( option2, "sfx" ) == 0 ) {
cursetting |= 0x01;
} else if ( stricmp( option2, "off" ) == 0 ) {
cursetting |= 0x00;
}
}
// determine new setting
Op_SoundEffects = ( ( cursetting & 0x01 ) != 0x00 );
Op_Music = ( ( cursetting & 0x02 ) != 0x00 );
// start/stop according to setting
switch ( cursetting ) {
//NOTE:
// the sequence of AUDs_CloseMenuSound() and AUDs_StopAudioStream()
// must not be changed, or the stream active flag will wrongly stick.
case 0x00:
//AUDs_CDStop();
AUDs_CloseMenuSound();
AUDs_StopAudioStream();
break;
case 0x01:
//AUDs_CDStop();
AUDs_CloseMenuSound();
AUDs_StopAudioStream();
break;
case 0x02:
if ( aud_do_open_menu_sound_on_aud_conf )
AUDs_OpenMenuSound();
break;
case 0x03:
if ( aud_do_open_menu_sound_on_aud_conf )
AUDs_OpenMenuSound();
break;
default:
ASSERT( 0 );
}
}
// set input configuration (mouse, joy) --------------------------------------
//
PRIVATE
void SetInputConfiguration()
{
//NOTE:
//CONCOM:
// input_config ::= 'inp.conf' [conf_spec] [conf_spec]
// conf_spec ::= 'off' | 'joystick' | 'mouse'
//NOTE:
// displays currently input configuration
// if no parameter supplied.
// fetch first option
char *option = strtok( NULL, " " );
if ( option == NULL ) {
int cursetting = 0x00;
if ( Op_Joystick )
cursetting |= 0x01;
if ( Op_Mouse )
cursetting |= 0x02;
switch ( cursetting ) {
case 0x00:
sprintf( paste_str, "current input configuration: off (keyboard only)" );
break;
case 0x01:
sprintf( paste_str, "current input configuration: joystick and keyboard" );
break;
case 0x02:
sprintf( paste_str, "current input configuration: mouse and keyboard" );
break;
}
CON_AddLine( paste_str );
return;
}
int cursetting = 0x00;
if ( stricmp( option, "mouse" ) == 0 ) {
cursetting |= 0x02;
} else if ( stricmp( option, "joystick" ) == 0 ) {
cursetting |= 0x01;
} else if ( stricmp( option, "off" ) == 0 ) {
cursetting |= 0x00;
}
// ensure joystick is available
if ( ( cursetting & 0x01 ) && JoystickDisabled ) {
cursetting &= ~0x01;
}
// determine new setting
Op_Joystick = ( ( cursetting & 0x01 ) != 0x00 );
Op_Mouse = ( ( cursetting & 0x02 ) != 0x00 );
}
// commands to do on-the-fly configuration ------------------------------------
//
struct configcomm_s {
int cmdid;
void (*func)();
};
configcomm_s config_comms[] = {
{ CM_VID_SUBSYS, SetVideoConfiguration },
{ CM_NET_SUBSYS, SetNetworkConfiguration },
{ CM_AUD_CONF, SetAudioConfiguration },
{ CM_INP_CONF, SetInputConfiguration },
{ 0, NULL }
};
// check single command for on-the-fly configuration --------------------------
//
INLINE
int CheckConfigCommand( int cmdid, char *scan )
{
ASSERT( cmdid >= 0 );
ASSERT( config_comms[ cmdid ].func );
ASSERT( scan != NULL );
if ( strcmp( scan, CMSTR( config_comms[ cmdid ].cmdid ) ) == 0 ) {
if ( config_comms[ cmdid ].func != NULL )
(*config_comms[ cmdid ].func)();
return TRUE;
}
return FALSE;
}
// check configuration command ------------------------------------------------
//
int CheckConfigCommand( char *scan )
{
ASSERT( scan != NULL );
for ( int curcmd = 0; config_comms[ curcmd ].func; curcmd++ ) {
if ( CheckConfigCommand( curcmd, scan ) )
return TRUE;
}
return FALSE;
}
|