📄 config.c
字号:
//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
This file is NOT part of Duke Nukem 3D version 1.5 - Atomic EditionHowever, it is either an older version of a file that is, or issome test code written during the development of Duke Nukem 3D.This file is provided purely for educational interest.Duke Nukem 3D 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.
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <dos.h>
#include "duke3d.h"
#include "scriplib.h"
// we load this in to get default button and key assignments
// as well as setting up function mappings
#include "_functio.h"
//
// Sound variables
//
int32 FXDevice;
int32 MusicDevice;
int32 FXVolume;
int32 MusicVolume;
int32 SoundToggle;
int32 MusicToggle;
int32 VoiceToggle;
int32 AmbienceToggle;
fx_blaster_config BlasterConfig;
int32 NumVoices;
int32 NumChannels;
int32 NumBits;
int32 MixRate;
int32 MidiPort;
int32 ReverseStereo;
int32 ControllerType;
int32 MouseAiming;
//
// Screen variables
//
int32 ScreenMode;
int32 ScreenWidth;
int32 ScreenHeight;
static char setupfilename[128]={SETUPFILENAME};
static int32 scripthandle;
static int32 setupread=0;
/*
===================
=
= CONFIG_GetSetupFilename
=
===================
*/
#define MAXSETUPFILES 20
void CONFIG_GetSetupFilename( void )
{
struct find_t fblock;
char extension[10];
char * src;
char * filenames[MAXSETUPFILES];
int32 numfiles;
int32 i;
strcpy(setupfilename,SETUPFILENAME);
// determine extension
src = setupfilename + strlen(setupfilename) - 1;
while (*src != '.')
{
src--;
}
strcpy (&extension[1],src);
extension[0] = '*';
numfiles=0;
if (_dos_findfirst(extension,0,&fblock)==0)
{
do
{
filenames[numfiles]=SafeMalloc(128);
strcpy(filenames[numfiles],fblock.name);
numfiles++;
if (numfiles == MAXSETUPFILES)
break;
}
while(!_dos_findnext(&fblock));
}
i = CheckParm (SETUPNAMEPARM);
if (i!=0)
{
numfiles = 0;
strcpy(setupfilename,_argv[i+1]);
}
if (numfiles>1)
{
int32 time;
int32 oldtime;
int32 count;
printf("\nMultiple Configuration Files Encountered\n");
printf("========================================\n");
printf("Please choose a configuration file from the following list by pressing its\n");
printf("corresponding letter:\n");
for (i=0;i<numfiles;i++)
{
if (strcmpi(filenames[i],SETUPFILENAME))
{
printf("%c. %s\n",'a'+(char)i,filenames[i]);
}
else
{
printf("%c. %s <DEFAULT>\n",'a'+(char)i,filenames[i]);
}
}
printf("\n");
printf("(%s will be used if no selection is made within 10 seconds.)\n\n",SETUPFILENAME);
KB_FlushKeyboardQueue();
KB_ClearKeysDown();
count = 9;
oldtime = clock();
time=clock()+(10*CLOCKS_PER_SEC);
while (clock()<time)
{
if (clock()>oldtime)
{
printf("%ld seconds left. \r",count);
fflush(stdout);
oldtime = clock()+CLOCKS_PER_SEC;
count--;
}
if (KB_KeyWaiting())
{
int32 ch = KB_Getch();
ch -='a';
if (ch>=0 && ch<numfiles)
{
strcpy (setupfilename, filenames[ch]);
break;
}
}
}
printf("\n\n");
}
if (numfiles==1)
strcpy (setupfilename, filenames[0]);
printf("Using Setup file: '%s'\n",setupfilename);
i=clock()+(3*CLOCKS_PER_SEC/4);
while (clock()<i)
{
;
}
for (i=0;i<numfiles;i++)
{
SafeFree(filenames[i]);
}
}
/*
===================
=
= CONFIG_FunctionNameToNum
=
===================
*/
int32 CONFIG_FunctionNameToNum( char * func )
{
int32 i;
for (i=0;i<NUMGAMEFUNCTIONS;i++)
{
if (!stricmp(func,gamefunctions[i]))
{
return i;
}
}
return -1;
}
/*
===================
=
= CONFIG_FunctionNumToName
=
===================
*/
char * CONFIG_FunctionNumToName( int32 func )
{
if (func < NUMGAMEFUNCTIONS)
{
return gamefunctions[func];
}
else
{
return NULL;
}
}
/*
===================
=
= CONFIG_AnalogNameToNum
=
===================
*/
int32 CONFIG_AnalogNameToNum( char * func )
{
if (!stricmp(func,"analog_turning"))
{
return analog_turning;
}
if (!stricmp(func,"analog_strafing"))
{
return analog_strafing;
}
if (!stricmp(func,"analog_moving"))
{
return analog_moving;
}
if (!stricmp(func,"analog_lookingupanddown"))
{
return analog_lookingupanddown;
}
return -1;
}
/*
===================
=
= CONFIG_SetDefaults
=
===================
*/
void CONFIG_SetDefaults( void )
{
SoundToggle = 1;
MusicToggle = 1;
VoiceToggle = 1;
AmbienceToggle = 1;
FXVolume = 192;
MusicVolume = 128;
ReverseStereo = 0;
ps[0].aim_mode = 0;
ud.screen_size = 8;
ud.screen_tilting = 1;
ud.shadows = 1;
ud.detail = 1;
ud.lockout = 0;
ud.pwlockout[0] = '\0';
ud.crosshair = 0;
ud.m_marker = 1;
ud.m_ffire = 1;
}
/*
===================
=
= CONFIG_ReadKeys
=
===================
*/
void CONFIG_ReadKeys( void )
{
int32 i;
int32 numkeyentries;
int32 function;
char keyname1[80];
char keyname2[80];
kb_scancode key1,key2;
numkeyentries = SCRIPT_NumberEntries( scripthandle, "KeyDefinitions" );
for (i=0;i<numkeyentries;i++)
{
function = CONFIG_FunctionNameToNum(SCRIPT_Entry( scripthandle, "KeyDefinitions", i ));
if (function != -1)
{
memset(keyname1,0,sizeof(keyname1));
memset(keyname2,0,sizeof(keyname2));
SCRIPT_GetDoubleString
(
scripthandle,
"KeyDefinitions",
SCRIPT_Entry( scripthandle,"KeyDefinitions", i ),
keyname1,
keyname2
);
key1 = 0;
key2 = 0;
if (keyname1[0])
{
key1 = (byte) KB_StringToScanCode( keyname1 );
}
if (keyname2[0])
{
key2 = (byte) KB_StringToScanCode( keyname2 );
}
CONTROL_MapKey( function, key1, key2 );
}
}
}
/*
===================
=
= CONFIG_SetupMouse
=
===================
*/
void CONFIG_SetupMouse( int32 scripthandle )
{
int32 i;
char str[80];
char temp[80];
int32 function, scale;
for (i=0;i<MAXMOUSEBUTTONS;i++)
{
sprintf(str,"MouseButton%ld",i);
memset(temp,0,sizeof(temp));
SCRIPT_GetString( scripthandle,"Controls", str,temp);
function = CONFIG_FunctionNameToNum(temp);
if (function != -1)
CONTROL_MapButton( function, i, false );
sprintf(str,"MouseButtonClicked%ld",i);
memset(temp,0,sizeof(temp));
SCRIPT_GetString( scripthandle,"Controls", str,temp);
function = CONFIG_FunctionNameToNum(temp);
if (function != -1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -