mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 01:52:43 +00:00
Added download estimate time to join panel
This commit is contained in:
parent
d57646ab5f
commit
a216b9c2d9
7 changed files with 82 additions and 21 deletions
|
|
@ -621,7 +621,7 @@ function bhv_ball_loop(obj)
|
|||
end
|
||||
|
||||
-- send out object if we touched it
|
||||
local updateRateSend = (obj.oGlobalOwner == my_global_index() and (get_network_area_timer() - obj.oNetworkTime) > 5)
|
||||
local updateRateSend = (obj.oGlobalOwner == my_global_index() and (get_network_area_timer() - obj.oNetworkTime) > 2)
|
||||
if gBallTouchedLocal or updateRateSend then
|
||||
if gBallTouchedLocal then
|
||||
obj.oGlobalOwner = my_global_index()
|
||||
|
|
|
|||
|
|
@ -9,9 +9,13 @@
|
|||
|
||||
#define DJUI_JOIN_MESSAGE_ELAPSE 60
|
||||
bool gDjuiPanelJoinMessageVisible = false;
|
||||
float gDownloadProgress = 0;
|
||||
float gDownloadProgressInf = 0;
|
||||
char gDownloadEstimate[DOWNLOAD_ESTIMATE_LENGTH] = "";
|
||||
|
||||
static struct DjuiText* sPanelText = NULL;
|
||||
static bool sDisplayingError = false;
|
||||
float gDownloadProgress = 0;
|
||||
|
||||
|
||||
void djui_panel_join_message_error(char* message) {
|
||||
djui_panel_join_message_create(NULL);
|
||||
|
|
@ -33,11 +37,13 @@ void djui_panel_join_message_render_pre(struct DjuiBase* base, UNUSED bool* unus
|
|||
base->tag = (base->tag + 1) % (DJUI_JOIN_MESSAGE_ELAPSE * 3);
|
||||
u16 elapse = (base->tag / DJUI_JOIN_MESSAGE_ELAPSE);
|
||||
if (lastElapse != elapse) {
|
||||
char tmp[DOWNLOAD_ESTIMATE_LENGTH + 4] = "";
|
||||
switch (base->tag / DJUI_JOIN_MESSAGE_ELAPSE) {
|
||||
case 0: djui_text_set_text(text1, "..."); break;
|
||||
case 1: djui_text_set_text(text1, "."); break;
|
||||
default: djui_text_set_text(text1, ".."); break;
|
||||
case 0: snprintf(tmp, DOWNLOAD_ESTIMATE_LENGTH + 4, "%s\n...", gDownloadEstimate); break;
|
||||
case 1: snprintf(tmp, DOWNLOAD_ESTIMATE_LENGTH + 4, "%s\n.", gDownloadEstimate); break;
|
||||
default: snprintf(tmp, DOWNLOAD_ESTIMATE_LENGTH + 4, "%s\n..", gDownloadEstimate); break;
|
||||
}
|
||||
djui_text_set_text(text1, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,23 +54,24 @@ void djui_panel_join_message_create(struct DjuiBase* caller) {
|
|||
// don't recreate panel if it's already visible
|
||||
if (gDjuiPanelJoinMessageVisible) { return; }
|
||||
|
||||
u16 directLines = 8;
|
||||
f32 directTextHeight = 32 * 0.8125f * directLines + 8;
|
||||
|
||||
struct DjuiThreePanel* panel = djui_panel_menu_create(DLANG(JOIN_MESSAGE, JOINING));
|
||||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
struct DjuiText* text1 = djui_text_create(body, "...");
|
||||
snprintf(gDownloadEstimate, 32, " ");
|
||||
struct DjuiText* text1 = djui_text_create(body, "\n...");
|
||||
djui_base_set_size_type(&text1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&text1->base, 1.0f, directTextHeight);
|
||||
djui_base_set_size(&text1->base, 1.0f, 32 * 4);
|
||||
djui_base_set_color(&text1->base, 200, 200, 200, 255);
|
||||
djui_text_set_alignment(text1, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
|
||||
text1->base.tag = 0;
|
||||
text1->base.on_render_pre = djui_panel_join_message_render_pre;
|
||||
sPanelText = text1;
|
||||
|
||||
gDownloadProgressInf = 0;
|
||||
djui_progress_bar_create(body, &gDownloadProgressInf, 0.0f, 1.0f, true);
|
||||
|
||||
gDownloadProgress = 0;
|
||||
djui_progress_bar_create(body, &gDownloadProgress, 0.0f, 1.0f);
|
||||
djui_progress_bar_create(body, &gDownloadProgress, 0.0f, 1.0f, false);
|
||||
|
||||
djui_button_create(body, DLANG(MENU, CANCEL), DJUI_BUTTON_STYLE_BACK, djui_panel_join_message_cancel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
#include "djui.h"
|
||||
|
||||
extern bool gDjuiPanelJoinMessageVisible;
|
||||
extern float gDownloadProgress;
|
||||
extern float gDownloadProgressInf;
|
||||
#define DOWNLOAD_ESTIMATE_LENGTH 32
|
||||
extern char gDownloadEstimate[];
|
||||
|
||||
void djui_panel_join_message_error(char* message);
|
||||
void djui_panel_join_message_create(struct DjuiBase* caller);
|
||||
|
|
|
|||
|
|
@ -3,11 +3,26 @@
|
|||
void djui_progress_bar_render_pre(struct DjuiBase* base, UNUSED bool* unused) {
|
||||
struct DjuiProgressBar* progress = (struct DjuiProgressBar*)base;
|
||||
progress->smoothValue = progress->smoothValue * 0.95f + *progress->value * 0.05f;
|
||||
float min = progress->min;
|
||||
float max = progress->max;
|
||||
float min = progress->min;
|
||||
float max = progress->max;
|
||||
djui_base_set_size(&progress->rectValue->base, ((f32)progress->smoothValue - min) / ((f32)max - min), 1.0f);
|
||||
}
|
||||
|
||||
void djui_progress_bar_render_pre_infinite(struct DjuiBase* base, UNUSED bool* unused) {
|
||||
struct DjuiProgressBar* progress = (struct DjuiProgressBar*)base;
|
||||
float min = progress->min;
|
||||
float max = progress->max;
|
||||
|
||||
progress->smoothValue = progress->smoothValue * 0.95f + *progress->value * 0.05f;
|
||||
float modValue = progress->smoothValue - ((int)progress->smoothValue);
|
||||
float x = (modValue - min - 0.25f) / (max - min - 0.25f);
|
||||
float w = 0.25f;
|
||||
if (x + w > 1.0f) { w = 1.0f - x; }
|
||||
|
||||
djui_base_set_location(&progress->rectValue->base, x, 0);
|
||||
djui_base_set_size(&progress->rectValue->base, w, 1.0f);
|
||||
}
|
||||
|
||||
static void djui_progress_bar_set_default_style(struct DjuiBase* base) {
|
||||
struct DjuiProgressBar* progress = (struct DjuiProgressBar*)base;
|
||||
djui_base_set_border_color(&progress->rect->base, 173, 173, 173, 255);
|
||||
|
|
@ -20,7 +35,7 @@ static void djui_progress_bar_destroy(struct DjuiBase* base) {
|
|||
free(progress);
|
||||
}
|
||||
|
||||
struct DjuiProgressBar* djui_progress_bar_create(struct DjuiBase* parent, float* value, float min, float max) {
|
||||
struct DjuiProgressBar* djui_progress_bar_create(struct DjuiBase* parent, float* value, float min, float max, bool infinite) {
|
||||
struct DjuiProgressBar* progress = calloc(1, sizeof(struct DjuiProgressBar));
|
||||
struct DjuiBase* base = &progress->base;
|
||||
|
||||
|
|
@ -32,7 +47,7 @@ struct DjuiProgressBar* djui_progress_bar_create(struct DjuiBase* parent, float*
|
|||
djui_base_init(parent, base, NULL, djui_progress_bar_destroy);
|
||||
djui_base_set_size_type(base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(base, 1.0f, 16);
|
||||
base->on_render_pre = djui_progress_bar_render_pre;
|
||||
base->on_render_pre = infinite ? djui_progress_bar_render_pre_infinite : djui_progress_bar_render_pre;
|
||||
|
||||
struct DjuiRect* rect = djui_rect_create(&progress->base);
|
||||
djui_base_set_size_type(&rect->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
|
||||
|
|
@ -45,6 +60,11 @@ struct DjuiProgressBar* djui_progress_bar_create(struct DjuiBase* parent, float*
|
|||
djui_base_set_size_type(&rectValue->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
|
||||
progress->rectValue = rectValue;
|
||||
|
||||
if (infinite) {
|
||||
djui_base_set_location_type(&progress->rectValue->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
|
||||
djui_base_set_size_type(&progress->rectValue->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
|
||||
}
|
||||
|
||||
djui_progress_bar_set_default_style(base);
|
||||
|
||||
return progress;
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@ struct DjuiProgressBar {
|
|||
float max;
|
||||
};
|
||||
|
||||
struct DjuiProgressBar* djui_progress_bar_create(struct DjuiBase* parent, float* value, float min, float max);
|
||||
struct DjuiProgressBar* djui_progress_bar_create(struct DjuiBase* parent, float* value, float min, float max, bool infinite);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "pc/djui/djui.h"
|
||||
#include "pc/mods/mods.h"
|
||||
#include "pc/mods/mods_utils.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/djui/djui_panel_join_message.h"
|
||||
//#define DISABLE_MODULE_LOG 1
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
|
|
@ -22,8 +24,9 @@ static struct OffsetGroup sOffsetGroup[2] = { 0 };
|
|||
static bool* sOffsetGroupsCompleted = NULL;
|
||||
static u64 sOffsetGroupCount = 0;
|
||||
|
||||
u64 sTotalDownloadBytes = 0;
|
||||
extern float gDownloadProgress;
|
||||
static u64 sTotalDownloadBytes = 0;
|
||||
static f32 sDownloadStartTime = 0;
|
||||
static u64 sDownloadReceivedBytes = 0;
|
||||
|
||||
static bool network_start_offset_group(struct OffsetGroup* og);
|
||||
static void network_update_offset_groups(void);
|
||||
|
|
@ -32,6 +35,9 @@ static void mark_groups_loaded_from_hash(void);
|
|||
void network_start_download_requests(void) {
|
||||
sTotalDownloadBytes = 0;
|
||||
gDownloadProgress = 0;
|
||||
gDownloadProgressInf = 0;
|
||||
sDownloadStartTime = clock_elapsed();
|
||||
sDownloadReceivedBytes = 0;
|
||||
|
||||
sOffsetGroupCount = (gRemoteMods.size / GROUP_SIZE) + 1;
|
||||
|
||||
|
|
@ -453,7 +459,31 @@ after_poured:;
|
|||
|
||||
// update progress
|
||||
sTotalDownloadBytes += wroteBytes;
|
||||
gDownloadProgress = (float)sTotalDownloadBytes / (float)gRemoteMods.size;
|
||||
gDownloadProgress = (f32)sTotalDownloadBytes / (f32)gRemoteMods.size;
|
||||
gDownloadProgressInf += 0.01f * ((f32)wroteBytes / (f32)CHUNK_SIZE);
|
||||
|
||||
// update speed
|
||||
f32 elapsed = clock_elapsed() - sDownloadStartTime;
|
||||
sDownloadReceivedBytes += wroteBytes;
|
||||
f32 bytesPerSecond = (f32)sDownloadReceivedBytes / elapsed;
|
||||
|
||||
// update estimated time
|
||||
u64 remaining = gRemoteMods.size - sTotalDownloadBytes;
|
||||
if (sTotalDownloadBytes > 0 && remaining > 0) {
|
||||
u32 seconds = (remaining / bytesPerSecond) + 1;
|
||||
u32 minutes = seconds / 60;
|
||||
u32 hours = minutes / 60;
|
||||
|
||||
seconds = seconds % 60;
|
||||
minutes = minutes % 60;
|
||||
if (hours) {
|
||||
snprintf(gDownloadEstimate, DOWNLOAD_ESTIMATE_LENGTH, "%uh %um %us", hours, minutes, seconds);
|
||||
} else if (minutes) {
|
||||
snprintf(gDownloadEstimate, DOWNLOAD_ESTIMATE_LENGTH, "%um %us", minutes, seconds);
|
||||
} else {
|
||||
snprintf(gDownloadEstimate, DOWNLOAD_ESTIMATE_LENGTH, "%us", seconds);
|
||||
}
|
||||
}
|
||||
|
||||
network_update_offset_groups();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ void network_send_ping(struct NetworkPlayer* toNp) {
|
|||
packet_write(&p, ×tamp, sizeof(f64));
|
||||
network_send_to(toNp->localIndex, &p);
|
||||
|
||||
LOG_INFO("tx ping");
|
||||
//LOG_INFO("tx ping");
|
||||
}
|
||||
|
||||
void network_receive_ping(struct Packet* p) {
|
||||
LOG_INFO("rx ping");
|
||||
//LOG_INFO("rx ping");
|
||||
|
||||
u8 globalIndex;
|
||||
f64 timestamp;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue