diff options
-rw-r--r-- | build/q2pro.mk | 11 | ||||
-rwxr-xr-x | configure | 11 | ||||
-rw-r--r-- | source/cl_console.c | 2 | ||||
-rw-r--r-- | source/cl_local.h | 15 | ||||
-rw-r--r-- | source/cl_main.c | 89 | ||||
-rw-r--r-- | source/cl_parse.c | 9 |
6 files changed, 114 insertions, 23 deletions
diff --git a/build/q2pro.mk b/build/q2pro.mk index 8f901c1..ebe2a4d 100644 --- a/build/q2pro.mk +++ b/build/q2pro.mk @@ -40,9 +40,14 @@ SRCFILES+=m_flash.c \ cl_view.c \ cl_console.c \ cl_keys.c \ - cl_aastat.c \ - snd_main.c \ - snd_mem.c + cl_aastat.c + +ifdef USE_CURL +SRCFILES+=cl_http.c +LDFLAGS+=-lcurl +endif + +SRCFILES+=snd_main.c snd_mem.c ifdef USE_SNDDMA SRCFILES+=snd_mix.c snd_dma.c @@ -87,6 +87,7 @@ use_dsound="no" use_dinput="no" use_lirc="no" use_zlib="yes" +use_curl="no" use_tga="yes" use_png="no" use_jpg="no" @@ -164,6 +165,8 @@ for opt do ;; --disable-zlib) use_zlib="no" ;; + --enable-curl) use_curl="yes" + ;; --disable-tga) use_tga="no" ;; --enable-png) use_png="yes" @@ -226,6 +229,7 @@ echo " --enable-dsound enable direct sound driver" echo " --enable-dinput enable direct input driver" echo " --enable-lirc enable LIRC input interface" echo " --disable-zlib disable linking with zlib" +echo " --enable-curl enable linking with libcurl" echo " --disable-tga disable TGA images support" echo " --enable-png enable PNG images support" echo " --enable-jpg enable JPG images support" @@ -419,6 +423,7 @@ if [ "$use_client" = "yes" ]; then if [ "$mingw" = "no" ]; then echo "LIRC support $use_lirc" fi + echo "CURL support $use_curl" if [ "$use_ref" = "gl" ]; then echo "TGA support $use_tga" echo "JPG support $use_jpg" @@ -443,6 +448,7 @@ else use_dsound="no" use_dinput="no" use_lirc="no" + use_curl="no" use_tga="no" use_png="no" use_jpg="no" @@ -638,6 +644,11 @@ if [ "$use_lirc" = "yes" ]; then echo "#define USE_LIRC 1" >> $config_h fi +if [ "$use_curl" = "yes" ]; then + echo "USE_CURL=yes" >> $config_mk + echo "#define USE_CURL 1" >> $config_h +fi + if [ "$use_asm" = "yes" ]; then echo "USE_ASM=yes" >> $config_mk echo "#define USE_ASM 1" >> $config_h diff --git a/source/cl_console.c b/source/cl_console.c index 0410a66..c6ddcdb 100644 --- a/source/cl_console.c +++ b/source/cl_console.c @@ -776,7 +776,7 @@ void Con_DrawSolidConsole( void ) { //ZOID // draw the download bar // figure out width - if( cls.download.file ) { + if( cls.download.name[0] ) { int n, j; if( ( text = strrchr( cls.download.name, '/') ) != NULL ) diff --git a/source/cl_local.h b/source/cl_local.h index 2c79de8..8ba2f9f 100644 --- a/source/cl_local.h +++ b/source/cl_local.h @@ -421,12 +421,12 @@ void CL_Init (void); void CL_Quit_f (void); void CL_Disconnect( error_type_t type, const char *text ); void CL_RequestNextDownload (void); +void CL_ResetPrecacheCheck( void ); void CL_CheckForResend( void ); void CL_ClearState (void); void CL_RestartFilesystem( qboolean total ); void CL_RestartRefresh( qboolean total ); void CL_ClientCommand( const char *string ); -void CL_UpdateLocalFovSetting( void ); void CL_LoadState( load_state_t state ); void CL_SendRcon( const netadr_t *adr, const char *pass, const char *cmd ); const char *CL_Server_g( const char *partial, int argnum, int state ); @@ -758,3 +758,16 @@ void Key_WriteBindings( fileHandle_t f ); // void CL_InitAscii( void ); +#if USE_CURL +// +// cl_http.c +// +void HTTP_CancelDownloads (void); +void HTTP_Init (void); +void HTTP_Shutdown (void); +qboolean HTTP_QueueDownload (const char *path); +void HTTP_RunDownloads (void); +qboolean HTTP_DownloadsPending (void); +void HTTP_SetServer (const char *url); +#endif + diff --git a/source/cl_main.c b/source/cl_main.c index 306c604..faf3b7a 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -656,6 +656,10 @@ void CL_Disconnect( error_type_t type, const char *text ) { cls.netchan = NULL; } +#if USE_CURL + HTTP_CancelDownloads(); +#endif + // stop download if( cls.download.file ) { FS_FCloseFile( cls.download.file ); @@ -1341,6 +1345,11 @@ static void CL_ConnectionlessPacket( void ) { } else if( !strncmp( s, "map=", 4 ) ) { Q_strlcpy( mapname, s + 4, sizeof( mapname ) ); } +#if USE_CURL + else if( !strncmp( s, "dlserver=", 9 ) ) { + HTTP_SetServer( s + 9 ); + } +#endif } Com_Printf( "Connected to %s (protocol %d).\n", @@ -1643,6 +1652,7 @@ static void CL_RegisterModels( void ) { } void CL_LoadState( load_state_t state ) { +#if 0 char *s; switch( state ) { @@ -1667,7 +1677,8 @@ void CL_LoadState( load_state_t state ) { default: return; } - Con_Printf( "\rLoading %s...", s ); + Con_Printf( "\rLoading %s...", s ); +#endif // Com_ProcessEvents(); SCR_UpdateScreen(); @@ -1708,6 +1719,32 @@ void CL_RequestNextDownload ( void ) { } if ( precache_check >= CS_MODELS && precache_check < CS_MODELS + MAX_MODELS ) { if ( allow_download_models->integer ) { + if ( precache_model_skin == -1 ) { + // checking for models + while ( precache_check < CS_MODELS + MAX_MODELS && + cl.configstrings[ precache_check ][ 0 ] ) { + + if ( cl.configstrings[ precache_check ][ 0 ] == '*' || + cl.configstrings[ precache_check ][ 0 ] == '#' ) { + precache_check++; + continue; + } + if ( !CL_CheckOrDownloadFile( cl.configstrings[ precache_check ] ) ) { + precache_check++; + return; // started a download + } + precache_check++; + } + precache_model_skin = 0; + precache_check = CS_MODELS + 2; // 0 isn't used +#if USE_CURL + if( HTTP_DownloadsPending() ) { + //pending downloads (models), let's wait here before we can check skins. + return; + } +#endif + } + // checking for skins while ( precache_check < CS_MODELS + MAX_MODELS && cl.configstrings[ precache_check ][ 0 ] ) { size_t num_skins, ofs_skins, end_skins; @@ -1717,15 +1754,6 @@ void CL_RequestNextDownload ( void ) { precache_check++; continue; } - if ( precache_model_skin == 0 ) { - if ( !CL_CheckOrDownloadFile( cl.configstrings[ precache_check ] ) ) { - precache_model_skin = 1; - return; // started a download - } - precache_model_skin = 1; - } - - // checking for skins in the model if ( !precache_model ) { length = FS_LoadFile ( cl.configstrings[ precache_check ], ( void ** ) & precache_model ); if ( !precache_model ) { @@ -1762,9 +1790,9 @@ void CL_RequestNextDownload ( void ) { num_skins = LittleLong( pheader->num_skins ); ofs_skins = LittleLong( pheader->ofs_skins ); - while ( precache_model_skin - 1 < num_skins ) { + while ( precache_model_skin < num_skins ) { Q_strlcpy( fn, ( char * )precache_model + ofs_skins + - ( precache_model_skin - 1 ) * MD2_MAX_SKINNAME, sizeof( fn ) ); + precache_model_skin * MD2_MAX_SKINNAME, sizeof( fn ) ); if ( !CL_CheckOrDownloadFile( fn ) ) { precache_model_skin++; return; // started a download @@ -1892,6 +1920,13 @@ void CL_RequestNextDownload ( void ) { precache_check = ENV_CNT; } +#if USE_CURL + if( HTTP_DownloadsPending() ) { + //map might still be downloading? + return; + } +#endif + if ( precache_check == ENV_CNT ) { precache_check = ENV_CNT + 1; @@ -1979,6 +2014,15 @@ void CL_RequestNextDownload ( void ) { cls.state = ca_precached; } +void CL_ResetPrecacheCheck( void ) { + precache_check = CS_MODELS; + if( precache_model ) { + FS_FreeFile( precache_model ); + precache_model = NULL; + } + precache_model_skin = -1; +} + /* ================= CL_Precache_f @@ -2013,13 +2057,8 @@ static void CL_Precache_f( void ) { return; } - precache_check = CS_MODELS; precache_spawncount = atoi( Cmd_Argv( 1 ) ); - if( precache_model ) { - FS_FreeFile( precache_model ); - precache_model = NULL; - } - precache_model_skin = 0; + CL_ResetPrecacheCheck(); CL_RequestNextDownload(); @@ -2284,6 +2323,8 @@ void CL_RestartFilesystem( qboolean total ) { return; } + Com_DPrintf( "%s(%d)\n", __func__, total ); + // temporary switch to loading state cls_state = cls.state; if( cls.state >= ca_precached ) { @@ -3008,6 +3049,10 @@ void CL_ProcessEvents( void ) { while( NET_GetPacket( NS_CLIENT ) ) { CL_PacketEvent(); } + +#if USE_CURL + HTTP_RunDownloads(); +#endif } //============================================================================ @@ -3048,6 +3093,10 @@ void CL_Init( void ) { } #endif +#if USE_CURL + HTTP_Init(); +#endif + #if USE_UI UI_OpenMenu( UIMENU_MAIN ); #endif @@ -3114,6 +3163,10 @@ void CL_Shutdown( void ) { inflateEnd( &cls.z ); #endif +#if USE_CURL + HTTP_Shutdown(); +#endif + S_Shutdown(); IN_Shutdown(); Con_Shutdown(); diff --git a/source/cl_parse.c b/source/cl_parse.c index 2a988cf..f37872c 100644 --- a/source/cl_parse.c +++ b/source/cl_parse.c @@ -53,6 +53,15 @@ qboolean CL_CheckOrDownloadFile( const char *path ) { return qtrue; } +#if USE_CURL + if( HTTP_QueueDownload( path ) ) { + //we return true so that the precache check keeps feeding us more files. + //since we have multiple HTTP connections we want to minimize latency + //and be constantly sending requests, not one at a time. + return qtrue; + } +#endif + memcpy( cls.download.name, path, len + 1 ); // download to a temp name, and only rename |