Move towards using Http_CheckProgress instead of Http_GetCurrent

This commit is contained in:
UnknownShadow200 2020-09-05 16:04:08 +10:00
parent 99fb94bbed
commit ddf7b10d91
4 changed files with 25 additions and 25 deletions

View File

@ -99,7 +99,7 @@ static volatile cc_bool http_terminate;
static struct RequestList pendingReqs; static struct RequestList pendingReqs;
static struct RequestList processedReqs; static struct RequestList processedReqs;
static struct HttpRequest http_curRequest; static struct HttpRequest http_curRequest;
static volatile int http_curProgress = HTTP_PROGRESS_NOTHING; static volatile int http_curProgress = HTTP_PROGRESS_NOT_WORKING_ON;
#ifdef CC_BUILD_WEB #ifdef CC_BUILD_WEB
static void Http_DownloadNextAsync(void); static void Http_DownloadNextAsync(void);
@ -219,7 +219,7 @@ static void Http_FinishRequest(struct HttpRequest* req) {
Mutex_Lock(curRequestMutex); Mutex_Lock(curRequestMutex);
{ {
http_curRequest.id = 0; http_curRequest.id = 0;
http_curProgress = HTTP_PROGRESS_NOTHING; http_curProgress = HTTP_PROGRESS_NOT_WORKING_ON;
} }
Mutex_Unlock(curRequestMutex); Mutex_Unlock(curRequestMutex);
} }
@ -1064,6 +1064,19 @@ cc_bool Http_GetCurrent(struct HttpRequest* request, int* progress) {
return request->id != 0; return request->id != 0;
} }
int Http_CheckProgress(int reqID) {
int curReqID, progress;
Mutex_Lock(curRequestMutex);
{
curReqID = http_curRequest.id;
progress = http_curProgress;
}
Mutex_Unlock(curRequestMutex);
if (reqID != curReqID) progress = HTTP_PROGRESS_NOT_WORKING_ON;
return progress;
}
void Http_ClearPending(void) { void Http_ClearPending(void) {
Mutex_Lock(pendingMutex); Mutex_Lock(pendingMutex);
{ {

View File

@ -14,7 +14,7 @@ extern struct IGameComponent Http_Component;
enum HttpRequestType { REQUEST_TYPE_GET, REQUEST_TYPE_HEAD, REQUEST_TYPE_POST }; enum HttpRequestType { REQUEST_TYPE_GET, REQUEST_TYPE_HEAD, REQUEST_TYPE_POST };
enum HttpProgress { enum HttpProgress {
HTTP_PROGRESS_NOTHING = -3, HTTP_PROGRESS_NOT_WORKING_ON = -3,
HTTP_PROGRESS_MAKING_REQUEST = -2, HTTP_PROGRESS_MAKING_REQUEST = -2,
HTTP_PROGRESS_FETCHING_DATA = -1 HTTP_PROGRESS_FETCHING_DATA = -1
}; };
@ -73,6 +73,10 @@ cc_bool Http_DescribeError(cc_result res, String* dst);
cc_bool Http_GetResult(int reqID, struct HttpRequest* item); cc_bool Http_GetResult(int reqID, struct HttpRequest* item);
/* Retrieves information about the request currently being processed. */ /* Retrieves information about the request currently being processed. */
cc_bool Http_GetCurrent(struct HttpRequest* request, int* progress); cc_bool Http_GetCurrent(struct HttpRequest* request, int* progress);
/* Retrieves information about the download progress of the given request. */
/* NOTE: This may return HTTP_PROGRESS_NOT_WORKING_ON if download has finished. */
/* As such, this method should always be paired with a call to Http_GetResult. */
int Http_CheckProgress(int reqID);
/* Clears the list of pending requests. */ /* Clears the list of pending requests. */
void Http_ClearPending(void); void Http_ClearPending(void);
#endif #endif

View File

@ -1529,11 +1529,7 @@ static void UpdatesScreen_CheckTick(struct UpdatesScreen* s) {
static void UpdatesScreen_UpdateProgress(struct UpdatesScreen* s, struct LWebTask* task) { static void UpdatesScreen_UpdateProgress(struct UpdatesScreen* s, struct LWebTask* task) {
String str; char strBuffer[STRING_SIZE]; String str; char strBuffer[STRING_SIZE];
struct HttpRequest item; int progress = Http_CheckProgress(task->reqID);
int progress;
if (!Http_GetCurrent(&item, &progress)) return;
if (item.id != task->reqID) return;
if (progress == s->buildProgress) return; if (progress == s->buildProgress) return;
s->buildProgress = progress; s->buildProgress = progress;

View File

@ -850,22 +850,9 @@ static void ChatScreen_EnterChatInput(struct ChatScreen* s, cc_bool close) {
} }
static void ChatScreen_UpdateTexpackStatus(struct ChatScreen* s) { static void ChatScreen_UpdateTexpackStatus(struct ChatScreen* s) {
static const String texPack = String_FromConst("texturePack"); int progress = Http_CheckProgress(TexturePack_ReqID);
struct HttpRequest request;
int progress;
cc_bool hasRequest = Http_GetCurrent(&request, &progress);
/* Is terrain/texture pack currently being downloaded? */
if (!hasRequest || request.id != TexturePack_ReqID) {
if (s->status.textures[0].ID) {
Chat_Status[0].length = 0;
TextGroupWidget_Redraw(&s->status, 0);
}
s->lastDownloadStatus = Int32_MinValue;
return;
}
if (progress == s->lastDownloadStatus) return; if (progress == s->lastDownloadStatus) return;
s->lastDownloadStatus = progress; s->lastDownloadStatus = progress;
Chat_Status[0].length = 0; Chat_Status[0].length = 0;
@ -1259,7 +1246,7 @@ static const struct ScreenVTABLE ChatScreen_VTABLE = {
}; };
void ChatScreen_Show(void) { void ChatScreen_Show(void) {
struct ChatScreen* s = &ChatScreen_Instance; struct ChatScreen* s = &ChatScreen_Instance;
s->lastDownloadStatus = Int32_MinValue; s->lastDownloadStatus = HTTP_PROGRESS_NOT_WORKING_ON;
s->VTABLE = &ChatScreen_VTABLE; s->VTABLE = &ChatScreen_VTABLE;
Gui_Chat = s; Gui_Chat = s;