1
0
Fork 0

Change: Switch various window timers to real time instead of game ticks.

pull/7036/head
Peter Nelson 2018-05-10 21:49:52 +01:00 committed by PeterN
parent 15320a37b9
commit ead9c9eab5
2 changed files with 35 additions and 29 deletions

View File

@ -1473,10 +1473,6 @@ void GameLoop()
IncreaseSpriteLRU(); IncreaseSpriteLRU();
InteractiveRandom(); InteractiveRandom();
extern int _caret_timer;
_caret_timer += 3;
CursorTick();
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
/* Check for UDP stuff */ /* Check for UDP stuff */
if (_network_available) NetworkBackgroundLoop(); if (_network_available) NetworkBackgroundLoop();
@ -1493,13 +1489,6 @@ void GameLoop()
/* Singleplayer */ /* Singleplayer */
StateGameLoop(); StateGameLoop();
} }
/* Check chat messages roughly once a second. */
static uint check_message = 0;
if (++check_message > 1000 / MILLISECONDS_PER_TICK) {
check_message = 0;
NetworkChatMessageLoop();
}
#else #else
StateGameLoop(); StateGameLoop();
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -37,6 +37,7 @@
#include "game/game.hpp" #include "game/game.hpp"
#include "video/video_driver.hpp" #include "video/video_driver.hpp"
#include "framerate_type.h" #include "framerate_type.h"
#include "network/network_func.h"
#include "safeguards.h" #include "safeguards.h"
@ -1919,6 +1920,8 @@ void ResetWindowSystem()
static void DecreaseWindowCounters() static void DecreaseWindowCounters()
{ {
if (_scroller_click_timeout != 0) _scroller_click_timeout--;
Window *w; Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) { FOR_ALL_WINDOWS_FROM_FRONT(w) {
if (_scroller_click_timeout == 0) { if (_scroller_click_timeout == 0) {
@ -3046,7 +3049,6 @@ void InputLoop()
assert(HasModalProgress() || IsLocalCompany()); assert(HasModalProgress() || IsLocalCompany());
CheckSoftLimit(); CheckSoftLimit();
HandleKeyScrolling();
/* Do the actual free of the deleted windows. */ /* Do the actual free of the deleted windows. */
for (Window *v = _z_front_window; v != NULL; /* nothing */) { for (Window *v = _z_front_window; v != NULL; /* nothing */) {
@ -3059,9 +3061,6 @@ void InputLoop()
free(w); free(w);
} }
if (_scroller_click_timeout != 0) _scroller_click_timeout--;
DecreaseWindowCounters();
if (_input_events_this_tick != 0) { if (_input_events_this_tick != 0) {
/* The input loop is called only once per GameLoop() - so we can clear the counter here */ /* The input loop is called only once per GameLoop() - so we can clear the counter here */
_input_events_this_tick = 0; _input_events_this_tick = 0;
@ -3071,7 +3070,6 @@ void InputLoop()
/* HandleMouseEvents was already called for this tick */ /* HandleMouseEvents was already called for this tick */
HandleMouseEvents(); HandleMouseEvents();
HandleAutoscroll();
} }
/** /**
@ -3101,11 +3099,30 @@ void UpdateWindows()
CallWindowRealtimeTickEvent(delta_ms); CallWindowRealtimeTickEvent(delta_ms);
static int network_message_timer = 1;
if (TimerElapsed(network_message_timer, delta_ms)) {
network_message_timer = 1000;
NetworkChatMessageLoop();
}
Window *w; Window *w;
static int window_timer = 1;
if (TimerElapsed(window_timer, delta_ms)) {
window_timer = MILLISECONDS_PER_TICK;
extern int _caret_timer;
_caret_timer += 3;
CursorTick();
HandleKeyScrolling();
HandleAutoscroll();
DecreaseWindowCounters();
}
static int highlight_timer = 1; static int highlight_timer = 1;
if (--highlight_timer == 0) { if (TimerElapsed(highlight_timer, delta_ms)) {
highlight_timer = 15; highlight_timer = 450;
_window_highlight_colour = !_window_highlight_colour; _window_highlight_colour = !_window_highlight_colour;
} }
@ -3118,25 +3135,25 @@ void UpdateWindows()
* But still empty the invalidation queues above. */ * But still empty the invalidation queues above. */
if (_network_dedicated) return; if (_network_dedicated) return;
static int we4_timer = 0; static int hundredth_timer = 1;
int t = we4_timer + 1; if (TimerElapsed(hundredth_timer, delta_ms)) {
hundredth_timer = 3000; // Historical reason: 100 * MILLISECONDS_PER_TICK
if (t >= 100) {
FOR_ALL_WINDOWS_FROM_FRONT(w) { FOR_ALL_WINDOWS_FROM_FRONT(w) {
w->OnHundredthTick(); w->OnHundredthTick();
} }
t = 0;
} }
we4_timer = t;
FOR_ALL_WINDOWS_FROM_FRONT(w) { if (window_timer == MILLISECONDS_PER_TICK) { // window_timer has elapsed this call
if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) { FOR_ALL_WINDOWS_FROM_FRONT(w) {
CLRBITS(w->flags, WF_WHITE_BORDER); if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) {
w->SetDirty(); CLRBITS(w->flags, WF_WHITE_BORDER);
w->SetDirty();
}
} }
}
DrawDirtyBlocks(); DrawDirtyBlocks();
}
FOR_ALL_WINDOWS_FROM_BACK(w) { FOR_ALL_WINDOWS_FROM_BACK(w) {
/* Update viewport only if window is not shaded. */ /* Update viewport only if window is not shaded. */