]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix lightmap loading from TGAs; fix display of QC-initiated downloads
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 13 Sep 2008 09:15:36 +0000 (09:15 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 13 Sep 2008 09:15:36 +0000 (09:15 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8505 d7cf8633-e32d-0410-b094-e92efae38249

libcurl.c
libcurl.h
model_brush.c

index bfbc1f13151c333fbe7196720db602667f0d6b4b..f97946fe1bd2b365c1fe399d429837574eab03dc 100644 (file)
--- a/libcurl.c
+++ b/libcurl.c
@@ -400,6 +400,38 @@ typedef enum
 }
 CurlStatus;
 
+static void curl_default_callback(int status, size_t length_received, unsigned char *buffer, void *cbdata)
+{
+       downloadinfo *di = (downloadinfo *) cbdata;
+       switch(status)
+       {
+               case CURLCBSTATUS_OK:
+                       Con_Printf("Download of %s: OK\n", di->filename);
+                       break;
+               case CURLCBSTATUS_FAILED:
+                       Con_Printf("Download of %s: FAILED\n", di->filename);
+                       break;
+               case CURLCBSTATUS_ABORTED:
+                       Con_Printf("Download of %s: ABORTED\n", di->filename);
+                       break;
+               case CURLCBSTATUS_SERVERERROR:
+                       Con_Printf("Download of %s: (unknown server error)\n", di->filename);
+                       break;
+               case CURLCBSTATUS_UNKNOWN:
+                       Con_Printf("Download of %s: (unknown client error)\n", di->filename);
+                       break;
+               default:
+                       Con_Printf("Download of %s: %d\n", di->filename, status);
+                       break;
+       }
+}
+
+static void curl_quiet_callback(int status, size_t length_received, unsigned char *buffer, void *cbdata)
+{
+       if(developer.integer)
+               curl_default_callback(status, length_received, buffer, cbdata);
+}
+
 /*
 ====================
 Curl_EndDownload
@@ -417,29 +449,16 @@ static void Curl_EndDownload(downloadinfo *di, CurlStatus status, CURLcode error
        switch(status)
        {
                case CURL_DOWNLOAD_SUCCESS:
-                       Con_Printf("Download of %s: OK\n", di->filename);
                        ok = true;
-
-                       if(di->callback)
-                               di->callback(CURLCBSTATUS_OK, di->bytes_received, di->buffer, di->callback_data);
+                       di->callback(CURLCBSTATUS_OK, di->bytes_received, di->buffer, di->callback_data);
                        break;
                case CURL_DOWNLOAD_FAILED:
-                       Con_Printf("Download of %s: FAILED\n", di->filename);
-                       if(error)
-                               Con_Printf("Reason given by libcurl: %s\n", qcurl_easy_strerror(error));
-
-                       if(di->callback)
-                               di->callback(CURLCBSTATUS_FAILED, di->bytes_received, di->buffer, di->callback_data);
+                       di->callback(CURLCBSTATUS_FAILED, di->bytes_received, di->buffer, di->callback_data);
                        break;
                case CURL_DOWNLOAD_ABORTED:
-                       Con_Printf("Download of %s: ABORTED\n", di->filename);
-
-                       if(di->callback)
-                               di->callback(CURLCBSTATUS_ABORTED, di->bytes_received, di->buffer, di->callback_data);
+                       di->callback(CURLCBSTATUS_ABORTED, di->bytes_received, di->buffer, di->callback_data);
                        break;
                case CURL_DOWNLOAD_SERVERERROR:
-                       Con_Printf("Download of %s: %d\n", di->filename, (int) error);
-
                        // reopen to enforce it to have zero bytes again
                        if(di->stream)
                        {
@@ -451,8 +470,6 @@ static void Curl_EndDownload(downloadinfo *di, CurlStatus status, CURLcode error
                                di->callback(error ? (int) error : CURLCBSTATUS_SERVERERROR, di->bytes_received, di->buffer, di->callback_data);
                        break;
                default:
-                       Con_Printf("Download of %s: ???\n", di->filename);
-
                        if(di->callback)
                                di->callback(CURLCBSTATUS_UNKNOWN, di->bytes_received, di->buffer, di->callback_data);
                        break;
@@ -514,10 +531,10 @@ static void CheckPendingDownloads()
                {
                        if(!di->started)
                        {
-                               Con_Printf("Downloading %s -> %s", di->url, di->filename);
-
                                if(!di->buffer)
                                {
+                                       Con_Printf("Downloading %s -> %s", di->url, di->filename);
+
                                        di->stream = FS_OpenRealFile(di->filename, "ab", false);
                                        if(!di->stream)
                                        {
@@ -527,16 +544,17 @@ static void CheckPendingDownloads()
                                        }
                                        FS_Seek(di->stream, 0, SEEK_END);
                                        di->startpos = FS_Tell(di->stream);
+
+                                       if(di->startpos > 0)
+                                               Con_Printf(", resuming from position %ld", (long) di->startpos);
+                                       Con_Print("...\n");
                                }
                                else
                                {
+                                       Con_DPrintf("Downloading %s -> memory\n", di->url);
                                        di->startpos = 0;
                                }
 
-                               if(di->startpos > 0)
-                                       Con_Printf(", resuming from position %ld", (long) di->startpos);
-                               Con_Print("...\n");
-
                                di->curle = qcurl_easy_init();
                                qcurl_easy_setopt(di->curle, CURLOPT_URL, di->url);
                                qcurl_easy_setopt(di->curle, CURLOPT_USERAGENT, engineversion);
@@ -611,6 +629,24 @@ static downloadinfo *Curl_Find(const char *filename)
        return NULL;
 }
 
+void Curl_Cancel_ToMemory(curl_callback_t callback, void *cbdata)
+{
+       downloadinfo *di;
+       if(!curl_dll)
+               return;
+       for(di = downloads; di; )
+       {
+               if(di->callback == callback && di->callback_data == cbdata)
+               {
+                       di->callback = curl_quiet_callback; // do NOT call the callback
+                       Curl_EndDownload(di, CURL_DOWNLOAD_ABORTED, CURLE_OK);
+                       di = downloads;
+               }
+               else
+                       di = di->next;
+       }
+}
+
 /*
 ====================
 Curl_Begin
@@ -764,8 +800,16 @@ static qboolean Curl_Begin(const char *URL, const char *name, qboolean ispak, qb
 
                di->buffer = buf;
                di->buffersize = bufsize;
-               di->callback = callback;
-               di->callback_data = cbdata;
+               if(callback == NULL)
+               {
+                       di->callback = curl_default_callback;
+                       di->callback_data = di;
+               }
+               else
+               {
+                       di->callback = callback;
+                       di->callback_data = cbdata;
+               }
 
                downloads = di;
                return true;
@@ -1176,7 +1220,7 @@ array must be freed later using Z_Free.
 */
 Curl_downloadinfo_t *Curl_GetDownloadInfo(int *nDownloads, const char **additional_info)
 {
-       int n, i;
+       int i;
        downloadinfo *di;
        Curl_downloadinfo_t *downinfo;
        static char addinfo[128];
@@ -1189,14 +1233,18 @@ Curl_downloadinfo_t *Curl_GetDownloadInfo(int *nDownloads, const char **addition
                return NULL;
        }
 
-       n = 0;
+       i = 0;
        for(di = downloads; di; di = di->next)
-               ++n;
+               ++i;
 
-       downinfo = (Curl_downloadinfo_t *) Z_Malloc(sizeof(*downinfo) * n);
+       downinfo = (Curl_downloadinfo_t *) Z_Malloc(sizeof(*downinfo) * i);
        i = 0;
        for(di = downloads; di; di = di->next)
        {
+               // do not show infobars for background downloads
+               if(!developer.integer)
+                       if(di->buffer)
+                               continue;
                strlcpy(downinfo[i].filename, di->filename, sizeof(downinfo[i].filename));
                if(di->curle)
                {
@@ -1228,7 +1276,7 @@ Curl_downloadinfo_t *Curl_GetDownloadInfo(int *nDownloads, const char **addition
                        *additional_info = NULL;
        }
 
-       *nDownloads = n;
+       *nDownloads = i;
        return downinfo;
 }
 
index 5b861278f4a5763dd892714ebd5fe090ebcf0f2d..f8de728e34a2e7fd059bf0ad6039fd011fdff454 100644 (file)
--- a/libcurl.h
+++ b/libcurl.h
@@ -14,6 +14,8 @@ qboolean Curl_Running();
 qboolean Curl_Begin_ToFile(const char *URL, const char *name, qboolean ispak, qboolean forthismap);
 qboolean Curl_Begin_ToMemory(const char *URL, unsigned char *buf, size_t bufsize, curl_callback_t callback, void *cbdata);
        // NOTE: if it returns false, the callback will NOT get called, so free your buffer then!
+void Curl_Cancel_ToMemory(curl_callback_t callback, void *cbdata);
+       // removes all downloads with the given callback and cbdata (this does NOT call the callbacks!)
 void Curl_Init();
 void Curl_Init_Commands();
 void Curl_Shutdown();
index 2aea6f858bcacc886f9d3382eef556cc056c0a5e..024f2a85c8c33219a6cb6ec40dcd91a0410af750 100644 (file)
@@ -4518,13 +4518,13 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
                if (l->filelen % sizeof(*input_pointer))
                        Host_Error("Mod_Q3BSP_LoadLightmaps: funny lump size in %s",loadmodel->name);
                count = l->filelen / sizeof(*input_pointer);
-               loadmodel->brushq3.num_originallightmaps = count;
                for(i = 0; i < count; ++i)
                        inpixels[i] = input_pointer[i].rgb;
        }
 
        convertedpixels = Mem_Alloc(tempmempool, size*size*4); // TODO free this
        loadmodel->brushq3.lightmapsize = size;
+       loadmodel->brushq3.num_originallightmaps = count;
 
        // now check the surfaces to see if any of them index an odd numbered
        // lightmap, if so this is not a deluxemapped bsp file