summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2007-12-07 17:29:24 +0000
committerAndrey Nazarov <skuller@skuller.net>2007-12-07 17:29:24 +0000
commit439dd89a479e2d02fa40a421849c73616f92198e (patch)
tree96731a474ea0198a611f5fa03bcb360119d212a2
parent5c30b8152eb6a0fae6e50dbd834d73a2846df4ec (diff)
Optimized FS_ListFiles (and broken Windows build).
Initial changes to demo browser to support caching.
-rw-r--r--source/cl_demo.c63
-rw-r--r--source/cl_local.h2
-rw-r--r--source/cl_main.c7
-rw-r--r--source/cl_public.h10
-rw-r--r--source/com_local.h18
-rw-r--r--source/com_public.h20
-rw-r--r--source/common.c8
-rw-r--r--source/files.c433
-rw-r--r--source/q_shared.c17
-rw-r--r--source/q_shared.h12
-rw-r--r--source/sys_unix.c103
-rw-r--r--source/sys_win.c77
-rw-r--r--source/ui_atoms.c10
-rw-r--r--source/ui_demos.c218
-rw-r--r--source/ui_main.c8
-rw-r--r--source/ui_mods.c98
-rw-r--r--source/ui_playermodels.c14
-rw-r--r--source/vid_sdl.c6
18 files changed, 421 insertions, 703 deletions
diff --git a/source/cl_demo.c b/source/cl_demo.c
index 9ba42fe..5de8e14 100644
--- a/source/cl_demo.c
+++ b/source/cl_demo.c
@@ -591,39 +591,36 @@ static const char *CL_PlayDemo_g( const char *partial, int state ) {
CL_GetDemoInfo
====================
*/
-qboolean CL_GetDemoInfo( const char *path, demoInfo_t *info ) {
- fileHandle_t hFile;
- int c, protocol;
+demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info ) {
+ fileHandle_t f;
+ int c, protocol, len;
char *s, *p;
+ int clientNum;
- memset( info, 0, sizeof( *info ) );
-
- FS_FOpenFile( path, &hFile, FS_MODE_READ );
- if( !hFile ) {
- return qfalse;
+ FS_FOpenFile( path, &f, FS_MODE_READ );
+ if( !f ) {
+ return NULL;
}
- if( !CL_ReadNextDemoMessage( hFile ) ) {
+ if( !CL_ReadNextDemoMessage( f ) ) {
goto fail;
}
if( MSG_ReadByte() != svc_serverdata ) {
goto fail;
- }
-
- protocol = MSG_ReadLong();
-
- msg_read.readcount += 5;
-
- Q_strncpyz( info->gamedir, MSG_ReadString(), sizeof( info->gamedir ) );
+ }
- info->clientNum = MSG_ReadShort();
+ memset( info, 0, sizeof( *info ) );
- Q_strncpyz( info->fullLevelName, MSG_ReadString(), sizeof( info->fullLevelName ) );
+ protocol = MSG_ReadLong();
+ MSG_ReadLong();
+ MSG_ReadByte();
+ MSG_ReadString();
+ clientNum = MSG_ReadShort();
+ MSG_ReadString();
switch( protocol ) {
case PROTOCOL_VERSION_MVD:
- info->mvd = qtrue;
msg_read.readcount += 2;
break;
case PROTOCOL_VERSION_R1Q2:
@@ -639,7 +636,7 @@ qboolean CL_GetDemoInfo( const char *path, demoInfo_t *info ) {
while( 1 ) {
c = MSG_ReadByte();
if( c == -1 ) {
- if( !CL_ReadNextDemoMessage( hFile ) ) {
+ if( !CL_ReadNextDemoMessage( f ) ) {
break;
}
continue; // parse new message
@@ -649,26 +646,28 @@ qboolean CL_GetDemoInfo( const char *path, demoInfo_t *info ) {
}
c = MSG_ReadShort();
s = MSG_ReadString();
- if( c >= CS_PLAYERSKINS && c < CS_PLAYERSKINS + MAX_DEMOINFO_CLIENTS ) {
- c -= CS_PLAYERSKINS;
- Q_strncpyz( info->clients[c], s, sizeof( info->clients[0] ) );
- if( ( p = strchr( info->clients[c], '\\' ) ) != NULL ) {
- *p = 0;
- }
+ if( c >= CS_PLAYERSKINS && c < CS_PLAYERSKINS + MAX_CLIENTS ) {
+ if( c - CS_PLAYERSKINS == clientNum ) {
+ p = strchr( s, '\\' );
+ if( p ) {
+ *p = 0;
+ }
+ Q_strncpyz( info->pov, s, sizeof( info->pov ) );
+ }
} else if( c == CS_MODELS + 1 ) {
if( strlen( s ) > 9 ) {
- Q_strncpyz( info->mapname, s + 5, sizeof( info->mapname ) ); // skip "maps/"
- info->mapname[ strlen( info->mapname ) - 4 ] = 0; // cut off ".bsp"
+ len = Q_strncpyz( info->map, s + 5, sizeof( info->map ) ); // skip "maps/"
+ info->map[ len - 4 ] = 0; // cut off ".bsp"
}
}
}
- FS_FCloseFile( hFile );
- return qtrue;
+ FS_FCloseFile( f );
+ return info;
fail:
- FS_FCloseFile( hFile );
- return qfalse;
+ FS_FCloseFile( f );
+ return NULL;
}
diff --git a/source/cl_local.h b/source/cl_local.h
index 3b0daf9..3acede2 100644
--- a/source/cl_local.h
+++ b/source/cl_local.h
@@ -594,7 +594,7 @@ void CL_WriteDemoMessage( sizebuf_t *buf );
void CL_EmitDemoFrame( void );
void CL_Stop_f( void );
void CL_Record_f( void );
-qboolean CL_GetDemoInfo( const char *path, demoInfo_t *info );
+demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info );
//
diff --git a/source/cl_main.c b/source/cl_main.c
index 38116e1..71f6ebc 100644
--- a/source/cl_main.c
+++ b/source/cl_main.c
@@ -2428,7 +2428,7 @@ static void CL_MeasureStats( void ) {
if( cls.netchan ) {
int ack = cls.netchan->incoming_acknowledged;
int ping = 0;
- int i, j;
+ int i, j, k = 0;
i = ack - 16 + 1;
if( i < cl.initialSeq ) {
@@ -2438,12 +2438,11 @@ static void CL_MeasureStats( void ) {
client_history_t *h = &cl.history[j & CMD_MASK];
if( h->rcvd > h->sent ) {
ping += h->rcvd - h->sent;
+ k++;
}
}
- if( j != i ) {
- cls.ping = ping / ( j - i );
- }
+ cls.ping = k ? ping / k : 0;
}
cls.measureTime = time;
diff --git a/source/cl_public.h b/source/cl_public.h
index 38a5dd4..b495921 100644
--- a/source/cl_public.h
+++ b/source/cl_public.h
@@ -56,12 +56,8 @@ typedef struct {
} serverStatus_t;
typedef struct {
- qboolean mvd; // FIXME: can also use clientNum == -1
- int clientNum;
- char gamedir[MAX_QPATH];
- char mapname[MAX_QPATH];
- char fullLevelName[MAX_QPATH];
- char clients[MAX_DEMOINFO_CLIENTS][MAX_CLIENT_NAME];
+ char map[MAX_QPATH];
+ char pov[MAX_CLIENT_NAME];
} demoInfo_t;
typedef struct {
@@ -78,7 +74,7 @@ typedef struct {
void (*StartLocalSound)( const char *name );
void (*StopAllSounds)( void );
- qboolean (*GetDemoInfo)( const char *path, demoInfo_t *info );
+ demoInfo_t *(*GetDemoInfo)( const char *path, demoInfo_t *info );
qboolean (*SendStatusRequest)( char *buffer, int bufferSize );
void (*GetClientStatus)( clientStatus_t *status );
void (*UpdateScreen)( void );
diff --git a/source/com_local.h b/source/com_local.h
index 0c4a97b..3ea55ee 100644
--- a/source/com_local.h
+++ b/source/com_local.h
@@ -791,6 +791,9 @@ FILESYSTEM
==============================================================
*/
+#define FS_Malloc( size ) Z_TagMalloc( size, TAG_FILESYSTEM )
+#define FS_CopyString( string ) Z_TagCopyString( string, TAG_FILESYSTEM )
+
void FS_Init( void );
void FS_Shutdown( qboolean total );
qboolean FS_NeedRestart( void );
@@ -803,11 +806,11 @@ qboolean FS_RenameFile( const char *from, const char *to );
char *FS_CopyExtraInfo( const char *name, const fsFileInfo_t *info );
-int FS_FOpenFile( const char *filename, fileHandle_t *f, uint32 mode );
+int FS_FOpenFile( const char *filename, fileHandle_t *f, int mode );
void FS_FCloseFile( fileHandle_t hFile );
int FS_LoadFile( const char *path, void **buffer );
-int FS_LoadFileEx( const char *path, void **buffer, uint32 flags );
+int FS_LoadFileEx( const char *path, void **buffer, int flags );
void *FS_AllocTempMem( int length );
void FS_FreeFile( void *buffer );
// a null buffer will just return the file length without loading
@@ -829,8 +832,10 @@ int FS_GetFileLengthNoCache( fileHandle_t f );
qboolean FS_WildCmp( const char *filter, const char *string );
qboolean FS_ExtCmp( const char *extension, const char *string );
-char **FS_ListFiles( const char *path, const char *extension, uint32 flags, int *numFiles );
-void FS_FreeFileList( char **list );
+void **FS_ListFiles( const char *path, const char *extension, int flags, int *numFiles );
+void **FS_CopyList( void **list, int count );
+fsFileInfo_t *FS_CopyInfo( const char *name, int size, time_t ctime, time_t mtime );
+void FS_FreeList( void **list );
qboolean FS_LastFileFromPak( void );
@@ -999,13 +1004,12 @@ void Sys_ConsoleOutput( const char *string );
void Sys_Error( const char *error, ... ) q_noreturn q_printf( 1, 2 );
void Sys_Quit( void );
-char **Sys_ListFiles( const char *path, const char *extension, uint32 flags, int *numFiles );
-void Sys_FreeFileList( char **list );
+void **Sys_ListFiles( const char *path, const char *extension, int flags, int length, int *numFiles );
void Sys_Mkdir( const char *path );
qboolean Sys_RemoveFile( const char *path );
qboolean Sys_RenameFile( const char *from, const char *to );
-qboolean Sys_GetFileInfo( const char *path, fsFileInfo_t *info );
+fsFileInfo_t *Sys_GetFileInfo( const char *path, fsFileInfo_t *info );
char *Sys_GetCurrentDirectory( void );
diff --git a/source/com_public.h b/source/com_public.h
index 403c6f1..5ad6d7f 100644
--- a/source/com_public.h
+++ b/source/com_public.h
@@ -123,13 +123,13 @@ FILESYSTEM
#define MAX_LISTED_FILES 4096
-typedef struct fsSearchInfo_s {
- int fileSize;
- qtime_t timeCreate;
- qtime_t timeModify;
+typedef struct fsFileInfo_s {
+ int size;
+ time_t ctime;
+ time_t mtime;
+ char name[1];
} fsFileInfo_t;
-
/* bits 0 - 1, enum */
#define FS_MODE_APPEND 0x00000000
#define FS_MODE_READ 0x00000001
@@ -177,15 +177,17 @@ typedef struct fsAPI_s {
void (*FCloseFile)( fileHandle_t f );
int (*Read)( void *buffer, int len, fileHandle_t f );
int (*Write)( const void *buffer, int len, fileHandle_t f );
- int (*FOpenFile)( const char *filename, fileHandle_t *f, uint32 mode );
+ int (*FOpenFile)( const char *filename, fileHandle_t *f, int mode );
+ void (*FPrintf)( fileHandle_t f, const char *format, ... );
+ int (*ReadLine)( fileHandle_t f, char *buffer, int size );
int (*Tell)( fileHandle_t f );
int (*RawTell)( fileHandle_t f );
int (*LoadFile)( const char *path, void **buffer );
- int (*LoadFileEx)( const char *path, void **buffer, uint32 flags );
+ int (*LoadFileEx)( const char *path, void **buffer, int flags );
void *(*AllocTempMem)( int length );
void (*FreeFile)( void *buffer );
- char **(*ListFiles)( const char *path, const char *extension, uint32 flags, int *numFiles );
- void (*FreeFileList)( char **list );
+ void **(*ListFiles)( const char *path, const char *extension, int flags, int *numFiles );
+ void (*FreeList)( void **list );
} fsAPI_t;
extern fsAPI_t fs;
diff --git a/source/common.c b/source/common.c
index 7e56e50..c8046d3 100644
--- a/source/common.c
+++ b/source/common.c
@@ -1217,7 +1217,7 @@ static void Com_VsnprintfTest_f( void ) {
const char *Com_FileNameGenerator( const char *path, const char *ext,
const char *partial, qboolean stripExtension, int state ) {
static int length, numFiles;
- static char **list;
+ static void **list;
static int curpos;
char *s, *p;
@@ -1244,7 +1244,7 @@ const char *Com_FileNameGenerator( const char *path, const char *ext,
finish:
if( list ) {
- FS_FreeFileList( list );
+ FS_FreeList( list );
list = NULL;
}
return NULL;
@@ -1253,7 +1253,7 @@ finish:
const char *Com_FileNameGeneratorByFilter( const char *path, const char *filter,
const char *partial, qboolean stripExtension, int state ) {
static int length, numFiles;
- static char **list;
+ static void **list;
static int curpos;
char *s, *p;
@@ -1281,7 +1281,7 @@ const char *Com_FileNameGeneratorByFilter( const char *path, const char *filter,
finish:
if( list ) {
- FS_FreeFileList( list );
+ FS_FreeList( list );
list = NULL;
}
return NULL;
diff --git a/source/files.c b/source/files.c
index 8be2bac..bc77e7d 100644
--- a/source/files.c
+++ b/source/files.c
@@ -41,9 +41,6 @@ QUAKE FILESYSTEM
#define MAX_FILES_IN_PK2 0x4000
#define MAX_FILE_HANDLES 8
-#define FS_Malloc( size ) Z_TagMalloc( size, TAG_FILESYSTEM )
-#define FS_CopyString( string ) Z_TagCopyString( string, TAG_FILESYSTEM )
-
// macros for dealing portably with files at OS level
#ifdef _WIN32
#define FS_strcmp Q_strcasecmp
@@ -879,7 +876,7 @@ static char *FS_ExpandLinks( const char *filename ) {
FS_FOpenFile
============
*/
-int FS_FOpenFile( const char *name, fileHandle_t *f, uint32 mode ) {
+int FS_FOpenFile( const char *name, fileHandle_t *f, int mode ) {
fsFile_t *file;
fileHandle_t hFile;
int ret = -1;
@@ -1017,7 +1014,7 @@ Filenames are relative to the quake search path
a null buffer will just return the file length without loading
============
*/
-int FS_LoadFileEx( const char *path, void **buffer, uint32 flags ) {
+int FS_LoadFileEx( const char *path, void **buffer, int flags ) {
fsFile_t *file;
fileHandle_t f;
byte *buf;
@@ -1343,7 +1340,7 @@ static pack_t *FS_LoadPakFile( const char *packfile ) {
names += len;
}
- FS_DPrintf( "Added pakfile %s, %d files, %d hash table entries\n",
+ FS_DPrintf( "%s: %d files, %d hash table entries\n",
packfile, numpackfiles, hashSize );
return pack;
@@ -1456,7 +1453,7 @@ static pack_t *FS_LoadZipFile( const char *packfile ) {
}
}
- FS_DPrintf( "Added zipfile '%s', %d files, %d hash table entries\n",
+ FS_DPrintf( "%s: %d files, %d hash table entries\n",
packfile, numFiles, hashSize );
return pack;
@@ -1500,11 +1497,11 @@ static void FS_LoadPackFiles( const char *extension, pack_t *(loadfunc)( const c
int i;
searchpath_t *search;
pack_t *pak;
- char ** list;
+ void **list;
int numFiles;
char path[MAX_OSPATH];
- list = Sys_ListFiles( fs_gamedir, extension, FS_SEARCH_NOSORT, &numFiles );
+ list = Sys_ListFiles( fs_gamedir, extension, FS_SEARCH_NOSORT, 0, &numFiles );
if( !list ) {
return;
}
@@ -1521,8 +1518,7 @@ static void FS_LoadPackFiles( const char *extension, pack_t *(loadfunc)( const c
fs_searchpaths = search;
}
- Sys_FreeFileList( list );
-
+ FS_FreeList( list );
}
/*
@@ -1574,81 +1570,40 @@ static void q_printf( 1, 2 ) FS_AddGameDirectory( const char *fmt, ... ) {
#endif
}
-
/*
=================
-FS_GetModList
+FS_CopyInfo
=================
*/
-#define MAX_LISTED_MODS 32
-
-static void FS_GetModList( char **list, int *count ) {
- char path[MAX_OSPATH];
- FILE *fp;
- char **dirlist;
- int numDirs;
- int i;
+fsFileInfo_t *FS_CopyInfo( const char *name, int size, time_t ctime, time_t mtime ) {
+ fsFileInfo_t *out;
+ int len;
- if( !( dirlist = Sys_ListFiles( sys_basedir->string, NULL, FS_SEARCHDIRS_ONLY, &numDirs ) ) ) {
- return;
+ if( !name ) {
+ return NULL;
}
- for( i = 0; i < numDirs; i++ ) {
- if( !strcmp( dirlist[i], BASEGAME ) ) {
- continue;
- }
-
-#ifdef _WIN32
- Com_sprintf( path, sizeof( path ), "%s/%s/gamex86.dll", sys_basedir->string, dirlist[i] );
-#else
- Com_sprintf( path, sizeof( path ), "%s/%s/gamei386.so", sys_basedir->string, dirlist[i] );
-#endif
+ len = strlen( name );
+ out = FS_Malloc( sizeof( *out ) + len );
+ out->size = size;
+ out->ctime = ctime;
+ out->mtime = mtime;
+ memcpy( out->name, name, len + 1 );
- if( !( fp = fopen( path, "rb" ) ) ) {
- continue;
- }
- fclose( fp );
-
- Com_sprintf( path, sizeof( path ), "%s/%s/description.txt", sys_basedir->string, dirlist[i] );
-
- if( ( fp = fopen( path, "r" ) ) != NULL ) {
- Q_strncpyz( path, va( "%s\n", dirlist[i] ), sizeof( path ) - MAX_QPATH );
- fgets( path + strlen( path ), MAX_QPATH, fp );
- fclose( fp );
- list[*count] = FS_CopyString( path );
- } else {
- list[*count] = FS_CopyString( dirlist[i] );
- }
-
- if( (*count)++ == MAX_LISTED_MODS ) {
- break;
- }
- }
-
- Sys_FreeFileList( dirlist );
+ return out;
}
-/*
-=================
-FS_CopyExtraInfo
-=================
-*/
-char *FS_CopyExtraInfo( const char *name, const fsFileInfo_t *info ) {
- char *out;
- int length;
+void **FS_CopyList( void **list, int count ) {
+ void **out;
+ int i;
- if( !name ) {
- return NULL;
+ out = FS_Malloc( sizeof( void * ) * ( count + 1 ) );
+ for( i = 0; i < count; i++ ) {
+ out[i] = list[i];
}
+ out[i] = NULL;
- length = strlen( name ) + 1;
-
- out = FS_Malloc( sizeof( *info ) + length );
- strcpy( out, name );
-
- memcpy( out + length, info, sizeof( *info ) );
-
- return out;
+ return out;
}
#if 0
@@ -1757,19 +1712,20 @@ rescan:
FS_ListFiles
=================
*/
-char **FS_ListFiles( const char *path, const char *extension,
- uint32 flags, int *numFiles )
+void **FS_ListFiles( const char *path,
+ const char *extension,
+ int flags,
+ int *numFiles )
{
searchpath_t *search;
- char *listedFiles[MAX_LISTED_FILES];
+ void *listedFiles[MAX_LISTED_FILES];
int count, total;
char buffer[MAX_OSPATH];
- char **dirlist;
- int numFilesInDir;
- char **list;
- int i, length;
- char *name, *filename;
- fsFileInfo_t info;
+ void **dirlist;
+ int dircount;
+ void **list;
+ int i, len, pathlen;
+ char *s;
if( flags & FS_SEARCH_BYFILTER ) {
if( !extension ) {
@@ -1779,7 +1735,10 @@ char **FS_ListFiles( const char *path, const char *extension,
if( !path ) {
path = "";
- }
+ pathlen = 0;
+ } else {
+ pathlen = strlen( path );
+ }
count = 0;
@@ -1787,161 +1746,155 @@ char **FS_ListFiles( const char *path, const char *extension,
*numFiles = 0;
}
- if( !strcmp( path, "$modlist" ) ) {
- FS_GetModList( listedFiles, &count );
- } else {
- memset( &info, 0, sizeof( info ) );
+ for( search = FS_SearchPath( flags ); search; search = search->next ) {
+ if( ( flags & FS_PATH_MASK ) == FS_PATH_GAME ) {
+ if( fs_searchpaths != fs_base_searchpaths && search == fs_base_searchpaths ) {
+ // consider baseq2 a gamedir if no gamedir loaded
+ break;
+ }
+ }
+ if( search->pack ) {
+ if( ( flags & FS_TYPE_MASK ) == FS_TYPE_REAL ) {
+ // don't search in paks
+ continue;
+ }
- for( search = FS_SearchPath( flags ); search; search = search->next ) {
- if( ( flags & FS_PATH_MASK ) == FS_PATH_GAME ) {
- if( fs_searchpaths != fs_base_searchpaths && search == fs_base_searchpaths ) {
- // consider baseq2 a gamedir if no gamedir loaded
- break;
- }
- }
- if( search->pack ) {
- if( ( flags & FS_TYPE_MASK ) == FS_TYPE_REAL ) {
- // don't search in paks
- continue;
- }
+ // TODO: add directory search support for pak files
+ if( ( flags & FS_SEARCHDIRS_MASK ) == FS_SEARCHDIRS_ONLY ) {
+ continue;
+ }
- // TODO: add directory search support for pak files
- if( ( flags & FS_SEARCHDIRS_MASK ) == FS_SEARCHDIRS_ONLY ) {
- continue;
- }
+ if( flags & FS_SEARCH_BYFILTER ) {
+ for( i = 0; i < search->pack->numfiles; i++ ) {
+ s = search->pack->files[i].name;
+
+ // check path
+ if( pathlen ) {
+ if( Q_stricmpn( s, path, pathlen ) ) {
+ continue;
+ }
+ s += pathlen + 1;
+ }
- if( flags & FS_SEARCH_BYFILTER ) {
- for( i = 0; i < search->pack->numfiles; i++ ) {
- name = search->pack->files[i].name;
-
- // check path
- filename = name;
- if( *path ) {
- length = strlen( path );
- if( Q_stricmpn( name, path, length ) ) {
- continue;
- }
- filename += length + 1;
- }
+ // check filter
+ if( !FS_WildCmp( extension, s ) ) {
+ continue;
+ }
- // check filter
- if( !FS_WildCmp( extension, filename ) ) {
- continue;
- }
+ // copy filename
+ if( count == MAX_LISTED_FILES ) {
+ break;
+ }
- // copy filename
- if( count == MAX_LISTED_FILES ) {
- break;
- }
+ if( !( flags & FS_SEARCH_SAVEPATH ) ) {
+ s = COM_SkipPath( s );
+ }
+ if( flags & FS_SEARCH_EXTRAINFO ) {
+ listedFiles[count++] = FS_CopyInfo( s,
+ search->pack->files[i].filelen, 0, 0 );
+ } else {
+ listedFiles[count++] = FS_CopyString( s );
+ }
+ }
+ } else {
+ for( i = 0; i < search->pack->numfiles; i++ ) {
+ s = search->pack->files[i].name;
+
+ // check path
+ if( pathlen && Q_stricmpn( s, path, pathlen ) ) {
+ continue;
+ }
- if( !( flags & FS_SEARCH_SAVEPATH ) ) {
- filename = COM_SkipPath( filename );
- }
- if( flags & FS_SEARCH_EXTRAINFO ) {
- info.fileSize = search->pack->files[i].filelen;
- listedFiles[count++] = FS_CopyExtraInfo( filename, &info );
- } else {
- listedFiles[count++] = FS_CopyString( filename );
- }
+ // check extension
+ if( extension && !FS_ExtCmp( extension, s ) ) {
+ continue;
}
- } else {
- for( i = 0; i < search->pack->numfiles; i++ ) {
- name = search->pack->files[i].name;
-
- // check path
- if( *path ) {
- COM_FilePath( name, buffer, sizeof( buffer ) );
- if( Q_stricmp( path, buffer ) ) {
- continue;
- }
- }
+
+ // copy filename
+ if( count == MAX_LISTED_FILES ) {
+ break;
+ }
+ if( !( flags & FS_SEARCH_SAVEPATH ) ) {
+ s = COM_SkipPath( s );
+ }
+ if( flags & FS_SEARCH_EXTRAINFO ) {
+ listedFiles[count++] = FS_CopyInfo( s,
+ search->pack->files[i].filelen, 0, 0 );
+ } else {
+ listedFiles[count++] = FS_CopyString( s );
+ }
+ }
+ }
+ } else {
+ if( ( flags & FS_TYPE_MASK ) == FS_TYPE_PAK ) {
+ // don't search in OS filesystem
+ continue;
+ }
- // check extension
- if( extension && !FS_ExtCmp( extension, name ) ) {
- continue;
- }
-
- // copy filename
- if( count == MAX_LISTED_FILES ) {
- break;
- }
- if( !( flags & FS_SEARCH_SAVEPATH ) ) {
- name = COM_SkipPath( name );
- }
- if( flags & FS_SEARCH_EXTRAINFO ) {
- info.fileSize = search->pack->files[i].filelen;
- listedFiles[count++] = FS_CopyExtraInfo( name, &info );
- } else {
- listedFiles[count++] = FS_CopyString( name );
- }
- }
- }
- } else {
- if( ( flags & FS_TYPE_MASK ) == FS_TYPE_PAK ) {
- // don't search in OS filesystem
- continue;
- }
+ len = strlen( search->filename );
- if( *path ) {
- Q_concat( buffer, sizeof( buffer ), search->filename, "/", path, NULL );
- } else {
- Q_strncpyz( buffer, search->filename, sizeof( buffer ) );
+ if( pathlen ) {
+ if( len + pathlen + 1 >= MAX_OSPATH ) {
+ continue;
}
+ memcpy( buffer, search->filename, len );
+ buffer[len] = '/';
+ memcpy( buffer + len + 1, path, pathlen + 1 );
+ s = buffer;
+ } else {
+ s = search->filename;
+ }
- if( flags & FS_SEARCH_BYFILTER ) {
- dirlist = Sys_ListFiles( buffer, extension, flags|FS_SEARCH_NOSORT, &numFilesInDir );
- } else {
- dirlist = Sys_ListFiles( buffer, extension, flags|FS_SEARCH_NOSORT, &numFilesInDir );
- }
+ if( flags & FS_SEARCH_BYFILTER ) {
+ len += len + pathlen + 1;
+ }
- if( !dirlist ) {
- continue;
- }
+ dirlist = Sys_ListFiles( s, extension,
+ flags|FS_SEARCH_NOSORT, len + 1, &dircount );
+ if( !dirlist ) {
+ continue;
+ }
- for( i = 0; i < numFilesInDir; i++ ) {
- if( count == MAX_LISTED_FILES ) {
- break;
- }
- name = dirlist[i];
- if( ( flags & FS_SEARCH_SAVEPATH ) && !( flags & FS_SEARCH_BYFILTER ) ) {
- // skip search path
- name += strlen( search->filename ) + 1;
- }
- if( flags & FS_SEARCH_EXTRAINFO ) {
- listedFiles[count++] = FS_CopyExtraInfo( name, ( fsFileInfo_t * )( dirlist[i] + strlen( dirlist[i] ) + 1 ) );
- } else {
- listedFiles[count++] = FS_CopyString( name );
- }
- }
- Sys_FreeFileList( dirlist );
-
- }
- if( count == MAX_LISTED_FILES ) {
- break;
- }
- }
- }
+ if( count + dircount > MAX_LISTED_FILES ) {
+ dircount = MAX_LISTED_FILES - count;
+ }
+ for( i = 0; i < dircount; i++ ) {
+ listedFiles[count++] = dirlist[i];
+ }
+
+ Z_Free( dirlist );
+
+ }
+ if( count == MAX_LISTED_FILES ) {
+ break;
+ }
+ }
if( !count ) {
return NULL;
}
- // sort alphabetically (ignoring FS_SEARCH_NOSORT)
- qsort( listedFiles, count, sizeof( listedFiles[0] ), SortStrcmp );
-
- // remove duplicates
- total = 1;
- for( i = 1; i < count; i++ ) {
- // FIXME: use Q_stricmp instead of FS_strcmp here?
- if( !FS_strcmp( listedFiles[ i - 1 ], listedFiles[i] ) ) {
- Z_Free( listedFiles[ i - 1 ] );
- listedFiles[i-1] = NULL;
- } else {
- total++;
- }
- }
+ if( flags & FS_SEARCH_EXTRAINFO ) {
+ // TODO
+ total = count;
+ } else {
+ // sort alphabetically (ignoring FS_SEARCH_NOSORT)
+ qsort( listedFiles, count, sizeof( listedFiles[0] ), SortStrcmp );
+
+ // remove duplicates
+ total = 1;
+ for( i = 1; i < count; i++ ) {
+ // FIXME: use Q_stricmp instead of FS_strcmp here?
+ if( !FS_strcmp( listedFiles[ i - 1 ], listedFiles[i] ) ) {
+ Z_Free( listedFiles[ i - 1 ] );
+ listedFiles[i-1] = NULL;
+ } else {
+ total++;
+ }
+ }
+ }
- list = FS_Malloc( sizeof( char * ) * ( total + 1 ) );
+ list = FS_Malloc( sizeof( void * ) * ( total + 1 ) );
total = 0;
for( i = 0; i < count; i++ ) {
@@ -1956,23 +1909,16 @@ char **FS_ListFiles( const char *path, const char *extension,
}
return list;
-
-
}
/*
=================
-FS_FreeFileList
+FS_FreeList
=================
*/
-void FS_FreeFileList( char **list ) {
- char **p;
+void FS_FreeList( void **list ) {
+ void **p = list;
- if( !list ) {
- Com_Error( ERR_FATAL, "FS_FreeFileList: NULL" );
- }
-
- p = list;
while( *p ) {
Z_Free( *p++ );
}
@@ -2006,7 +1952,7 @@ FS_FDir_f
============
*/
static void FS_FDir_f( void ) {
- char **dirnames;
+ void **list;
int ndirs = 0;
int i;
char *filter;
@@ -2022,15 +1968,14 @@ static void FS_FDir_f( void ) {
if( Cmd_Argc() > 2 ) {
i |= FS_SEARCH_SAVEPATH;
}
-
- if( ( dirnames = FS_ListFiles( NULL, filter, i, &ndirs ) ) != NULL ) {
+
+ if( ( list = FS_ListFiles( NULL, filter, i, &ndirs ) ) != NULL ) {
for( i = 0; i < ndirs; i++ ) {
- Com_Printf( "%s\n", dirnames[i] );
+ Com_Printf( "%s\n", ( char * )list[i] );
}
- FS_FreeFileList( dirnames );
+ FS_FreeList( list );
}
Com_Printf( "%i files listed\n", ndirs );
-
}
/*
@@ -2039,7 +1984,7 @@ FS_Dir_f
============
*/
static void FS_Dir_f( void ) {
- char **dirnames;
+ void **list;
int ndirs = 0;
int i;
char *ext;
@@ -2053,15 +1998,14 @@ static void FS_Dir_f( void ) {
} else {
ext = NULL;
}
- dirnames = FS_ListFiles( Cmd_Argv( 1 ), ext, 0, &ndirs );
- if( dirnames ) {
+ list = FS_ListFiles( Cmd_Argv( 1 ), ext, 0, &ndirs );
+ if( list ) {
for( i = 0; i < ndirs; i++ ) {
- Com_Printf( "%s\n", dirnames[i] );
+ Com_Printf( "%s\n", ( char * )list[i] );
}
- FS_FreeFileList( dirnames );
+ FS_FreeList( list );
}
Com_Printf( "%i files listed\n", ndirs );
-
}
/*
@@ -2116,8 +2060,7 @@ static void FS_WhereIs_f( void ) {
search->filename, "/", path, NULL );
//FS_ConvertToSysPath( fullpath );
if( Sys_GetFileInfo( fullpath, &info ) ) {
- Com_Printf( "%s/%s (%d bytes)\n", search->filename, filename,
- info.fileSize );
+ Com_Printf( "%s/%s (%d bytes)\n", search->filename, filename, info.size );
if( Cmd_Argc() < 3 ) {
return;
}
@@ -2588,7 +2531,9 @@ void FS_FillAPI( fsAPI_t *api ) {
api->Read = FS_Read;
api->Write = FS_Write;
api->ListFiles = FS_ListFiles;
- api->FreeFileList = FS_FreeFileList;
+ api->FreeList = FS_FreeList;
+ api->FPrintf = FS_FPrintf;
+ api->ReadLine = FS_ReadLine;
}
static const cmdreg_t c_fs[] = {
diff --git a/source/q_shared.c b/source/q_shared.c
index 6442483..fe04769 100644
--- a/source/q_shared.c
+++ b/source/q_shared.c
@@ -796,17 +796,16 @@ COM_FilePath
Returns the path up to, but not including the last /
============
*/
-void COM_FilePath( const char *in, char *out, int outSize ) {
+void COM_FilePath( const char *in, char *out, int size ) {
char *s;
- Q_strncpyz( out, in, outSize );
-
- s = out + strlen( out );
-
- while( s != out && *s != '/' )
- s--;
-
- *s = 0;
+ Q_strncpyz( out, in, size );
+ s = strrchr( out, '/' );
+ if( s ) {
+ *s = 0;
+ } else {
+ *out = 0;
+ }
}
diff --git a/source/q_shared.h b/source/q_shared.h
index 36e0177..f20a41e 100644
--- a/source/q_shared.h
+++ b/source/q_shared.h
@@ -258,12 +258,12 @@ static inline float Q_fabs( float f ) {
(d)[2]=(a)[2]+(c)*((b)[2]-(a)[2]))
#define PlaneDiff(v,p) (DotProduct(v,(p)->normal)-(p)->dist)
-#define Vector4Subtract(a,b,c) (c[0]=a[0]-b[0],c[1]=a[1]-b[1],c[2]=a[2]-b[2],c[3]=a[3]-b[3])
-#define Vector4Add(a,b,c) (c[0]=a[0]+b[0],c[1]=a[1]+b[1],c[2]=a[2]+b[2],c[3]=a[3]+b[3])
-#define Vector4Copy(a,b) (b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3])
-#define Vector4Clear(a) (a[0]=a[1]=a[2]=a[3]=0)
-#define Vector4Negate(a,b) (b[0]=-a[0],b[1]=-a[1],b[2]=-a[2],b[3]=-a[3])
-#define Vector4Set(v, a, b, c, d) (v[0]=(a),v[1]=(b),v[2]=(c),v[3]=(d))
+#define Vector4Subtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2],(c)[3]=(a)[3]-(b)[3])
+#define Vector4Add(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2],(c)[3]=(a)[3]+(b)[3])
+#define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
+#define Vector4Clear(a) ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0)
+#define Vector4Negate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2],(b)[3]=-(a)[3])
+#define Vector4Set(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3]=(d))
void ClearBounds (vec3_t mins, vec3_t maxs);
void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs);
diff --git a/source/sys_unix.c b/source/sys_unix.c
index c9e500b..e70a271 100644
--- a/source/sys_unix.c
+++ b/source/sys_unix.c
@@ -507,21 +507,18 @@ qboolean Sys_RenameFile( const char *from, const char *to ) {
Sys_GetFileInfo
================
*/
-qboolean Sys_GetFileInfo( const char *path, fsFileInfo_t *info ) {
+fsFileInfo_t *Sys_GetFileInfo( const char *path, fsFileInfo_t *info ) {
struct stat st;
- qtime_t *ctime, *mtime;
- if( stat( path, &st ) ) {
- return qfalse;
+ if( stat( path, &st ) == -1 ) {
+ return NULL;
}
- info->fileSize = st.st_size;
- ctime = localtime( &st.st_ctime );
- mtime = localtime( &st.st_mtime );
- info->timeCreate = *ctime;
- info->timeModify = *mtime;
+ info->size = st.st_size;
+ info->ctime = st.st_ctime;
+ info->mtime = st.st_mtime;
- return qtrue;
+ return info;
}
/*
@@ -884,29 +881,23 @@ MISC
===============================================================================
*/
-static inline void st2fi( struct stat *st, fsFileInfo_t *info ) {
- qtime_t *ctime = localtime( &st->st_ctime );
- qtime_t *mtime = localtime( &st->st_mtime );
-
- info->fileSize = st->st_size;
- info->timeCreate = *ctime;
- info->timeModify = *mtime;
-}
-
-
/*
=================
Sys_ListFilteredFiles
=================
*/
-static void Sys_ListFilteredFiles( char **listedFiles, int *count,
- const char *path, const char *filter, uint flags, int length, int depth )
+static void Sys_ListFilteredFiles( void **listedFiles,
+ int *count,
+ const char *path,
+ const char *filter,
+ int flags,
+ int length,
+ int depth )
{
struct dirent *findInfo;
DIR *findHandle;
struct stat st;
char findPath[MAX_OSPATH];
- fsFileInfo_t info;
char *name;
if( depth >= 32 ) {
@@ -960,10 +951,10 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count,
}
if( flags & FS_SEARCH_EXTRAINFO ) {
- st2fi( &st, &info );
- listedFiles[( *count )++] = FS_CopyExtraInfo( name, &info );
+ listedFiles[( *count )++] = FS_CopyInfo( name,
+ st.st_size, st.st_ctime, st.st_mtime );
} else {
- listedFiles[( *count )++] = Z_CopyString( name );
+ listedFiles[( *count )++] = FS_CopyString( name );
}
if( *count >= MAX_LISTED_FILES ) {
break;
@@ -980,33 +971,27 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count,
Sys_ListFiles
=================
*/
-char **Sys_ListFiles( const char *path, const char *extension,
- uint32 flags, int *numFiles )
+void **Sys_ListFiles( const char *path,
+ const char *extension,
+ int flags,
+ int length,
+ int *numFiles )
{
struct dirent *findInfo;
DIR *findHandle;
struct stat st;
char findPath[MAX_OSPATH];
- char *listedFiles[MAX_LISTED_FILES];
- fsFileInfo_t info;
- int count;
- char **list;
+ void *listedFiles[MAX_LISTED_FILES];
+ int count = 0;
char *s;
- int i, length;
-
- count = 0;
if( numFiles ) {
*numFiles = 0;
}
if( flags & FS_SEARCH_BYFILTER ) {
- length = strlen( path );
- if( !length ) {
- return NULL;
- }
Sys_ListFilteredFiles( listedFiles, &count, path,
- extension, flags, length + 1, 0 );
+ extension, flags, length, 0 );
} else {
if( ( findHandle = opendir( path ) ) == NULL ) {
return NULL;
@@ -1041,15 +1026,15 @@ char **Sys_ListFiles( const char *path, const char *extension,
}
if( flags & FS_SEARCH_SAVEPATH ) {
- s = findPath;
+ s = findPath + length;
} else {
s = findInfo->d_name;
}
if( flags & FS_SEARCH_EXTRAINFO ) {
- st2fi( &st, &info );
- listedFiles[count++] = FS_CopyExtraInfo( s, &info );
+ listedFiles[count++] = FS_CopyInfo( s, st.st_size,
+ st.st_ctime, st.st_mtime );
} else {
- listedFiles[count++] = Z_CopyString( s );
+ listedFiles[count++] = FS_CopyString( s );
}
if( count >= MAX_LISTED_FILES ) {
@@ -1064,39 +1049,11 @@ char **Sys_ListFiles( const char *path, const char *extension,
return NULL;
}
- qsort( listedFiles, count, sizeof( listedFiles[0] ), SortStrcmp );
-
- list = Z_Malloc( sizeof( char * ) * ( count + 1 ) );
- for( i = 0; i < count; i++ ) {
- list[i] = listedFiles[i];
- }
- list[count] = NULL;
-
if( numFiles ) {
*numFiles = count;
}
- return list;
-}
-
-/*
-=================
-Sys_FreeFileList
-=================
-*/
-void Sys_FreeFileList( char **list ) {
- char **p;
-
- if( !list ) {
- Com_Error( ERR_FATAL, "Sys_FreeFileList: NULL" );
- }
-
- p = list;
- while( *p ) {
- Z_Free( *p++ );
- }
-
- Z_Free( list );
+ return FS_CopyList( listedFiles, count );
}
/*
diff --git a/source/sys_win.c b/source/sys_win.c
index ead61c3..034c409 100644
--- a/source/sys_win.c
+++ b/source/sys_win.c
@@ -924,8 +924,12 @@ static qboolean Sys_FindInfoToExtraInfo( WIN32_FIND_DATAA *findInfo, fsFileInfo_
Sys_ListFilteredFiles
=================
*/
-static void Sys_ListFilteredFiles( char **listedFiles, int *count, const char *path,
- const char *filter, uint32 flags, int length )
+static void Sys_ListFilteredFiles( void **listedFiles,
+ int *count,
+ const char *path,
+ const char *filter,
+ int flags,
+ int length )
{
WIN32_FIND_DATAA findInfo;
HANDLE findHandle;
@@ -972,17 +976,19 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count, const char *p
name = ( flags & FS_SEARCH_SAVEPATH ) ? dirPath + length : findInfo.cFileName;
+ // reformat it back to quake filesystem style
+ FS_ReplaceSeparators( name, '/' );
+
if( flags & FS_SEARCH_EXTRAINFO ) {
Sys_FindInfoToExtraInfo( &findInfo, &info );
- listedFiles[( *count )++] = FS_CopyExtraInfo( name, &info );
+ listedFiles[( *count )++] = FS_CopyInfo( name, &info );
} else {
- listedFiles[( *count )++] = Z_CopyString( name );
+ listedFiles[( *count )++] = FS_CopyString( name );
}
} while( *count < MAX_LISTED_FILES && FindNextFileA( findHandle, &findInfo ) != FALSE );
FindClose( findHandle );
-
}
/*
@@ -990,16 +996,18 @@ static void Sys_ListFilteredFiles( char **listedFiles, int *count, const char *p
Sys_ListFiles
=================
*/
-char **Sys_ListFiles( const char *rawPath, const char *extension, uint32 flags, int *numFiles ) {
+void **Sys_ListFiles( const char *rawPath,
+ const char *extension,
+ int flags,
+ int length,
+ int *numFiles )
+{
WIN32_FIND_DATAA findInfo;
HANDLE findHandle;
char path[MAX_OSPATH];
char findPath[MAX_OSPATH];
- char *listedFiles[MAX_LISTED_FILES];
+ void *listedFiles[MAX_LISTED_FILES];
int count;
- char **list;
- int i, length;
- fsFileInfo_t info;
char *name;
count = 0;
@@ -1008,16 +1016,13 @@ char **Sys_ListFiles( const char *rawPath, const char *extension, uint32 flags,
*numFiles = 0;
}
- length = Q_strncpyz( path, rawPath, sizeof( path ) );
+ Q_strncpyz( path, rawPath, sizeof( path ) );
FS_ReplaceSeparators( path, '\\' );
if( flags & FS_SEARCH_BYFILTER ) {
- if( !length ) {
- return NULL;
- }
Q_strncpyz( findPath, extension, sizeof( findPath ) );
FS_ReplaceSeparators( findPath, '\\' );
- Sys_ListFilteredFiles( listedFiles, &count, path, findPath, flags, length + 1 );
+ Sys_ListFilteredFiles( listedFiles, &count, path, findPath, flags, length );
} else {
if( !extension || strchr( extension, ';' ) ) {
Q_concat( findPath, sizeof( findPath ), path, "\\*", NULL );
@@ -1054,12 +1059,15 @@ char **Sys_ListFiles( const char *rawPath, const char *extension, uint32 flags,
}
name = ( flags & FS_SEARCH_SAVEPATH ) ? va( "%s\\%s", path, findInfo.cFileName ) : findInfo.cFileName;
+
+ // reformat it back to quake filesystem style
+ FS_ReplaceSeparators( name, '/' );
if( flags & FS_SEARCH_EXTRAINFO ) {
Sys_FindInfoToExtraInfo( &findInfo, &info );
- listedFiles[count++] = FS_CopyExtraInfo( name, &info );
+ listedFiles[count++] = FS_CopyInfo( name, &info );
} else {
- listedFiles[count++] = Z_CopyString( name );
+ listedFiles[count++] = FS_CopyString( name );
}
} while( count < MAX_LISTED_FILES && FindNextFileA( findHandle, &findInfo ) != FALSE );
@@ -1070,44 +1078,11 @@ char **Sys_ListFiles( const char *rawPath, const char *extension, uint32 flags,
return NULL;
}
- if( !( flags & FS_SEARCH_NOSORT ) ) {
- qsort( listedFiles, count, sizeof( listedFiles[0] ), SortStrcmp );
- }
-
- // reformat filenames back to quake filesystem style
- list = Z_Malloc( sizeof( char * ) * ( count + 1 ) );
- for( i = 0; i < count; i++ ) {
- name = listedFiles[i];
- FS_ReplaceSeparators( name, '/' );
- list[i] = name;
- }
- list[count] = NULL;
-
if( numFiles ) {
*numFiles = count;
}
- return list;
-}
-
-/*
-=================
-Sys_FreeFileList
-=================
-*/
-void Sys_FreeFileList( char **list ) {
- char **p;
-
- if( !list ) {
- Com_Error( ERR_FATAL, "Sys_FreeFileList: NULL" );
- }
-
- p = list;
- while( *p ) {
- Z_Free( *p++ );
- }
-
- Z_Free( list );
+ return FS_CopyList( listedFiles, count );
}
/*
diff --git a/source/ui_atoms.c b/source/ui_atoms.c
index d1346b6..66e2629 100644
--- a/source/ui_atoms.c
+++ b/source/ui_atoms.c
@@ -243,7 +243,7 @@ UI_FormatColumns
char *UI_FormatColumns( int numArgs, ... ) {
va_list argptr;
char *buffer, *p;
- int i, totalLength;
+ int i, total = 0;
char *strings[MAX_COLUMNS];
int lengths[MAX_COLUMNS];
@@ -251,26 +251,22 @@ char *UI_FormatColumns( int numArgs, ... ) {
Com_Error( ERR_FATAL, "UI_FormatColumns: too many columns" );
}
- totalLength = 0;
-
va_start( argptr, numArgs );
for( i = 0; i < numArgs; i++ ) {
strings[i] = va_arg( argptr, char * );
lengths[i] = strlen( strings[i] ) + 1;
- totalLength += lengths[i];
+ total += lengths[i];
}
va_end( argptr );
- buffer = p = UI_Malloc( totalLength + 1 );
+ buffer = p = UI_Malloc( total + 1 );
for( i = 0; i < numArgs; i++ ) {
memcpy( p, strings[i], lengths[i] );
p += lengths[i];
}
-
*p = 0;
return buffer;
-
}
/*
diff --git a/source/ui_demos.c b/source/ui_demos.c
index 9c249f3..b32f5bd 100644
--- a/source/ui_demos.c
+++ b/source/ui_demos.c
@@ -38,121 +38,89 @@ DEMOS MENU
#define ID_LIST 105
+typedef struct {
+ int type;
+ int size;
+ time_t mtime;
+} demoEntry_t;
+
typedef struct m_demos_s {
menuFrameWork_t menu;
menuList_t list;
- menuList_t playerList;
menuStatic_t banner;
- int count;
+ int count;
char *names[MAX_MENU_DEMOS+1];
- int types[MAX_MENU_DEMOS];
- char *playerNames[MAX_DEMOINFO_CLIENTS+1];
-
- // Demo file info
- demoInfo_t demo;
+ demoEntry_t entries[MAX_MENU_DEMOS];
} m_demos_t;
static m_demos_t m_demos;
-static void Demos_FreeInfo( void ) {
- memset( &m_demos.demo, 0, sizeof( m_demos.demo ) );
-
- m_demos.playerList.generic.flags |= QMF_HIDDEN;
-}
-
-static void Demos_LoadInfo( int index ) {
- char buffer[MAX_OSPATH];
- int i, numNames, localPlayerNum;
-
- if( m_demos.types[index] != FFILE_DEMO ) {
- m_demos.playerList.generic.flags |= QMF_HIDDEN;
- m_demos.menu.statusbar = NULL;
- return;
- }
-
- Q_concat( buffer, sizeof( buffer ),
- uis.m_demos_browse + 1, "/", m_demos.names[index], NULL );
-
- client.GetDemoInfo( buffer, &m_demos.demo );
+static void Demos_BuildName( const char *path, fsFileInfo_t *info ) {
+ char buffer[MAX_OSPATH];
+ demoInfo_t demo;
- if( !m_demos.demo.mapname[0] ) {
- m_demos.menu.statusbar = "Couldn't read demo info";
- m_demos.playerList.generic.flags |= QMF_HIDDEN;
+#if 1
+ Q_concat( buffer, sizeof( buffer ), path, "/", info->name, NULL );
+ if( !client.GetDemoInfo( buffer, &demo ) ) {
return;
- }
-
- localPlayerNum = 0;
-
- numNames = 0;
- for( i = 0; i < MAX_DEMOINFO_CLIENTS; i++ ) {
- if( !m_demos.demo.clients[i][0] ) {
- continue;
- }
-
- if( i == m_demos.demo.clientNum ) {
- localPlayerNum = numNames;
- }
-
- // ( m_demos.demo.mvd || i == m_demos.demo.clientNum ) ? colorYellow : NULL
-
- m_demos.playerNames[numNames++] = m_demos.demo.clients[i];
- }
-
- if( numNames ) {
- m_demos.playerList.generic.flags &= ~QMF_HIDDEN;
- } else {
- m_demos.playerList.generic.flags |= QMF_HIDDEN;
- }
-
- m_demos.playerNames[numNames] = NULL;
-
- m_demos.menu.statusbar = "Press Enter to play";
+ }
+#else
+ strcpy( demo.map, "???" );
+ strcpy( demo.pov, "???" );
+#endif
+
+ if( info->size >= 1000000 ) {
+ sprintf( buffer, "%2.1fM", ( float )info->size / 1000000 );
+ } else if( info->size >= 1000 ) {
+ sprintf( buffer, "%3dK", info->size / 1000 );
+ } else {
+ sprintf( buffer, "%3db", info->size );
+ }
- MenuList_Init( &m_demos.playerList );
- MenuList_SetValue( &m_demos.playerList, localPlayerNum );
+ m_demos.names[m_demos.count] = UI_FormatColumns( 4,
+ info->name, buffer, demo.map, demo.pov );
+ m_demos.entries[m_demos.count].type = FFILE_DEMO;
+ m_demos.entries[m_demos.count].size = info->size;
+ m_demos.entries[m_demos.count].mtime = info->mtime;
+ m_demos.count++;
}
-static char *Demos_BuildName( const char *path, const char *name,
- fsFileInfo_t *info )
-{
+static void Demos_WriteCache( const char *path ) {
char buffer[MAX_OSPATH];
- demoInfo_t demo;
- char *s;
+ fileHandle_t f;
+ int i;
+ char *name, *map, *pov;
+ demoEntry_t *e;
- Q_concat( buffer, sizeof( buffer ), path, "/", name, NULL );
-
- client.GetDemoInfo( buffer, &demo );
- if( !demo.mapname[0] ) {
- return NULL;
- }
+ if( *path == '/' ) {
+ path++;
+ }
- if( info->fileSize >= 1000000 ) {
- sprintf( buffer, "%2.1fM", ( float )info->fileSize / 1000000 );
- } else if( info->fileSize >= 1000 ) {
- sprintf( buffer, "%3dK", info->fileSize / 1000 );
- } else {
- sprintf( buffer, "%3db", info->fileSize );
+ Q_concat( buffer, sizeof( buffer ), path, "/.democache", NULL );
+ fs.FOpenFile( buffer, &f, FS_MODE_WRITE );
+ if( !f ) {
+ return;
}
-// Com_sprintf( buffer, sizeof( buffer ), "%4d", info->fileSize >> 10 );
-
- if( demo.clientNum >= 0 && demo.clientNum < MAX_DEMOINFO_CLIENTS ) {
- s = UI_FormatColumns( 4, name, buffer, demo.mapname,
- demo.clients[demo.clientNum] );
- } else {
- s = UI_FormatColumns( 3, name, buffer, demo.mapname );
+ for( i = 0; i < m_demos.count; i++ ) {
+ e = &m_demos.entries[i];
+ if( e->type != FFILE_DEMO ) {
+ continue;
+ }
+ name = m_demos.names[i];
+ map = name + strlen( name ) + 1;
+ map = map + strlen( map ) + 1;
+ pov = map + strlen( map ) + 1;
+ fs.FPrintf( f, "%s %d %d %s %s\n", name, e->mtime, e->size, map, pov );
}
-
- return s;
+ fs.FCloseFile( f );
}
static void Demos_BuildList( const char *path ) {
- fsFileInfo_t *info;
int numFiles;
- char **list, *s;
- int pos;
- int i;
+ void **list;
+ int i, pos;
if( *path == '/' ) {
path++;
@@ -160,7 +128,7 @@ static void Demos_BuildList( const char *path ) {
if( *path ) {
m_demos.names[m_demos.count] = UI_FormatColumns( 1, ".." );
- m_demos.types[m_demos.count] = FFILE_UP;
+ m_demos.entries[m_demos.count].type = FFILE_UP;
m_demos.count++;
}
@@ -173,11 +141,10 @@ static void Demos_BuildList( const char *path ) {
}
for( i = 0; i < numFiles; i++ ) {
m_demos.names[m_demos.count] = UI_FormatColumns( 1, list[i] );
- m_demos.types[m_demos.count] = FFILE_FOLDER;
+ m_demos.entries[m_demos.count].type = FFILE_FOLDER;
m_demos.count++;
}
-
- fs.FreeFileList( list );
+ fs.FreeList( list );
}
pos = m_demos.count;
@@ -190,20 +157,14 @@ static void Demos_BuildList( const char *path ) {
numFiles = MAX_MENU_DEMOS - m_demos.count;
}
for( i = 0; i < numFiles; i++ ) {
- info = ( fsFileInfo_t * )( list[i] + strlen( list[i] ) + 1 );
- s = Demos_BuildName( path, list[i], info );
- if( s ) {
- m_demos.names[m_demos.count] = s;
- m_demos.types[m_demos.count] = FFILE_DEMO;
- m_demos.count++;
- }
+ Demos_BuildName( path, list[i] );
}
// sort them
qsort( m_demos.names + pos, m_demos.count - pos,
sizeof( m_demos.names[0] ), SortStrcmp );
- fs.FreeFileList( list );
+ fs.FreeList( list );
}
// terminate the list
@@ -213,12 +174,12 @@ static void Demos_BuildList( const char *path ) {
static void Demos_Free( void ) {
int i;
- Demos_FreeInfo();
+ Demos_WriteCache( uis.m_demos_browse );
for( i = 0; i < m_demos.count; i++ ) {
com.Free( m_demos.names[i] );
m_demos.names[i] = NULL;
- m_demos.types[i] = 0;
+ memset( &m_demos.entries[i], 0, sizeof( m_demos.entries[0] ) );
}
m_demos.count = 0;
@@ -264,15 +225,17 @@ static void Demos_LeaveDirectory( void ) {
static int Demos_Action( void ) {
char buffer[MAX_OSPATH];
int length, baseLength;
+ char *s = m_demos.names[m_demos.list.curvalue];
+ demoEntry_t *e = &m_demos.entries[m_demos.list.curvalue];
- switch( m_demos.types[m_demos.list.curvalue] ) {
+ switch( e->type ) {
case FFILE_UP:
Demos_LeaveDirectory();
return QMS_OUT;
case FFILE_FOLDER:
baseLength = strlen( uis.m_demos_browse );
- length = strlen( m_demos.names[m_demos.list.curvalue] );
+ length = strlen( s );
if( baseLength + length > sizeof( uis.m_demos_browse ) - 2 ) {
return QMS_BEEP;
}
@@ -280,8 +243,7 @@ static int Demos_Action( void ) {
uis.m_demos_browse[ baseLength++ ] = '/';
}
- strcpy( uis.m_demos_browse + baseLength,
- m_demos.names[m_demos.list.curvalue] );
+ strcpy( uis.m_demos_browse + baseLength, s );
// rebuild list
Demos_Free();
@@ -290,14 +252,10 @@ static int Demos_Action( void ) {
return QMS_IN;
case FFILE_DEMO:
- if( !m_demos.demo.mapname[0] ) {
- return QMS_BEEP;
- }
Com_sprintf( buffer, sizeof( buffer ), "%s \"%s/%s\"\n",
- m_demos.demo.mvd ? "mvdplay" : "demo",
- uis.m_demos_browse, m_demos.names[m_demos.list.curvalue] );
+ /*m_demos.demo.mvd ? "mvdplay" : */"demo",
+ uis.m_demos_browse, s );
cmd.ExecuteText( EXEC_APPEND, buffer );
- //UI_ForceMenuOff();
return QMS_SILENT;
}
@@ -316,7 +274,11 @@ static int Demos_MenuCallback( int id, int msg, int param ) {
case QM_CHANGE:
switch( id ) {
case ID_LIST:
- Demos_LoadInfo( m_demos.list.curvalue );
+ if( m_demos.entries[m_demos.list.curvalue].type == FFILE_DEMO ) {
+ m_demos.menu.statusbar = "Press Enter to play";
+ } else {
+ m_demos.menu.statusbar = NULL;
+ }
break;
default:
break;
@@ -351,17 +313,12 @@ static int Demos_MenuCallback( int id, int msg, int param ) {
}
static void Demos_MenuInit( void ) {
- int w1, w2;
-
memset( &m_demos, 0, sizeof( m_demos ) );
m_demos.menu.callback = Demos_MenuCallback;
Demos_BuildList( uis.m_demos_browse );
- w1 = ( uis.width - 30 ) * 0.8f;
- w2 = ( uis.width - 30 ) * 0.2f;
-
m_demos.list.generic.type = MTYPE_LIST;
m_demos.list.generic.id = ID_LIST;
m_demos.list.generic.flags = QMF_HASFOCUS;
@@ -374,7 +331,7 @@ static void Demos_MenuInit( void ) {
m_demos.list.drawNames = qtrue;
m_demos.list.numcolumns = 4;
- m_demos.list.columns[0].width = w1 - 180;
+ m_demos.list.columns[0].width = uis.width - 30 - 196;
m_demos.list.columns[0].name = uis.m_demos_browse;
m_demos.list.columns[0].uiFlags = UI_LEFT;
@@ -386,28 +343,13 @@ static void Demos_MenuInit( void ) {
m_demos.list.columns[2].name = "Map";
m_demos.list.columns[2].uiFlags = UI_CENTER;
- m_demos.list.columns[3].width = 80;
+ m_demos.list.columns[3].width = 96;
m_demos.list.columns[3].name = "POV";
m_demos.list.columns[3].uiFlags = UI_CENTER;
- m_demos.playerList.generic.type = MTYPE_LIST;
- m_demos.playerList.generic.flags = QMF_HIDDEN|QMF_DISABLED;
- m_demos.playerList.generic.x = w1 + 20;
- m_demos.playerList.generic.y = 32;
- m_demos.playerList.generic.height = uis.height - 64;
- m_demos.playerList.itemnames = ( const char ** )m_demos.playerNames;
- m_demos.playerList.mlFlags = MLF_HIDE_SCROLLBAR_EMPTY;
- m_demos.playerList.numcolumns = 1;
- m_demos.playerList.drawNames = qtrue;
-
- m_demos.playerList.columns[0].width = w2;
- m_demos.playerList.columns[0].name = "Players";
- m_demos.playerList.columns[0].uiFlags = UI_CENTER;
-
- UI_SetupDefaultBanner( &m_demos.banner, "Demos" );
+ UI_SetupDefaultBanner( &m_demos.banner, "Demo Browser" );
Menu_AddItem( &m_demos.menu, (void *)&m_demos.list );
- Menu_AddItem( &m_demos.menu, (void *)&m_demos.playerList );
Menu_AddItem( &m_demos.menu, (void *)&m_demos.banner );
// move cursor to previous position
diff --git a/source/ui_main.c b/source/ui_main.c
index 59ca1e2..3381cec 100644
--- a/source/ui_main.c
+++ b/source/ui_main.c
@@ -28,13 +28,12 @@ MAIN MENU
=======================================================================
*/
-#define MAIN_ITEMS 5
+#define MAIN_ITEMS 4
static const char names[MAIN_ITEMS][16] = {
- "Multiplayer",
+ "Servers",
"Demos",
"Options",
- "Mods",
"Quit"
};
@@ -66,9 +65,6 @@ static int MainMenu_Callback( int id, int msg, int param ) {
M_Menu_Options_f();
break;
case 3:
- M_Menu_Mods_f();
- break;
- case 4:
M_Menu_Confirm_f( "Quit game? y/n", MainMenu_QuitAction );
break;
}
diff --git a/source/ui_mods.c b/source/ui_mods.c
index 2aced90..a069237 100644
--- a/source/ui_mods.c
+++ b/source/ui_mods.c
@@ -29,104 +29,6 @@ MODS MENU
=======================================================================
*/
-#define ID_LIST 102
-
-#define MAX_LISTED_MODS 32
-
-typedef struct modsMenu_s {
- menuFrameWork_t menu;
- menuList_t list;
- menuStatic_t banner;
- int numMods;
- char *names[MAX_LISTED_MODS+1];
- char *directories[MAX_LISTED_MODS];
- char **modlist;
- int lastClick;
-} modsMenu_t;
-
-static modsMenu_t m_mods;
-
-static int ModsMenu_Callback( int id, int msg, int param ) {
- switch( msg ) {
- case QM_ACTIVATE:
- cvar.Set( "game", m_mods.directories[m_mods.list.curvalue] );
- cmd.ExecuteText( EXEC_APPEND, "fs_restart" );
- UI_ForceMenuOff();
- return QMS_SILENT;
- case QM_DESTROY:
- if( m_mods.modlist ) {
- fs.FreeFileList( m_mods.modlist );
- m_mods.modlist = NULL;
- }
- break;
- default:
- break;
- }
-
- return QMS_NOTHANDLED;
-}
-
-static void ModsMenu_Init( void ) {
- int i;
- char *p;
- char *current;
-
- memset( &m_mods, 0, sizeof( m_mods ) );
-
- m_mods.names[0] = "Quake II";
- m_mods.directories[0] = "";
-
- current = cvar.VariableString( "game" );
-
- if( ( m_mods.modlist = fs.ListFiles( "$modlist", NULL, 0, &m_mods.numMods ) ) != NULL ) {
- if( m_mods.numMods > MAX_LISTED_MODS - 1 ) {
- m_mods.numMods = MAX_LISTED_MODS - 1;
- }
- for( i=0 ; i<m_mods.numMods ; i++ ) {
- m_mods.directories[i + 1] = m_mods.modlist[i];
- if( ( p = strchr( m_mods.modlist[i], '\n' ) ) != NULL ) {
- *p = 0; // TODO: file list should remain read-only...
- m_mods.names[i + 1] = p + 1;
- } else {
- m_mods.names[i + 1] = m_mods.modlist[i];
- }
-
- if( *current && !strcmp( m_mods.modlist[i], current ) ) {
- m_mods.list.curvalue = i + 1;
- }
- }
-
- m_mods.names[i + 1] = NULL;
- }
-
- m_mods.menu.callback = ModsMenu_Callback;
-
- m_mods.list.generic.type = MTYPE_LIST;
- m_mods.list.generic.id = ID_LIST;
- m_mods.list.generic.flags = QMF_HASFOCUS;
- m_mods.list.generic.x = ( uis.glconfig.vidWidth - 300 ) / 2;
- m_mods.list.generic.y = 32;
- m_mods.list.generic.width = 0;
- m_mods.list.generic.height = uis.glconfig.vidHeight - 64;
- m_mods.list.generic.name = NULL;
- m_mods.list.mlFlags = MLF_HIDE_SCROLLBAR_EMPTY;
- m_mods.list.itemnames = ( const char ** )m_mods.names;
- m_mods.list.numcolumns = 1;
- m_mods.list.columns[0].width = 300;
- m_mods.list.columns[0].name = NULL;
- m_mods.list.columns[0].uiFlags = UI_CENTER;
-
- UI_SetupDefaultBanner( &m_mods.banner, "Mods" );
-
- m_mods.menu.statusbar = "Press Enter to load";
-
- Menu_AddItem( &m_mods.menu, (void *)&m_mods.list );
- Menu_AddItem( &m_mods.menu, (void *)&m_mods.banner );
-
-}
-
void M_Menu_Mods_f( void ) {
- ModsMenu_Init();
- UI_PushMenu( &m_mods.menu );
}
diff --git a/source/ui_playermodels.c b/source/ui_playermodels.c
index ac2e589..83f22a7 100644
--- a/source/ui_playermodels.c
+++ b/source/ui_playermodels.c
@@ -93,7 +93,7 @@ void PlayerModel_Load( void ) {
/*
** get a list of directories
*/
- if( !( list = fs.ListFiles( NULL, "players/*/*", FS_SEARCH_BYFILTER|FS_SEARCH_SAVEPATH, &numFiles ) ) ) {
+ if( !( list = ( char ** )fs.ListFiles( NULL, "players/*/*", FS_SEARCH_BYFILTER|FS_SEARCH_SAVEPATH, &numFiles ) ) ) {
return;
}
@@ -119,7 +119,7 @@ void PlayerModel_Load( void ) {
}
}
- fs.FreeFileList( list );
+ fs.FreeList( ( void ** )list );
if( !ndirs ) {
return;
@@ -146,7 +146,7 @@ void PlayerModel_Load( void ) {
// verify the existence of at least one pcx skin
Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], NULL );
- pcxnames = fs.ListFiles( scratch, ".pcx", 0, &npcxfiles );
+ pcxnames = ( char ** )fs.ListFiles( scratch, ".pcx", 0, &npcxfiles );
if( !pcxnames ) {
continue;
}
@@ -161,7 +161,7 @@ void PlayerModel_Load( void ) {
}
if( !nskins ) {
- fs.FreeFileList( pcxnames );
+ fs.FreeList( ( void ** )pcxnames );
continue;
}
@@ -178,11 +178,11 @@ void PlayerModel_Load( void ) {
}
}
- fs.FreeFileList( pcxnames );
+ fs.FreeList( ( void ** )pcxnames );
// load vweap models
Q_concat( scratch, sizeof( scratch ), "players/", dirnames[i], "/w_*.md2", NULL );
- weaponNames = fs.ListFiles( NULL, scratch, FS_SEARCH_BYFILTER, &numWeapons );
+ weaponNames = ( char ** )fs.ListFiles( NULL, scratch, FS_SEARCH_BYFILTER, &numWeapons );
pmi = &uis.pmi[uis.numPlayerModels++];
pmi->numWeapons = 0;
@@ -199,7 +199,7 @@ void PlayerModel_Load( void ) {
}
}
- fs.FreeFileList( weaponNames );
+ fs.FreeList( ( void ** )weaponNames );
}
// at this point we have a valid player model
diff --git a/source/vid_sdl.c b/source/vid_sdl.c
index 34ec7eb..4b51ada 100644
--- a/source/vid_sdl.c
+++ b/source/vid_sdl.c
@@ -93,9 +93,14 @@ success:
}
void Video_ModeChanged( void ) {
+ SDL_Event event;
+
if( !QSDL_SetMode( sdl.surface->flags, sdl.surface->format->BitsPerPixel ) ) {
Com_Error( ERR_FATAL, "Couldn't change video mode: %s", SDL_GetError() );
}
+
+ while( SDL_PollEvent( &event ) )
+ ;
}
static qboolean QSDL_InitVideo( void ) {
@@ -321,6 +326,7 @@ void Video_PumpEvents( void ) {
Cvar_Set( "vid_placement", va( "%dx%d", event.resize.w,
event.resize.h ) );
Video_ModeChanged();
+ return;
}
break;