From e8949e1c31030baa2c3eca21bbfe565767268eb2 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 28 Jul 2014 06:42:28 +0000 Subject: [PATCH] Elimininate some codedup between game.c and astub.c. DONT_BUILD. git-svn-id: https://svn.eduke32.com/eduke32@4557 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 2 +- polymer/eduke32/build/include/common.h | 4 +- polymer/eduke32/build/include/editor.h | 3 + polymer/eduke32/build/src/build.c | 13 + polymer/eduke32/build/src/sdlayer.c | 14 + polymer/eduke32/source/astub.c | 244 ++++------------- polymer/eduke32/source/common.c | 346 +++++++++++++++++++++++-- polymer/eduke32/source/common_game.h | 17 ++ polymer/eduke32/source/game.c | 318 +---------------------- polymer/eduke32/source/game.h | 5 +- polymer/eduke32/source/global.h | 1 - 11 files changed, 444 insertions(+), 523 deletions(-) diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 1b6ddfcb0..98546ac9d 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -220,7 +220,7 @@ COMMON_OBJS=common rev COMMON_EDITOR_OBJS=common m32def m32exec m32vars mathutil rev DUKE3D_OBJS=game actors anim config demo gamedef gameexec gamevars global input menus namesdyn net player premap savegame sector rts osdfuncs osdcmds grpscan sounds soundsdyn $(MACT_OBJ) -DUKE3D_EDITOR_OBJS=astub sounds_mapster32 +DUKE3D_EDITOR_OBJS=astub grpscan sounds_mapster32 ifneq ($(USE_LIBVPX),0) DUKE3D_OBJS+= animvpx diff --git a/polymer/eduke32/build/include/common.h b/polymer/eduke32/build/include/common.h index cea197d58..fc469bc9c 100644 --- a/polymer/eduke32/build/include/common.h +++ b/polymer/eduke32/build/include/common.h @@ -62,6 +62,8 @@ void G_AddClipMap(const char *buffer); int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens); +int32_t G_CheckCmdSwitch(int32_t argc, const char **argv, const char *str); + int32_t testkopen(const char *filename, char searchfirst); // full-blown kopen4load int32_t check_file_exist(const char *fn); // findfrompath with pathsearchmode=1 / search in zips @@ -80,8 +82,6 @@ int32_t dist(const spritetype *s1, const spritetype *s2); void COMMON_clearbackground(int32_t numcols, int32_t numrows); -extern void G_ExtPreInit(void); - // timer defs for profiling function chunks the simple way #define EDUKE32_TMRDEF int32_t t[20], ti=0; const char *tmrstr=__func__; fprintf(stderr,"%s\n",tmrstr); t[ti++]=getticks(); #define EDUKE32_TMRTIC t[ti++]=getticks() diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index ceb054492..2fd02b4f9 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -16,6 +16,8 @@ #define SETUPFILENAME "mapster32.cfg" extern char setupfilename[BMAX_PATH]; +extern char levelname[BMAX_PATH]; + // Build keys #define BK_MOVEFORWARD 0 #define BK_MOVEBACKWARD 1 @@ -161,6 +163,7 @@ extern void clearkeys(void); extern const char *ExtGetVer(void); extern int32_t ExtInit(void); extern int32_t ExtPreInit(int32_t argc,const char **argv); +extern int32_t ExtPostStartupWindow(void); extern void ExtUnInit(void); extern void ExtPreCheckKeys(void); extern void ExtAnalyzeSprites(int32_t, int32_t, int32_t, int32_t); diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 2bb42a1f7..a9363de2e 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -23,6 +23,8 @@ #include "m32script.h" +char levelname[BMAX_PATH] = {0}; + #define TIMERINTSPERSECOND 120 #define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctable[((((uint16_t)crc)>>8)&65535)^dat])) @@ -32,6 +34,7 @@ static char kensig[64]; static const char *CallExtGetVer(void); static int32_t CallExtInit(void); static int32_t CallExtPreInit(int32_t argc,const char **argv); +static int32_t CallExtPostStartupWindow(void); static void CallExtUnInit(void); static void CallExtPreCheckKeys(void); static void CallExtAnalyzeSprites(int32_t, int32_t, int32_t, int32_t); @@ -585,7 +588,11 @@ int32_t app_main(int32_t argc, const char **argv) Bstrcat(boardfilename, ".map"); //Bcanonicalisefilename(boardfilename,0); + if (!getcwd(program_origcwd,BMAX_PATH)) + program_origcwd[0] = '\0'; + if ((i = CallExtInit()) < 0) return -1; + #ifdef STARTUP_SETUP_WINDOW if (i || forcesetup || cmdsetup) { @@ -599,6 +606,8 @@ int32_t app_main(int32_t argc, const char **argv) } #endif + if (CallExtPostStartupWindow() < 0) return -1; + loadnames(g_namesFileName, 1); if (initinput()) return -1; @@ -10766,6 +10775,10 @@ static int32_t CallExtPreInit(int32_t argc,const char **argv) { return ExtPreInit(argc, argv); } +static int32_t CallExtPostStartupWindow(void) +{ + return ExtPostStartupWindow(); +} static void CallExtUnInit(void) { ExtUnInit(); diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 505a35484..c85d1188b 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -287,6 +287,13 @@ void wm_setapptitle(char *name) // // +#ifdef GEKKO +#include "gctypes.h" // for bool +void L2Enhance(); +void CON_EnableGecko(int channel,int safe); +bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice); +#endif + int32_t main(int32_t argc, char *argv[]) { int32_t r; @@ -294,6 +301,13 @@ int32_t main(int32_t argc, char *argv[]) char *argp; #endif +#ifdef GEKKO + L2Enhance(); + CON_EnableGecko(1, 1); + Bprintf("Console started\n"); + fatInit(28, true); +#endif + buildkeytranslationtable(); #ifdef HAVE_GTK2 diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index d85ae6c0c..ab5ec1d06 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -34,6 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "osdfuncs.h" #include "names.h" +#include "grpscan.h" + #include "common.h" #include "common_game.h" #include "mapster32.h" @@ -79,9 +81,6 @@ const char* AppTechnicalName = "mapster32"; static int32_t floor_over_floor; static int32_t g_fillCurSector = 0; -static char g_modDir[BMAX_PATH]; -static char levelname[BMAX_PATH]; - // static char *startwin_labeltext = "Starting Mapster32..."; char setupfilename[BMAX_PATH] = SETUPFILENAME; @@ -107,8 +106,6 @@ static int16_t g_sndnum[MAXSOUNDS]; // maps current order index to g_sounds ind int32_t g_numsounds = 0; static int32_t lastupdate, mousecol, mouseadd = 1, bstatus; -static int32_t usecwd = 0; - char *scripthist[SCRIPTHISTSIZ]; int32_t scripthistend = 0; @@ -683,23 +680,6 @@ static const char *Help3d[]= " END = PGUP/PGDN MODIFIER (512 UNITS)", }; -int32_t kopen4loadfrommod(const char *filename, char searchfirst) -{ - static char fn[BMAX_PATH]; - int32_t r=-1; - - if (g_modDir[0]) - { - Bsnprintf(fn,sizeof(fn),"%s/%s",g_modDir,filename); - r = kopen4load(fn,searchfirst); - } - - if (r < 0) - r = kopen4load(filename,searchfirst); - - return r; -} - const char *ExtGetVer(void) { return s_buildRev; @@ -8594,6 +8574,23 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) Bexit(0); } + if (!Bstrcasecmp(c+1,"addon")) + { + if (argc > i+1) + { + g_usingAddon = Batoi(argv[i+1]); + + if (!(g_usingAddon > ADDON_NONE && g_usingAddon < NUMADDONS)) + g_usingAddon = ADDON_NONE; + + COPYARG(i); + COPYARG(i+1); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1, "g") || !Bstrcasecmp(c+1, "grp")) { if (argc > i+1) @@ -8611,10 +8608,6 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) { if (argc > i+1) { -#ifdef USE_OPENGL - Bsnprintf(tempbuf,sizeof(tempbuf),"%s/%s",argv[i+1],TEXCACHEFILE); - Bstrncpyz(TEXCACHEFILE, tempbuf, sizeof(TEXCACHEFILE)); -#endif Bstrncpyz(g_modDir, argv[i+1], sizeof(g_modDir)); G_AddPath(argv[i+1]); @@ -8918,19 +8911,15 @@ int32_t ExtPreInit(int32_t argc,const char **argv) { wm_setapptitle("Mapster32"); - G_ExtPreInit(); - #ifdef _WIN32 { extern int32_t (*check_filename_casing_fn)(void); check_filename_casing_fn = check_filename_casing; } - - tempbuf[GetModuleFileName(NULL,tempbuf,BMAX_PATH)] = 0; - Bcorrectfilename(tempbuf,1); - //chdir(tempbuf); #endif + G_ExtPreInit(argc, argv); + OSD_SetLogFile("mapster32.log"); OSD_SetVersion("Mapster32" " " VERSION,0,2); initprintf("Mapster32 %s %s %s\n", VERSION, s_buildRev, s_buildInfo); @@ -9766,11 +9755,13 @@ static int32_t parsegroupfiles(scriptfile *script) return 0; } -int32_t loadgroupfiles(const char *fn) +int32_t loaddefinitions_game(const char *fn, int32_t preload) { scriptfile *script; int32_t i; + UNREFERENCED_PARAMETER(preload); + script = scriptfile_fromfile(fn); if (!script) return -1; @@ -10362,149 +10353,13 @@ static void M32_HandleMemErr(int32_t line, const char *file, const char *func) int32_t ExtInit(void) { int32_t rv = 0; - int32_t i; - char cwd[BMAX_PATH]; set_memerr_handler(&M32_HandleMemErr); - G_AddSearchPaths(); - - if (getcwd(cwd,BMAX_PATH)) - { -#if defined(__APPLE__) - /* Dirty hack on OS X to also look for gamedata inside the application bundle - rhoenie 08/08 */ - char seekinappcontainer[BMAX_PATH]; - Bsnprintf(seekinappcontainer,sizeof(seekinappcontainer),"%s/EDuke32.app/", cwd); - addsearchpath(seekinappcontainer); -#endif - addsearchpath(cwd); - Bstrcpy(program_origcwd, cwd); - } - else - program_origcwd[0] = '\0'; - - if (CommandPaths) - { - struct strllist *s; - while (CommandPaths) - { - s = CommandPaths->next; - i = addsearchpath(CommandPaths->str); - if (i < 0) - { - initprintf("Failed adding %s for game data: %s\n", CommandPaths->str, - i==-1 ? "not a directory" : "no such directory"); - } - - Bfree(CommandPaths->str); - Bfree(CommandPaths); - CommandPaths = s; - } - } - -#if defined(_WIN32) - if (!access("user_profiles_enabled", F_OK)) -#else - if (usecwd == 0 && access("user_profiles_disabled", F_OK)) -#endif - { - char *homedir; - int32_t asperr; - - if ((homedir = Bgethomedir())) - { - Bsnprintf(cwd,sizeof(cwd),"%s/" -#if defined(_WIN32) - "EDuke32 Settings" -#elif defined(__APPLE__) - "Library/Application Support/EDuke32" -#elif defined(GEKKO) - "apps/eduke32" -#else - ".eduke32" -#endif - ,homedir); - asperr = addsearchpath(cwd); - if (asperr == -2) - { - if (Bmkdir(cwd,S_IRWXU) == 0) asperr = addsearchpath(cwd); - else asperr = -1; - } - if (asperr == 0) - chdir(cwd); - Bfree(homedir); - } - } - - { - // JBF 20031220: Because it's annoying renaming GRP files whenever I want to test different game data - // (CODEDUP game.c) - if (g_grpNamePtr == NULL) - { - const char *cp = getenv("DUKE3DGRP"); - if (cp) - { - clearGrpNamePtr(); - g_grpNamePtr = dup_filename(cp); - initprintf("Using \"%s\" as main GRP file\n", g_grpNamePtr); - } - } - - { - const char *grpfile = G_GrpFile(); - - i = initgroupfile(grpfile); - - if (!NoAutoLoad) - { - G_LoadGroupsInDir("autoload"); - - if (i != -1) - G_DoAutoload(grpfile); - } - } - } - - // (CODEDUP game.c) - if (g_defNamePtr == NULL) - { - const char *tmpptr = getenv("DUKE3DDEF"); - if (tmpptr) - { - clearDefNamePtr(); - g_defNamePtr = dup_filename(tmpptr); - initprintf("Using \"%s\" as definitions file\n", g_defNamePtr); - } - } - - loadgroupfiles(G_DefFile()); // the defs are actually loaded in app_main in build.c - - { - struct strllist *s; - int32_t j; - - pathsearchmode = 1; - while (CommandGrps) - { - s = CommandGrps->next; - j = initgroupfile(CommandGrps->str); - if (j == -1) initprintf("Could not find group file \"%s\".\n",CommandGrps->str); - else - { - initprintf("Using group file \"%s\".\n",CommandGrps->str); - if (!NoAutoLoad) - G_DoAutoload(CommandGrps->str); - } - - Bfree(CommandGrps->str); - Bfree(CommandGrps); - CommandGrps = s; - } - pathsearchmode = 0; - } - if (!usecwd) - G_CleanupSearchPaths(); + G_AddSearchPaths(); + + G_ExtInit(); bpp = 32; @@ -10517,25 +10372,12 @@ int32_t ExtInit(void) //#endif Bmemcpy(buildkeys, default_buildkeys, NUMBUILDKEYS); //Trick to make build use setup.dat keys - if (initengine()) - { - initprintf("There was a problem initializing the engine.\n"); - return -1; - } - - setbasepaltable(basepaltable, BASEPALCOUNT); - kensplayerheight = 40; //32 zmode = 2; zlock = kensplayerheight<<8; showinvisibility = 1; - if (ReadPaletteTable()) - return -1; - - InitCustomColors(); - getmessageleng = 0; getmessagetimeoff = 0; @@ -10559,6 +10401,34 @@ int32_t ExtInit(void) // backup pathsearchmode so that a later open // will hopefully be the same file pathsearchmode_oninit = pathsearchmode; + + G_ExtPreStartupWindow(); + + signal(SIGINT, m32script_interrupt_handler); + + return rv; +} + +int32_t ExtPostStartupWindow(void) +{ + G_ExtPostStartupWindow(!NoAutoLoad); + + if (!usecwd) + G_CleanupSearchPaths(); + + if (initengine()) + { + initprintf("There was a problem initializing the engine.\n"); + return -1; + } + + setbasepaltable(basepaltable, BASEPALCOUNT); + + if (ReadPaletteTable()) + return -1; + + InitCustomColors(); + loadtilegroups(default_tiles_cfg); ReadHelpFile("m32help.hlp"); @@ -10581,9 +10451,7 @@ int32_t ExtInit(void) } #endif - signal(SIGINT, m32script_interrupt_handler); - - return rv; + return 0; } void app_crashhandler(void) diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index f7d7ddfb6..9526744d5 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -9,6 +9,7 @@ #include "kplib.h" #include "baselayer.h" #include "names.h" +#include "grpscan.h" #ifdef _WIN32 # include "winbits.h" @@ -41,6 +42,13 @@ const char* s_buildInfo = int32_t g_gameType = GAMEFLAG_DUKE; +int32_t g_dependencyCRC = 0; +int32_t g_usingAddon = 0; + +// g_gameNamePtr can point to one of: grpfiles[].name (string literal), string +// literal, malloc'd block (XXX: possible leak) +const char *g_gameNamePtr = NULL; + // grp/con/def handling const char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" }; @@ -270,23 +278,271 @@ void G_SetupGlobalPsky(void) ////////// -#ifdef GEKKO -#include "gctypes.h" // for bool -void L2Enhance(); -void CON_EnableGecko(int channel,int safe); -bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice); -#endif +static char g_rootDir[BMAX_PATH]; +char g_modDir[BMAX_PATH] = "/"; -void G_ExtPreInit(void) +int32_t kopen4loadfrommod(const char *filename, char searchfirst) { -#ifdef GEKKO - L2Enhance(); - CON_EnableGecko(1, 1); - Bprintf("Console started\n"); - fatInit(28, true); + int32_t r=-1; + + if (g_modDir[0]!='/' || g_modDir[1]!=0) + { + static char fn[BMAX_PATH]; + + Bsnprintf(fn, sizeof(fn), "%s/%s",g_modDir,filename); + r = kopen4load(fn,searchfirst); + } + + if (r < 0) + r = kopen4load(filename,searchfirst); + + return r; +} + +int32_t usecwd; +static void G_LoadAddon(void); +int32_t g_groupFileHandle; + +void G_ExtPreInit(int32_t argc,const char **argv) +{ + usecwd = G_CheckCmdSwitch(argc, argv, "-usecwd"); + +#ifdef _WIN32 + GetModuleFileName(NULL,g_rootDir,BMAX_PATH); + Bcorrectfilename(g_rootDir,1); + //chdir(g_rootDir); +#else + getcwd(g_rootDir,BMAX_PATH); + strcat(g_rootDir,"/"); #endif } +void G_ExtInit(void) +{ + char cwd[BMAX_PATH]; + + if (getcwd(cwd,BMAX_PATH)) + { +#if defined(__APPLE__) + /* Dirty hack on OS X to also look for gamedata inside the application bundle - rhoenie 08/08 */ + char seekinappcontainer[BMAX_PATH]; + Bsnprintf(seekinappcontainer,sizeof(seekinappcontainer),"%s/EDuke32.app/", cwd); + addsearchpath(seekinappcontainer); +#endif + addsearchpath(cwd); + } + + if (CommandPaths) + { + int32_t i; + struct strllist *s; + while (CommandPaths) + { + s = CommandPaths->next; + i = addsearchpath(CommandPaths->str); + if (i < 0) + { + initprintf("Failed adding %s for game data: %s\n", CommandPaths->str, + i==-1 ? "not a directory" : "no such directory"); + } + + Bfree(CommandPaths->str); + Bfree(CommandPaths); + CommandPaths = s; + } + } + +#if defined(_WIN32) + if (!access("user_profiles_enabled", F_OK)) +#else + if (usecwd == 0 && access("user_profiles_disabled", F_OK)) +#endif + { + char *homedir; + int32_t asperr; + + if ((homedir = Bgethomedir())) + { + Bsnprintf(cwd,sizeof(cwd),"%s/" +#if defined(_WIN32) + "EDuke32 Settings" +#elif defined(__APPLE__) + "Library/Application Support/EDuke32" +#elif defined(GEKKO) + "apps/eduke32" +#else + ".eduke32" +#endif + ,homedir); + asperr = addsearchpath(cwd); + if (asperr == -2) + { + if (Bmkdir(cwd,S_IRWXU) == 0) asperr = addsearchpath(cwd); + else asperr = -1; + } + if (asperr == 0) + chdir(cwd); + Bfree(homedir); + } + } + + // JBF 20031220: Because it's annoying renaming GRP files whenever I want to test different game data + if (g_grpNamePtr == NULL) + { + const char *cp = getenv("DUKE3DGRP"); + if (cp) + { + clearGrpNamePtr(); + g_grpNamePtr = dup_filename(cp); + initprintf("Using \"%s\" as main GRP file\n", g_grpNamePtr); + } + } +} + +void G_ExtPreStartupWindow(void) +{ + ScanGroups(); + { + // try and identify the 'defaultgamegrp' in the set of GRPs. + // if it is found, set up the environment accordingly for the game it represents. + // if it is not found, choose the first GRP from the list + struct grpfile *fg, *first = NULL; + + for (fg = foundgrps; fg; fg=fg->next) + { + struct grpfile *grp; + for (grp = listgrps; grp; grp=grp->next) + if (fg->crcval == grp->crcval) break; + + if (grp == NULL) + continue; + + fg->game = grp->game; + if (!first) first = fg; + if (!Bstrcasecmp(fg->name, G_DefaultGrpFile())) + { + g_gameType = grp->game; + g_gameNamePtr = grp->name; + break; + } + } + if (!fg && first) + { + if (g_grpNamePtr == NULL) + { + clearGrpNamePtr(); + g_grpNamePtr = dup_filename(first->name); + } + g_gameType = first->game; + g_gameNamePtr = listgrps->name; + } + else if (!fg) g_gameNamePtr = NULL; + } +} + +void G_ExtPostStartupWindow(int32_t autoload) +{ + if (g_modDir[0] != '/') + { + char cwd[BMAX_PATH]; + + Bstrcat(g_rootDir,g_modDir); + addsearchpath(g_rootDir); +// addsearchpath(mod_dir); + + if (getcwd(cwd,BMAX_PATH)) + { + Bsprintf(cwd,"%s/%s",cwd,g_modDir); + if (!Bstrcmp(g_rootDir, cwd)) + { + if (addsearchpath(cwd) == -2) + if (Bmkdir(cwd,S_IRWXU) == 0) addsearchpath(cwd); + } + } + +#ifdef USE_OPENGL + Bsprintf(cwd,"%s/%s",g_modDir,TEXCACHEFILE); + Bstrcpy(TEXCACHEFILE,cwd); +#endif + } + + if (g_usingAddon) + G_LoadAddon(); + + { + int32_t i; + const char *grpfile = G_GrpFile(); + + if (g_dependencyCRC) + { + struct grpfile * grp = FindGroup(g_dependencyCRC); + if (grp) + { + if ((i = initgroupfile(grp->name)) == -1) + initprintf("Warning: could not find main data file \"%s\"!\n",grp->name); + else + initprintf("Using \"%s\" as main game data file.\n", grp->name); + } + } + + if ((i = initgroupfile(grpfile)) == -1) + initprintf("Warning: could not find main data file \"%s\"!\n",grpfile); + else + initprintf("Using \"%s\" as main game data file.\n", grpfile); + + if (autoload) + { + G_LoadGroupsInDir("autoload"); + + if (i != -1) + G_DoAutoload(grpfile); + } + } + + if (g_modDir[0] != '/') + G_LoadGroupsInDir(g_modDir); + + if (g_defNamePtr == NULL) + { + const char *tmpptr = getenv("DUKE3DDEF"); + if (tmpptr) + { + clearDefNamePtr(); + g_defNamePtr = dup_filename(tmpptr); + initprintf("Using \"%s\" as definitions file\n", g_defNamePtr); + } + } + + loaddefinitions_game(G_DefFile(), TRUE); + + { + struct strllist *s; + + pathsearchmode = 1; + while (CommandGrps) + { + int32_t j; + + s = CommandGrps->next; + + if ((j = initgroupfile(CommandGrps->str)) == -1) + initprintf("Could not find file \"%s\".\n",CommandGrps->str); + else + { + g_groupFileHandle = j; + initprintf("Using file \"%s\" as game data.\n",CommandGrps->str); + if (autoload) + G_DoAutoload(CommandGrps->str); + } + + Bfree(CommandGrps->str); + Bfree(CommandGrps); + CommandGrps = s; + } + pathsearchmode = 0; + } +} + #ifdef _WIN32 const char * G_GetInstallPath(int32_t insttype) { @@ -323,6 +579,52 @@ const char * G_GetInstallPath(int32_t insttype) } #endif +static void G_LoadAddon(void) +{ + struct grpfile * grp; + int32_t crc = 0; // compiler-happy + + switch (g_usingAddon) + { + case ADDON_DUKEDC: + crc = DUKEDC_CRC; + break; + case ADDON_NWINTER: + crc = DUKENW_CRC; + break; + case ADDON_CARIBBEAN: + crc = DUKECB_CRC; + break; + } + + if (!crc) return; + + grp = FindGroup(crc); + + if (grp && FindGroup(DUKE15_CRC)) + { + clearGrpNamePtr(); + g_grpNamePtr = dup_filename(FindGroup(DUKE15_CRC)->name); + + G_AddGroup(grp->name); + + for (grp = listgrps; grp; grp=grp->next) + if (crc == grp->crcval) break; + + if (grp != NULL && grp->scriptname) + { + clearScriptNamePtr(); + g_scriptNamePtr = dup_filename(grp->scriptname); + } + + if (grp != NULL && grp->defname) + { + clearDefNamePtr(); + g_defNamePtr = dup_filename(grp->defname); + } + } +} + void G_AddSearchPaths(void) { #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) @@ -340,10 +642,10 @@ void G_AddSearchPaths(void) if ((instpath = G_GetInstallPath(INSTPATH_STEAM))) { - Bsprintf(buf, "%s/gameroot", instpath); + Bsnprintf(buf, sizeof(buf), "%s/gameroot", instpath); addsearchpath(buf); - Bsprintf(buf, "%s/gameroot/addons", instpath); + Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons", instpath); addsearchpath(buf); } @@ -360,10 +662,10 @@ void G_CleanupSearchPaths(void) if ((instpath = G_GetInstallPath(INSTPATH_STEAM))) { - Bsprintf(buf, "%s/gameroot", instpath); + Bsnprintf(buf, sizeof(buf), "%s/gameroot", instpath); removesearchpath(buf); - Bsprintf(buf, "%s/gameroot/addons", instpath); + Bsnprintf(buf, sizeof(buf), "%s/gameroot/addons", instpath); removesearchpath(buf); } @@ -482,6 +784,18 @@ int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) ////////// +int32_t G_CheckCmdSwitch(int32_t argc, const char **argv, const char *str) +{ + int32_t i; + for (i=0; iname); - - G_AddGroup(grp->name); - - for (grp = listgrps; grp; grp=grp->next) - if (crc == grp->crcval) break; - - if (grp != NULL && grp->scriptname) - { - clearScriptNamePtr(); - g_scriptNamePtr = dup_filename(grp->scriptname); - } - - if (grp != NULL && grp->defname) - { - clearDefNamePtr(); - g_defNamePtr = dup_filename(grp->defname); - } - } -} - EDUKE32_STATIC_ASSERT(sizeof(actor_t)==128); EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t)%4 == 0); int32_t app_main(int32_t argc, const char **argv) { int32_t i = 0, j; - char cwd[BMAX_PATH]; - - G_ExtPreInit(); #ifndef NETCODE_DISABLE if (enet_initialize() != 0) @@ -11219,8 +11128,6 @@ int32_t app_main(int32_t argc, const char **argv) else atexit(enet_deinitialize); #endif - usecwd = G_CheckCmdSwitch(argc, argv, "-usecwd"); - #ifdef _WIN32 if (!G_CheckCmdSwitch(argc, argv, "-noinstancechecking") && win_checkinstance()) { @@ -11235,15 +11142,10 @@ int32_t app_main(int32_t argc, const char **argv) extern int32_t (*check_filename_casing_fn)(void); check_filename_casing_fn = check_filename_casing; } - - tempbuf[GetModuleFileName(NULL,g_rootDir,BMAX_PATH)] = 0; - Bcorrectfilename(g_rootDir,1); - //chdir(g_rootDir); -#else - getcwd(g_rootDir,BMAX_PATH); - strcat(g_rootDir,"/"); #endif + G_ExtPreInit(argc, argv); + OSD_SetParameters(0,0, 0,12, 2,12); #ifdef __APPLE__ @@ -11280,6 +11182,8 @@ int32_t app_main(int32_t argc, const char **argv) if (!usecwd) G_AddSearchPaths(); + G_ExtInit(); + g_numSkills = 4; ud.multimode = 1; @@ -11296,70 +11200,6 @@ int32_t app_main(int32_t argc, const char **argv) if (forcegl) initprintf("GL driver blacklist disabled.\n"); #endif - if (getcwd(cwd,BMAX_PATH)) - { - addsearchpath(cwd); -#if defined(__APPLE__) - /* Dirty hack on OS X to also look for gamedata inside the application bundle - rhoenie 08/08 */ - char seekinappcontainer[BMAX_PATH]; - Bsnprintf(seekinappcontainer,sizeof(seekinappcontainer),"%s/EDuke32.app/", cwd); - addsearchpath(seekinappcontainer); -#endif - } - - if (CommandPaths) - { - struct strllist *s; - while (CommandPaths) - { - s = CommandPaths->next; - i = addsearchpath(CommandPaths->str); - if (i < 0) - { - initprintf("Failed adding %s for game data: %s\n", CommandPaths->str, - i==-1 ? "not a directory" : "no such directory"); - } - - Bfree(CommandPaths->str); - Bfree(CommandPaths); - CommandPaths = s; - } - } - -#if defined(_WIN32) - if (!access("user_profiles_enabled", F_OK)) -#else - if (usecwd == 0 && access("user_profiles_disabled", F_OK)) -#endif - { - char *homedir; - int32_t asperr; - - if ((homedir = Bgethomedir())) - { - Bsnprintf(cwd,sizeof(cwd),"%s/" -#if defined(_WIN32) - "EDuke32 Settings" -#elif defined(__APPLE__) - "Library/Application Support/EDuke32" -#elif defined(GEKKO) - "apps/eduke32" -#else - ".eduke32" -#endif - ,homedir); - asperr = addsearchpath(cwd); - if (asperr == -2) - { - if (Bmkdir(cwd,S_IRWXU) == 0) asperr = addsearchpath(cwd); - else asperr = -1; - } - if (asperr == 0) - chdir(cwd); - Bfree(homedir); - } - } - // used with binds for fast function lookup hash_init(&h_gamefuncs); for (i=NUMGAMEFUNCTIONS-1; i>=0; i--) @@ -11376,18 +11216,6 @@ int32_t app_main(int32_t argc, const char **argv) i = CONFIG_ReadSetup(); - // CODEDUP astub.c - if (g_grpNamePtr == NULL) - { - const char *cp = getenv("DUKE3DGRP"); - if (cp) - { - clearGrpNamePtr(); - g_grpNamePtr = dup_filename(cp); - initprintf("Using \"%s\" as main GRP file\n", g_grpNamePtr); - } - } - #ifdef _WIN32 // initprintf("build %d\n",(uint8_t)Batoi(BUILDDATE)); @@ -11450,43 +11278,7 @@ int32_t app_main(int32_t argc, const char **argv) if (Bstrcmp(setupfilename, SETUPFILENAME)) initprintf("Using config file \"%s\".\n",setupfilename); - ScanGroups(); - { - // try and identify the 'defaultgamegrp' in the set of GRPs. - // if it is found, set up the environment accordingly for the game it represents. - // if it is not found, choose the first GRP from the list - struct grpfile *fg, *first = NULL; - - for (fg = foundgrps; fg; fg=fg->next) - { - struct grpfile *grp; - for (grp = listgrps; grp; grp=grp->next) - if (fg->crcval == grp->crcval) break; - - if (grp == NULL) - continue; - - fg->game = grp->game; - if (!first) first = fg; - if (!Bstrcasecmp(fg->name, G_DefaultGrpFile())) - { - g_gameType = grp->game; - g_gameNamePtr = grp->name; - break; - } - } - if (!fg && first) - { - if (g_grpNamePtr == NULL) - { - clearGrpNamePtr(); - g_grpNamePtr = dup_filename(first->name); - } - g_gameType = first->game; - g_gameNamePtr = listgrps->name; - } - else if (!fg) g_gameNamePtr = NULL; - } + G_ExtPreStartupWindow(); #ifdef STARTUP_SETUP_WINDOW if (i < 0 || (!g_noSetup && (ud.configversion != BYTEVERSION_JF || ud.config.ForceSetup)) || g_commandSetup) @@ -11505,106 +11297,10 @@ int32_t app_main(int32_t argc, const char **argv) Bstrcpy(GametypeNames[2],"GruntMatch (No Spawn)"); } - if (g_modDir[0] != '/') - { - char cwd[BMAX_PATH]; - - Bstrcat(g_rootDir,g_modDir); - addsearchpath(g_rootDir); -// addsearchpath(mod_dir); - - if (getcwd(cwd,BMAX_PATH)) - { - Bsprintf(cwd,"%s/%s",cwd,g_modDir); - if (!Bstrcmp(g_rootDir, cwd)) - { - if (addsearchpath(cwd) == -2) - if (Bmkdir(cwd,S_IRWXU) == 0) addsearchpath(cwd); - } - } - -#ifdef USE_OPENGL - Bsprintf(tempbuf,"%s/%s",g_modDir,TEXCACHEFILE); - Bstrcpy(TEXCACHEFILE,tempbuf); -#endif - } - - if (g_usingAddon) - G_LoadAddon(); - - { - const char *grpfile = G_GrpFile(); - - if (g_dependencyCRC) - { - struct grpfile * grp = FindGroup(g_dependencyCRC); - if (grp) - { - if ((i = initgroupfile(grp->name)) == -1) - initprintf("Warning: could not find main data file \"%s\"!\n",grp->name); - else - initprintf("Using \"%s\" as main game data file.\n", grp->name); - } - } - - if ((i = initgroupfile(grpfile)) == -1) - initprintf("Warning: could not find main data file \"%s\"!\n",grpfile); - else - initprintf("Using \"%s\" as main game data file.\n", grpfile); - - if (!g_noAutoLoad && !ud.config.NoAutoLoad) - { - G_LoadGroupsInDir("autoload"); - - if (i != -1) - G_DoAutoload(grpfile); - } - } - - if (g_modDir[0] != '/') - G_LoadGroupsInDir(g_modDir); - - // CODEDUP astub.c - if (g_defNamePtr == NULL) - { - const char *tmpptr = getenv("DUKE3DDEF"); - if (tmpptr) - { - clearDefNamePtr(); - g_defNamePtr = dup_filename(tmpptr); - initprintf("Using \"%s\" as definitions file\n", g_defNamePtr); - } - } - flushlogwindow = 0; - loaddefinitions_game(G_DefFile(), TRUE); + G_ExtPostStartupWindow(!g_noAutoLoad && !ud.config.NoAutoLoad); // flushlogwindow = 1; - { - struct strllist *s; - - pathsearchmode = 1; - while (CommandGrps) - { - s = CommandGrps->next; - - if ((j = initgroupfile(CommandGrps->str)) == -1) - initprintf("Could not find file \"%s\".\n",CommandGrps->str); - else - { - g_groupFileHandle = j; - initprintf("Using file \"%s\" as game data.\n",CommandGrps->str); - if (!g_noAutoLoad && !ud.config.NoAutoLoad) - G_DoAutoload(CommandGrps->str); - } - - Bfree(CommandGrps->str); - Bfree(CommandGrps); - CommandGrps = s; - } - pathsearchmode = 0; - } - if (!usecwd) G_CleanupSearchPaths(); diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index d02ba865a..234179bc8 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -257,7 +257,7 @@ typedef struct { // this is checked against http://eduke32.com/VERSION extern const char *s_buildDate; -extern const char *g_gameNamePtr; + extern const char *g_rtsNamePtr; extern char CheatStrings[][MAXCHEATLEN]; @@ -267,7 +267,6 @@ extern char boardfilename[BMAX_PATH]; extern const char *defaultrtsfilename[GAMECOUNT]; extern const char *G_DefaultRtsFile(void); -extern char g_modDir[BMAX_PATH]; #ifdef LEGACY_ROR extern char ror_protectedsectors[MAXSECTORS]; #endif @@ -286,7 +285,6 @@ extern int32_t g_cameraClock; extern int32_t g_cameraDistance; #endif extern int32_t g_crosshairSum; -extern int32_t g_dependencyCRC; extern int32_t g_doQuickSave; extern int32_t g_forceWeaponChoice; extern int32_t g_fakeMultiMode; @@ -294,7 +292,6 @@ extern int32_t g_levelTextTime; extern int32_t g_noSetup; extern int32_t g_quitDeadline; extern int32_t g_restorePalette; -extern int32_t g_usingAddon; extern int32_t hud_glowingquotes; extern int32_t hud_showmapname; extern int32_t quotebot; diff --git a/polymer/eduke32/source/global.h b/polymer/eduke32/source/global.h index 30b3a1266..995045b35 100644 --- a/polymer/eduke32/source/global.h +++ b/polymer/eduke32/source/global.h @@ -93,7 +93,6 @@ G_EXTERN int32_t g_damageCameras,g_freezerSelfDamage; G_EXTERN int32_t g_doQuickSave; G_EXTERN uint16_t g_earthquakeTime; G_EXTERN int32_t g_gameQuit; -G_EXTERN int32_t g_groupFileHandle; G_EXTERN int32_t g_impactDamage,g_maxPlayerHealth; G_EXTERN int32_t g_musicSize; G_EXTERN int32_t g_numLabels,g_numDefaultLabels;