moved Host_Game_f to common.c, made it to use COM_AddGameDirectory(). moved in-memory pak structures, searchpatch structure and searchpath global declarations to common.h. adjusted affected extra patches.

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1003 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2014-09-08 21:10:33 +00:00
parent dc4799f48a
commit 717b452da0
5 changed files with 121 additions and 249 deletions

View file

@ -4,9 +4,9 @@ might not be compatible with the homedir patch yet -- O.S.
Index: Quake/common.c Index: Quake/common.c
=================================================================== ===================================================================
--- Quake/common.c (revision 998) --- Quake/common.c (revision 1003)
+++ Quake/common.c (working copy) +++ Quake/common.c (working copy)
@@ -1926,13 +1926,6 @@ static void COM_AddGameDirectory (const @@ -1898,13 +1898,6 @@ static void COM_AddGameDirectory (const
path_id = com_searchpaths->path_id << 1; path_id = com_searchpaths->path_id << 1;
else path_id = 1U; else path_id = 1U;
@ -20,7 +20,7 @@ Index: Quake/common.c
// add any pak files in the format pak0.pak pak1.pak, ... // add any pak files in the format pak0.pak pak1.pak, ...
for (i = 0; ; i++) for (i = 0; ; i++)
{ {
@@ -1962,6 +1955,13 @@ static void COM_AddGameDirectory (const @@ -1934,6 +1927,13 @@ static void COM_AddGameDirectory (const
} }
if (!pak) break; if (!pak) break;
} }
@ -33,35 +33,4 @@ Index: Quake/common.c
+ com_searchpaths = search; + com_searchpaths = search;
} }
/* //==============================================================================
Index: Quake/host_cmd.c
===================================================================
--- Quake/host_cmd.c (revision 998)
+++ Quake/host_cmd.c (working copy)
@@ -153,11 +153,6 @@ void Host_Game_f (void)
if (com_searchpaths)
path_id = com_searchpaths->path_id << 1;
else path_id = 1U;
- search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
- search->path_id = path_id;
- q_strlcpy (search->filename, com_gamedir, sizeof(search->filename));
- search->next = com_searchpaths;
- com_searchpaths = search;
//Load the paks if any are found:
for (i = 0; ; i++)
@@ -172,6 +167,13 @@ void Host_Game_f (void)
search->next = com_searchpaths;
com_searchpaths = search;
}
+
+ // moved here from before the pakX.pak loop -- svdijk
+ search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
+ search->path_id = path_id;
+ q_strlcpy (search->filename, com_gamedir, sizeof(search->filename));
+ search->next = com_searchpaths;
+ com_searchpaths = search;
}
//clear out and reload appropriate data

View file

@ -4,7 +4,7 @@ initial support for user directories, based on uhexen2 and tyrquake.
Index: Quake/sys_sdl_unix.c Index: Quake/sys_sdl_unix.c
=================================================================== ===================================================================
--- Quake/sys_sdl_unix.c (revision 998) --- Quake/sys_sdl_unix.c (revision 1003)
+++ Quake/sys_sdl_unix.c (working copy) +++ Quake/sys_sdl_unix.c (working copy)
@@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
@ -72,9 +72,9 @@ Index: Quake/sys_sdl_unix.c
void Sys_mkdir (const char *path) void Sys_mkdir (const char *path)
Index: Quake/common.c Index: Quake/common.c
=================================================================== ===================================================================
--- Quake/common.c (revision 998) --- Quake/common.c (revision 1003)
+++ Quake/common.c (working copy) +++ Quake/common.c (working copy)
@@ -1918,6 +1918,7 @@ static void COM_AddGameDirectory (const @@ -1890,6 +1890,7 @@ static void COM_AddGameDirectory (const
searchpath_t *search; searchpath_t *search;
pack_t *pak, *qspak; pack_t *pak, *qspak;
char pakfile[MAX_OSPATH]; char pakfile[MAX_OSPATH];
@ -82,7 +82,7 @@ Index: Quake/common.c
q_strlcpy (com_gamedir, va("%s/%s", base, dir), sizeof(com_gamedir)); q_strlcpy (com_gamedir, va("%s/%s", base, dir), sizeof(com_gamedir));
@@ -1926,6 +1927,7 @@ static void COM_AddGameDirectory (const @@ -1898,6 +1899,7 @@ static void COM_AddGameDirectory (const
path_id = com_searchpaths->path_id << 1; path_id = com_searchpaths->path_id << 1;
else path_id = 1U; else path_id = 1U;
@ -90,7 +90,7 @@ Index: Quake/common.c
// add the directory to the search path // add the directory to the search path
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t)); search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
search->path_id = path_id; search->path_id = path_id;
@@ -1942,6 +1944,7 @@ static void COM_AddGameDirectory (const @@ -1914,6 +1916,7 @@ static void COM_AddGameDirectory (const
qspak = NULL; qspak = NULL;
else { else {
qboolean old = com_modified; qboolean old = com_modified;
@ -98,7 +98,7 @@ Index: Quake/common.c
q_snprintf (pakfile, sizeof(pakfile), "%s/quakespasm.pak", base); q_snprintf (pakfile, sizeof(pakfile), "%s/quakespasm.pak", base);
qspak = COM_LoadPackFile (pakfile); qspak = COM_LoadPackFile (pakfile);
com_modified = old; com_modified = old;
@@ -1962,6 +1965,14 @@ static void COM_AddGameDirectory (const @@ -1934,6 +1937,14 @@ static void COM_AddGameDirectory (const
} }
if (!pak) break; if (!pak) break;
} }
@ -112,36 +112,5 @@ Index: Quake/common.c
+ } + }
} }
/* //==============================================================================
Index: Quake/host_cmd.c
===================================================================
--- Quake/host_cmd.c (revision 998)
+++ Quake/host_cmd.c (working copy)
@@ -149,10 +149,12 @@ void Host_Game_f (void)
if (q_strcasecmp(p, GAMENAME)) //game is not id1
{
+ qboolean been_here = false;
// assign a path_id to this game directory
if (com_searchpaths)
path_id = com_searchpaths->path_id << 1;
else path_id = 1U;
+ _add_path:
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
search->path_id = path_id;
q_strlcpy (search->filename, com_gamedir, sizeof(search->filename));
@@ -172,6 +174,14 @@ void Host_Game_f (void)
search->next = com_searchpaths;
com_searchpaths = search;
}
+
+ if (!been_here && host_parms->userdir != host_parms->basedir)
+ {
+ been_here = true;
+ q_strlcpy(com_gamedir, va("%s/%s", host_parms->userdir, p), sizeof(com_gamedir));
+ Sys_mkdir(com_gamedir);
+ goto _add_path;
+ }
}
//clear out and reload appropriate data

View file

@ -32,7 +32,7 @@ int safemode;
cvar_t registered = {"registered","1",CVAR_ROM}; /* set to correct value in COM_CheckRegistered() */ cvar_t registered = {"registered","1",CVAR_ROM}; /* set to correct value in COM_CheckRegistered() */
cvar_t cmdline = {"cmdline","",CVAR_ROM/*|CVAR_SERVERINFO*/}; /* sending cmdline upon CCREQ_RULE_INFO is evil */ cvar_t cmdline = {"cmdline","",CVAR_ROM/*|CVAR_SERVERINFO*/}; /* sending cmdline upon CCREQ_RULE_INFO is evil */
qboolean com_modified; // set true if using non-id files static qboolean com_modified; // set true if using non-id files
qboolean fitzmode; qboolean fitzmode;
@ -1414,25 +1414,7 @@ int com_filesize;
// //
// in memory // on-disk pakfile
//
typedef struct
{
char name[MAX_QPATH];
int filepos, filelen;
} packfile_t;
typedef struct pack_s
{
char filename[MAX_OSPATH];
int handle;
int numfiles;
packfile_t *files;
} pack_t;
//
// on disk
// //
typedef struct typedef struct
{ {
@ -1453,16 +1435,6 @@ char com_gamedir[MAX_OSPATH];
char com_basedir[MAX_OSPATH]; char com_basedir[MAX_OSPATH];
int file_from_pak; // ZOID: global indicating that file came from a pak int file_from_pak; // ZOID: global indicating that file came from a pak
typedef struct searchpath_s
{
unsigned int path_id; // identifier assigned to the game directory
// Note that <install_dir>/game1 and
// <userdir>/game1 have the same id.
char filename[MAX_OSPATH];
pack_t *pack; // only one of filename / pack will be used
struct searchpath_s *next;
} searchpath_t;
searchpath_t *com_searchpaths; searchpath_t *com_searchpaths;
searchpath_t *com_base_searchpaths; searchpath_t *com_base_searchpaths;
@ -1842,7 +1814,7 @@ Loads the header and directory, adding the files at the beginning
of the list so they override previous pack files. of the list so they override previous pack files.
================= =================
*/ */
pack_t *COM_LoadPackFile (const char *packfile) static pack_t *COM_LoadPackFile (const char *packfile)
{ {
dpackheader_t header; dpackheader_t header;
int i; int i;
@ -1964,6 +1936,79 @@ static void COM_AddGameDirectory (const char *base, const char *dir)
} }
} }
//==============================================================================
//johnfitz -- dynamic gamedir stuff -- modified by QuakeSpasm team.
//==============================================================================
void ExtraMaps_NewGame (void);
static void COM_Game_f (void)
{
if (Cmd_Argc() > 1)
{
const char *p = Cmd_Argv(1);
searchpath_t *search;
if (!registered.value) //disable shareware quake
{
Con_Printf("You must have the registered version to use modified games\n");
return;
}
if (!strcmp(p, ".") || strstr(p, "..") || strstr(p, "/") || strstr(p, "\\") || strstr(p, ":"))
{
Con_Printf ("gamedir should be a single directory name, not a path\n");
return;
}
if (!q_strcasecmp(p, COM_SkipPath(com_gamedir))) //no change
{
Con_Printf("\"game\" is already \"%s\"\n", COM_SkipPath(com_gamedir));
return;
}
com_modified = true;
//Kill the server
CL_Disconnect ();
Host_ShutdownServer(true);
//Write config file
Host_WriteConfiguration ();
//Kill the extra game if it is loaded
while (com_searchpaths != com_base_searchpaths)
{
if (com_searchpaths->pack)
{
Sys_FileClose (com_searchpaths->pack->handle);
Z_Free (com_searchpaths->pack->files);
Z_Free (com_searchpaths->pack);
}
search = com_searchpaths->next;
Z_Free (com_searchpaths);
com_searchpaths = search;
}
if (q_strcasecmp(p, GAMENAME)) //game is not id1
COM_AddGameDirectory (com_basedir, p);
//clear out and reload appropriate data
Cache_Flush ();
Mod_ResetAll();
if (!isDedicated)
{
TexMgr_NewGame ();
Draw_NewGame ();
R_NewGame ();
}
ExtraMaps_NewGame ();
//Cbuf_InsertText ("exec quake.rc\n");
Con_Printf("\"game\" changed to \"%s\"\n", COM_SkipPath(com_gamedir));
}
else //Diplay the current gamedir
Con_Printf("\"game\" is \"%s\"\n", COM_SkipPath(com_gamedir));
}
/* /*
================= =================
COM_InitFilesystem COM_InitFilesystem
@ -1976,6 +2021,7 @@ void COM_InitFilesystem (void) //johnfitz -- modified based on topaz's tutorial
Cvar_RegisterVariable (&registered); Cvar_RegisterVariable (&registered);
Cvar_RegisterVariable (&cmdline); Cvar_RegisterVariable (&cmdline);
Cmd_AddCommand ("path", COM_Path_f); Cmd_AddCommand ("path", COM_Path_f);
Cmd_AddCommand ("game", COM_Game_f); //johnfitz
i = COM_CheckParm ("-basedir"); i = COM_CheckParm ("-basedir");
if (i && i < com_argc-1) if (i && i < com_argc-1)
@ -2011,8 +2057,11 @@ void COM_InitFilesystem (void) //johnfitz -- modified based on topaz's tutorial
i = COM_CheckParm ("-game"); i = COM_CheckParm ("-game");
if (i && i < com_argc-1) if (i && i < com_argc-1)
{ {
const char *p = com_argv[i + 1];
if (!strcmp(p, ".") || strstr(p, "..") || strstr(p, "/") || strstr(p, "\\") || strstr(p, ":"))
Sys_Error ("gamedir should be a single directory name, not a path\n");
com_modified = true; com_modified = true;
COM_AddGameDirectory (com_basedir, com_argv[i + 1]); COM_AddGameDirectory (com_basedir, p);
} }
COM_CheckRegistered (); COM_CheckRegistered ();

View file

@ -190,6 +190,34 @@ char *va (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
//============================================================================ //============================================================================
// QUAKEFS
typedef struct
{
char name[MAX_QPATH];
int filepos, filelen;
} packfile_t;
typedef struct pack_s
{
char filename[MAX_OSPATH];
int handle;
int numfiles;
packfile_t *files;
} pack_t;
typedef struct searchpath_s
{
unsigned int path_id; // identifier assigned to the game directory
// Note that <install_dir>/game1 and
// <userdir>/game1 have the same id.
char filename[MAX_OSPATH];
pack_t *pack; // only one of filename / pack will be used
struct searchpath_s *next;
} searchpath_t;
extern searchpath_t *com_searchpaths;
extern searchpath_t *com_base_searchpaths;
extern int com_filesize; extern int com_filesize;
struct cache_user_s; struct cache_user_s;

View file

@ -50,148 +50,6 @@ void Host_Quit_f (void)
Sys_Quit (); Sys_Quit ();
} }
//==============================================================================
//johnfitz -- dynamic gamedir stuff
//==============================================================================
// Declarations shared with common.c:
// FIXME: **** CLEAN THIS MESS!!! ***
typedef struct
{
char name[MAX_QPATH];
int filepos, filelen;
} packfile_t;
typedef struct pack_s
{
char filename[MAX_OSPATH];
int handle;
int numfiles;
packfile_t *files;
} pack_t;
typedef struct searchpath_s
{
unsigned int path_id; // identifier assigned to the game directory
// Note that <install_dir>/game1 and
// <userdir>/game1 have the same id.
char filename[MAX_OSPATH];
pack_t *pack; // only one of filename / pack will be used
struct searchpath_s *next;
} searchpath_t;
extern qboolean com_modified;
extern searchpath_t *com_searchpaths;
extern searchpath_t *com_base_searchpaths;
pack_t *COM_LoadPackFile (const char *packfile);
void ExtraMaps_NewGame (void);
/*
==================
Host_Game_f
==================
*/
void Host_Game_f (void)
{
int i;
unsigned int path_id;
searchpath_t *search;
pack_t *pak;
char pakfile[MAX_OSPATH];
if (Cmd_Argc() > 1)
{
const char *p = Cmd_Argv(1);
if (!registered.value) //disable command for shareware quake
{
Con_Printf("You must have the registered version to use modified games\n");
return;
}
if (!strcmp(p, ".") || strstr(p, "..") || strstr(p, "/") || strstr(p, "\\") || strstr(p, ":"))
{
Con_Printf ("gamedir should be a single directory name, not a path\n");
return;
}
if (!q_strcasecmp(p, COM_SkipPath(com_gamedir))) //no change
{
Con_Printf("\"game\" is already \"%s\"\n", COM_SkipPath(com_gamedir));
return;
}
com_modified = true;
//Kill the server
CL_Disconnect ();
Host_ShutdownServer(true);
//Write config file
Host_WriteConfiguration ();
//Kill the extra game if it is loaded
while (com_searchpaths != com_base_searchpaths)
{
if (com_searchpaths->pack)
{
Sys_FileClose (com_searchpaths->pack->handle);
Z_Free (com_searchpaths->pack->files);
Z_Free (com_searchpaths->pack);
}
search = com_searchpaths->next;
Z_Free (com_searchpaths);
com_searchpaths = search;
}
q_strlcpy (com_gamedir, va("%s/%s", com_basedir, p), sizeof(com_gamedir));
if (q_strcasecmp(p, GAMENAME)) //game is not id1
{
// assign a path_id to this game directory
if (com_searchpaths)
path_id = com_searchpaths->path_id << 1;
else path_id = 1U;
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
search->path_id = path_id;
q_strlcpy (search->filename, com_gamedir, sizeof(search->filename));
search->next = com_searchpaths;
com_searchpaths = search;
//Load the paks if any are found:
for (i = 0; ; i++)
{
q_snprintf (pakfile, sizeof(pakfile), "%s/pak%i.pak", com_gamedir, i);
pak = COM_LoadPackFile (pakfile);
if (!pak)
break;
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
search->path_id = path_id;
search->pack = pak;
search->next = com_searchpaths;
com_searchpaths = search;
}
}
//clear out and reload appropriate data
Cache_Flush ();
Mod_ResetAll();
if (!isDedicated)
{
TexMgr_NewGame ();
Draw_NewGame ();
R_NewGame ();
}
ExtraMaps_NewGame ();
//Cbuf_InsertText ("exec quake.rc\n");
Con_Printf("\"game\" changed to \"%s\"\n", COM_SkipPath(com_gamedir));
}
else //Diplay the current gamedir
Con_Printf("\"game\" is \"%s\"\n", COM_SkipPath(com_gamedir));
}
//============================================================================== //==============================================================================
//johnfitz -- extramaps management //johnfitz -- extramaps management
//============================================================================== //==============================================================================
@ -2278,7 +2136,6 @@ Host_InitCommands
void Host_InitCommands (void) void Host_InitCommands (void)
{ {
Cmd_AddCommand ("maps", Host_Maps_f); //johnfitz Cmd_AddCommand ("maps", Host_Maps_f); //johnfitz
Cmd_AddCommand ("game", Host_Game_f); //johnfitz
Cmd_AddCommand ("mods", Host_Mods_f); //johnfitz Cmd_AddCommand ("mods", Host_Mods_f); //johnfitz
Cmd_AddCommand ("games", Host_Mods_f); // as an alias to "mods" -- S.A. / QuakeSpasm Cmd_AddCommand ("games", Host_Mods_f); // as an alias to "mods" -- S.A. / QuakeSpasm
Cmd_AddCommand ("mapname", Host_Mapname_f); //johnfitz Cmd_AddCommand ("mapname", Host_Mapname_f); //johnfitz