changeset 7018:a05bbdc788a2 draft

(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on -Codechange: renamed _timer_counter to _palette_animation_counter, as that is what it is
author truelight <truelight@openttd.org>
date Fri, 22 Jun 2007 20:04:21 +0000
parents 4b0010087f79
children 4dd485dafed0
files src/genworld_gui.cpp src/gfx.cpp src/misc.cpp src/openttd.cpp src/variables.h src/video/cocoa_v.mm src/video/sdl_v.cpp src/video/win32_v.cpp src/window.cpp
diffstat 9 files changed, 26 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -875,14 +875,12 @@
 		_tp.percent = percent_table[cls];
 	}
 
-	/* Don't update the screen too often. So update it once in every 200ms.
-	 * However, the _tick_counter increases by 8 every 30ms, so compensate
-	 * for that. */
-	if (!_network_dedicated && _tp.timer != 0 && _timer_counter - _tp.timer < (200 * 8 / 30)) return;
+	/* Don't update the screen too often. So update it once in every 200ms */
+	if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < 200) return;
 
 	/* Percentage is about the number of completed tasks, so 'current - 1' */
 	_tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
-	_tp.timer = _timer_counter;
+	_tp.timer = _realtime_tick;
 
 	if (_network_dedicated) {
 		static uint last_percent = 0;
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -665,8 +665,8 @@
 	_pal_count_dirty = 255;
 }
 
-#define EXTR(p, q) (((uint16)(_timer_counter * (p)) * (q)) >> 16)
-#define EXTR2(p, q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16)
+#define EXTR(p, q) (((uint16)(_palette_animation_counter * (p)) * (q)) >> 16)
+#define EXTR2(p, q) (((uint16)(~_palette_animation_counter * (p)) * (q)) >> 16)
 
 void DoPaletteAnimations()
 {
@@ -681,10 +681,10 @@
 	Colour old_val[38];
 	uint i;
 	uint j;
-	uint old_tc = _timer_counter;
+	uint old_tc = _palette_animation_counter;
 
 	if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
-		_timer_counter = 0;
+		_palette_animation_counter = 0;
 	}
 
 	d = &_cur_palette[217];
@@ -727,7 +727,7 @@
 
 	/* Radio tower blinking */
 	{
-		byte i = (_timer_counter >> 1) & 0x7F;
+		byte i = (_palette_animation_counter >> 1) & 0x7F;
 		byte v;
 
 		(v = 255, i < 0x3f) ||
@@ -779,7 +779,7 @@
 	}
 
 	if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
-		_timer_counter = old_tc;
+		_palette_animation_counter = old_tc;
 	} else {
 		if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) {
 			_pal_first_dirty = 217;
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -110,6 +110,7 @@
 	_pause_game = 0;
 	_fast_forward = 0;
 	_tick_counter = 0;
+	_realtime_tick = 0;
 	_date_fract = 0;
 	_cur_tileloop_tile = 0;
 
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1099,7 +1099,7 @@
 	}
 
 	_caret_timer += 3;
-	_timer_counter += 8;
+	_palette_animation_counter += 8;
 	CursorTick();
 
 #ifdef ENABLE_NETWORK
--- a/src/variables.h
+++ b/src/variables.h
@@ -270,10 +270,11 @@
 VARDEF Cheats _cheats;
 
 /* NOSAVE: Used in palette animations only, not really important. */
-VARDEF int _timer_counter;
+VARDEF int _palette_animation_counter;
 
 
 VARDEF uint32 _frame_counter;
+VARDEF uint32 _realtime_tick;
 
 VARDEF bool _is_old_ai_player; // current player is an oldAI player? (enables a lot of cheats..)
 
--- a/src/video/cocoa_v.mm
+++ b/src/video/cocoa_v.mm
@@ -685,6 +685,7 @@
 static void QZ_GameLoop()
 {
 	uint32 cur_ticks = GetTick();
+	uint32 last_cur_ticks = cur_ticks;
 	uint32 next_tick = cur_ticks + 30;
 	uint32 pal_tick = 0;
 #ifdef _DEBUG
@@ -731,6 +732,8 @@
 		}
 
 		cur_ticks = GetTick();
+		_realtime_tick += cur_ticks - last_cur_ticks;
+		last_cur_ticks = cur_ticks;
 		if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
 			next_tick = cur_ticks + 30;
 
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -442,6 +442,7 @@
 static void SdlVideoMainLoop()
 {
 	uint32 cur_ticks = SDL_CALL SDL_GetTicks();
+	uint32 last_cur_ticks = cur_ticks;
 	uint32 next_tick = cur_ticks + 30;
 	uint32 pal_tick = 0;
 	uint32 mod;
@@ -471,6 +472,8 @@
 		}
 
 		cur_ticks = SDL_CALL SDL_GetTicks();
+		_realtime_tick += cur_ticks - last_cur_ticks;
+		last_cur_ticks = cur_ticks;
 		if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
 			next_tick = cur_ticks + 30;
 
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -795,6 +795,7 @@
 {
 	MSG mesg;
 	uint32 cur_ticks = GetTickCount();
+	uint32 last_cur_ticks = cur_ticks;
 	uint32 next_tick = cur_ticks + 30;
 
 	_wnd.running = true;
@@ -822,6 +823,8 @@
 		}
 
 		cur_ticks = GetTickCount();
+		_realtime_tick += cur_ticks - last_cur_ticks;
+		last_cur_ticks = cur_ticks;
 		if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
 			next_tick = cur_ticks + 30;
 			_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1639,8 +1639,8 @@
 	MC_RIGHT,
 	MC_DOUBLE_LEFT,
 
-	MAX_OFFSET_DOUBLE_CLICK = 5,
-	TIME_BETWEEN_DOUBLE_CLICK = 50,
+	MAX_OFFSET_DOUBLE_CLICK = 5,     ///< How much the mouse is allowed to move to call it a double click
+	TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
 };
 
 void MouseLoop(MouseClick click, int mousewheel)
@@ -1759,12 +1759,12 @@
 	click = MC_NONE;
 	if (_left_button_down && !_left_button_clicked) {
 		click = MC_LEFT;
-		if (double_click_time != 0 && _tick_counter - double_click_time   < TIME_BETWEEN_DOUBLE_CLICK &&
+		if (double_click_time != 0 && _realtime_tick - double_click_time   < TIME_BETWEEN_DOUBLE_CLICK &&
 			  double_click_x != 0    && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK  &&
 			  double_click_y != 0    && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) {
 			click = MC_DOUBLE_LEFT;
 		}
-		double_click_time = _tick_counter;
+		double_click_time = _realtime_tick;
 		double_click_x = _cursor.pos.x;
 		double_click_y = _cursor.pos.y;
 		_left_button_clicked = true;