mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Move towards using Http_CheckProgress instead of Http_GetCurrent
This commit is contained in:
parent
99fb94bbed
commit
ddf7b10d91
17
src/Http.c
17
src/Http.c
@ -99,7 +99,7 @@ static volatile cc_bool http_terminate;
|
||||
static struct RequestList pendingReqs;
|
||||
static struct RequestList processedReqs;
|
||||
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
|
||||
static void Http_DownloadNextAsync(void);
|
||||
@ -219,7 +219,7 @@ static void Http_FinishRequest(struct HttpRequest* req) {
|
||||
Mutex_Lock(curRequestMutex);
|
||||
{
|
||||
http_curRequest.id = 0;
|
||||
http_curProgress = HTTP_PROGRESS_NOTHING;
|
||||
http_curProgress = HTTP_PROGRESS_NOT_WORKING_ON;
|
||||
}
|
||||
Mutex_Unlock(curRequestMutex);
|
||||
}
|
||||
@ -1064,6 +1064,19 @@ cc_bool Http_GetCurrent(struct HttpRequest* request, int* progress) {
|
||||
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) {
|
||||
Mutex_Lock(pendingMutex);
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ extern struct IGameComponent Http_Component;
|
||||
|
||||
enum HttpRequestType { REQUEST_TYPE_GET, REQUEST_TYPE_HEAD, REQUEST_TYPE_POST };
|
||||
enum HttpProgress {
|
||||
HTTP_PROGRESS_NOTHING = -3,
|
||||
HTTP_PROGRESS_NOT_WORKING_ON = -3,
|
||||
HTTP_PROGRESS_MAKING_REQUEST = -2,
|
||||
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);
|
||||
/* Retrieves information about the request currently being processed. */
|
||||
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. */
|
||||
void Http_ClearPending(void);
|
||||
#endif
|
||||
|
@ -1529,11 +1529,7 @@ static void UpdatesScreen_CheckTick(struct UpdatesScreen* s) {
|
||||
|
||||
static void UpdatesScreen_UpdateProgress(struct UpdatesScreen* s, struct LWebTask* task) {
|
||||
String str; char strBuffer[STRING_SIZE];
|
||||
struct HttpRequest item;
|
||||
int progress;
|
||||
if (!Http_GetCurrent(&item, &progress)) return;
|
||||
|
||||
if (item.id != task->reqID) return;
|
||||
int progress = Http_CheckProgress(task->reqID);
|
||||
if (progress == s->buildProgress) return;
|
||||
|
||||
s->buildProgress = progress;
|
||||
|
@ -850,22 +850,9 @@ static void ChatScreen_EnterChatInput(struct ChatScreen* s, cc_bool close) {
|
||||
}
|
||||
|
||||
static void ChatScreen_UpdateTexpackStatus(struct ChatScreen* s) {
|
||||
static const String texPack = String_FromConst("texturePack");
|
||||
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;
|
||||
}
|
||||
|
||||
int progress = Http_CheckProgress(TexturePack_ReqID);
|
||||
if (progress == s->lastDownloadStatus) return;
|
||||
|
||||
s->lastDownloadStatus = progress;
|
||||
Chat_Status[0].length = 0;
|
||||
|
||||
@ -1258,8 +1245,8 @@ static const struct ScreenVTABLE ChatScreen_VTABLE = {
|
||||
ChatScreen_Layout, ChatScreen_ContextLost, ChatScreen_ContextRecreated
|
||||
};
|
||||
void ChatScreen_Show(void) {
|
||||
struct ChatScreen* s = &ChatScreen_Instance;
|
||||
s->lastDownloadStatus = Int32_MinValue;
|
||||
struct ChatScreen* s = &ChatScreen_Instance;
|
||||
s->lastDownloadStatus = HTTP_PROGRESS_NOT_WORKING_ON;
|
||||
|
||||
s->VTABLE = &ChatScreen_VTABLE;
|
||||
Gui_Chat = s;
|
||||
|
Loading…
x
Reference in New Issue
Block a user