]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fixed intermission freeze for secondary timer
authorz411 <z411@omaera.org>
Mon, 28 Feb 2022 04:50:02 +0000 (01:50 -0300)
committerz411 <z411@omaera.org>
Mon, 28 Feb 2022 04:50:02 +0000 (01:50 -0300)
qcsrc/client/hud/panel/timer.qc
qcsrc/server/round_handler.qc

index 94028d864f7863a95d50c8e637d8bbe1cc96e9d9..b7f2222fcfe7f9e08706af8145f168151671f3d7 100644 (file)
@@ -48,14 +48,15 @@ void HUD_Timer()
        string timer;
        string subtimer = string_null;
        string subtext = string_null;
-       float timelimit, timeleft, round_timelimit, round_timeleft;
+       float hudtime, timelimit, timeleft;
        int overtimes;
        vector timer_size, subtext_size, subtimer_size;
        vector timer_color = '1 1 1';
        vector subtimer_color = '1 1 1';
        bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
 
-       // Calculate timelimit
+       // Calculate game time and timelimit
+       hudtime = (intermission_time ? intermission_time : time);
        if(warmup_stage)
        {
                timelimit = STAT(WARMUP_TIMELIMIT);
@@ -68,20 +69,19 @@ void HUD_Timer()
        }
 
        // Calculate time left
-       timeleft = timelimit + STAT(GAMESTARTTIME) - time;
+       timeleft = timelimit + STAT(GAMESTARTTIME) - hudtime;
        if (!autocvar_hud_panel_timer_unbound)
                timeleft = bound(0, timeleft, timelimit);
        timeleft = ceil(timeleft);
+       //LOG_INFOF("Hudtime %d - intermission_time %d - timelimit %d - timeleft %d", hudtime, intermission_time, timelimit, timeleft);
 
        // Timer color
        if(!intermission_time && !warmup_stage && timelimit > 0)
                timer_color = HUD_Timer_Color(timeleft);
 
        // Timer text
-       if (intermission_time) {
-               timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME))));
-       } else if (autocvar_hud_panel_timer_increment || timelimit <= 0) {
-               float time_elapsed = floor(time - STAT(GAMESTARTTIME));
+       if (autocvar_hud_panel_timer_increment || timelimit == 0) {
+               float time_elapsed = floor(hudtime - STAT(GAMESTARTTIME));
                if (!autocvar_hud_panel_timer_unbound)
                        time_elapsed = max(0, time_elapsed);
 
@@ -93,29 +93,36 @@ void HUD_Timer()
        // Round-based game modes
        if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
        {
-               round_timelimit = STAT(ROUND_TIMELIMIT);
+               if(STAT(ROUNDSTARTTIME) == -1) {
+                       // Round can't start
+                       subtimer = "--:--";
+                       subtimer_color = '1 0 0';
+               } else {
+                       float round_hudtime, round_timelimit, round_timeleft;
 
-               // Calculate round time left
-               round_timeleft = round_timelimit + STAT(ROUNDSTARTTIME) - (game_stopped_time ? game_stopped_time : time);
-               if (!autocvar_hud_panel_timer_unbound)
-                       round_timeleft = bound(0, round_timeleft, round_timelimit);
-               round_timeleft = ceil(round_timeleft);
-
-               // Subtimer color
-               if(!intermission_time && round_timelimit > 0)
-                       subtimer_color = HUD_Timer_Color(round_timeleft);
-
-               // Subtimer text
-               if (intermission_time) {
-                       subtimer = seconds_tostring(max(0, floor(intermission_time - STAT(ROUNDSTARTTIME))));
-               } else if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) {
-                       float round_time_elapsed = floor((game_stopped_time ? game_stopped_time : time) - STAT(ROUNDSTARTTIME));
-                       if (!autocvar_hud_panel_timer_unbound)
-                               round_time_elapsed = max(0, round_time_elapsed);
+                       round_hudtime = (game_stopped_time ? game_stopped_time : time);
+                       round_timelimit = STAT(ROUND_TIMELIMIT);
 
-                       subtimer = seconds_tostring(round_time_elapsed);
-               } else {
-                       subtimer = seconds_tostring(round_timeleft);
+                       // Calculate round time left
+                       round_timeleft = round_timelimit + STAT(ROUNDSTARTTIME) - round_hudtime;
+                       if (!autocvar_hud_panel_timer_unbound)
+                               round_timeleft = bound(0, round_timeleft, round_timelimit);
+                       round_timeleft = ceil(round_timeleft);
+
+                       // Subtimer color
+                       if(!intermission_time && round_timelimit > 0)
+                               subtimer_color = HUD_Timer_Color(round_timeleft);
+
+                       // Subtimer text
+                       if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) {
+                               float round_time_elapsed = floor(round_hudtime - STAT(ROUNDSTARTTIME));
+                               if (!autocvar_hud_panel_timer_unbound)
+                                       round_time_elapsed = max(0, round_time_elapsed);
+
+                               subtimer = seconds_tostring(round_time_elapsed);
+                       } else {
+                               subtimer = seconds_tostring(round_timeleft);
+                       }
                }
        }
 
index fa68211f9e8fd442c42dc0875505a819fa5943f1..b63883dcc828e4b932a984d6bd8d959455610100 100644 (file)
@@ -50,6 +50,7 @@ void round_handler_Think(entity this)
                else
                {
                        round_handler_Reset(0);
+                       round_starttime = -1; // can't start
                }
                this.nextthink = time + 1;  // canRoundStart every second
        }
@@ -112,7 +113,8 @@ void round_handler_Reset(float next_think)
        if (this.count)
                if (this.cnt < this.count + 1) this.cnt = this.count + 1;
        this.nextthink = next_think;
-       round_starttime = (next_think) ? (next_think + this.count) : -1;
+       if (next_think)
+               round_starttime = next_think + this.count;
 }
 
 void round_handler_Remove()