raze-gles/source/duke3d/src/config.cpp

272 lines
7.7 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 2016 EDuke32 developers and contributors
This file is part of EDuke32.
EDuke32 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include "duke3d.h"
#include "scriplib.h"
#include "osdcmds.h"
#include "renderlayer.h"
#include "cmdline.h"
#include "vfs.h"
#if defined RENDERTYPESDL && defined SDL_TARGET && SDL_TARGET > 1
# include "sdl_inc.h"
#endif
// we load this in to get default button and key assignments
// as well as setting up function mappings
#define __SETUP__ // JBF 20031211
#include "_functio.h"
BEGIN_DUKE_NS
void CONFIG_SetDefaults(void)
{
ud.config.scripthandle = -1;
# if defined RENDERTYPESDL && SDL_MAJOR_VERSION > 1
uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO);
if (inited == 0)
SDL_Init(SDL_INIT_VIDEO);
else if (!(inited & SDL_INIT_VIDEO))
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_DisplayMode dm;
if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
{
ud.setup.xdim = dm.w;
ud.setup.ydim = dm.h;
}
else
# endif
{
ud.setup.xdim = 1024;
ud.setup.ydim = 768;
}
ud.setup.bpp = 32;
ud.camera_time = 0;//4;
g_player[0].ps->aim_mode = 1;
ud.setup.fullscreen = 1;
ud.althud = 1;
ud.angleinterpolation = 0;
ud.brightness = 8;
ud.camerasprite = -1;
ud.color = 0;
ud.config.ShowWeapons = 0;
ud.default_skill = 1;
ud.detail = 0;
ud.display_bonus_screen = 1;
hud_position = 0;
ud.lockout = 0;
ud.m_marker = 1;
ud.menu_scrollbartilenum = -1;
ud.menu_scrollbarz = 65536;
ud.menu_scrollcursorz = 65536;
ud.menu_slidebarmargin = 65536;
ud.menu_slidebarz = 65536;
ud.menu_slidecursorz = 65536;
ud.menubackground = 1;
ud.pwlockout[0] = '\0';
ud.runkey_mode = 0;
ud.screen_size = 4;
ud.screen_tilting = 1;
ud.screenfade = 1;
ud.shadow_pal = 4;
ud.show_level_text = 1;
ud.slidebar_paldisabled = 1;
ud.statusbarflags = 0;//STATUSBAR_NOSHRINK;
ud.statusbarmode = 1;
ud.statusbarscale = 100;
ud.team = 0;
Bstrcpy(ud.rtsname, G_DefaultRtsFile());
Bstrcpy(szPlayerName, "Player");
VM_OnEvent(EVENT_SETDEFAULTS, g_player[myconnectindex].ps->i, myconnectindex);
}
int CONFIG_ReadSetup(void)
{
char tempbuf[1024];
CONFIG_SetDefaults();
ud.config.setupread = 1;
pathsearchmode = 1;
if (ud.config.scripthandle < 0)
{
if (buildvfs_exists(g_setupFileName)) // JBF 20031211
ud.config.scripthandle = SCRIPT_Load(g_setupFileName);
#if !defined(EDUKE32_TOUCH_DEVICES) && !defined(EDUKE32_STANDALONE)
else if (buildvfs_exists(SETUPFILENAME))
{
int const i = wm_ynbox("Import Configuration Settings",
"The configuration file \"%s\" was not found. "
"Import configuration data from \"%s\"?",
g_setupFileName, SETUPFILENAME);
if (i)
ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
}
#endif
}
pathsearchmode = 0;
if (ud.config.scripthandle < 0)
return -1;
Bmemset(tempbuf, 0, sizeof(tempbuf));
SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
char nameBuf[64];
while (Bstrlen(OSD_StripColors(nameBuf, tempbuf)) > 10)
tempbuf[Bstrlen(tempbuf) - 1] = '\0';
Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
if (g_noSetup == 0 && g_modDir[0] == '/')
{
SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
if (!buildvfs_isdir(g_modDir))
{
initprintf("Invalid mod dir in cfg!\n");
Bsprintf(g_modDir,"/");
}
}
if (g_grpNamePtr == NULL && g_addonNum == 0)
{
SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup", "SelectedGRP", &g_grpNamePtr);
if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
g_grpNamePtr = dup_filename(G_DefaultGrpFile());
}
if (!NAM_WW2GI)
{
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out", &ud.lockout);
SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "Password", &ud.pwlockout[0]);
}
windowx = -1;
windowy = -1;
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
if (ud.setup.bpp < 8) ud.setup.bpp = 32;
ud.config.setupread = 1;
return 0;
}
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
{
}
static const char *CONFIG_GetMapEntryName(char m[], char const * const mapname)
{
strcpy(m, mapname);
char *p = strrchr(m, '/');
if (!p) p = strrchr(m, '\\');
if (p) Bmemmove(m, p, Bstrlen(p)+1);
for (p=m; *p; p++) *p = tolower(*p);
// cheap hack because SCRIPT_GetNumber doesn't like the slashes
p = m;
while (*p == '/') p++;
return p;
}
static void CONFIG_GetMD4EntryName(char m[], uint8_t const * const md4)
{
sprintf(m, "MD4_%08x%08x%08x%08x",
B_BIG32(B_UNBUF32(&md4[0])), B_BIG32(B_UNBUF32(&md4[4])),
B_BIG32(B_UNBUF32(&md4[8])), B_BIG32(B_UNBUF32(&md4[12])));
}
int32_t CONFIG_GetMapBestTime(char const * const mapname, uint8_t const * const mapmd4)
{
if (!ud.config.setupread || ud.config.scripthandle < 0)
return -1;
char m[37];
CONFIG_GetMD4EntryName(m, mapmd4);
int32_t t = -1;
if (SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t))
{
// fall back to map filenames
char m2[BMAX_PATH];
auto p = CONFIG_GetMapEntryName(m2, mapname);
SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
}
return t;
}
int CONFIG_SetMapBestTime(uint8_t const * const mapmd4, int32_t tm)
{
if (ud.config.scripthandle < 0 && (ud.config.scripthandle = SCRIPT_Init(g_setupFileName)) < 0)
return -1;
char m[37];
CONFIG_GetMD4EntryName(m, mapmd4);
SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", m, tm, FALSE, FALSE);
return 0;
}
END_DUKE_NS